← 返回
未分类 中文

Diagrams

Generate visual flow diagrams, architecture diagrams, and system maps as SVG/PNG. Use when the user asks for flowcharts, user flow diagrams, architecture dia...
生成流程图、架构图和系统图,输出SVG/PNG格式。适用于用户请求流程图、用户流程图、架构图等可视化需求。
brennerspear brennerspear 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 267
下载
💾 3
安装
1
版本
#latest

概述

Diagrams

Generate diagrams from structured JSON → SVG (and optionally PNG).

Quick Start

  1. Install elkjs in the target directory (if not already present):

```bash

cd /docs/diagrams && npm init -y && npm install elkjs

# Set "type": "module" in package.json

```

  1. Write ELK JSON files describing the diagram (see schema below)
  1. Render:

```bash

# Single file

node /scripts/render-elk.mjs diagram.json output.svg

# Batch: all .json files in a folder → svg/ subfolder

node /scripts/render-elk.mjs --dir

# Batch + PNG (macOS only, uses sips)

node /scripts/render-elk.mjs --dir --png

```

  1. Embed in markdown:

```markdown

!Diagram Title

```

ELK JSON Schema

{
  "id": "root",
  "title": "Diagram Title (rendered as heading)",
  "layoutOptions": {
    "elk.algorithm": "layered",
    "elk.direction": "DOWN",
    "elk.spacing.nodeNode": "30",
    "elk.layered.spacing.nodeNodeBetweenLayers": "40",
    "elk.padding": "[top=40,left=20,bottom=20,right=20]"
  },
  "children": [
    {
      "id": "node1",
      "width": 220,
      "height": 45,
      "labels": [{"text": "Node label for ELK layout"}],
      "label": "📦 Display label (rendered in SVG)",
      "color": "core",
      "subtitle": "Optional second line"
    }
  ],
  "edges": [
    {
      "id": "e1",
      "sources": ["node1"],
      "targets": ["node2"],
      "labels": [{"text": "Yes", "width": 25, "height": 14}],
      "edgeColor": "#10B981",
      "dashed": true
    }
  ]
}

Node Properties

PropertyTypeDescription
-----------------------------
idstringRequired. Unique identifier
widthnumberNode width in px (default 120)
heightnumberNode height in px (default 40)
labelsarray[{text}] — used by ELK for layout calculation
labelstringDisplay text rendered in SVG (supports emoji). Falls back to id
colorstringColor key from palette (see below)
subtitlestringSmaller text below the label
fontSizenumberLabel font size (default 13)
childrenarrayNested nodes — makes this a container
containerColorstringColor key for container background

Edge Properties

PropertyTypeDescription
-----------------------------
idstringRequired. Unique identifier
sourcesstring[]Source node id(s)
targetsstring[]Target node id(s)
labelsarray[{text, width, height}] — edge labels
edgeColorstringHex color (default #64748B)
dashedbooleanDashed line style
strokeWidthnumberLine thickness (default 1.5)

Color Palette

8 semantic colors. Every node maps to one. A legend auto-renders at the bottom of each SVG.

KeyColorMeaningUse For
------------------------------
action🔵 BlueSystem actionSteps the app performs — API calls, DB writes, cron triggers
external🟢 TealExternal serviceThird-party APIs — Google, Twilio, Stripe, Resend
decision🩷 PinkDecision pointYes/no branches, if/else, conditional checks
user🟠 OrangeUser actionThings the user does — clicks, inputs, reviews
success🟢 GreenPositive outcomeDone, confirmed, created, visible
negative🔴 RedNegative outcomeCanceled, error, failed, not built
neutral⚫ GrayNeutral / infoStarting points, labels, inactive, informational
data🟡 AmberData / artifactRecords, drafts, outputs, intermediate data

Set "legend": false on the root graph to hide the auto-legend.

Layout Options

Common layoutOptions values:

  • elk.direction: DOWN (default), RIGHT, LEFT, UP
  • elk.algorithm: layered (default, best for flowcharts), force, stress
  • elk.spacing.nodeNode: Space between sibling nodes (px)
  • elk.layered.spacing.nodeNodeBetweenLayers: Space between layers (px)
  • elk.padding: [top=N,left=N,bottom=N,right=N]

Design Tips

  • Sizing: 200-280px wide for most nodes. 45px tall for single-line, 55px for two-line labels.
  • Decision nodes: Use context (pink) color for yes/no branching.
  • Edge labels: Keep short (Yes/No/Error). Set width/height for proper positioning.
  • Containers: Add children array to a node. Use containerColor: "step" for a light blue group.
  • Manual trips vs automated: Use dashed: true on edges for alternative/optional paths.
  • Title: Set title on the root graph for a rendered heading above the diagram.
  • Emoji in labels: Supported and encouraged for visual scanning.

Gotchas

  • Container layout: ELK's layered algorithm with nested containers in RIGHT direction can produce overlapping layouts. Prefer DOWN for containers, or flatten to a non-container layout if horizontal.
  • labels vs label: labels (array) is what ELK uses for layout spacing. label (string) is what gets rendered in the SVG. Always set both — labels[0].text should approximate the display label length for correct sizing.
  • package.json must have "type": "module" for the ESM import to work.
  • elkjs must be installed locally in the directory where you run the script. It's not global.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-05-12 05:44 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

knowledge-management

Research

brennerspear
对主题进行开放式研究,构建动态 Markdown 文档。支持交互式和深度研究模式。
★ 0 📥 5,145
design-media

UI/UX Pro Max

xobi667
提供 UI/UX 设计智能与实现指导,帮助打造精美界面。适用于 UI 设计、UX 流程、信息架构、视觉风格、设计系统/标记、组件规格、文案/微文案、无障碍及前端 UI(HTML/CSS/JS、React、Next.js、Vue、Svelte
★ 231 📥 49,198
design-media

Openai Whisper

steipete
使用 Whisper CLI 进行本地语音转文字(无需 API 密钥)
★ 335 📥 94,886