@achmadya-dev/mcp-diagram 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +191 -0
- package/README.md +172 -0
- package/dist/assets/shape-search/search-index.json +83954 -0
- package/dist/assets/shared/create-diagram-intro.md +52 -0
- package/dist/assets/shared/mermaid-reference.md +473 -0
- package/dist/assets/shared/xml-reference.md +479 -0
- package/dist/assets/vendor/app/libavoid/LICENSE +505 -0
- package/dist/assets/vendor/app/libavoid/libavoid.min.js +22 -0
- package/dist/assets/vendor/app/libavoid/libavoid.wasm +0 -0
- package/dist/drawio/drawio.d.ts +27 -0
- package/dist/drawio/drawio.d.ts.map +1 -0
- package/dist/drawio/drawio.js +77 -0
- package/dist/drawio/drawio.js.map +1 -0
- package/dist/drawio/utils.d.ts +29 -0
- package/dist/drawio/utils.d.ts.map +1 -0
- package/dist/drawio/utils.js +419 -0
- package/dist/drawio/utils.js.map +1 -0
- package/dist/drawio/viewer/html.d.ts +59 -0
- package/dist/drawio/viewer/html.d.ts.map +1 -0
- package/dist/drawio/viewer/html.js +6528 -0
- package/dist/drawio/viewer/html.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +94 -0
- package/dist/index.js.map +1 -0
- package/dist/scripts/copy-assets.d.ts +3 -0
- package/dist/scripts/copy-assets.d.ts.map +1 -0
- package/dist/scripts/copy-assets.js +28 -0
- package/dist/scripts/copy-assets.js.map +1 -0
- package/dist/scripts/generate-shape-index.d.ts +15 -0
- package/dist/scripts/generate-shape-index.d.ts.map +1 -0
- package/dist/scripts/generate-shape-index.js +347 -0
- package/dist/scripts/generate-shape-index.js.map +1 -0
- package/dist/tools/search_shapes.d.ts +2 -0
- package/dist/tools/search_shapes.d.ts.map +1 -0
- package/dist/tools/search_shapes.js +34 -0
- package/dist/tools/search_shapes.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1,479 @@
|
|
|
1
|
+
# draw.io XML Reference
|
|
2
|
+
|
|
3
|
+
Detailed reference for styles, edge routing, containers, layers, tags, metadata, and dark mode. Consult this when generating draw.io XML diagrams.
|
|
4
|
+
|
|
5
|
+
## Reasoning budget (read this first)
|
|
6
|
+
|
|
7
|
+
Your job is to declare the **logical structure** of the diagram — what nodes exist, what edges connect them, what labels they carry, what lane/container groups them. draw.io's edge router and (when available) a post-layout pass handle routing and placement; you do **not** need to do layout math.
|
|
8
|
+
|
|
9
|
+
**Do NOT** in your reasoning:
|
|
10
|
+
|
|
11
|
+
- Do NOT debate the topic. The user asked for a flowchart / architecture / sequence / etc. — pick one concrete scenario on your first impulse and commit. Never write "Actually, let me think of something else…" or pitch alternatives.
|
|
12
|
+
- Do NOT debate flat-lanes vs nested-pools, horizontal vs vertical orientation, one vs multiple variations. Pick the first reasonable option (almost always: flat swimlanes, top-down or left-right based on what fits the content). Do not flip-flop.
|
|
13
|
+
- Do NOT compute x/y coordinates in prose. No "column spacings of 160px totaling 1840px width — that's too wide, let me tighten to 1700…" loops. Use the rigid grid below; do the arithmetic in your head and write the XML.
|
|
14
|
+
- Do NOT re-derive drawio mechanics (`horizontal=0`, `startSize=110`, nested-lane coordinates). Use the templates below as-is.
|
|
15
|
+
- Do NOT enumerate columns ("customer lane columns 0-10, web app 1-7"). Place a node, move on.
|
|
16
|
+
- Do NOT add `<Array as="points">` waypoints. Edges are routed automatically.
|
|
17
|
+
- Do NOT set `exitX` / `exitY` / `entryX` / `entryY` connection-point overrides unless you have specific geometric intent.
|
|
18
|
+
- Do NOT verify, re-check, or adjust coordinates after placing a node.
|
|
19
|
+
- Do NOT narrate "building the diagram / finalizing the XML / now let me…". Just emit XML.
|
|
20
|
+
- Do NOT write out lists of node positions as planning text. Emit them as `<mxCell>` elements directly.
|
|
21
|
+
|
|
22
|
+
**Do** in your reasoning:
|
|
23
|
+
|
|
24
|
+
- Identify the diagram type + actors/stages (1-2 short sentences).
|
|
25
|
+
- Identify any grouping (swimlanes? containers? none?).
|
|
26
|
+
- Go straight to XML.
|
|
27
|
+
|
|
28
|
+
**Rigid grid — use for every XML diagram:**
|
|
29
|
+
|
|
30
|
+
- Column x = `col_index * 180 + 40` (col 0 = 40, col 1 = 220, col 2 = 400, …)
|
|
31
|
+
- Row y = `row_index * 120 + 40` (row 0 = 40, row 1 = 160, row 2 = 280, …)
|
|
32
|
+
- Node size: rectangles `140×60`, diamonds `140×80`, circles `60×60`, documents `120×80`, cylinders `100×70`
|
|
33
|
+
|
|
34
|
+
Pick a `(col, row)` for each node. Don't think about centers, gaps, or overlap — ELK handles routing between rough positions. Slight misalignment is invisible in the result.
|
|
35
|
+
|
|
36
|
+
## General principles
|
|
37
|
+
|
|
38
|
+
- **Use proper draw.io shapes and connectors** — choose the semantically correct shape for each element (e.g., `shape=cylinder3` for databases and tanks, `rhombus` for decisions, `shape=mxgraph.pid2valves.*` for valves in P&IDs). draw.io has extensive shape libraries; prefer domain-appropriate shapes over generic rectangles.
|
|
39
|
+
- **Decide whether to search for shapes** — before generating a diagram, decide if it needs domain-specific shapes from draw.io's extended libraries. **Skip `search_shapes`** for standard diagram types that use basic geometric shapes: flowcharts, UML (class, sequence, state, activity), ERD, org charts, mind maps, Venn diagrams, timelines, wireframes, and any diagram using only rectangles, diamonds, circles, cylinders, and arrows. Also skip if the user explicitly asks to use basic/simple shapes or says not to search. **Use `search_shapes`** when the diagram requires industry-specific or branded icons: cloud architecture (AWS, Azure, GCP), network topology (Cisco, rack equipment), P&ID (valves, instruments, vessels), electrical/circuit diagrams, Kubernetes, BPMN with specific task types, or any domain where the user expects realistic/standardized symbols rather than labeled boxes.
|
|
40
|
+
- **Match the language of labels to the user's language** — if the user writes in German, French, Japanese, etc., all diagram labels, titles, and annotations should be in that same language.
|
|
41
|
+
- **Group related nodes, and surface a hub when edges converge** — put nodes that belong together inside a container or swimlane, and keep external actors (users, files, third-party systems) outside implementation containers. When many edges converge on one area or cross several groups, route them through a single hub/gateway node (a registry, broker, event log, …) instead of drawing every low-level dependency across the canvas — fewer crossings, clearer contract.
|
|
42
|
+
- **Encode secondary detail in node text, not edges** — draw an edge only when the relationship itself carries meaning; push incidental detail into the node label so the connector layer stays readable.
|
|
43
|
+
|
|
44
|
+
## Common styles
|
|
45
|
+
|
|
46
|
+
**Rounded rectangle:**
|
|
47
|
+
```xml
|
|
48
|
+
<mxCell id="2" value="Label" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
|
49
|
+
<mxGeometry x="100" y="100" width="120" height="60" as="geometry"/>
|
|
50
|
+
</mxCell>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
**Diamond (decision):**
|
|
54
|
+
```xml
|
|
55
|
+
<mxCell id="3" value="Condition?" style="rhombus;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
|
56
|
+
<mxGeometry x="100" y="200" width="120" height="80" as="geometry"/>
|
|
57
|
+
</mxCell>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
**Arrow (edge):**
|
|
61
|
+
```xml
|
|
62
|
+
<mxCell id="4" value="" style="edgeStyle=orthogonalEdgeStyle;html=1;" edge="1" source="2" target="3" parent="1">
|
|
63
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
64
|
+
</mxCell>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
**Labeled arrow:**
|
|
68
|
+
```xml
|
|
69
|
+
<mxCell id="5" value="Yes" style="edgeStyle=orthogonalEdgeStyle;html=1;" edge="1" source="3" target="6" parent="1">
|
|
70
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
71
|
+
</mxCell>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## Style properties
|
|
75
|
+
|
|
76
|
+
| Property | Values | Use for |
|
|
77
|
+
|----------|--------|---------|
|
|
78
|
+
| `rounded=1` | 0 or 1 | Rounded corners |
|
|
79
|
+
| `whiteSpace=wrap` | wrap | Text wrapping |
|
|
80
|
+
| `fillColor=#dae8fc` | Hex color | Background color |
|
|
81
|
+
| `strokeColor=#6c8ebf` | Hex color | Border color |
|
|
82
|
+
| `fontColor=#333333` | Hex color | Text color |
|
|
83
|
+
| `shape=cylinder3` | shape name | Database cylinders |
|
|
84
|
+
| `shape=mxgraph.flowchart.document` | shape name | Document shapes |
|
|
85
|
+
| `ellipse` | style keyword | Circles/ovals |
|
|
86
|
+
| `rhombus` | style keyword | Diamonds |
|
|
87
|
+
| `edgeStyle=orthogonalEdgeStyle` | style keyword | Right-angle connectors |
|
|
88
|
+
| `edgeStyle=elbowEdgeStyle` | style keyword | Elbow connectors |
|
|
89
|
+
| `dashed=1` | 0 or 1 | Dashed lines |
|
|
90
|
+
| `swimlane` | style keyword | Swimlane containers |
|
|
91
|
+
| `group` | style keyword | Invisible container (pointerEvents=0) |
|
|
92
|
+
| `container=1` | 0 or 1 | Enable container behavior on any shape |
|
|
93
|
+
| `pointerEvents=0` | 0 or 1 | Prevent container from capturing child connections |
|
|
94
|
+
| `html=1` | 0 or 1 | Enable HTML rendering in labels (required for `<b>`, `<br>`, `<font>`, etc.) |
|
|
95
|
+
| `shape=umlLifeline;perimeter=lifelinePerimeter;size=16` | shape | UML sequence diagram lifeline (size = header height) |
|
|
96
|
+
|
|
97
|
+
## HTML labels
|
|
98
|
+
|
|
99
|
+
**Always include `html=1` in the style** when the `value` attribute contains any HTML tags (`<b>`, `<br>`, `<font>`, `<i>`, `<u>`, `<hr>`, `<p>`, `<table>`, etc.). Without `html=1`, HTML tags are displayed as literal text instead of being rendered.
|
|
100
|
+
|
|
101
|
+
HTML in attribute values must be **XML-escaped**: `<` → `<`, `>` → `>`, `&` → `&`, `"` → `"`
|
|
102
|
+
|
|
103
|
+
```xml
|
|
104
|
+
<mxCell value="<b>Title</b><br>Description"
|
|
105
|
+
style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
|
106
|
+
<mxGeometry x="100" y="100" width="120" height="60" as="geometry"/>
|
|
107
|
+
</mxCell>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
**Line breaks:** Use `
` (works with both `html=1` and `html=0`) or `<br>` (requires `html=1`) for line breaks — never use `\n`, which renders as literal backslash-n text instead of a newline.
|
|
111
|
+
|
|
112
|
+
**Best practice:** Always include `html=1` in every cell style. This ensures labels render correctly whether they contain HTML or plain text — plain text is unaffected by the flag.
|
|
113
|
+
|
|
114
|
+
**Bold/italic/underline:** Use `fontStyle` in the style string when the entire label should be bold (`fontStyle=1`), italic (`fontStyle=2`), or underline (`fontStyle=4`). Values can be combined via bitwise OR (e.g., `fontStyle=3` = bold+italic). Use HTML tags (`<b>`, `<i>`, `<u>`) only when formatting part of the label (e.g., bold title with normal description). Never combine `fontStyle` with HTML tags for the same effect — this is redundant and causes visible raw tags if `html=1` is missing.
|
|
115
|
+
|
|
116
|
+
## Edges
|
|
117
|
+
|
|
118
|
+
**CRITICAL: Every edge `mxCell` must contain a `<mxGeometry relative="1" as="geometry" />` child element.** Self-closing edge cells (e.g. `<mxCell ... edge="1" ... />`) are invalid and will not render correctly. Always use the expanded form:
|
|
119
|
+
```xml
|
|
120
|
+
<mxCell id="e1" edge="1" parent="1" source="a" target="b" style="...">
|
|
121
|
+
<mxGeometry relative="1" as="geometry" />
|
|
122
|
+
</mxCell>
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Don't hand-route edges.** Just declare `source` and `target`. You do **not** need to:
|
|
126
|
+
- Add `<mxPoint>` waypoints
|
|
127
|
+
- Set `exitX` / `exitY` / `entryX` / `entryY`
|
|
128
|
+
- Route around obstacles
|
|
129
|
+
- Worry about edge-vertex collisions or parallel edge spacing
|
|
130
|
+
|
|
131
|
+
draw.io's built-in router is **basic**: it draws each edge as a straight line or a simple right-angle path between `source` and `target`, with **no awareness of other shapes** — a wire will run straight across any box that sits between its endpoints. That's fine when connected nodes have open space between them. When edges would otherwise cross over shapes, or you want consistently clean orthogonal wires that route *around* the boxes, set **`routing: "libavoid"`** on `create_diagram`; for a full re-layout use **`postLayout: "elk"`** (see **Edge routing & layout passes** below). Both compute the waypoints for you — you never add them by hand either way.
|
|
132
|
+
|
|
133
|
+
**What you still choose: the edge style.** The style determines the overall look (orthogonal angles, curves, straight lines) — the router honors the style family.
|
|
134
|
+
|
|
135
|
+
| Style | Syntax | Best for |
|
|
136
|
+
|-------|--------|---------|
|
|
137
|
+
| **Orthogonal** | `edgeStyle=orthogonalEdgeStyle` | Flowcharts, architecture, network diagrams, BPMN — any diagram with right-angle connectors |
|
|
138
|
+
| **Straight** | no `edgeStyle` | UML class/sequence diagrams, direct point-to-point connections. For sequence diagram messages use `endSize=6;startSize=6;` to keep arrowheads small |
|
|
139
|
+
| **Entity Relation** | `edgeStyle=entityRelationEdgeStyle` | ER diagrams — creates perpendicular stubs at both ends |
|
|
140
|
+
| **Curved** | `curved=1` | Mind maps, informal diagrams |
|
|
141
|
+
| **Elbow** | `edgeStyle=elbowEdgeStyle;elbow=vertical;` | Rarely needed — `orthogonalEdgeStyle` handles almost all cases; use this only for simple 1-bend linear flows |
|
|
142
|
+
|
|
143
|
+
**Use a consistent edge style within each diagram.** Pick one based on diagram type and apply it to all edges: ER → `entityRelationEdgeStyle`; UML class → straight; mind maps → curved; flowcharts/architecture/network → `orthogonalEdgeStyle`.
|
|
144
|
+
|
|
145
|
+
**Useful edge style attributes** that apply regardless of routing:
|
|
146
|
+
- `rounded=1` — rounded corners at bend points (recommended for orthogonal)
|
|
147
|
+
- `endArrow=classic` / `endArrow=none` — arrow heads
|
|
148
|
+
- `dashed=1` — dashed line
|
|
149
|
+
- `strokeColor=#...`, `strokeWidth=2` — color/width
|
|
150
|
+
- Edge labels: set `value` directly on the edge cell
|
|
151
|
+
|
|
152
|
+
**Keep edge labels short and meaningful** — one to three words (`Yes`, `async`, `reads`). Drop labels that merely restate an obvious action (`call`, `register`); move longer explanations into node text or a small legend node.
|
|
153
|
+
|
|
154
|
+
**Visual semantics — stay consistent, add a legend when mixing styles.** Within one diagram apply `dashed=1`, `strokeColor`, and `strokeWidth` consistently for one chosen meaning (e.g. dashed = optional / async / inferred relationship). Don't mix several dashed meanings without a small legend explaining them.
|
|
155
|
+
|
|
156
|
+
## Containers and groups
|
|
157
|
+
|
|
158
|
+
For architecture diagrams or any diagram with nested elements, use draw.io's proper parent-child containment — do **not** just place shapes on top of larger shapes.
|
|
159
|
+
|
|
160
|
+
### How containment works
|
|
161
|
+
|
|
162
|
+
Set `parent="containerId"` on child cells. Children use **relative coordinates** within the container.
|
|
163
|
+
|
|
164
|
+
### Container types
|
|
165
|
+
|
|
166
|
+
| Type | Style | When to use |
|
|
167
|
+
|------|-------|-------------|
|
|
168
|
+
| **Group** (invisible) | `group;` | No visual border needed, container has no connections. Includes `pointerEvents=0` so child connections are not captured |
|
|
169
|
+
| **Swimlane** (titled) | `swimlane;startSize=30;` | Container needs a visible title bar/header, or the container itself has connections |
|
|
170
|
+
| **Custom container** | Add `container=1;pointerEvents=0;` to any shape style | Any shape acting as a container without its own connections |
|
|
171
|
+
|
|
172
|
+
### Key rules
|
|
173
|
+
|
|
174
|
+
- **Edges to children inside containers naturally cross the container boundary** — this is correct and expected. Do not add extra waypoints or complex routing to avoid a parent container when connecting to shapes inside it.
|
|
175
|
+
- **Always add `pointerEvents=0;`** to container styles that should not capture connections being rewired between children
|
|
176
|
+
- Only omit `pointerEvents=0` when the container itself needs to be connectable — in that case, use `swimlane` style which handles this correctly (the client area is transparent for mouse events while the header remains connectable)
|
|
177
|
+
- Children must set `parent="containerId"` and use coordinates **relative to the container**
|
|
178
|
+
|
|
179
|
+
### Example: Architecture container with swimlane
|
|
180
|
+
|
|
181
|
+
```xml
|
|
182
|
+
<mxCell id="svc1" value="User Service" style="swimlane;startSize=30;fillColor=#dae8fc;strokeColor=#6c8ebf;html=1;" vertex="1" parent="1">
|
|
183
|
+
<mxGeometry x="100" y="100" width="300" height="200" as="geometry"/>
|
|
184
|
+
</mxCell>
|
|
185
|
+
<mxCell id="api1" value="REST API" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="svc1">
|
|
186
|
+
<mxGeometry x="20" y="40" width="120" height="60" as="geometry"/>
|
|
187
|
+
</mxCell>
|
|
188
|
+
<mxCell id="db1" value="Database" style="shape=cylinder3;whiteSpace=wrap;html=1;" vertex="1" parent="svc1">
|
|
189
|
+
<mxGeometry x="160" y="40" width="120" height="60" as="geometry"/>
|
|
190
|
+
</mxCell>
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Example: Invisible group container
|
|
194
|
+
|
|
195
|
+
```xml
|
|
196
|
+
<mxCell id="grp1" value="" style="group;" vertex="1" parent="1">
|
|
197
|
+
<mxGeometry x="100" y="100" width="300" height="200" as="geometry"/>
|
|
198
|
+
</mxCell>
|
|
199
|
+
<mxCell id="c1" value="Component A" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="grp1">
|
|
200
|
+
<mxGeometry x="10" y="10" width="120" height="60" as="geometry"/>
|
|
201
|
+
</mxCell>
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Swimlanes for grouped actors (BPMN-style flowcharts)
|
|
205
|
+
|
|
206
|
+
Use **flat swimlanes** at `parent="1"`, stacked vertically. One row of nodes per lane.
|
|
207
|
+
|
|
208
|
+
**Fixed values — do not compute or debate:**
|
|
209
|
+
- Lane size: `x=0, y=lane_index*150, width=CANVAS_W, height=150`
|
|
210
|
+
- Lane style: `swimlane;horizontal=0;startSize=110;fillColor=<pastel>;html=1;`
|
|
211
|
+
- Child nodes inside a lane: `parent="<lane_id>"`, `x = 120 + col*180`, `y = 45` (always 45), size 140×60 (or 140×80 for diamonds)
|
|
212
|
+
- Cross-lane edges: `parent="1"` (not inside a lane)
|
|
213
|
+
|
|
214
|
+
Pick `CANVAS_W = max_col * 180 + 300`. Choose lane colors from `#f5f5f5, #e8f4f8, #fff0e6, #e8f5e9, #fff9e6, #fce4ec` in that order.
|
|
215
|
+
|
|
216
|
+
```xml
|
|
217
|
+
<mxCell id="lane1" value="Customer" style="swimlane;horizontal=0;startSize=110;fillColor=#f5f5f5;html=1;" vertex="1" parent="1">
|
|
218
|
+
<mxGeometry x="0" y="0" width="1800" height="150" as="geometry"/>
|
|
219
|
+
</mxCell>
|
|
220
|
+
<mxCell id="n1" value="Place Order" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="lane1">
|
|
221
|
+
<mxGeometry x="120" y="45" width="140" height="60" as="geometry"/>
|
|
222
|
+
</mxCell>
|
|
223
|
+
<mxCell id="lane2" value="System" style="swimlane;horizontal=0;startSize=110;fillColor=#e8f4f8;html=1;" vertex="1" parent="1">
|
|
224
|
+
<mxGeometry x="0" y="150" width="1800" height="150" as="geometry"/>
|
|
225
|
+
</mxCell>
|
|
226
|
+
<mxCell id="n2" value="Validate" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="lane2">
|
|
227
|
+
<mxGeometry x="300" y="45" width="140" height="60" as="geometry"/>
|
|
228
|
+
</mxCell>
|
|
229
|
+
<mxCell id="e1" edge="1" parent="1" source="n1" target="n2" style="edgeStyle=orthogonalEdgeStyle;rounded=1;html=1;">
|
|
230
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
231
|
+
</mxCell>
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Do NOT nest lanes inside a pool. Do NOT vary lane heights. Do NOT compute title-area offset — it is always 110, children start at x=120 to clear it.
|
|
235
|
+
|
|
236
|
+
### Nested architecture containers (cloud, infra, network topologies)
|
|
237
|
+
|
|
238
|
+
For diagrams with **nested groupings** — VPC → Availability Zone → EC2 instance, Datacenter → Rack → Server, Region → Environment → Service — use nested swimlanes. This is where the AI most often flattens hierarchy that should be nested. Treat each level as a swimlane container.
|
|
239
|
+
|
|
240
|
+
**Rules:**
|
|
241
|
+
- Every container is a `swimlane` with `startSize=24` (title area at the top).
|
|
242
|
+
- Child cells set `parent="<container_id>"` and use coordinates **relative to their parent** (origin 0,0 is the parent's top-left, below the title).
|
|
243
|
+
- Edges between cells in **different** containers must have `parent="1"` (not a container) — otherwise they render inside the container and get clipped.
|
|
244
|
+
- For industry-specific icons (AWS/Azure/GCP logos, Cisco equipment, etc.), call `search_shapes` to get the exact `style` string and substitute it into a regular vertex — the container structure stays the same.
|
|
245
|
+
|
|
246
|
+
```xml
|
|
247
|
+
<mxCell id="vpc" value="VPC" style="swimlane;startSize=24;fillColor=#dae8fc;strokeColor=#6c8ebf;html=1;" vertex="1" parent="1">
|
|
248
|
+
<mxGeometry x="0" y="0" width="720" height="360" as="geometry"/>
|
|
249
|
+
</mxCell>
|
|
250
|
+
<mxCell id="az1" value="AZ us-east-1a" style="swimlane;startSize=24;fillColor=#fff2cc;strokeColor=#d6b656;html=1;" vertex="1" parent="vpc">
|
|
251
|
+
<mxGeometry x="20" y="36" width="320" height="300" as="geometry"/>
|
|
252
|
+
</mxCell>
|
|
253
|
+
<mxCell id="web1" value="web-1" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="az1">
|
|
254
|
+
<mxGeometry x="30" y="40" width="120" height="60" as="geometry"/>
|
|
255
|
+
</mxCell>
|
|
256
|
+
<mxCell id="db1" value="db-1" style="shape=cylinder3;whiteSpace=wrap;html=1;" vertex="1" parent="az1">
|
|
257
|
+
<mxGeometry x="180" y="40" width="100" height="70" as="geometry"/>
|
|
258
|
+
</mxCell>
|
|
259
|
+
<mxCell id="az2" value="AZ us-east-1b" style="swimlane;startSize=24;fillColor=#fff2cc;strokeColor=#d6b656;html=1;" vertex="1" parent="vpc">
|
|
260
|
+
<mxGeometry x="360" y="36" width="340" height="300" as="geometry"/>
|
|
261
|
+
</mxCell>
|
|
262
|
+
<mxCell id="web2" value="web-2" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="az2">
|
|
263
|
+
<mxGeometry x="30" y="40" width="120" height="60" as="geometry"/>
|
|
264
|
+
</mxCell>
|
|
265
|
+
<mxCell id="e1" edge="1" parent="1" source="web1" target="web2" style="edgeStyle=orthogonalEdgeStyle;rounded=1;html=1;">
|
|
266
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
267
|
+
</mxCell>
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Cross-functional flowcharts (actor × phase grid, as a table)
|
|
271
|
+
|
|
272
|
+
Cross-functional flowcharts show a process across **two axes at once** — actors (rows) and phases (columns). Use drawio's `table` shape, which auto-arranges cells into a grid via `childLayout=tableLayout`. This is the canonical draw.io pattern and is distinct from plain swimlanes (which only group on one axis).
|
|
273
|
+
|
|
274
|
+
**Structure:**
|
|
275
|
+
- Outer container: `shape=table;childLayout=tableLayout;startSize=0;collapsible=0;fillColor=none;`
|
|
276
|
+
- Rows are children of the table: `shape=tableRow;horizontal=0;startSize=0;collapsible=0;`
|
|
277
|
+
- Cells are children of rows — regular vertices, one per (actor, phase) intersection
|
|
278
|
+
- Row heights and cell widths are set via `mxGeometry`; they tile automatically
|
|
279
|
+
- First row = phase headers; first cell of every other row = actor label
|
|
280
|
+
- Process nodes go INSIDE the appropriate cell (parent = cell id) at coordinates relative to the cell
|
|
281
|
+
- Cross-cell edges must use `parent="1"` (same rule as containers)
|
|
282
|
+
|
|
283
|
+
```xml
|
|
284
|
+
<mxCell id="tbl" style="shape=table;childLayout=tableLayout;startSize=0;collapsible=0;fillColor=none;" vertex="1" parent="1">
|
|
285
|
+
<mxGeometry x="0" y="0" width="900" height="320" as="geometry"/>
|
|
286
|
+
</mxCell>
|
|
287
|
+
<mxCell id="r0" style="shape=tableRow;horizontal=0;startSize=0;collapsible=0;" vertex="1" parent="tbl">
|
|
288
|
+
<mxGeometry width="900" height="40" as="geometry"/>
|
|
289
|
+
</mxCell>
|
|
290
|
+
<mxCell id="h0" style="text;html=1;" vertex="1" parent="r0">
|
|
291
|
+
<mxGeometry width="140" height="40" as="geometry"/>
|
|
292
|
+
</mxCell>
|
|
293
|
+
<mxCell id="h1" value="Order" style="text;align=center;fontStyle=1;fillColor=#e8e8e8;" vertex="1" parent="r0">
|
|
294
|
+
<mxGeometry x="140" width="380" height="40" as="geometry"/>
|
|
295
|
+
</mxCell>
|
|
296
|
+
<mxCell id="h2" value="Fulfill" style="text;align=center;fontStyle=1;fillColor=#e8e8e8;" vertex="1" parent="r0">
|
|
297
|
+
<mxGeometry x="520" width="380" height="40" as="geometry"/>
|
|
298
|
+
</mxCell>
|
|
299
|
+
<mxCell id="r1" style="shape=tableRow;horizontal=0;startSize=0;collapsible=0;" vertex="1" parent="tbl">
|
|
300
|
+
<mxGeometry y="40" width="900" height="140" as="geometry"/>
|
|
301
|
+
</mxCell>
|
|
302
|
+
<mxCell id="a1" value="Customer" style="fillColor=#dae8fc;fontStyle=1;" vertex="1" parent="r1">
|
|
303
|
+
<mxGeometry width="140" height="140" as="geometry"/>
|
|
304
|
+
</mxCell>
|
|
305
|
+
<mxCell id="c_cust_order" style="fillColor=none;" vertex="1" parent="r1">
|
|
306
|
+
<mxGeometry x="140" width="380" height="140" as="geometry"/>
|
|
307
|
+
</mxCell>
|
|
308
|
+
<mxCell id="t_place" value="Place Order" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="c_cust_order">
|
|
309
|
+
<mxGeometry x="120" y="40" width="140" height="60" as="geometry"/>
|
|
310
|
+
</mxCell>
|
|
311
|
+
<mxCell id="c_cust_fulfill" style="fillColor=none;" vertex="1" parent="r1">
|
|
312
|
+
<mxGeometry x="520" width="380" height="140" as="geometry"/>
|
|
313
|
+
</mxCell>
|
|
314
|
+
<mxCell id="r2" style="shape=tableRow;horizontal=0;startSize=0;collapsible=0;" vertex="1" parent="tbl">
|
|
315
|
+
<mxGeometry y="180" width="900" height="140" as="geometry"/>
|
|
316
|
+
</mxCell>
|
|
317
|
+
<mxCell id="a2" value="System" style="fillColor=#d5e8d4;fontStyle=1;" vertex="1" parent="r2">
|
|
318
|
+
<mxGeometry width="140" height="140" as="geometry"/>
|
|
319
|
+
</mxCell>
|
|
320
|
+
<mxCell id="c_sys_order" style="fillColor=none;" vertex="1" parent="r2">
|
|
321
|
+
<mxGeometry x="140" width="380" height="140" as="geometry"/>
|
|
322
|
+
</mxCell>
|
|
323
|
+
<mxCell id="t_validate" value="Validate" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="c_sys_order">
|
|
324
|
+
<mxGeometry x="120" y="40" width="140" height="60" as="geometry"/>
|
|
325
|
+
</mxCell>
|
|
326
|
+
<mxCell id="c_sys_fulfill" style="fillColor=none;" vertex="1" parent="r2">
|
|
327
|
+
<mxGeometry x="520" width="380" height="140" as="geometry"/>
|
|
328
|
+
</mxCell>
|
|
329
|
+
<mxCell id="t_ship" value="Ship" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="c_sys_fulfill">
|
|
330
|
+
<mxGeometry x="120" y="40" width="140" height="60" as="geometry"/>
|
|
331
|
+
</mxCell>
|
|
332
|
+
<mxCell id="e1" edge="1" parent="1" source="t_place" target="t_validate" style="edgeStyle=orthogonalEdgeStyle;rounded=1;html=1;">
|
|
333
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
334
|
+
</mxCell>
|
|
335
|
+
<mxCell id="e2" edge="1" parent="1" source="t_validate" target="t_ship" style="edgeStyle=orthogonalEdgeStyle;rounded=1;html=1;">
|
|
336
|
+
<mxGeometry relative="1" as="geometry"/>
|
|
337
|
+
</mxCell>
|
|
338
|
+
```
|
|
339
|
+
|
|
340
|
+
**When to use cross-functional tables vs flat swimlanes:**
|
|
341
|
+
- Flat swimlanes — one-dimensional (actors only, or phases only). Simpler. Use this when you just need to show who does what in sequence.
|
|
342
|
+
- Cross-functional table — two-dimensional (actors AND phases). Use this when **both** the actor and the process stage matter, and every step belongs to a specific (actor, phase) cell.
|
|
343
|
+
|
|
344
|
+
**Do NOT** nest swimlanes inside a table row, do NOT set `startSize` on rows or cells (columns tile from `x=0`), and do NOT rely on the AI to produce exact widths that sum to the table width — close-enough totals are fine, the `tableLayout` normalizes them.
|
|
345
|
+
|
|
346
|
+
## Layers
|
|
347
|
+
|
|
348
|
+
Layers control visibility and z-order. Every cell belongs to exactly one layer. Use layers to manage diagram complexity — viewers can toggle layer visibility to show or hide groups of elements (e.g., "Physical Infrastructure" vs "Logical Network" vs "Security Zones").
|
|
349
|
+
|
|
350
|
+
Cell `id="0"` is the root and cell `id="1"` is the default layer — both always exist. Additional layers are `mxCell` elements with `parent="0"`:
|
|
351
|
+
|
|
352
|
+
```xml
|
|
353
|
+
<mxGraphModel>
|
|
354
|
+
<root>
|
|
355
|
+
<mxCell id="0"/>
|
|
356
|
+
<mxCell id="1" parent="0"/>
|
|
357
|
+
<mxCell id="2" value="Annotations" parent="0"/>
|
|
358
|
+
<mxCell id="10" value="Server" style="rounded=1;html=1;" vertex="1" parent="1">
|
|
359
|
+
<mxGeometry x="100" y="100" width="120" height="60" as="geometry"/>
|
|
360
|
+
</mxCell>
|
|
361
|
+
<mxCell id="20" value="Note: deprecated" style="text;" vertex="1" parent="2">
|
|
362
|
+
<mxGeometry x="100" y="170" width="120" height="30" as="geometry"/>
|
|
363
|
+
</mxCell>
|
|
364
|
+
</root>
|
|
365
|
+
</mxGraphModel>
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
- A layer is an `mxCell` with `parent="0"` and no `vertex` or `edge` attribute
|
|
369
|
+
- Assign shapes to a layer by setting `parent` to the layer's id
|
|
370
|
+
- Later layers render on top of earlier layers (higher z-order)
|
|
371
|
+
- Add `visible="0"` as an attribute on the layer cell to hide it by default
|
|
372
|
+
- Use layers when the diagram has distinct conceptual groupings that viewers may want to toggle independently
|
|
373
|
+
|
|
374
|
+
## Tags
|
|
375
|
+
|
|
376
|
+
Tags are visual filters that let viewers show or hide elements by category. Unlike layers, a single element can have multiple tags, making tags ideal for cross-cutting concerns (e.g., tagging shapes as "critical", "v2", or "backend").
|
|
377
|
+
|
|
378
|
+
Tags require wrapping `mxCell` in an `<object>` element. Tags are assigned via the `tags` attribute as a space-separated string:
|
|
379
|
+
|
|
380
|
+
```xml
|
|
381
|
+
<mxGraphModel>
|
|
382
|
+
<root>
|
|
383
|
+
<mxCell id="0"/>
|
|
384
|
+
<mxCell id="1" parent="0"/>
|
|
385
|
+
<object id="2" label="Auth Service" tags="critical v2">
|
|
386
|
+
<mxCell style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
|
387
|
+
<mxGeometry x="100" y="100" width="120" height="60" as="geometry"/>
|
|
388
|
+
</mxCell>
|
|
389
|
+
</object>
|
|
390
|
+
<object id="3" label="Legacy API" tags="critical deprecated">
|
|
391
|
+
<mxCell style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
|
392
|
+
<mxGeometry x="300" y="100" width="120" height="60" as="geometry"/>
|
|
393
|
+
</mxCell>
|
|
394
|
+
</object>
|
|
395
|
+
</root>
|
|
396
|
+
</mxGraphModel>
|
|
397
|
+
```
|
|
398
|
+
|
|
399
|
+
- Tags require the `<object>` wrapper — a plain `mxCell` cannot have tags
|
|
400
|
+
- The `label` attribute on `<object>` replaces `value` on `mxCell`
|
|
401
|
+
- Tags are space-separated in the `tags` attribute
|
|
402
|
+
- Viewers filter the diagram by selecting tags in the draw.io UI (Edit > Tags)
|
|
403
|
+
- Tags do not affect z-order or structural grouping — they are purely a visibility filter
|
|
404
|
+
|
|
405
|
+
## Metadata and placeholders
|
|
406
|
+
|
|
407
|
+
Metadata stores custom key-value properties on shapes as additional attributes on the `<object>` wrapper element. Combined with placeholders, metadata values can be displayed in labels — useful for data-driven diagrams showing status, owner, IP addresses, or versions on each shape.
|
|
408
|
+
|
|
409
|
+
Set `placeholders="1"` on the `<object>` to enable `%propertyName%` substitution in the `label`:
|
|
410
|
+
|
|
411
|
+
```xml
|
|
412
|
+
<mxGraphModel>
|
|
413
|
+
<root>
|
|
414
|
+
<mxCell id="0"/>
|
|
415
|
+
<mxCell id="1" parent="0"/>
|
|
416
|
+
<object id="2" label="<b>%component%</b><br>Owner: %owner%<br>Status: %status%"
|
|
417
|
+
placeholders="1" component="Auth Service" owner="Team Backend" status="Active">
|
|
418
|
+
<mxCell style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
|
|
419
|
+
<mxGeometry x="100" y="100" width="160" height="80" as="geometry"/>
|
|
420
|
+
</mxCell>
|
|
421
|
+
</object>
|
|
422
|
+
</root>
|
|
423
|
+
</mxGraphModel>
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
- Custom properties are plain XML attributes on `<object>` (e.g., `component="Auth Service"`)
|
|
427
|
+
- Set `placeholders="1"` to enable `%key%` substitution in the label and tooltip
|
|
428
|
+
- The label must use `html=1` style when using HTML formatting with placeholders
|
|
429
|
+
- Placeholders resolve by walking up the containment hierarchy: shape attributes first, then parent container, then layer, then root — first match wins
|
|
430
|
+
- Predefined placeholders work without custom properties: `%id%`, `%width%`, `%height%`, `%date%`, `%time%`, `%timestamp%`, `%page%`, `%pagenumber%`, `%pagecount%`, `%filename%`
|
|
431
|
+
- Use `%%` for a literal percent sign in labels
|
|
432
|
+
- Tags, metadata, and placeholders can all be combined on the same `<object>` element
|
|
433
|
+
- Use metadata when shapes represent data records (servers, services, components) and you want to attach structured information beyond the visible label
|
|
434
|
+
|
|
435
|
+
## Dark mode colors
|
|
436
|
+
|
|
437
|
+
draw.io supports automatic dark mode rendering. How colors behave depends on the property:
|
|
438
|
+
|
|
439
|
+
- **`strokeColor`, `fillColor`, `fontColor`** default to `"default"`, which renders as black in light theme and white in dark theme. When no explicit color is set, colors adapt automatically.
|
|
440
|
+
- **Explicit colors** (e.g. `fillColor=#DAE8FC`) specify the light-mode color. The dark-mode color is computed automatically by inverting the RGB values (blending toward the inverse at 93%) and rotating the hue by 180° (via `mxUtils.getInverseColor`).
|
|
441
|
+
- **`light-dark()` function** — To specify both colors explicitly, use `light-dark(lightColor,darkColor)` in the style string, e.g. `fontColor=light-dark(#7EA6E0,#FF0000)`. The first argument is used in light mode, the second in dark mode.
|
|
442
|
+
|
|
443
|
+
To enable dark mode color adaptation, the `mxGraphModel` element must include `adaptiveColors="auto"`.
|
|
444
|
+
|
|
445
|
+
When generating diagrams, you generally do not need to specify dark-mode colors — the automatic inversion handles most cases. Use `light-dark()` only when the automatic inverse color is unsatisfactory.
|
|
446
|
+
|
|
447
|
+
## Edge routing & layout passes
|
|
448
|
+
|
|
449
|
+
By default, edges are drawn by draw.io's **built-in router**, which is intentionally basic: each edge is a straight line or a simple right-angle path between its endpoints, with **no obstacle avoidance** — a connector runs straight through any shape lying between its `source` and `target`. There is no server-side post-processing. Two **opt-in** passes on `create_diagram` upgrade this; they are independent and combine freely, run client-side after the diagram renders, and the exported XML (copy/clipboard, "Open in draw.io") reflects the final routed result.
|
|
450
|
+
|
|
451
|
+
- **`routing: "libavoid"`** (XML only) — obstacle-avoiding orthogonal **edge routing**. Vertices stay exactly where you placed them; only the connectors are recomputed, so they run in clean right-angle segments that route *around* the boxes (and spread apart when parallel) instead of cutting across them. Use it for diagrams you laid out deliberately — architecture, network topology, deployment, swimlanes, UML, floor plans — where you want tidy wires without disturbing your layout.
|
|
452
|
+
- **`postLayout: "elk"`** — a **full re-layout** (ELK `layered` flow). Vertices animate (morph) from your positions to canonical hierarchical positions, and the edges are routed as part of that. Best for flowcharts, process/state diagrams, decision flows, pipelines, and other directional/hierarchical diagrams. (You should rarely hand-write these as XML — prefer Mermaid.) Flow **direction**: on XML set the optional `direction` field (`"vertical"` (default) / `"horizontal"`); on Mermaid it is read from the flowchart code (`flowchart TD/TB` vs `LR/RL`) and `direction` is ignored.
|
|
453
|
+
|
|
454
|
+
The four combinations:
|
|
455
|
+
|
|
456
|
+
| `postLayout` | `routing` | Result |
|
|
457
|
+
|---|---|---|
|
|
458
|
+
| — | — | basic built-in router (straight / simple right-angle, no obstacle avoidance); your positions kept |
|
|
459
|
+
| — | `libavoid` | your positions kept; wires re-routed orthogonally *around* the shapes |
|
|
460
|
+
| `elk` | — | ELK places the vertices **and** routes the edges (decent routing built in) |
|
|
461
|
+
| `elk` | `libavoid` | rarely worth it — ELK already routes; only add `libavoid` if ELK's routing specifically comes out poor |
|
|
462
|
+
|
|
463
|
+
**Pick ONE — they are essentially alternatives, not a stack:**
|
|
464
|
+
- **Neither** — fine when connected nodes sit in clear rows/columns with open space between them, so the basic router's straight/right-angle lines won't cross another shape. Simplest and lightest; do this by default for sparse layouts.
|
|
465
|
+
- **`routing: "libavoid"`** — keep your hand-placed layout but clean up the wires: use whenever an edge would otherwise cut across a box, or you want consistently clean orthogonal wires routed around shapes (architecture, network topology, deployment, UML, floor plans — anything densely connected).
|
|
466
|
+
- **`postLayout: "elk"`** — when you want a canonical re-layout (vertices moved). ELK routes the edges itself as part of the layout, so **do not also set `routing`** — the combination is redundant in almost all cases. Add `direction: "horizontal"` for left-to-right flow.
|
|
467
|
+
|
|
468
|
+
**For Mermaid diagrams: see the `postLayout` parameter description for when to set it.** Complex Mermaid flowcharts (≥ ~20 nodes, ≥ 3 decision diamonds, feedback edges, or ≥ 3 endpoints) need `postLayout: "elk"` because the native parser's layout goes cramped or unbalanced past that threshold — the direction follows the flowchart code, so no `direction` is needed. Simple flowcharts and all non-flowchart Mermaid types (sequence, class, ER, sankey, …) need no `postLayout`.
|
|
469
|
+
|
|
470
|
+
**When NOT to use (XML):**
|
|
471
|
+
- The user has asked for specific positions (swim lanes with exact lanes, architecture diagrams with meaningful spatial arrangement).
|
|
472
|
+
- The diagram relies on containers/grouping where spatial layout encodes information.
|
|
473
|
+
|
|
474
|
+
## CRITICAL: XML well-formedness
|
|
475
|
+
|
|
476
|
+
When generating draw.io XML, the output **must** be well-formed XML:
|
|
477
|
+
- **NEVER include ANY XML comments (`<!-- -->`) in the output.** XML comments are strictly forbidden — they waste tokens, can cause parse errors, and serve no purpose in diagram XML.
|
|
478
|
+
- Escape special characters in attribute values: `&`, `<`, `>`, `"`
|
|
479
|
+
- Always use unique `id` values for each `mxCell`
|