drawio
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseDraw.io Diagram Skill
Draw.io 图表生成技能
Generate draw.io diagrams as native files. Optionally export to PNG, SVG, or PDF with the diagram XML embedded (so the exported file remains editable in draw.io).
.drawio生成原生格式的绘图文件。还可选择将其导出为嵌入图表XML的PNG、SVG或PDF格式(这样导出后的文件仍可在draw.io中编辑)。
.drawioHow to create a diagram
如何创建图表
- Generate draw.io XML in mxGraphModel format for the requested diagram
- Write the XML to a file in the current working directory using the Write tool
.drawio - If the user requested an export format (png, svg, pdf), export using the draw.io CLI with , then delete the source
--embed-diagramfile.drawio - Open the result — the exported file if exported, or the file otherwise
.drawio
- 生成mxGraphModel格式的draw.io XML,以匹配所需的图表内容
- 将XML写入文件:使用写入工具在当前工作目录中创建文件
.drawio - 如果用户要求特定导出格式(png、svg、pdf),使用draw.io CLI并添加参数进行导出,然后删除源
--embed-diagram文件.drawio - 打开结果文件:如果进行了导出则打开导出后的文件,否则打开文件
.drawio
Choosing the output format
选择输出格式
Check the user's request for a format preference. Examples:
- →
/drawio create a flowchartflowchart.drawio - →
/drawio png flowchart for loginlogin-flow.drawio.png - →
/drawio svg: ER diagramer-diagram.drawio.svg - →
/drawio pdf architecture overviewarchitecture-overview.drawio.pdf
If no format is mentioned, just write the file and open it in draw.io. The user can always ask to export later.
.drawio检查用户请求中的格式偏好。示例:
- →
/drawio create a flowchartflowchart.drawio - →
/drawio png flowchart for loginlogin-flow.drawio.png - →
/drawio svg: ER diagramer-diagram.drawio.svg - →
/drawio pdf architecture overviewarchitecture-overview.drawio.pdf
如果未提及格式,仅创建文件并在draw.io中打开。用户后续可随时要求导出。
.drawioSupported export formats
支持的导出格式
| Format | Embed XML | Notes |
|---|---|---|
| Yes ( | Viewable everywhere, editable in draw.io |
| Yes ( | Scalable, editable in draw.io |
| Yes ( | Printable, editable in draw.io |
| No | Lossy, no embedded XML support |
PNG, SVG, and PDF all support — the exported file contains the full diagram XML, so opening it in draw.io recovers the editable diagram.
--embed-diagram| 格式 | 嵌入XML | 说明 |
|---|---|---|
| 是 ( | 可在所有平台查看,可在draw.io中编辑 |
| 是 ( | 可缩放,可在draw.io中编辑 |
| 是 ( | 可打印,可在draw.io中编辑 |
| 否 | 有损压缩,不支持嵌入XML |
PNG、SVG和PDF均支持参数——导出的文件包含完整的图表XML,因此在draw.io中打开时可恢复为可编辑的图表。
--embed-diagramdraw.io CLI
draw.io CLI
The draw.io desktop app includes a command-line interface for exporting.
draw.io桌面应用包含用于导出功能的命令行界面。
Locating the CLI
定位CLI
Try first (works if on PATH), then fall back to the platform-specific path:
drawio- macOS:
/Applications/draw.io.app/Contents/MacOS/draw.io - Linux: (typically on PATH via snap/apt/flatpak)
drawio - Windows:
"C:\Program Files\draw.io\draw.io.exe"
Use (or on Windows) to check if it's on PATH before falling back.
which drawiowhere drawio首先尝试使用命令(如果已添加到PATH),如果失败则使用平台特定路径:
drawio- macOS:
/Applications/draw.io.app/Contents/MacOS/draw.io - Linux: (通常通过snap/apt/flatpak添加到PATH)
drawio - Windows:
"C:\Program Files\draw.io\draw.io.exe"
在使用备选路径前,可通过(Windows系统使用)检查该命令是否在PATH中。
which drawiowhere drawioExport command
导出命令
bash
drawio -x -f <format> -e -b 10 -o <output> <input.drawio>Key flags:
- /
-x: export mode--export - /
-f: output format (png, svg, pdf, jpg)--format - /
-e: embed diagram XML in the output (PNG, SVG, PDF only)--embed-diagram - /
-o: output file path--output - /
-b: border width around diagram (default: 0)--border - /
-t: transparent background (PNG only)--transparent - /
-s: scale the diagram size--scale - /
--width: fit into specified dimensions (preserves aspect ratio)--height - /
-a: export all pages (PDF only)--all-pages - /
-p: select a specific page (1-based)--page-index
bash
drawio -x -f <format> -e -b 10 -o <output> <input.drawio>关键参数说明:
- /
-x: 导出模式--export - /
-f: 输出格式(png, svg, pdf, jpg)--format - /
-e: 在输出文件中嵌入图表XML(仅支持PNG、SVG、PDF)--embed-diagram - /
-o: 输出文件路径--output - /
-b: 图表周围的边框宽度(默认值:0)--border - /
-t: 透明背景(仅PNG支持)--transparent - /
-s: 缩放图表尺寸--scale - /
--width: 将图表适配到指定尺寸(保持宽高比)--height - /
-a: 导出所有页面(仅PDF支持)--all-pages - /
-p: 选择特定页面(从1开始计数)--page-index
Opening the result
打开结果文件
- macOS:
open <file> - Linux:
xdg-open <file> - Windows:
start <file>
- macOS:
open <file> - Linux:
xdg-open <file> - Windows:
start <file>
File naming
文件命名规范
- Use a descriptive filename based on the diagram content (e.g., ,
login-flow)database-schema - Use lowercase with hyphens for multi-word names
- For export, use double extensions: ,
name.drawio.png,name.drawio.svg— this signals the file contains embedded diagram XMLname.drawio.pdf - After a successful export, delete the intermediate file — the exported file contains the full diagram
.drawio
- 根据图表内容使用描述性文件名(例如:、
login-flow)database-schema - 多词名称使用小写字母加连字符分隔
- 导出文件使用双重扩展名:、
name.drawio.png、name.drawio.svg——这表明文件中嵌入了图表XMLname.drawio.pdf - 导出成功后,删除中间的文件——导出后的文件已包含完整的图表内容
.drawio
XML format
XML格式
A file is native mxGraphModel XML. Always generate XML directly — Mermaid and CSV formats require server-side conversion and cannot be saved as native files.
.drawio.drawioBasic structure
基本结构
Every diagram must have this structure:
xml
<mxGraphModel>
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<!-- Diagram cells go here with parent="1" -->
</root>
</mxGraphModel>- Cell is the root layer
id="0" - Cell is the default parent layer
id="1" - All diagram elements use unless using multiple layers
parent="1"
每个图表必须遵循以下结构:
xml
<mxGraphModel>
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<!-- 图表元素需设置parent="1",并放在此处 -->
</root>
</mxGraphModel>- Cell 是根图层
id="0" - Cell 是默认父图层
id="1" - 所有图表元素除非使用多图层,否则均需设置
parent="1"
Common styles
常用样式
Rounded rectangle:
xml
<mxCell id="2" value="Label" style="rounded=1;whiteSpace=wrap;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="120" height="60" as="geometry"/>
</mxCell>Diamond (decision):
xml
<mxCell id="3" value="Condition?" style="rhombus;whiteSpace=wrap;" vertex="1" parent="1">
<mxGeometry x="100" y="200" width="120" height="80" as="geometry"/>
</mxCell>Arrow (edge):
xml
<mxCell id="4" value="" style="edgeStyle=orthogonalEdgeStyle;" edge="1" source="2" target="3" parent="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>Labeled arrow:
xml
<mxCell id="5" value="Yes" style="edgeStyle=orthogonalEdgeStyle;" edge="1" source="3" target="6" parent="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>圆角矩形:
xml
<mxCell id="2" value="Label" style="rounded=1;whiteSpace=wrap;" vertex="1" parent="1">
<mxGeometry x="100" y="100" width="120" height="60" as="geometry"/>
</mxCell>菱形(决策节点):
xml
<mxCell id="3" value="Condition?" style="rhombus;whiteSpace=wrap;" vertex="1" parent="1">
<mxGeometry x="100" y="200" width="120" height="80" as="geometry"/>
</mxCell>箭头(连接线):
xml
<mxCell id="4" value="" style="edgeStyle=orthogonalEdgeStyle;" edge="1" source="2" target="3" parent="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>带标签的箭头:
xml
<mxCell id="5" value="Yes" style="edgeStyle=orthogonalEdgeStyle;" edge="1" source="3" target="6" parent="1">
<mxGeometry relative="1" as="geometry"/>
</mxCell>Useful style properties
实用样式属性
| Property | Values | Use for |
|---|---|---|
| 0 or 1 | Rounded corners |
| wrap | Text wrapping |
| Hex color | Background color |
| Hex color | Border color |
| Hex color | Text color |
| shape name | Database cylinders |
| shape name | Document shapes |
| style keyword | Circles/ovals |
| style keyword | Diamonds |
| style keyword | Right-angle connectors |
| style keyword | Elbow connectors |
| 0 or 1 | Dashed lines |
| style keyword | Swimlane containers |
| 属性 | 取值 | 用途 |
|---|---|---|
| 0或1 | 设置圆角 |
| wrap | 文本自动换行 |
| 十六进制颜色码 | 背景颜色 |
| 十六进制颜色码 | 边框颜色 |
| 十六进制颜色码 | 文本颜色 |
| 形状名称 | 数据库圆柱形状 |
| 形状名称 | 文档形状 |
| 样式关键字 | 圆形/椭圆形 |
| 样式关键字 | 菱形 |
| 样式关键字 | 直角连接线 |
| 样式关键字 | 弯头连接线 |
| 0或1 | 虚线 |
| 样式关键字 | 泳道容器 |
CRITICAL: XML well-formedness
重要提示:XML格式正确性
- NEVER use double hyphens () inside XML comments.
--is illegal inside--per the XML spec and causes parse errors. Use single hyphens or rephrase.<!-- --> - Escape special characters in attribute values: ,
&,<,>" - Always use unique values for each
idmxCell
- 绝对不要在XML注释中使用双连字符()。根据XML规范,
--在--注释中是非法的,会导致解析错误。请使用单连字符或重新表述。<!-- --> - 转义属性值中的特殊字符:、
&、<、>" - 确保每个的
mxCell值唯一id