Skip to content

feat: auto-layout (Arrange) — tidy a bound diagram into a clean flow - #118

Open
Amark19 wants to merge 1 commit into
masterfrom
feat/auto-layout
Open

feat: auto-layout (Arrange) — tidy a bound diagram into a clean flow#118
Amark19 wants to merge 1 commit into
masterfrom
feat/auto-layout

Conversation

@Amark19

@Amark19 Amark19 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

What changed

Adds auto-layout — the foundation for the AI-diagram track, and useful on its own.

  • utils/autoLayout.js: reads the canvas as a graph (bindable shapes = nodes, arrows bound at both ends = edges), lays it out with dagre (the Sugiyama layout mermaid uses), then moves shapes to their computed spots and re-routes their arrows — all in one undo step. Unconnected shapes are left alone; the result is re-centred where the diagram already was.
  • Toolbar "Arrange" action (lucide Network icon, next to Delete-canvas) runs it.

Why

Manual box-placement is the biggest tax in drawing diagrams, and auto-layout is the prerequisite for everything downstream (mermaid import, prompt→diagram). layoutGraph is a pure function, so the coming IR→canvas render reuses it directly.

Notes

  • dep: @dagrejs/dagre@3.1.1 — no engines floor, so the Cloudflare Pages build is safe.
  • setupTests.js polyfills structuredClone (dagre uses it; jsdom lacks it — it exists at runtime in modern browsers).

Test plan

  • New autoLayout.test.js: null on empty/edgeless graphs, A→B→C descends into ranks, centroid preserved, rankdir: LR flows left-to-right. 93 tests pass; lint + prettier clean.
  • Verified in-browser: a crisscrossed 4-node bound diagram tidies into a clean top-to-bottom flow (A → B/C → D) with arrows re-routed and glued.

🤖 Generated with Claude Code

Add utils/autoLayout.js: read the canvas as a graph (bindable shapes = nodes,
both-ends-bound arrows = edges), lay it out with dagre (Sugiyama, the layout
mermaid uses), move shapes to their new spots and re-route arrows in one undo
step. Toolbar 'Arrange' action (Network icon) runs it; unconnected shapes are
left in place, and the result is re-centred where the diagram already was.

This is also the layout the future IR->canvas render will reuse.

- dep: @dagrejs/dagre@3.1.1 (no engines floor → Cloudflare-safe)
- setupTests: polyfill structuredClone (dagre uses it; jsdom lacks it)
- tests: layoutGraph ranks/centre/rankdir

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying whiteboard with  Cloudflare Pages  Cloudflare Pages

Latest commit: f7ada22
Status: ✅  Deploy successful!
Preview URL: https://445f0514.whiteboard-988.pages.dev
Branch Preview URL: https://feat-auto-layout.whiteboard-988.pages.dev

View logs

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.

1 participant