synergycodes/ng-diagram/ng-diagram-export
Claude Code and agent skill by synergycodes/ng-diagram
- community
Checking that the SKILL.md file is still in the repository.
Use when exporting an ng-diagram as an image (PNG, JPEG or SVG with html-to-image) or as a JSON file, choosing the export region, or fixing cropped, offset, blank or incomplete image exports.
Install
npx vskill@latest install synergycodes/ng-diagram/ng-diagram-exportSKILL.md
Export: images and JSON
Image export captures the rendered DOM with html-to-image, like the docs "Download Image" example (https://www.ngdiagram.dev/docs/examples/download-image/). JSON export is toJSON(); saving and loading in depth is in ng-diagram-persistence, viewport math in ng-diagram-viewport.
npm install html-to-image (the docs example uses 1.11.11).
Rules
- Capture
ng-diagram-canvas, the element inside<ng-diagram>that holds the nodes and edges, and replace its pan/zoom transform withtranslate(-x, -y) scale(1), where(x, y)is the top-left corner of the region you export. Then the image does not depend on the current pan and zoom. - Get the region from
computePartsBounds(nodes, edges)plus a margin. It uses the measured bounds (ports, rotation, edge points, edge labels) and skips hidden elements (since 1.4.0). Pass both lists, so edges and their labels count too. (Before 1.4.0 an empty list, or an edge without points, stretched the result to include(0, 0).) - The image is a copy of the DOM: export after
diagramInit,awaityour changes, and wait until the DOM shows them (waitForRenderbelow). Until the first change detection after init the canvas hasvisibility: hidden, so a capture made right then is blank. - The canvas is transparent: pass
backgroundColor.<ng-diagram>paints--ngd-diagram-background-color; read it withgetComputedStyle. The dot or grid background is a sibling of the canvas and is not in the image. - Set
pixelRatioyourself; the default is the screen'sdevicePixelRatio, so files differ between screens. html-to-image scales a canvas wider or taller than 16384 px down (unlessskipAutoScale), but it does not check the area: browsers limit it too (iOS: 4096 × 4096 px), and a bigger canvas stays blank. The service below lowers the ratio for big diagrams. - With virtualization only the elements near the viewport are in the DOM, so a DOM capture misses the rest. Build the file from the model data instead, or turn virtualization off for the export (it needs a model re-init, see
ng-diagram-performance).
Export service
The docs example computes the box from node position + size and uses translate(Math.abs(left), Math.abs(top)). That is correct only while the box starts at negative coordinates; for content placed at positive coordinates use -x/-y as above.
Wiring, selection, JSON
model is a signal(initializeModel()) bound as <ng-diagram [model]="model()" />.
What you see, with the background
Capturing <ng-diagram> itself gives the current view, including the dot or grid background and the watermark. Fit first and wait for the DOM:
The resolution is limited to the element size times pixelRatio, and the user's view changes. zoomToFit() is disabled under virtualization.
Vector and CAD files
toSvg wraps the copied HTML in an SVG <foreignObject>. Browsers show it, but it is not a clean vector drawing. For editable SVG or DXF, generate the file from the model: node position, size and angle, edge points, and your data. The official templates show complete exporters:
- Electric Circuit: SVG built from the model, JPEG capture, JSON — https://github.com/synergycodes/ng-diagram-electric-circuit
- AV Schematic: PNG capture, DXF from the model — https://github.com/synergycodes/ng-diagram-av-schematic
- Assembly Line: PNG and SVG captures (with the edge-stroke fix and SVG style pruning), DXF from the model — https://github.com/synergycodes/ng-diagram-assembly-line
Edge cases
- Hidden elements: their
display: noneis copied, so they are not in the image, andcomputePartsBoundsleaves them out. - Edges styled through CSS variables: the base edge sets
stroke,stroke-width,stroke-dasharrayandstroke-opacityas SVG attributes that holdvar(...). The service copies the computed values to inline styles during the capture and restores them after (inlineEdgeStrokes); the Assembly Line template does the same to keep edge colors and dashes in its exports. - Fonts: html-to-image embeds web fonts by reading the page's font CSS. Cross-origin font stylesheets can fail with CORS errors;
skipFonts: trueskips embedding (check the text afterwards) andfontEmbedCSSlets you pass the CSS yourself. - Images in node templates are fetched and inlined. A failed fetch (no CORS headers, 404) logs a console warning and leaves the image empty;
imagePlaceholdersets a replacement andcacheBust: trueavoids stale cached copies.
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-export/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-export)