synergycodes/ng-diagram/ng-diagram-linking
Claude Code and agent skill by synergycodes/ng-diagram
- community
Checking that the SKILL.md file is still in the repository.
Use when users draw ng-diagram edges between ports - validateConnection, finalEdgeDataBuilder, edgeDrawEnded, floating edges without ports, startLinking from a button, cancelling a draw, or drawn edges ignoring the custom edge type.
Install
npx vskill@latest install synergycodes/ng-diagram/ng-diagram-linkingSKILL.md
Linking (user-drawn edges)
How users draw new edges: port rules, connection validation, edge data builders, draw events, drawing from code, cancelling, and floating edges. Moving the ends of existing edges is in ng-diagram-edge-relinking, free ends in ng-diagram-dangling-edges, ports in ng-diagram-ports, touch details in ng-diagram-touch.
Rules
- A draw starts with a press on an
<ng-diagram-port>and ends on a port withinlinking.portSnapDistanceof the pointer. Porttype:'source'only starts edges,'target'only receives them,'both'does both. A press on a'target'port starts nothing. - Links between two different ports of the same node are allowed. Block self-links in
validateConnectionif you do not want them. - A drawn edge is built from the last preview edge (the
temporaryEdgeDataBuilderoutput) plus the drop target, and then goes throughfinalEdgeDataBuilder. Always return{ ...edge, ... }. Settype,routing,dataandrelinkableinfinalEdgeDataBuilder. The default preview hastargetArrowhead: 'ng-diagram-arrow', so drawn edges have it too; settargetArrowhead: undefinedto remove it. - Type the callbacks through
Partial<LinkingConfig>(or annotate their parameters). Inside an object typedNgDiagramConfig(also the argument ofupdateConfig),validateConnectionand the two builders get no parameter types: understrictthat is error TS7006 (implicitany), and a wrong signature is not caught. validateConnection(source, sourcePort, target, targetPort, context): the four node and port arguments can benull—sourcePort/targetPortfor floating ends, and since 1.4.0source/targetfor a free (dangling) end or a draw started withstartLinkingFromPosition. The optionalcontext(since 1.4.0) hasreason: 'draw' | 'relink' | 'attach', plusedge/endfor relink and attach. The validator runs while the pointer is over a port the edge could snap to (afalsekeeps the preview loose) and again on drop, so keep it fast and free of side effects. It is not called for a drop on empty canvas (a kept dangling edge); filter those withdanglingEdges.shouldKeepOnDrop.(edgeDrawEnded)(since 1.2.0) fires once per draw, whatever the outcome (except when the source node is deleted during the draw, see Edge cases). Branch onsuccessandtarget.sourceis optional since 1.4.0, so readevent.source?.id.(edgeDrawn)is deprecated.- Cancel a draw with
NgDiagramService.cancelActiveInteraction()(since 1.3.0) or Escape. Escape reaches the diagram only while focus is inside<ng-diagram>, so a toolbar outside it must handle Escape itself (recipe below). There is nostopLinkingmethod.
Validate connections and shape drawn edges
linking option | Default | Effect | |
|---|---|---|---|
portSnapDistance | 10 | Distance from the port's box at which the preview snaps. Flow units, so the on-screen distance changes with zoom (the TSDoc says pixels). | |
selectNodeOnPortPress | true | Pressing a port also selects its node (since 1.2.0). | |
edgePanningEnabled / edgePanningThreshold / edgePanningForce | true / 30 / 10 | Pan the viewport while the pointer is within the threshold (px) of the diagram edge. Needs viewportPanningEnabled. | |
validateConnection | allows all | See Rules. | |
temporaryEdgeDataBuilder / finalEdgeDataBuilder | return the edge unchanged | See Rules. | |
defaultRelinkable | false | Relink handles (since 1.4.0), see ng-diagram-edge-relinking. |
React to finished draws
reason | When | |
|---|---|---|
noTarget | Released away from a port the edge can take (also over a port with the wrong direction), and no dangling edge was kept. | |
invalidConnection | validateConnection returned false on drop. | |
invalidTarget | The snapped target became invalid (deleted, hidden, wrong port type). | |
cancelled (since 1.3.0) | Escape, cancelActiveInteraction(), a second touch gesture, a lost pointer (since 1.4.0), or the source node became hidden before a drop on a port. |
Start a draw from a button (toolbar, touch UI)
The next click connects when it lands on a port the edge can take; anywhere else the draw ends with noTarget, or keeps a dangling edge when that feature is on. Refused calls log [ngDiagram] startLinking ignored: another linking or relinking gesture is in progress. or [ngDiagram] startLinking ignored: source node "<id>" is missing or effectively hidden. A 'target' port, a hidden port or a port id that the node does not render is refused without a message ('port-right' exists only on the default node). To start from a point on the canvas instead of a node, use startLinkingFromPosition (ng-diagram-dangling-edges).
Floating edges (no ports)
A floating end belongs to a node but not to a port: it sits on the node border and moves with the node. One end can float while the other uses a port, with any routing. A dangling end is different: it has no node at all (source: ''), see ng-diagram-dangling-edges.
Edge cases
temporaryEdgeDataBuilderruns on every pointer move of a draw. It also builds relink previews, which arrive with the relinked edge'stype,routing,dataand arrowheads, so do not overwrite those blindly (seeedge.routing ?? 'bezier'above).- A port refused by
validateConnectionis never snapped to, so a drop on it usually ends withnoTarget.invalidConnectionappears when the validator says no on drop after saying yes during the drag. - Only ports of nodes whose box (
positionandsize) is withinportSnapDistanceof the pointer can snap. A port that sticks out of the node further than that does not snap over its outer part. - Touch, draws started from a port: a two-finger pan or pinch cancels them (
cancelled, since 1.3.0), and so does apointercancelsuch as palm rejection (since 1.4.0). A draw started withstartLinkingignores a second finger; the first finger lift ends it (ng-diagram-touch). - When the source node becomes hidden during a draw, no edge is created. When it is deleted, a draw started from a port is cancelled and no
edgeDrawEndedfires. A draw started withstartLinkingkeeps running, so cancel it before you delete its source node. edgeDrawn(deprecated) fires only for node-to-node edges, never for kept dangling edges.- Ports hidden with the port
hiddeninput cannot start or receive links, and the preview does not snap to them. - The
[config]binding is read only when the diagram engine is created. Change linking options later withNgDiagramService.updateConfig({ linking: this.linking }), passing aPartial<LinkingConfig>object so the callbacks keep their types.
Symptom → fix
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-linking/SKILL.md
Popularity
- Repository stars
- 583
- Repository forks
- 41
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. 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-linking)