synergycodes/ng-diagram/ng-diagram-auto-layout
Claude Code and agent skill by synergycodes/ng-diagram
- community
Checking that the SKILL.md file is still in the repository.
Use when arranging ng-diagram nodes automatically with ELK.js, dagre or another layout engine - trees, org charts, layered flows, applying computed positions and edge points, re-layout after edits, or nodes piled up at (0, 0).
Install
npx vskill@latest install synergycodes/ng-diagram/ng-diagram-auto-layoutSKILL.md
Auto layout (ELK.js and other engines)
ng-diagram has no built-in automatic layout: a layout library computes positions, and you write them back with the model service. This skill gives a complete ELK.js recipe based on the docs examples "Layout Integration" (https://www.ngdiagram.dev/docs/examples/layout-integration/) and "Expand/Collapse Subtree" (https://www.ngdiagram.dev/docs/examples/expand-collapse/). Routing modes in detail are in ng-diagram-edge-routing, hiding in ng-diagram-visibility, fitting in ng-diagram-viewport.
npm install elkjs (the docs examples use elkjs 0.10).
Rules
- Lay out measured nodes. Run the first layout in
(diagramInit): rendered nodes have their realsizethen. For nodes you add later,await addNodes(nodes, { waitForMeasurements: true })first (option since 1.3.0). A node withoutsizegoes into the layout as 0 × 0 and ends up overlapping others. - Read the input with
modelService.getModel().getNodes()/getEdges(). They are fresh right after anawait; thenodes()/edges()signals can still show the previous state there and inside event handlers. - Lay out what is visible: nodes with
!node.computedHidden(since 1.4.0) and the edges whose both ends are among them (this also drops dangling edges, whose free end is''). Hidden nodes keep their old positions. With groups, lay out top-level nodes only and move each group's content with it (see Edge cases). - Write the result in one commit (
transactionwithupdateNodesandupdateEdges) andawaitit. Never re-create the model to apply a layout: that re-initializes and re-measures the whole diagram. - Choose who draws the edges. Positions only: edges stay
routingMode: 'auto'and ng-diagram routes them. Engine routes: setroutingMode: 'manual'with the engine'spoints. Manual edges keep their points through every node change (drag, resize, content that changes size, your ownupdateNodes), so switch the connected edges back to'auto'after such changes (selectionMovedcovers drags, arrow keys andmoveNodesBy; alsonodeResized), or run the layout again. Keep'auto'when the engine returned no route: a manual edge without points draws nothing. - Fit after the layout:
awaitthe commit, thenawait zoomToFit().zoom.zoomToFit.onInitruns as soon as yourdiagramInithandler starts, before an async layout ends. - Hide the canvas until the first layout is done with
visibility: hiddenon a wrapper. Do not usedisplay: none: elements then measure 0 × 0, those measurements are ignored, and the layout gets no sizes.
Layered layout with edge routes (perform-layout.ts)
ELK returns top-left positions, the same as node.position, and absolute edge points for this flat graph. The points are drawn by the edge's routing (the default orthogonal, as in the docs example). For positions only, skip the port mapping and the edge results and leave the edges alone.
Apply, re-run, release (layout.service.ts)
Wire it in the component that provides provideNgDiagram() and LayoutService:
<ng-diagram> fills its parent, so the wrapper needs a size. edgeDrawEnded exists since 1.2.0. selectionMoved fires for user drags and moveNodesBy, not for updateNodes, so the layout does not trigger it.
Trees, org charts and other engines
- Trees: use ELK
mrtree, lay out positions only (edges stay'auto'), and pin the root to its old place so the tree does not jump on every re-layout. For expand/collapse, lay out the tree as it will look after the toggle, then commit thehiddenflags and the positions in one transaction. Both recipes:references/tree-layout.md. - Other engines (dagre, d3-hierarchy, your own): input = node ids with
size.width/size.heightplussource → targetpairs; output = a top-left{ x, y }per node, written with oneupdateNodescall. If the engine returns node centers, subtract half the size; edge bend points becomepointswithroutingMode: 'manual', as above.
Edge cases
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/ng-diagram-auto-layout/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/synergycodes/ng-diagram/ng-diagram-auto-layout)