excalidraw-diagrams
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseCreating Excalidraw Diagrams
创建Excalidraw图表
When creating Excalidraw diagrams, ensure you:
- Generate the layout with correct spacing
- Make consistent and logical use of colours, fonts, and shapes
- Text is correctly added within shapes, not as separate text elements (unless desired)
- Arrows and lines are correctly anchored / connected to shapes (not floating) so that when objects are moved any connections remain intact
- You save the Excalidraw diagram content to a file and link the file path
- Call before your first
read_mecall each session - it provides the colour palette, camera sizes, layout rules, and element format reference.create_view - If the user has asked you to create Excalidraw diagrams but you do not have the Excalidraw MCP enabled, you should ask them to add it for you, they can configured it by using the HTTP MCP URL of: https://excalidraw-mcp-app.vercel.app/mcp and they can view the MCP documentation here: https://github.com/excalidraw/excalidraw-mcp
创建Excalidraw图表时,请确保:
- 生成布局时保持正确的间距
- 颜色、字体和形状的使用保持一致且符合逻辑
- 文本应正确添加到形状内部,而非作为独立的文本元素(除非有特殊需求)
- 箭头和线条应正确锚定/连接到形状上(而非悬浮状态),这样移动对象时所有连接都能保持完整
- 将Excalidraw图表内容保存到文件并提供文件路径
- 每个会话中首次调用前先调用
create_view——它会提供调色板、画布尺寸、布局规则和元素格式参考read_me - 如果用户要求你创建Excalidraw图表,但Excalidraw MCP未启用,你应请求用户添加它,用户可通过HTTP MCP URL:https://excalidraw-mcp-app.vercel.app/mcp 进行配置,MCP文档可在此查看:https://github.com/excalidraw/excalidraw-mcp
Choose your workflow
选择你的工作流
Pick one based on what the user needs. Do not default to doing both.
根据用户需求选择其中一种,不要默认同时执行两种。
Inline preview only (create_view
)
create_view仅在线预览(create_view
)
create_viewUse when the diagram is for the conversation only - the user wants to see it in the chat and does not need a file.
- Use with
create_viewon shapes (works fine here)label - Use to animate and guide attention
cameraUpdate - No file output needed
适用于图表仅用于会话场景——用户希望在聊天中查看图表,不需要文件。
- 在形状上使用带的
label(在此场景下效果良好)create_view - 使用来制作动画并引导注意力
cameraUpdate - 无需输出文件
File output only (Python script)
仅输出文件(Python脚本)
Use when the user needs a file to open, share, edit, or keep. Skip entirely.
.excalidrawcreate_view- Generate the file with (see below)
scripts/generate_excalidraw.py - Provide the file path to the user
- Files can be opened by dragging into excalidraw.com, the Excalidraw desktop app, or VS Code with the Excalidraw extension
适用于用户需要文件来打开、分享、编辑或保存的场景。完全跳过。
.excalidrawcreate_view- 使用生成文件(见下文)
scripts/generate_excalidraw.py - 向用户提供文件路径
- 文件可通过拖拽方式在excalidraw.com、Excalidraw桌面应用或安装了Excalidraw扩展的VS Code中打开
Both (inline preview + file)
两者兼顾(在线预览+文件)
Use when the user wants to see the diagram in the chat AND keep a file. Note: these are built independently with different element formats. There is no data bridge between them - you define the diagram structure once conceptually but render it twice.
- with
create_viewfor the inline previewlabel - Python script with for the
labeled_rectfile.excalidraw
适用于用户既希望在聊天中查看图表,又需要保存文件的场景。注意:这两种方式是独立构建的,使用不同的元素格式,它们之间没有数据桥接——你只需在概念上定义一次图表结构,但要渲染两次。
- 在线预览使用带的
labelcreate_view - 文件使用带
.excalidraw的Python脚本labeled_rect
Critical: text does not survive export
重要提示:文本无法在导出中保留
The property on shapes is a convenience only. It does NOT work in:
labelcreate_view- uploads (shapes render, text is invisible)
export_to_excalidraw - files written from
.excalidrawcheckpoint datacreate_view
Do NOT use for shareable diagrams. It seems to have a bug that can silently drop all text.
export_to_excalidrawNative Excalidraw represents text inside shapes as two linked elements:
- Shape:
"boundElements": [{"id": "text-id", "type": "text"}] - Text: ,
"containerId": "shape-id","textAlign": "center""verticalAlign": "middle"
The text element requires fields the shorthand omits: (1), , , , (1.25), (true).
labelfontFamilywidthheightoriginalTextlineHeightautoResizeAll elements in .excalidraw files also need: , , , , , , , , , .
angleseedversionversionNonceisDeletedgroupIdsframeIdupdatedlinklockedHand-writing this JSON is error-prone. Use the Python script instead.
形状上的属性只是的便捷写法,它在以下场景中无效:
labelcreate_view- 上传(形状会渲染,但文本不可见)
export_to_excalidraw - 从检查点数据生成的
create_view文件.excalidraw
不要使用来创建可分享的图表,它存在一个会导致所有文本被静默丢失的bug。
export_to_excalidraw原生Excalidraw将形状内的文本表示为两个关联元素:
- 形状:
"boundElements": [{"id": "text-id", "type": "text"}] - 文本:,
"containerId": "shape-id","textAlign": "center""verticalAlign": "middle"
文本元素需要简写方式省略的字段:(1)、、、、(1.25)、(true)。
labelfontFamilywidthheightoriginalTextlineHeightautoResize.excalidrawangleseedversionversionNonceisDeletedgroupIdsframeIdupdatedlinklocked手动编写此JSON容易出错,请改用Python脚本。
Python script: scripts/generate_excalidraw.py
scripts/generate_excalidraw.pyPython脚本:scripts/generate_excalidraw.py
scripts/generate_excalidraw.pyGenerates native .excalidraw files with all required fields. Can be used inline in a bash heredoc or imported as a library.
Key functions:
| Function | Returns | Purpose |
|---|---|---|
| | Shape with centred bound text (handles all binding and field generation) |
| element | Rectangle without text |
| element | Standalone or bound text |
| element | Arrow anchored to two shapes (mutates shapes' boundElements) |
| element | Unbound/floating arrow (use |
| element | Other shape types |
| writes file | Wraps in scene structure and saves |
Example:
bash
python3 << 'PYEOF'
import sys, random
sys.path.insert(0, "/Users/samm/.claude/skills/excalidraw-diagrams/scripts")
from generate_excalidraw import *
random.seed(42)
elements = []
elements.append(txt("t1", 200, 10, 300, 30, "My Diagram", 24))
elements.extend(labeled_rect("a", 50, 60, 200, 70, "#a5d8ff", "#4a9eed", "Step One"))
elements.extend(labeled_rect("b", 350, 60, 200, 70, "#b2f2bb", "#22c55e", "Step Two"))
elements.append(bound_arrow("a1", elements, "a", [1, 0.5], "b", [0, 0.5]))
write_scene(elements, "/path/to/output.excalidraw")
PYEOFFor shapes without the convenience, pair with .
labeled_rectrect(..., bound_text="tid")txt(..., container="rid", align="center", valign="middle")生成包含所有必填字段的原生文件。可在bash heredoc中内联使用,也可作为库导入。
.excalidraw核心函数:
| 函数 | 返回值 | 用途 |
|---|---|---|
| | 包含居中关联文本的形状(处理所有关联和字段生成) |
| 元素 | 无文本的矩形 |
| 元素 | 独立或关联的文本 |
| 元素 | 锚定到两个形状的箭头(会修改形状的 |
| 元素 | 未锚定/悬浮的箭头(连接形状时请改用 |
| 元素 | 其他形状类型 |
| 写入文件 | 将元素包装为场景结构并保存 |
示例:
bash
python3 << 'PYEOF'
import sys, random
sys.path.insert(0, "/Users/samm/.claude/skills/excalidraw-diagrams/scripts")
from generate_excalidraw import *
random.seed(42)
elements = []
elements.append(txt("t1", 200, 10, 300, 30, "My Diagram", 24))
elements.extend(labeled_rect("a", 50, 60, 200, 70, "#a5d8ff", "#4a9eed", "Step One"))
elements.extend(labeled_rect("b", 350, 60, 200, 70, "#b2f2bb", "#22c55e", "Step Two"))
elements.append(bound_arrow("a1", elements, "a", [1, 0.5], "b", [0, 0.5]))
write_scene(elements, "/path/to/output.excalidraw")
PYEOF对于没有便捷方法的形状,可将与配合使用。
labeled_rectrect(..., bound_text="tid")txt(..., container="rid", align="center", valign="middle")Arrow anchoring
箭头锚定
By default, arrows float free - moving a shape leaves the arrow behind. Use instead of to anchor arrows to shapes. It handles the bidirectional binding automatically (arrow references shapes, shapes list the arrow in ).
bound_arrowarrowboundElementsfixedPoint[0.5, 0][1, 0.5][0.5, 1][0, 0.5][fx, fy]Important:
- Shapes must already exist in before calling
elements, since it looks them up and mutates theirbound_arrow.boundElements - Minimum 60px between connected shapes. Excalidraw recalculates bound arrow geometry at render time. When shapes are too close together (under ~60px gap), arrows overlap and pass through boxes instead of connecting at edges. The script warns if this threshold is violated. Plan layouts with adequate spacing.
- Avoid large background rectangles that overlap connectable shapes. Excalidraw's binding resolution can misfire when a bound arrow's endpoint falls inside a background rect that overlaps the intended target shape. If you need section backgrounds, add them after all bound arrows, or use standalone text labels and colour-coded boxes instead.
For the inline workflow, use / with directly on arrow elements.
create_viewstartBindingendBindingfixedPoint默认情况下,箭头是悬浮的——移动形状时箭头会留在原地。请使用替代来将箭头锚定到形状上,它会自动处理双向关联(箭头引用形状,形状在中列出箭头)。
bound_arrowarrowboundElements形状连接点的值:顶部=、右侧=、底部=、左侧=。任何值都有效,其中0,0是形状的左上角,1,1是右下角。
fixedPoint[0.5, 0][1, 0.5][0.5, 1][0, 0.5][fx, fy]重要注意事项:
- 调用前,形状必须已存在于
bound_arrow中,因为它需要查找并修改形状的elements。boundElements - 连接的形状之间至少保持60px间距。Excalidraw会在渲染时重新计算关联箭头的几何形状。当形状间距过近(小于约60px)时,箭头会重叠并穿过方框,而非连接到边缘。如果违反此阈值,脚本会发出警告。规划布局时请预留足够的间距。
- 避免使用会覆盖可连接形状的大型背景矩形。当关联箭头的端点落在覆盖目标形状的背景矩形内时,Excalidraw的关联解析可能会出错。如果需要分区背景,请在所有关联箭头添加完成后再添加背景,或使用独立文本标签和颜色编码的方框替代。
对于在线工作流,可在箭头元素上直接使用带的/。
create_viewfixedPointstartBindingendBindingPrivacy
隐私说明
Note that if the diagram contains potentially sensitive information (e.g. detailed network diagrams, identifiable information etc...) and the user asks you to upload the diagram to excalidraw.com - you should first warn them that this will make the diagram publicly accessible and ask if they want to proceed.
请注意,如果图表包含潜在敏感信息(例如详细的网络图表、可识别信息等),且用户要求你将图表上传到excalidraw.com,你应首先警告用户这会使图表公开可访问,并询问用户是否要继续。