Skip to content

feat(layout): hierarchical auto-layout for draw.io diagrams#378

Merged
raifdmueller merged 1 commit into
mainfrom
302-auto-layout-in-drawio
May 26, 2026
Merged

feat(layout): hierarchical auto-layout for draw.io diagrams#378
raifdmueller merged 1 commit into
mainfrom
302-auto-layout-in-drawio

Conversation

@paulefl
Copy link
Copy Markdown
Collaborator

@paulefl paulefl commented May 7, 2026

Summary

Adds hierarchical layout engine for automatic element positioning in draw.io diagrams.

Changes:

  • internal/layout/: Core layout computation
    • Hierarchical layout via longest-path algorithm
    • Layer assignment based on relationship direction
    • Cycle detection and handling
    • Pin mechanism for preserving manual positioning
  • cmd/bausteinsicht/layout: CLI command
    • Usage: bausteinsicht layout [--rank-dir TB|LR] [--preserve-pinned]
    • Auto-detects model and diagram files
  • Tests: 6 tests covering layer assignment, cycles, edge cases

Features:

  • ✅ Hierarchical layout (longest-path algorithm)
  • ✅ Top-to-bottom (TB) and left-to-right (LR) ranking
  • ✅ Cycle handling (no infinite recursion)
  • ✅ Pin mechanism (preserves manually positioned elements)
  • ⏳ Force-directed layout (future)
  • ⏳ Radial layout (future)

Fixes #302

🤖 Generated with Claude Code

Copy link
Copy Markdown
Collaborator

@raifdmueller raifdmueller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

Clean hierarchical layout algorithm with pinned element preservation and directional support. Isolated internal/layout package, good test coverage. Touches root.go — sequential merge needed.

Implements layout engine for automatic element positioning in draw.io diagrams.

Changes:
- internal/layout/types.go: Layout algorithm types and configuration
- internal/layout/hierarchical.go: Hierarchical layout via longest-path algorithm
  - Layers elements based on outgoing relationships
  - Supports top-to-bottom (TB) and left-to-right (LR) ranking
  - Detects cycles and handles disconnected components
- internal/layout/apply.go: Apply computed positions to draw.io XML
  - Respects pinned elements (bausteinsicht-pinned=true property)
  - Updates mxGeometry coordinates
- internal/layout/hierarchical_test.go: 6 comprehensive tests
  - Layer assignment validation
  - Cycle handling (no infinite recursion)
  - RankDir variations
  - Edge cases (empty model, single element)
- cmd/bausteinsicht/layout.go: CLI command
  - Usage: bausteinsicht layout [--rank-dir TB|LR] [--preserve-pinned]
  - Auto-detects model and diagram files
  - Reports applied layout

Implementation Status:
- ✅ Hierarchical layout (longest-path algorithm)
- ⏳ Force-directed layout (future)
- ⏳ Radial layout (future)

Fixes #302

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
@raifdmueller raifdmueller force-pushed the 302-auto-layout-in-drawio branch from fcdec4e to 4b28e29 Compare May 26, 2026 19:52
@raifdmueller raifdmueller merged commit 44bea26 into main May 26, 2026
@github-actions
Copy link
Copy Markdown

📊 Test Report (Multi-OS)

Metric 🐧 Linux 🪟 Windows 🍎 macOS
Total Tests 783 783 783
✅ Passed 780 (99.6%) 780 (99.6%) 780 (99.6%)
❌ Failed 0 0 0
⏱️ Duration 7.19s 11.58s 7.20s
📦 Coverage 69.8% 69.7% 69.8%

💡 Full report: Download artifacts from this workflow run.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Auto-Layout in draw.io

2 participants