Skip to content

Agent skill that turns natural language, code, Terraform/K8s, SQL, OpenAPI, AsyncAPI, Protobuf and GraphQL sources into editable, tested draw.io architecture diagrams: incremental sync, multi-view projection, drift diff, CI architecture tests, whiteboard derasterize, interactive HTML/PPTX/Mermaid exports.

feat: add tubemap.py — Tube-Map Mode (graph as a metro map)

Agents365-aid7c00df1e508
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0a58805..138625e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,20 @@ All notable changes to **drawio-skill** are documented here. The format is based
on [Keep a Changelog](https://keepachangelog.com/), and the project follows
semantic-ish versioning (the `version:` field in `skills/drawio-skill/SKILL.md`).
+## [1.34.0] — 2026-07-14
+### Added
+- **`scripts/tubemap.py`** — Tube-Map Mode: restyle a graph as a London-
+ Underground-style metro map. From a metro JSON (coloured *lines* = ordered
+ stations on an integer grid, shared stations = interchanges) it draws thick
+ coloured line strokes with octilinear routing (horizontal / vertical / 45°,
+ one automatic diagonal-then-straight bend when two stations aren't aligned),
+ white-fill black-ring interchange circles, small station stops, and offset
+ labels — an editable `.drawio`. Stdlib-only, no draw.io CLI or Graphviz
+ needed; a line without a `color` is assigned one from a built-in tube palette.
+ Schema + the one grid rule in `references/tubemap.md`. Scripts: 36 → 37;
+ tests: 116 → 128 (`test_tubemap` 12). Routing rows in SKILL.md's resources
+ table, toolbox (quick-guide + §1), and a README/README_CN example + demo image.
+
## [1.33.0] — 2026-07-14
### Added
- **`scripts/raster2drawio.py`** — image → editable `.drawio`. Converts a
diff --git a/README.md b/README.md
index 225f0f4..2a1b90c 100644
--- a/README.md
+++ b/README.md
@@ -84,6 +84,12 @@ It also speaks **Mermaid** — standard types (flowchart, mindmap, **kanban**, g
<img src="assets/kanban.png" width="900" alt="Kanban board generated by drawio-skill from Mermaid — this project's roadmap across Backlog / Todo / In Progress / Done">
</div>
+**Tube-Map Mode** restyles a pipeline or journey as a London-Underground-style metro map — coloured lines, octilinear (H/V/45°) routing, and white interchange circles. Here's the skill's own flow (this map is `assets/tubemap.json`, ~20 lines):
+
+<div align="center">
+ <img src="assets/tubemap.png" width="720" alt="drawio-skill's pipeline drawn as a metro map — Author / Import / Repurpose / Analyze lines meeting at the Auto-layout and .drawio interchange stations">
+</div>
+
Full walkthrough in [docs/USAGE.md](docs/USAGE.md).
## 🚀 Installation
@@ -233,6 +239,9 @@ python3 scripts/runbook.py triage.drawio -o triage.html
# CI: render base/head/diff PNGs + Markdown report for every .drawio a PR changed
python3 scripts/prdiff.py --base origin/main --head HEAD -o drawio-pr/report.md
+
+# Tube-Map Mode — restyle a pipeline / journey as a metro / subway map
+python3 scripts/tubemap.py metro.json -o metro.drawio
```
| Piece | What it does |
diff --git a/README_CN.md b/README_CN.md
index 74e36b2..07b53ce 100644
--- a/README_CN.md
+++ b/README_CN.md
@@ -83,6 +83,12 @@ Skill 在多种图表拓扑中尽量保持线条清晰路由,避免穿越无
<img src="assets/kanban-cn.png" width="900" alt="drawio-skill 用 Mermaid 生成的看板 —— 本项目路线图,分为 需求池 / 待办 / 进行中 / 已完成">
</div>
+**Tube-Map 模式** 把流水线或旅程重绘成伦敦地铁风格的线路图 —— 彩色线路、八向(水平/垂直/45°)路由、白色换乘圈。下面是 skill 自己的处理流程(这张图就是 `assets/tubemap-cn.json`,约 20 行):
+
+<div align="center">
+ <img src="assets/tubemap-cn.png" width="720" alt="drawio-skill 的处理流程画成地铁图 —— 作图 / 导入 / 二次利用 / 分析四条线在「自动布局」和「.drawio」两个换乘站汇合">
+</div>
+
完整演练见 [docs/USAGE_CN.md](docs/USAGE_CN.md)。
## 🚀 安装
@@ -231,6 +237,9 @@ python3 scripts/runbook.py triage.drawio -o triage.html
# CI:为 PR 改动的每个 .drawio 渲染 base/head/diff PNG + Markdown 报告
python3 scripts/prdiff.py --base origin/main --head HEAD -o drawio-pr/report.md
+
+# Tube-Map 模式 —— 把流水线 / 旅程重绘成地铁风格线路图
+python3 scripts/tubemap.py metro.json -o metro.drawio
```
| 组件 | 作用 |
diff --git a/assets/tubemap-cn.drawio b/assets/tubemap-cn.drawio
new file mode 100644
index 0000000..02b89f8
--- /dev/null
+++ b/assets/tubemap-cn.drawio
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mxfile host="drawio-skill" type="device">
+ <diagram id="tube" name="Tube Map">
+ <mxGraphModel dx="0" dy="0" grid="0" gridSize="10" pageWidth="1180" pageHeight="640" math="0" shadow="0" background="#ffffff">
+ <root><mxCell id="0"/><mxCell id="1" parent="0"/>
+ <mxCell id="e2" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#0098d4;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="80" y="300" as="sourcePoint"/><mxPoint x="300" y="300" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e3" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#0098d4;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="300" y="300" as="sourcePoint"/><mxPoint x="520" y="300" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e4" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#0098d4;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="520" y="300" as="sourcePoint"/><mxPoint x="740" y="300" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e5" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#0098d4;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="740" y="300" as="sourcePoint"/><mxPoint x="960" y="300" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e6" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#007d32;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="190" y="520" as="sourcePoint"/><mxPoint x="410" y="520" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e7" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#007d32;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="410" y="520" as="sourcePoint"/><mxPoint x="520" y="300" as="targetPoint"/><Array as="points"><mxPoint x="520" y="410"/></Array></mxGeometry></mxCell>
+ <mxCell id="e8" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#ee7c0e;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="740" y="300" as="sourcePoint"/><mxPoint x="740" y="520" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e9" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#ee7c0e;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="740" y="520" as="sourcePoint"/><mxPoint x="960" y="520" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e10" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#e1251b;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="740" y="300" as="sourcePoint"/><mxPoint x="740" y="80" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e11" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#e1251b;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="740" y="80" as="sourcePoint"/><mxPoint x="960" y="80" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="s12" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="72" y="292" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l13" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="自然语言"><mxGeometry x="97" y="288" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s14" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="292" y="292" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l15" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="手写 XML / Mermaid"><mxGeometry x="317" y="288" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s16" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#111111;strokeWidth=3;html=1;" value=""><mxGeometry x="505" y="285" width="30" height="30" as="geometry"/></mxCell>
+ <mxCell id="l17" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="自动布局"><mxGeometry x="537" y="288" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s18" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#111111;strokeWidth=3;html=1;" value=""><mxGeometry x="725" y="285" width="30" height="30" as="geometry"/></mxCell>
+ <mxCell id="l19" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value=".drawio(可编辑)"><mxGeometry x="757" y="288" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s20" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="952" y="292" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l21" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="PNG · SVG · PDF"><mxGeometry x="977" y="288" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s22" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="182" y="512" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l23" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="代码 / IaC / SQL"><mxGeometry x="207" y="508" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s24" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="402" y="512" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l25" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="提取图结构"><mxGeometry x="427" y="508" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s26" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="732" y="512" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l27" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="SVG 动画"><mxGeometry x="757" y="508" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s28" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="952" y="512" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l29" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="HTML 查看器"><mxGeometry x="977" y="508" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s30" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="732" y="72" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l31" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="差异 / 漂移"><mxGeometry x="757" y="68" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s32" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="952" y="72" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l33" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="高管压缩"><mxGeometry x="977" y="68" width="170" height="24" as="geometry"/></mxCell>
+ </root></mxGraphModel></diagram></mxfile>
\ No newline at end of file
diff --git a/assets/tubemap-cn.json b/assets/tubemap-cn.json
new file mode 100644
index 0000000..0a0f729
--- /dev/null
+++ b/assets/tubemap-cn.json
@@ -0,0 +1,21 @@
+{
+ "stations": {
+ "nl": {"label": "自然语言", "gx": 0, "gy": 2},
+ "author": {"label": "手写 XML / Mermaid", "gx": 2, "gy": 2},
+ "layout": {"label": "自动布局", "gx": 4, "gy": 2, "interchange": true},
+ "drawio": {"label": ".drawio(可编辑)", "gx": 6, "gy": 2, "interchange": true},
+ "export": {"label": "PNG · SVG · PDF", "gx": 8, "gy": 2},
+ "code": {"label": "代码 / IaC / SQL", "gx": 1, "gy": 4},
+ "extract": {"label": "提取图结构", "gx": 3, "gy": 4},
+ "svg": {"label": "SVG 动画", "gx": 6, "gy": 4},
+ "html": {"label": "HTML 查看器", "gx": 8, "gy": 4},
+ "diff": {"label": "差异 / 漂移", "gx": 6, "gy": 0},
+ "compress":{"label": "高管压缩", "gx": 8, "gy": 0}
+ },
+ "lines": [
+ {"name": "作图", "color": "#0098d4", "stations": ["nl", "author", "layout", "drawio", "export"]},
+ {"name": "导入", "color": "#007d32", "stations": ["code", "extract", "layout"]},
+ {"name": "二次利用","color": "#ee7c0e", "stations": ["drawio", "svg", "html"]},
+ {"name": "分析", "color": "#e1251b", "stations": ["drawio", "diff", "compress"]}
+ ]
+}
diff --git a/assets/tubemap-cn.png b/assets/tubemap-cn.png
new file mode 100644
index 0000000..84d7c31
Binary files /dev/null and b/assets/tubemap-cn.png differ
diff --git a/assets/tubemap.drawio b/assets/tubemap.drawio
new file mode 100644
index 0000000..c2c9fa7
--- /dev/null
+++ b/assets/tubemap.drawio
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<mxfile host="drawio-skill" type="device">
+ <diagram id="tube" name="Tube Map">
+ <mxGraphModel dx="0" dy="0" grid="0" gridSize="10" pageWidth="1180" pageHeight="640" math="0" shadow="0" background="#ffffff">
+ <root><mxCell id="0"/><mxCell id="1" parent="0"/>
+ <mxCell id="e2" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#0098d4;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="80" y="300" as="sourcePoint"/><mxPoint x="300" y="300" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e3" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#0098d4;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="300" y="300" as="sourcePoint"/><mxPoint x="520" y="300" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e4" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#0098d4;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="520" y="300" as="sourcePoint"/><mxPoint x="740" y="300" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e5" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#0098d4;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="740" y="300" as="sourcePoint"/><mxPoint x="960" y="300" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e6" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#007d32;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="190" y="520" as="sourcePoint"/><mxPoint x="410" y="520" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e7" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#007d32;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="410" y="520" as="sourcePoint"/><mxPoint x="520" y="300" as="targetPoint"/><Array as="points"><mxPoint x="520" y="410"/></Array></mxGeometry></mxCell>
+ <mxCell id="e8" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#ee7c0e;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="740" y="300" as="sourcePoint"/><mxPoint x="740" y="520" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e9" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#ee7c0e;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="740" y="520" as="sourcePoint"/><mxPoint x="960" y="520" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e10" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#e1251b;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="740" y="300" as="sourcePoint"/><mxPoint x="740" y="80" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="e11" edge="1" parent="1" style="endArrow=none;startArrow=none;strokeColor=#e1251b;strokeWidth=9;rounded=1;html=1;edgeStyle=none;"><mxGeometry relative="1" as="geometry"><mxPoint x="740" y="80" as="sourcePoint"/><mxPoint x="960" y="80" as="targetPoint"/></mxGeometry></mxCell>
+ <mxCell id="s12" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="72" y="292" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l13" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="Natural language"><mxGeometry x="97" y="288" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s14" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="292" y="292" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l15" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="Hand-XML / Mermaid"><mxGeometry x="317" y="288" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s16" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#111111;strokeWidth=3;html=1;" value=""><mxGeometry x="505" y="285" width="30" height="30" as="geometry"/></mxCell>
+ <mxCell id="l17" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="Auto-layout"><mxGeometry x="537" y="288" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s18" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#111111;strokeWidth=3;html=1;" value=""><mxGeometry x="725" y="285" width="30" height="30" as="geometry"/></mxCell>
+ <mxCell id="l19" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value=".drawio (editable)"><mxGeometry x="757" y="288" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s20" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="952" y="292" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l21" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="PNG · SVG · PDF"><mxGeometry x="977" y="288" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s22" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="182" y="512" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l23" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="Code / IaC / SQL"><mxGeometry x="207" y="508" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s24" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="402" y="512" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l25" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="Extract graph"><mxGeometry x="427" y="508" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s26" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="732" y="512" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l27" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="SVG animation"><mxGeometry x="757" y="508" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s28" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="952" y="512" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l29" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="HTML viewer"><mxGeometry x="977" y="508" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s30" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="732" y="72" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l31" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="Diff / drift"><mxGeometry x="757" y="68" width="170" height="24" as="geometry"/></mxCell>
+ <mxCell id="s32" vertex="1" parent="1" style="ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;html=1;" value=""><mxGeometry x="952" y="72" width="16" height="16" as="geometry"/></mxCell>
+ <mxCell id="l33" vertex="1" parent="1" style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;fontColor=#222222;labelBackgroundColor=#ffffff;" value="Exec compress"><mxGeometry x="977" y="68" width="170" height="24" as="geometry"/></mxCell>
+ </root></mxGraphModel></diagram></mxfile>
\ No newline at end of file
diff --git a/assets/tubemap.json b/assets/tubemap.json
new file mode 100644
index 0000000..6aeba4a
--- /dev/null
+++ b/assets/tubemap.json
@@ -0,0 +1,21 @@
+{
+ "stations": {
+ "nl": {"label": "Natural language", "gx": 0, "gy": 2},
+ "author": {"label": "Hand-XML / Mermaid", "gx": 2, "gy": 2},
+ "layout": {"label": "Auto-layout", "gx": 4, "gy": 2, "interchange": true},
+ "drawio": {"label": ".drawio (editable)", "gx": 6, "gy": 2, "interchange": true},
+ "export": {"label": "PNG · SVG · PDF", "gx": 8, "gy": 2},
+ "code": {"label": "Code / IaC / SQL", "gx": 1, "gy": 4},
+ "extract": {"label": "Extract graph", "gx": 3, "gy": 4},
+ "svg": {"label": "SVG animation", "gx": 6, "gy": 4},
+ "html": {"label": "HTML viewer", "gx": 8, "gy": 4},
+ "diff": {"label": "Diff / drift", "gx": 6, "gy": 0},
+ "compress":{"label": "Exec compress", "gx": 8, "gy": 0}
+ },
+ "lines": [
+ {"name": "Author", "color": "#0098d4", "stations": ["nl", "author", "layout", "drawio", "export"]},
+ {"name": "Import", "color": "#007d32", "stations": ["code", "extract", "layout"]},
+ {"name": "Repurpose", "color": "#ee7c0e", "stations": ["drawio", "svg", "html"]},
+ {"name": "Analyze", "color": "#e1251b", "stations": ["drawio", "diff", "compress"]}
+ ]
+}
diff --git a/assets/tubemap.png b/assets/tubemap.png
new file mode 100644
index 0000000..bad03e9
Binary files /dev/null and b/assets/tubemap.png differ
diff --git a/skills/drawio-skill/SKILL.md b/skills/drawio-skill/SKILL.md
index 7b5f9ef..3b8a332 100644
--- a/skills/drawio-skill/SKILL.md
+++ b/skills/drawio-skill/SKILL.md
@@ -1,6 +1,6 @@
---
name: drawio-skill
-version: 1.33.0
+version: 1.34.0
description: Use when the user requests diagrams, flowcharts, architecture diagrams, ER diagrams, UML / sequence / class diagrams, SysML / MBSE diagrams (block definition, internal block, requirement, parametric), BPMN business process diagrams, swimlane / cross-functional flowcharts, network topology, cloud architecture from Terraform or Kubernetes manifests, ML/DL model figures (Transformer/CNN/LSTM), mind maps, or any visualization. Also use proactively when explaining systems with 3+ components, complex data flows, or relationships that benefit from visual representation. Best suited when the diagram needs custom styling, rich shape vocabulary, swimlanes, or exportable images (PNG/SVG/PDF/JPG). Generates .drawio XML and exports locally via the native draw.io desktop CLI.
license: MIT
homepage: https://github.com/Agents365-ai/drawio-skill
@@ -71,6 +71,7 @@ When the workflow references one of these, read it on demand — none of them ne
| `scripts/compress.py` | The user wants an **executive / boardroom summary of a big diagram** — collapses clusters (pure-Python label propagation, no networkx) into one labeled node each with aggregated inter-cluster edges, emitting a 2-page `.drawio` (exec view + click-to-drill-down into the full original). Claude can rename clusters semantically afterward. Needs Graphviz `dot` |
| `scripts/runbook.py` | The user wants a flowchart/decision-tree `.drawio` turned into a **click-through triage app** (on-call runbook) — `runbook.py flow.drawio` reads the XML (no draw.io CLI needed) and emits a self-contained HTML runbook: current-step text, per-edge choice buttons, breadcrumb trail, Back/Restart, end-state on terminal nodes |
| `scripts/prdiff.py` | You're setting up **automated PR diagram review** in CI — for every `.drawio` changed between two git refs it renders base/head/diff PNGs and emits a Markdown report; ships with a composite GitHub Action (`.github/actions/drawio-diff/`) that posts a sticky PR comment. See `references/pr-bot.md` |
+| `scripts/tubemap.py` | The user wants a **metro / subway / tube map** — a system, pipeline, or journey drawn as coloured transit lines with octilinear (H/V/45°) routing, white interchange circles, and station stops. Compose a metro JSON (lines = ordered stations on an integer grid, shared stations = interchanges), then `tubemap.py metro.json -o metro.drawio`. Stdlib-only; schema + the one grid rule in `references/tubemap.md` |
## Prerequisites
diff --git a/skills/drawio-skill/references/toolbox.md b/skills/drawio-skill/references/toolbox.md
index ef70086..84c2f36 100644
--- a/skills/drawio-skill/references/toolbox.md
+++ b/skills/drawio-skill/references/toolbox.md
@@ -43,12 +43,14 @@ exports it:
| a big/sprawling diagram | a boardroom exec summary + drill-down | `compress` |
| a decision-tree flowchart | a click-through triage app | `runbook` (→ HTML, no CLI) |
| a PR touching `.drawio` | rendered before/after/diff for reviewers | `prdiff` (+ GitHub Action) |
+| a pipeline / journey / subsystem map | it drawn as a metro / subway map | `tubemap` (coloured lines, octilinear, interchanges) |
## 1. Author & place
- **`autolayout.py`** — graph JSON → placed `.drawio` (Graphviz `dot`; orthogonal routing, `--group` containers, `--tune` best direction). The hub every extractor feeds. See `references/autolayout.md`.
- **`seqlayout.py`** — participants + messages JSON → sequence diagram with computed lifelines/activation bars (no Graphviz).
- **`c4.py`** — levels JSON → one multi-page `.drawio` (Context→Container→Component) with click-to-drill-down links.
+- **`tubemap.py`** — metro JSON (coloured lines + grid-placed stations) → a London-Underground-style **tube map**: octilinear (H/V/45°) routing, white interchange circles, station stops. No Graphviz. See `references/tubemap.md`.
- **`shapesearch.py`** — search 10k+ official shapes for their exact `style=` string. **`aiicons.py`** — draw.io `image` styles for AI/LLM brand logos.
- **`raster2drawio.py`** — a vision-extracted image graph JSON (from a whiteboard photo / legacy PNG / Visio screenshot) → editable `.drawio` honouring the read coordinates; missing positions fall back to `autolayout.py`. See `references/derasterize.md`.
diff --git a/skills/drawio-skill/references/tubemap.md b/skills/drawio-skill/references/tubemap.md
new file mode 100644
index 0000000..5c0ecf3
--- /dev/null
+++ b/skills/drawio-skill/references/tubemap.md
@@ -0,0 +1,67 @@
+# Tube-Map Mode — a graph as a metro map
+
+`scripts/tubemap.py` restyles a graph as a **London-Underground-style metro map**:
+thick coloured lines, octilinear routing (horizontal / vertical / 45° only), white
+interchange circles, small station stops, and offset labels — the instantly-readable
+transit-map aesthetic.
+
+Read this when the user asks for a "metro map", "subway map", "tube map", or wants a
+system / pipeline / journey drawn as coloured transit lines instead of a boxes-and-
+arrows diagram.
+
+```bash
+python3 <this-skill-dir>/scripts/tubemap.py metro.json -o metro.drawio
+# then the normal workflow: validate.py → preview PNG → self-check → export
+```
+
+## When it fits
+
+A tube map reads best when the graph is a set of **overlapping paths** that share a few
+**interchange** nodes — pipelines, user journeys, request flows, a product's subsystems,
+a roadmap of parallel workstreams. It is *not* the right choice for a dense mesh or a
+strict hierarchy (use `autolayout.py` / a diagram-type preset for those).
+
+## Input schema
+
+You (the model) compose the metro JSON — from a system description, or by reading an
+existing diagram's structure and grouping its edges into a handful of named "lines".
+
+```json
+{
+ "stations": {
+ "nl": {"label": "Natural language", "gx": 0, "gy": 2},
+ "layout": {"label": "Auto-layout", "gx": 4, "gy": 2, "interchange": true},
+ "drawio": {"label": ".drawio", "gx": 6, "gy": 2, "interchange": true}
+ },
+ "lines": [
+ {"name": "Author", "color": "#0098d4", "stations": ["nl", "layout", "drawio"]},
+ {"name": "Import", "stations": ["code", "extract", "layout"]}
+ ]
+}
+```
+
+| Field | Required | Notes |
+|---|---|---|
+| `stations.<id>.label` | no (defaults to id) | Station name; XML-escaped automatically |
+| `stations.<id>.gx` / `gy` | **yes** | Integer **grid** coordinates (not pixels); `--grid` sets the pitch (default 110px) |
+| `stations.<id>.interchange` | no | `true` → white-fill black-ring circle (a transfer station); else a small stop |
+| `lines[].name` | no | For your own reference |
+| `lines[].color` | no | `#rrggbb`; a line without one gets the next colour from the built-in tube palette |
+| `lines[].stations` | **yes** | Ordered station ids the line passes through; a station id may appear on several lines (that's an interchange) |
+
+## The one layout rule: keep segments octilinear
+
+For the crispest map, place each line's consecutive stations so they are **aligned
+horizontally, vertically, or on a 45° diagonal** (same `gx`, same `gy`, or equal
+`|Δgx| == |Δgy|`). When two stations aren't aligned, the script inserts **one** bend —
+it runs the 45° diagonal for the shorter delta, then a straight axis segment into the
+target — so the line still reads as a metro line rather than an arbitrary curve. Mark the
+nodes where lines cross as `interchange: true`.
+
+## Limitation
+
+`tubemap.py` honours the grid coordinates you give it — it does **not** solve the
+(NP-hard) octilinear metro-layout problem for you. Placing the stations on a sensible
+grid is the authoring step; the script does the drawing, routing, markers, and colours.
+Parallel lines sharing the exact same segment are drawn on top of each other (offset them
+by a grid row if you need both visible).
diff --git a/skills/drawio-skill/scripts/tubemap.py b/skills/drawio-skill/scripts/tubemap.py
new file mode 100644
index 0000000..e893ae2
--- /dev/null
+++ b/skills/drawio-skill/scripts/tubemap.py
@@ -0,0 +1,177 @@
+#!/usr/bin/env python3
+"""Restyle a graph as a London-Underground-style metro map (Tube-Map Mode).
+
+Input JSON describes coloured *lines* (each an ordered list of station ids) and the
+*stations* they pass through, placed on an integer grid. The script snaps stations to
+a pixel grid, routes every line segment octilinearly (horizontal / vertical / 45°
+diagonal, inserting one bend when two stations are not already aligned), draws thick
+coloured line strokes, marks interchange stations as white-fill black-ring circles and
+regular stops as small white circles, and labels each station — the classic tube-map
+look — as an editable `.drawio`.
+
+ python3 tubemap.py metro.json -o metro.drawio
+
+Input schema (see references/tubemap.md for the full authoring guide):
+
+ {
+ "stations": {
+ "<id>": {"label": "...", "gx": <int>, "gy": <int>, "interchange": <bool?>}
+ },
+ "lines": [
+ {"name": "...", "color": "#rrggbb"?, "stations": ["<id>", "<id>", ...]}
+ ]
+ }
+
+Keep consecutive stations on a line horizontally, vertically, or 45°-diagonally aligned
+for the cleanest routing; any other offset gets one automatic diagonal-then-straight
+bend. A line with no "color" is assigned one from the default tube palette by order.
+
+Usage: python3 tubemap.py <metro.json> [-o out.drawio] [--grid N]
+"""
+import argparse
+import json
+import sys
+
+# Default palette (approx. real tube-line colours), cycled for lines lacking a "color".
+TUBE_PALETTE = [
+ "#0098d4", # blue
+ "#007d32", # green
+ "#e1251b", # red
+ "#ee7c0e", # orange
+ "#9b0056", # magenta
+ "#00a4a7", # teal
+ "#ffce00", # yellow
+ "#894e24", # brown
+]
+
+
+def esc(s):
+ return (s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;")
+ .replace('"', "&quot;"))
+
+
+def octilinear_waypoints(x1, y1, x2, y2):
+ """Waypoints so the path is horizontal, vertical, or 45°: diagonal then straight.
+
+ Returns [] when the two points are already octilinearly aligned, else a single bend
+ point (run the 45° diagonal for the shorter delta, then a straight axis segment).
+ """
+ dx, dy = x2 - x1, y2 - y1
+ if dx == 0 or dy == 0 or abs(dx) == abs(dy):
+ return []
+ sx = 1 if dx > 0 else -1
+ sy = 1 if dy > 0 else -1
+ d = min(abs(dx), abs(dy))
+ if abs(dx) > abs(dy): # diagonal first, then horizontal into the target
+ return [(x1 + sx * d, y2)]
+ return [(x2, y1 + sy * d)] # diagonal first, then vertical into the target
+
+
+def build(data, grid=110):
+ """Build the tube-map `.drawio` XML string from the parsed metro description."""
+ stations = data.get("stations", {})
+ lines = data.get("lines", [])
+ if not stations:
+ sys.exit("error: no stations in input")
+ for ln in lines:
+ for sid in ln.get("stations", []):
+ if sid not in stations:
+ sys.exit(f"error: line {ln.get('name', '?')!r} references unknown "
+ f"station id {sid!r}")
+
+ ox = oy = 80
+ G = grid
+
+ def px(sid):
+ s = stations[sid]
+ return ox + int(s["gx"]) * G, oy + int(s["gy"]) * G
+
+ maxx = ox + max(int(s["gx"]) for s in stations.values()) * G + 220
+ maxy = oy + max(int(s["gy"]) for s in stations.values()) * G + 120
+ lw = max(8, G // 12)
+
+ out = ['<?xml version="1.0" encoding="UTF-8"?>',
+ '<mxfile host="drawio-skill" type="device">',
+ ' <diagram id="tube" name="Tube Map">',
+ f' <mxGraphModel dx="0" dy="0" grid="0" gridSize="10" pageWidth="{maxx}" '
+ f'pageHeight="{maxy}" math="0" shadow="0" background="#ffffff">',
+ ' <root><mxCell id="0"/><mxCell id="1" parent="0"/>']
+
+ nid = [2]
+
+ def cid():
+ c = nid[0]
+ nid[0] += 1
+ return c
+
+ # 1) Line strokes first, so station markers sit on top of them.
+ for i, ln in enumerate(lines):
+ col = ln.get("color") or TUBE_PALETTE[i % len(TUBE_PALETTE)]
+ sts = ln.get("stations", [])
+ for a, b in zip(sts, sts[1:]):
+ x1, y1 = px(a)
+ x2, y2 = px(b)
+ wps = octilinear_waypoints(x1, y1, x2, y2)
+ arr = ""
+ if wps:
+ pts = "".join(f'<mxPoint x="{wx}" y="{wy}"/>' for wx, wy in wps)
+ arr = f'<Array as="points">{pts}</Array>'
+ out.append(
+ f' <mxCell id="e{cid()}" edge="1" parent="1" '
+ f'style="endArrow=none;startArrow=none;strokeColor={col};strokeWidth={lw};'
+ f'rounded=1;html=1;edgeStyle=none;">'
+ f'<mxGeometry relative="1" as="geometry">'
+ f'<mxPoint x="{x1}" y="{y1}" as="sourcePoint"/>'
+ f'<mxPoint x="{x2}" y="{y2}" as="targetPoint"/>{arr}</mxGeometry></mxCell>')
+
+ # 2) Station markers + labels.
+ for sid, s in stations.items():
+ x, y = px(sid)
+ label = esc(str(s.get("label", sid)))
+ if s.get("interchange"):
+ r = lw + 6
+ marker = (f'ellipse;fillColor=#ffffff;strokeColor=#111111;strokeWidth=3;'
+ f'html=1;')
+ else:
+ r = lw - 1
+ marker = (f'ellipse;fillColor=#ffffff;strokeColor=#555555;strokeWidth=2;'
+ f'html=1;')
+ out.append(
+ f' <mxCell id="s{cid()}" vertex="1" parent="1" style="{marker}" '
+ f'value=""><mxGeometry x="{x - r}" y="{y - r}" width="{2 * r}" '
+ f'height="{2 * r}" as="geometry"/></mxCell>')
+ out.append(
+ f' <mxCell id="l{cid()}" vertex="1" parent="1" '
+ f'style="text;html=1;align=left;verticalAlign=middle;fontSize=13;fontStyle=1;'
+ f'fontColor=#222222;labelBackgroundColor=#ffffff;" value="{label}">'
+ f'<mxGeometry x="{x + lw + 8}" y="{y - 12}" width="170" height="24" '
+ f'as="geometry"/></mxCell>')
+
+ out.append(' </root></mxGraphModel></diagram></mxfile>')
+ return "\n".join(out), len(stations), len(lines)
+
+
+def main():
+ ap = argparse.ArgumentParser(description="Restyle a graph as a metro / tube map.")
+ ap.add_argument("input", help="metro JSON (or - for stdin)")
+ ap.add_argument("-o", "--output", help="output .drawio (default: stdout)")
+ ap.add_argument("--grid", type=int, default=110, help="grid pitch in px (default 110)")
+ args = ap.parse_args()
+
+ raw = sys.stdin.read() if args.input == "-" else open(args.input, encoding="utf-8").read()
+ try:
+ data = json.loads(raw)
+ except json.JSONDecodeError as exc:
+ sys.exit(f"error: bad JSON in {args.input}: {exc}")
+
+ xml, n_st, n_ln = build(data, grid=args.grid)
+ if args.output:
+ with open(args.output, "w", encoding="utf-8") as f:
+ f.write(xml)
+ sys.stderr.write(f"wrote {args.output} ({n_st} stations, {n_ln} lines)\n")
+ else:
+ sys.stdout.write(xml)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/tests/test_tubemap.py b/tests/test_tubemap.py
new file mode 100644
index 0000000..9abd834
--- /dev/null
+++ b/tests/test_tubemap.py
@@ -0,0 +1,115 @@
+"""Tests for scripts/tubemap.py (Tube-Map Mode).
+
+Pure-function tests — tubemap builds `.drawio` XML directly from a metro JSON and
+needs neither the draw.io CLI nor Graphviz.
+"""
+import importlib.util
+import json
+import os
+import subprocess
+import sys
+import unittest
+
+ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+SCRIPTS = os.path.join(ROOT, "skills", "drawio-skill", "scripts")
+
+
+def load(name):
+ path = os.path.join(SCRIPTS, name + ".py")
+ spec = importlib.util.spec_from_file_location(name, path)
+ mod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(mod)
+ return mod
+
+
+def run(script, *args, **kw):
+ return subprocess.run(
+ [sys.executable, os.path.join(SCRIPTS, script), *args],
+ capture_output=True, text=True, **kw)
+
+
+tm = load("tubemap")
+
+DEMO = {
+ "stations": {
+ "a": {"label": "A", "gx": 0, "gy": 0},
+ "b": {"label": "B", "gx": 2, "gy": 0, "interchange": True},
+ "c": {"label": "C & <x>", "gx": 2, "gy": 2},
+ "d": {"label": "D", "gx": 4, "gy": 1},
+ },
+ "lines": [
+ {"name": "L1", "color": "#0098d4", "stations": ["a", "b", "c"]},
+ {"name": "L2", "stations": ["b", "d"]}, # no colour → palette
+ ],
+}
+
+
+class TestOctilinear(unittest.TestCase):
+ def test_horizontal_needs_no_bend(self):
+ self.assertEqual(tm.octilinear_waypoints(0, 0, 5, 0), [])
+
+ def test_vertical_needs_no_bend(self):
+ self.assertEqual(tm.octilinear_waypoints(0, 0, 0, 5), [])
+
+ def test_exact_diagonal_needs_no_bend(self):
+ self.assertEqual(tm.octilinear_waypoints(0, 0, 4, 4), [])
+ self.assertEqual(tm.octilinear_waypoints(0, 0, -3, 3), [])
+
+ def test_wide_delta_goes_diagonal_then_horizontal(self):
+ # dx=4, dy=1: diagonal run length 1, then straight into the target row.
+ self.assertEqual(tm.octilinear_waypoints(0, 0, 4, 1), [(1, 1)])
+
+ def test_tall_delta_goes_diagonal_then_vertical(self):
+ # dx=1, dy=4: diagonal run length 1, then straight into the target column.
+ self.assertEqual(tm.octilinear_waypoints(0, 0, 1, 4), [(1, 1)])
+
+ def test_bend_lands_on_the_target_axis(self):
+ # The single bend must leave a final straight (axis-aligned) run to the target.
+ for x2, y2 in [(7, 2), (2, 7), (-6, 3), (3, -6)]:
+ wp = tm.octilinear_waypoints(0, 0, x2, y2)
+ self.assertEqual(len(wp), 1)
+ bx, by = wp[0]
+ self.assertTrue(bx == x2 or by == y2,
+ f"bend {wp[0]} not aligned with target ({x2},{y2})")
+
+
+class TestBuild(unittest.TestCase):
+ def test_counts_and_wellformed(self):
+ xml, n_st, n_ln = tm.build(DEMO, grid=100)
+ self.assertEqual((n_st, n_ln), (4, 2))
+ self.assertTrue(xml.startswith("<?xml"))
+ self.assertIn('<mxCell id="1" parent="0"/>', xml) # layer footgun honoured
+
+ def test_interchange_marker_distinct(self):
+ xml, _, _ = tm.build(DEMO, grid=100)
+ # Interchange stations use the black ring; regular stops the grey ring.
+ self.assertIn("strokeColor=#111111", xml)
+ self.assertIn("strokeColor=#555555", xml)
+
+ def test_line_colour_and_palette_fallback(self):
+ xml, _, _ = tm.build(DEMO, grid=100)
+ self.assertIn("strokeColor=#0098d4", xml) # explicit colour
+ self.assertIn(f"strokeColor={tm.TUBE_PALETTE[1]}", xml) # 2nd line → palette[1]
+
+ def test_label_escaped(self):
+ xml, _, _ = tm.build(DEMO, grid=100)
+ self.assertIn("C &amp; &lt;x&gt;", xml)
+ self.assertNotIn("C & <x>", xml)
+
+ def test_unknown_station_id_errors(self):
+ bad = {"stations": {"a": {"gx": 0, "gy": 0}},
+ "lines": [{"name": "L", "stations": ["a", "ghost"]}]}
+ with self.assertRaises(SystemExit):
+ tm.build(bad)
+
+
+class TestCli(unittest.TestCase):
+ def test_stdout_roundtrip(self):
+ r = run("tubemap.py", "-", input=json.dumps(DEMO))
+ self.assertEqual(r.returncode, 0, r.stderr)
+ self.assertIn("<mxfile", r.stdout)
+ self.assertIn("Tube Map", r.stdout)
+
+
+if __name__ == "__main__":
+ unittest.main(verbosity=2)