agentic-mermaid 0.1.1 → 0.1.2

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.
Files changed (336) hide show
  1. package/CHANGELOG.md +144 -4
  2. package/LICENSES/Apache-2.0.txt +202 -0
  3. package/README.md +25 -32
  4. package/THIRD_PARTY_NOTICES.md +29 -0
  5. package/dist/agent-core.d.ts +463 -0
  6. package/dist/agent-core.js +397 -0
  7. package/dist/agent.d.ts +73 -1868
  8. package/dist/agent.js +336 -37325
  9. package/dist/agentic-mermaid-mcp.js +7 -38399
  10. package/dist/am.js +33632 -40445
  11. package/dist/chunk-4QECACIA.js +4702 -0
  12. package/dist/chunk-CDPKJ2BQ.js +37 -0
  13. package/dist/chunk-QKDLMOJJ.js +3487 -0
  14. package/dist/chunk-WI35L7IR.js +615 -0
  15. package/dist/chunk-WN3YDOBG.js +149 -0
  16. package/dist/chunk-ZYMMKQ3I.js +62637 -0
  17. package/dist/index-D54dqSdC.d.ts +6777 -0
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +310 -33014
  20. package/dist/mcp-cli-SBQSTJFC.js +17 -0
  21. package/docs/README.md +14 -6
  22. package/docs/schemas/style-spec.schema.json +1221 -30
  23. package/examples/styles/catalog.json +54 -0
  24. package/examples/styles/cloudflare-workers-inspired-prototype.mmd +9 -0
  25. package/examples/styles/cloudflare-workers-inspired-prototype.style.json +110 -0
  26. package/examples/styles/cupertino-prototype.mmd +10 -0
  27. package/examples/styles/cupertino-prototype.style.json +63 -0
  28. package/examples/styles/mid-century-report.style.json +2 -2
  29. package/examples/styles/star-chart-atlas.style.json +2 -1
  30. package/examples/styles/transit-route-map.style.json +2 -2
  31. package/examples/styles/vercel-inspired-prototype.mmd +6 -0
  32. package/examples/styles/vercel-inspired-prototype.style.json +87 -0
  33. package/package.json +68 -43
  34. package/server.json +2 -2
  35. package/skills/agentic-mermaid-diagram-workflow/SKILL.md +17 -36
  36. package/skills/agentic-mermaid-diagram-workflow/references/cli.md +4 -5
  37. package/skills/agentic-mermaid-diagram-workflow/references/code-mode.md +15 -31
  38. package/skills/agentic-mermaid-diagram-workflow/references/sequence.md +10 -14
  39. package/skills/agentic-mermaid-live-editor/SKILL.md +100 -206
  40. package/AGENT_NATIVE.md +0 -607
  41. package/Instructions_for_agents.md +0 -89
  42. package/TODO.md +0 -684
  43. package/assets/hero.png +0 -0
  44. package/dist/index-wjRjbsP-.d.ts +0 -1102
  45. package/docs/agent-api-cookbook.md +0 -308
  46. package/docs/agent-mutation-policy.md +0 -104
  47. package/docs/agent-workflow-examples.md +0 -46
  48. package/docs/api.md +0 -211
  49. package/docs/ascii.md +0 -103
  50. package/docs/assets/improvements/box-start-connector.png +0 -0
  51. package/docs/assets/improvements/comment-dropped-lint.png +0 -0
  52. package/docs/assets/improvements/er-content-loss.png +0 -0
  53. package/docs/assets/improvements/fan-in-trunks.png +0 -0
  54. package/docs/assets/improvements/gantt-family.png +0 -0
  55. package/docs/assets/improvements/gantt-milestone-clamp.png +0 -0
  56. package/docs/assets/improvements/gantt-verify-seam.png +0 -0
  57. package/docs/assets/improvements/subgraph-container-edges.png +0 -0
  58. package/docs/assets/improvements/wrapper-frontmatter.png +0 -0
  59. package/docs/assets/improvements/wrapper-init-directive.png +0 -0
  60. package/docs/assets/improvements/wrapper-leading-comment.png +0 -0
  61. package/docs/assets/style-cookbook/mid-century-report.png +0 -0
  62. package/docs/assets/style-cookbook/star-chart-atlas.png +0 -0
  63. package/docs/assets/style-cookbook/transit-route-map.png +0 -0
  64. package/docs/comparison.md +0 -94
  65. package/docs/config.md +0 -105
  66. package/docs/contributing/adding-diagram-types.md +0 -144
  67. package/docs/contributing/diagram-family-citizenship.matrix.json +0 -2127
  68. package/docs/contributing/diagram-family-citizenship.md +0 -82
  69. package/docs/contributing/harvesting-upstream-tests.md +0 -126
  70. package/docs/contributing/lessons-learned.md +0 -276
  71. package/docs/contributing/releasing.md +0 -82
  72. package/docs/contributing/visual-review-evidence.md +0 -53
  73. package/docs/custom-style-cookbook.md +0 -154
  74. package/docs/design/families/README.md +0 -26
  75. package/docs/design/families/architecture-beta.md +0 -48
  76. package/docs/design/families/flowchart-parser-conformance.md +0 -22
  77. package/docs/design/families/gantt-research.md +0 -137
  78. package/docs/design/families/gantt.md +0 -329
  79. package/docs/design/families/journey-agentic-cards-before.png +0 -0
  80. package/docs/design/families/journey-experience-curve-implementation.png +0 -0
  81. package/docs/design/families/journey-mermaid-classic-implementation.png +0 -0
  82. package/docs/design/families/journey-mermaid-classic-prototype.png +0 -0
  83. package/docs/design/families/journey-mermaid-classic-prototype.svg +0 -163
  84. package/docs/design/families/journey-mermaid-classic-prototype.svg.png +0 -0
  85. package/docs/design/families/journey-migration-parity.md +0 -439
  86. package/docs/design/families/journey-section-overlap-after.png +0 -0
  87. package/docs/design/families/journey-section-overlap-before.png +0 -0
  88. package/docs/design/families/journey-usage-research.md +0 -423
  89. package/docs/design/families/journey.md +0 -153
  90. package/docs/design/families/xychart.md +0 -85
  91. package/docs/design/system/README.md +0 -45
  92. package/docs/design/system/abstraction-audit.md +0 -224
  93. package/docs/design/system/abstraction-recommendations.md +0 -655
  94. package/docs/design/system/architecture.mmd +0 -29
  95. package/docs/design/system/architecture.svg +0 -137
  96. package/docs/design/system/layout-guarantees-and-robustness.md +0 -351
  97. package/docs/design/system/layout-rubric.md +0 -138
  98. package/docs/design/system/route-contracts.md +0 -848
  99. package/docs/design/system/source-preservation-ladder.md +0 -52
  100. package/docs/design/system/styles-rollout.md +0 -216
  101. package/docs/design/system/ugly-layouts.md +0 -119
  102. package/docs/diagram-families.md +0 -193
  103. package/docs/features.md +0 -147
  104. package/docs/fork-differences.md +0 -130
  105. package/docs/getting-started.md +0 -175
  106. package/docs/issue-derived-test-cases.md +0 -156
  107. package/docs/layout-characterization/README.md +0 -245
  108. package/docs/layout-characterization/contact-sheet-families.md +0 -498
  109. package/docs/layout-characterization/contact-sheet.md +0 -638
  110. package/docs/layout-characterization/properties.md +0 -281
  111. package/docs/layout-characterization/visual-quality.md +0 -160
  112. package/docs/layout-characterization/visual-snapshots/architecture.svg +0 -79
  113. package/docs/layout-characterization/visual-snapshots/class.svg +0 -60
  114. package/docs/layout-characterization/visual-snapshots/er.svg +0 -61
  115. package/docs/layout-characterization/visual-snapshots/flowchart.svg +0 -58
  116. package/docs/layout-characterization/visual-snapshots/gantt.svg +0 -52
  117. package/docs/layout-characterization/visual-snapshots/journey.svg +0 -98
  118. package/docs/layout-characterization/visual-snapshots/pie.svg +0 -36
  119. package/docs/layout-characterization/visual-snapshots/quadrant.svg +0 -47
  120. package/docs/layout-characterization/visual-snapshots/sequence.svg +0 -59
  121. package/docs/layout-characterization/visual-snapshots/state.svg +0 -52
  122. package/docs/layout-characterization/visual-snapshots/timeline.svg +0 -64
  123. package/docs/layout-characterization/visual-snapshots/xychart.svg +0 -97
  124. package/docs/mcp-code-mode-rationale.md +0 -101
  125. package/docs/mcp-http-transport.md +0 -223
  126. package/docs/mermaid-layout-complaints.md +0 -837
  127. package/docs/mutation-testing.md +0 -206
  128. package/docs/project/divergences.md +0 -98
  129. package/docs/project/dogfooding-docs-strategy.md +0 -66
  130. package/docs/project/hosted-mcp-cloudflare-plan.md +0 -338
  131. package/docs/project/lessons-learned.md +0 -1019
  132. package/docs/project/remove-role-styling-plan.md +0 -176
  133. package/docs/quality.md +0 -215
  134. package/docs/react.md +0 -97
  135. package/docs/style-authoring.md +0 -133
  136. package/docs/testing-strategy.md +0 -335
  137. package/docs/theming.md +0 -162
  138. package/examples/agent-improve-auth-flow.ts +0 -206
  139. package/examples/agent-loop.ts +0 -53
  140. package/examples/mcp-vs-cli-complex-diagrams.ts +0 -133
  141. package/llms.txt +0 -104
  142. package/skill-evals/README.md +0 -77
  143. package/skill-evals/fixtures/architecture-cache/input.mmd +0 -5
  144. package/skill-evals/fixtures/class-payment/input.mmd +0 -4
  145. package/skill-evals/fixtures/er-orders/input.mmd +0 -10
  146. package/skill-evals/fixtures/flowchart-cache/input.mmd +0 -3
  147. package/skill-evals/fixtures/gantt-release/input.mmd +0 -7
  148. package/skill-evals/fixtures/journey-checkout/input.mmd +0 -6
  149. package/skill-evals/fixtures/pie-exports/input.mmd +0 -5
  150. package/skill-evals/fixtures/quadrant-priorities/input.mmd +0 -11
  151. package/skill-evals/fixtures/sequence-retry/input.mmd +0 -8
  152. package/skill-evals/fixtures/state-lifecycle/input.mmd +0 -5
  153. package/skill-evals/fixtures/timeline-release/input.mmd +0 -6
  154. package/skill-evals/fixtures/xychart-growth/input.mmd +0 -5
  155. package/skill-evals/shared-benchmark.json +0 -510
  156. package/src/agent/analyze.ts +0 -157
  157. package/src/agent/apply.ts +0 -146
  158. package/src/agent/architecture-body.ts +0 -458
  159. package/src/agent/certificates.ts +0 -110
  160. package/src/agent/class-body.ts +0 -319
  161. package/src/agent/core.ts +0 -207
  162. package/src/agent/create.ts +0 -106
  163. package/src/agent/describe.ts +0 -368
  164. package/src/agent/er-body.ts +0 -224
  165. package/src/agent/facts.ts +0 -360
  166. package/src/agent/families-builtin.ts +0 -920
  167. package/src/agent/families.ts +0 -232
  168. package/src/agent/family-layouts.ts +0 -832
  169. package/src/agent/flowchart-body.ts +0 -372
  170. package/src/agent/flowchart-unsupported.ts +0 -243
  171. package/src/agent/font-coverage.ts +0 -288
  172. package/src/agent/gantt-body.ts +0 -495
  173. package/src/agent/index.ts +0 -10
  174. package/src/agent/journey-body.ts +0 -374
  175. package/src/agent/label-metrics.ts +0 -28
  176. package/src/agent/layout-to-rendered.ts +0 -63
  177. package/src/agent/mutate.ts +0 -97
  178. package/src/agent/mutation-ops.ts +0 -51
  179. package/src/agent/op-schema.ts +0 -443
  180. package/src/agent/parse.ts +0 -223
  181. package/src/agent/pie-body.ts +0 -270
  182. package/src/agent/png.ts +0 -171
  183. package/src/agent/quadrant-body.ts +0 -336
  184. package/src/agent/quality.ts +0 -363
  185. package/src/agent/readability-audit.ts +0 -92
  186. package/src/agent/rendered-route-audit.ts +0 -61
  187. package/src/agent/sequence-body.ts +0 -345
  188. package/src/agent/serialize.ts +0 -214
  189. package/src/agent/state-body.ts +0 -589
  190. package/src/agent/structural-count.ts +0 -150
  191. package/src/agent/timeline-body.ts +0 -280
  192. package/src/agent/trace-log.ts +0 -43
  193. package/src/agent/types.ts +0 -995
  194. package/src/agent/verify.ts +0 -603
  195. package/src/agent/xychart-body.ts +0 -472
  196. package/src/architecture/config.ts +0 -282
  197. package/src/architecture/layout.ts +0 -496
  198. package/src/architecture/parser.ts +0 -375
  199. package/src/architecture/renderer.ts +0 -611
  200. package/src/architecture/types.ts +0 -113
  201. package/src/ascii/ansi.ts +0 -423
  202. package/src/ascii/architecture.ts +0 -210
  203. package/src/ascii/canvas.ts +0 -443
  204. package/src/ascii/class-diagram.ts +0 -697
  205. package/src/ascii/converter.ts +0 -475
  206. package/src/ascii/draw.ts +0 -1693
  207. package/src/ascii/edge-bundling.ts +0 -328
  208. package/src/ascii/edge-routing.ts +0 -330
  209. package/src/ascii/er-diagram.ts +0 -439
  210. package/src/ascii/gantt.ts +0 -276
  211. package/src/ascii/grid.ts +0 -747
  212. package/src/ascii/index.ts +0 -196
  213. package/src/ascii/journey.ts +0 -169
  214. package/src/ascii/meta.ts +0 -244
  215. package/src/ascii/multiline-utils.ts +0 -80
  216. package/src/ascii/pathfinder.ts +0 -301
  217. package/src/ascii/pie.ts +0 -67
  218. package/src/ascii/quadrant.ts +0 -158
  219. package/src/ascii/reverse.ts +0 -216
  220. package/src/ascii/sequence.ts +0 -499
  221. package/src/ascii/shapes/circle.ts +0 -27
  222. package/src/ascii/shapes/corners.ts +0 -143
  223. package/src/ascii/shapes/diamond.ts +0 -27
  224. package/src/ascii/shapes/hexagon.ts +0 -27
  225. package/src/ascii/shapes/index.ts +0 -106
  226. package/src/ascii/shapes/rectangle.ts +0 -168
  227. package/src/ascii/shapes/rounded.ts +0 -27
  228. package/src/ascii/shapes/special.ts +0 -332
  229. package/src/ascii/shapes/stadium.ts +0 -110
  230. package/src/ascii/shapes/state.ts +0 -192
  231. package/src/ascii/shapes/types.ts +0 -73
  232. package/src/ascii/timeline.ts +0 -141
  233. package/src/ascii/types.ts +0 -312
  234. package/src/ascii/validate.ts +0 -120
  235. package/src/ascii/width.ts +0 -81
  236. package/src/ascii/wrap.ts +0 -131
  237. package/src/ascii/xychart.ts +0 -919
  238. package/src/browser.ts +0 -29
  239. package/src/class/layout.ts +0 -240
  240. package/src/class/parser.ts +0 -332
  241. package/src/class/renderer.ts +0 -638
  242. package/src/class/types.ts +0 -129
  243. package/src/cli/agent-instructions.ts +0 -1
  244. package/src/cli/am-bin.ts +0 -6
  245. package/src/cli/exit-codes.ts +0 -18
  246. package/src/cli/index.ts +0 -1132
  247. package/src/cli/init-agent.ts +0 -147
  248. package/src/cli/run-entrypoint.ts +0 -10
  249. package/src/color-resolver.ts +0 -152
  250. package/src/elk-instance.ts +0 -114
  251. package/src/er/layout.ts +0 -187
  252. package/src/er/parser.ts +0 -226
  253. package/src/er/renderer.ts +0 -792
  254. package/src/er/types.ts +0 -99
  255. package/src/family-rubric.ts +0 -425
  256. package/src/font-manifest.ts +0 -31
  257. package/src/gantt/layout.ts +0 -365
  258. package/src/gantt/parser.ts +0 -282
  259. package/src/gantt/pipeline.ts +0 -27
  260. package/src/gantt/renderer.ts +0 -414
  261. package/src/gantt/schedule.ts +0 -513
  262. package/src/gantt/types.ts +0 -255
  263. package/src/index.ts +0 -368
  264. package/src/journey/layout.ts +0 -554
  265. package/src/journey/parse-core.ts +0 -251
  266. package/src/journey/parser.ts +0 -101
  267. package/src/journey/renderer.ts +0 -917
  268. package/src/journey/types.ts +0 -144
  269. package/src/layout/geometry.ts +0 -182
  270. package/src/layout/pass.ts +0 -142
  271. package/src/layout/passes/index.ts +0 -3916
  272. package/src/layout-engine.ts +0 -1565
  273. package/src/layout-rubric.ts +0 -659
  274. package/src/mcp/artifacts.ts +0 -137
  275. package/src/mcp/dynamic-harness.ts +0 -31
  276. package/src/mcp/dynamic-modules.d.ts +0 -7
  277. package/src/mcp/facade.ts +0 -608
  278. package/src/mcp/harness-runtime.ts +0 -203
  279. package/src/mcp/hosted-server.ts +0 -468
  280. package/src/mcp/mcp-bin.ts +0 -3
  281. package/src/mcp/mcp-cli.ts +0 -82
  282. package/src/mcp/protocol.ts +0 -13
  283. package/src/mcp/sandbox.ts +0 -195
  284. package/src/mcp/sdk-decl.ts +0 -391
  285. package/src/mcp/server.ts +0 -362
  286. package/src/mcp/tool-surface.ts +0 -146
  287. package/src/mermaid-source.ts +0 -655
  288. package/src/multiline-utils.ts +0 -228
  289. package/src/parser.ts +0 -1031
  290. package/src/pie/layout.ts +0 -168
  291. package/src/pie/parser.ts +0 -136
  292. package/src/pie/renderer.ts +0 -234
  293. package/src/pie/types.ts +0 -82
  294. package/src/quadrant/layout.ts +0 -191
  295. package/src/quadrant/parser.ts +0 -183
  296. package/src/quadrant/renderer.ts +0 -322
  297. package/src/quadrant/types.ts +0 -113
  298. package/src/render-family-hooks.ts +0 -244
  299. package/src/renderer.ts +0 -1099
  300. package/src/route-contracts.ts +0 -2723
  301. package/src/scene/backend.ts +0 -76
  302. package/src/scene/fidelity.ts +0 -183
  303. package/src/scene/hybrid-backend.ts +0 -174
  304. package/src/scene/ir.ts +0 -181
  305. package/src/scene/marks.ts +0 -127
  306. package/src/scene/rough-backend.ts +0 -378
  307. package/src/scene/seed.ts +0 -46
  308. package/src/scene/style-registry.ts +0 -556
  309. package/src/sequence/layout.ts +0 -456
  310. package/src/sequence/parser.ts +0 -255
  311. package/src/sequence/renderer.ts +0 -604
  312. package/src/sequence/types.ts +0 -154
  313. package/src/shape-clipping.ts +0 -351
  314. package/src/shared/accessibility-directives.ts +0 -22
  315. package/src/shared/batched.ts +0 -61
  316. package/src/shared/color-math.ts +0 -93
  317. package/src/shared/svg-a11y.ts +0 -29
  318. package/src/shared/syntax-error.ts +0 -17
  319. package/src/shared/unicode-ranges.ts +0 -135
  320. package/src/styles.ts +0 -318
  321. package/src/svg-paths.ts +0 -28
  322. package/src/text-metrics.ts +0 -248
  323. package/src/theme.ts +0 -710
  324. package/src/timeline/layout.ts +0 -381
  325. package/src/timeline/parser.ts +0 -215
  326. package/src/timeline/renderer.ts +0 -538
  327. package/src/timeline/types.ts +0 -105
  328. package/src/types.ts +0 -462
  329. package/src/website-worker-modules.d.ts +0 -18
  330. package/src/xychart/axis-utils.ts +0 -109
  331. package/src/xychart/colors.ts +0 -124
  332. package/src/xychart/config.ts +0 -88
  333. package/src/xychart/layout.ts +0 -656
  334. package/src/xychart/parser.ts +0 -504
  335. package/src/xychart/renderer.ts +0 -640
  336. package/src/xychart/types.ts +0 -282
@@ -1,29 +0,0 @@
1
- graph TD
2
- SRC["Mermaid source text"] --> NORM["normalize source<br/>frontmatter · %%init%% · config"]
3
- NORM --> DET{"detect diagram type"}
4
- DET --> REG["FamilyPlugin registry<br/>detect · parse · layout · renderSvg · renderAscii<br/>serialize · mutate · verify"]
5
-
6
- subgraph SVGSTACK["SVG stack · renderMermaidSVG"]
7
- direction TB
8
- L1["source-context layout hook<br/>parse → config middleware → layout"] --> CTX["RenderContext<br/>positioned · colors · options"]
9
- CTX --> O1["SVG string"]
10
- end
11
-
12
- subgraph ASCIISTACK["ASCII stack · renderMermaidASCII"]
13
- direction TB
14
- L2["renderAscii hook"] --> GRID["grid geometry<br/>AsciiGraph · Canvas · A* pathfinder"]
15
- GRID --> O2["text grid"]
16
- end
17
-
18
- subgraph AGENTSTACK["Agent stack · parse / mutate / verify"]
19
- direction TB
20
- VD["ValidDiagram · DiagramBody<br/>structured | opaque"] --> RL["RenderedLayout"]
21
- end
22
-
23
- REG -->|"SVG hooks"| L1
24
- REG -->|"ASCII / unicode hook"| L2
25
- REG -->|"agent hooks"| VD
26
-
27
- REG -.same 12 families.-> FAM
28
- FAM["12 diagram families<br/>flowchart · sequence · class · er · gantt<br/>pie · journey · timeline · quadrant · xychart · architecture · state"]
29
- FAM --> CORE["shared core types · types.ts<br/>NodeShape · EdgeStyle · MermaidGraph · RouteClass"]
@@ -1,137 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1381.6179999999997 963.882" width="1381.6179999999997" height="963.882" style="--bg:#FFFFFF;--fg:#27272A;--font:Inter;background:#FFFFFF">
2
- <style>
3
- @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&amp;display=swap');
4
- text { font-family: var(--font, 'Inter'), system-ui, sans-serif; }
5
- svg {
6
- /* Derived from --bg and --fg (overridable via --line, --accent, etc.) */
7
- --_text: #27272A;
8
- --_text-sec: #575759;
9
- --_text-muted: #707072;
10
- --_text-faint: #8a8a8c;
11
- --_line: #939395;
12
- --_arrow: #47474a;
13
- --_node-fill: #f9f9f9;
14
- --_node-stroke: #d4d4d4;
15
- --_group-fill: #FFFFFF;
16
- --_group-hdr: #f4f4f4;
17
- --_inner-stroke: #e5e5e5;
18
- --_key-badge: #e9e9ea;
19
- }
20
- </style>
21
- <defs>
22
- <marker id="arrowhead" markerWidth="8" markerHeight="5" refX="7" refY="2.5" orient="auto">
23
- <polygon points="0 0, 8 2.5, 0 5" fill="#47474a" stroke="#47474a" stroke-width="0.75" stroke-linejoin="round" />
24
- </marker>
25
- <marker id="arrowhead-start" markerWidth="8" markerHeight="5" refX="7" refY="2.5" orient="auto-start-reverse">
26
- <polygon points="0 0, 8 2.5, 0 5" fill="#47474a" stroke="#47474a" stroke-width="0.75" stroke-linejoin="round" />
27
- </marker>
28
- </defs>
29
- <g class="subgraph" data-id="SVGSTACK" data-region="subgraph" data-label="SVG stack · renderMermaidSVG">
30
- <rect x="479.8599999999998" y="616.282" width="273.279" height="300.5" rx="0" ry="0" fill="#FFFFFF" stroke="#d4d4d4" stroke-width="1" />
31
- <path d="M479.8599999999998,616.282 H753.1389999999998 V644.282 H479.8599999999998 Z" fill="#f4f4f4" stroke="#d4d4d4" stroke-width="1" />
32
- <text x="491.8599999999998" y="630.282" font-size="12" font-weight="600" fill="#575759" dy="4.199999999999999">SVG stack · renderMermaidSVG</text>
33
- </g>
34
- <g class="subgraph" data-id="ASCIISTACK" data-region="subgraph" data-label="ASCII stack · renderMermaidASCII">
35
- <rect x="781.1389999999998" y="640.2819999999999" width="288.09899999999993" height="283.6" rx="0" ry="0" fill="#FFFFFF" stroke="#d4d4d4" stroke-width="1" />
36
- <path d="M781.1389999999998,640.2819999999999 H1069.2379999999998 V668.2819999999999 H781.1389999999998 Z" fill="#f4f4f4" stroke="#d4d4d4" stroke-width="1" />
37
- <text x="793.1389999999998" y="654.2819999999999" font-size="12" font-weight="600" fill="#575759" dy="4.199999999999999">ASCII stack · renderMermaidASCII</text>
38
- </g>
39
- <g class="subgraph" data-id="AGENTSTACK" data-region="subgraph" data-label="Agent stack · parse / mutate / verify">
40
- <rect x="1097.2379999999998" y="616.282" width="244.37999999999997" height="198.70000000000002" rx="0" ry="0" fill="#FFFFFF" stroke="#d4d4d4" stroke-width="1" />
41
- <path d="M1097.2379999999998,616.282 H1341.6179999999997 V644.282 H1097.2379999999998 Z" fill="#f4f4f4" stroke="#d4d4d4" stroke-width="1" />
42
- <text x="1109.2379999999998" y="630.282" font-size="12" font-weight="600" fill="#575759" dy="4.199999999999999">Agent stack · parse / mutate / verify</text>
43
- </g>
44
- <polyline class="edge" data-from="SRC" data-to="NORM" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" points="925.1884999999996,76.9 925.1884999999997,124.9" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
45
- <polyline class="edge" data-from="NORM" data-to="DET" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" points="925.1884999999997,178.70000000000002 925.1884999999997,226.70000000000002" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
46
- <polyline class="edge" data-from="DET" data-to="REG" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" points="925.1884999999997,405.28200000000004 925.1884999999997,453.28200000000004" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
47
- <polyline class="edge" data-from="FAM" data-to="CORE" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" points="249.9299999999999,110.7 249.9299999999999,158.7" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
48
- <polyline class="edge" data-from="REG" data-to="L1" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" data-label="SVG hooks" points="842.0829999999997,523.982 842.0829999999997,535.9820000000001 616.4994999999998,535.9820000000001 616.4994999999998,672.2819999999999" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
49
- <polyline class="edge" data-from="REG" data-to="L2" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" data-label="ASCII / unicode hook" points="925.1884999999997,523.982 925.1884999999997,672.2819999999999" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
50
- <polyline class="edge" data-from="REG" data-to="VD" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" data-label="agent hooks" points="1008.2939999999996,523.982 1008.2939999999998,535.9820000000001 1219.4279999999997,535.9820000000001 1219.4279999999999,672.2819999999999" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
51
- <polyline class="edge" data-from="L1" data-to="CTX" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" points="616.4994999999998,726.082 616.4994999999998,765.6320000000001" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
52
- <polyline class="edge" data-from="CTX" data-to="O1" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" points="616.4994999999998,819.432 616.4994999999998,867.432" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
53
- <polyline class="edge" data-from="L2" data-to="GRID" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" points="925.1884999999997,709.1819999999999 925.1884999999997,765.6320000000001" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
54
- <polyline class="edge" data-from="GRID" data-to="O2" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" points="925.1884999999997,819.4320000000001 925.1884999999997,867.432" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
55
- <polyline class="edge" data-from="VD" data-to="RL" data-style="solid" data-arrow-start="false" data-arrow-end="true" data-marker-end="arrow" points="1219.4279999999999,726.082 1219.4279999999999,765.6320000000001" fill="none" stroke="#939395" stroke-width="1" marker-end="url(#arrowhead)" />
56
- <g class="edge-label" data-from="REG" data-to="L1" data-label="SVG hooks">
57
- <rect class="edge-label-halo" x="576.9994999999998" y="538.9820000000001" width="78.51599999999999" height="38.3" rx="4" ry="4" fill="#FFFFFF" stroke="none" />
58
- <rect x="580.9994999999998" y="542.9820000000001" width="70.51599999999999" height="30.3" rx="2" ry="2" fill="#FFFFFF" stroke="#e5e5e5" stroke-width="1" />
59
- <text x="616.2574999999998" y="558.1320000000001" text-anchor="middle" font-size="11" font-weight="400" fill="#575759" dy="3.8499999999999996">SVG hooks</text>
60
- </g>
61
- <g class="edge-label" data-from="REG" data-to="L2" data-label="ASCII / unicode hook">
62
- <rect class="edge-label-halo" x="864.1884999999997" y="562.982" width="121.878" height="38.3" rx="4" ry="4" fill="#FFFFFF" stroke="none" />
63
- <rect x="868.1884999999997" y="566.982" width="113.878" height="30.3" rx="2" ry="2" fill="#FFFFFF" stroke="#e5e5e5" stroke-width="1" />
64
- <text x="925.1274999999997" y="582.132" text-anchor="middle" font-size="11" font-weight="400" fill="#575759" dy="3.8499999999999996">ASCII / unicode hook</text>
65
- </g>
66
- <g class="edge-label" data-from="REG" data-to="VD" data-label="agent hooks">
67
- <rect class="edge-label-halo" x="1177.4279999999997" y="538.9820000000001" width="83.268" height="38.3" rx="4" ry="4" fill="#FFFFFF" stroke="none" />
68
- <rect x="1181.4279999999997" y="542.9820000000001" width="75.268" height="30.3" rx="2" ry="2" fill="#FFFFFF" stroke="#e5e5e5" stroke-width="1" />
69
- <text x="1219.0619999999997" y="558.1320000000001" text-anchor="middle" font-size="11" font-weight="400" fill="#575759" dy="3.8499999999999996">agent hooks</text>
70
- </g>
71
- <g class="node" data-id="SRC" data-label="Mermaid source text" data-shape="rectangle">
72
- <rect x="844.5629999999996" y="40" width="161.251" height="36.900000000000006" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
73
- <text x="925.1884999999996" y="58.45" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A" dy="4.55">Mermaid source text</text>
74
- </g>
75
- <g class="node" data-id="NORM" data-label="normalize source
76
- frontmatter · %%init%% · config" data-shape="rectangle">
77
- <rect x="817.5164999999997" y="124.9" width="215.34399999999997" height="53.800000000000004" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
78
- <text x="925.1884999999997" y="151.8" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A"><tspan x="925.1884999999997" dy="-3.9000000000000012">normalize source</tspan><tspan x="925.1884999999997" dy="16.900000000000002">frontmatter · %%init%% · config</tspan></text>
79
- </g>
80
- <g class="node" data-id="DET" data-label="detect diagram type" data-shape="diamond">
81
- <polygon points="925.1884999999997,226.7 1014.4794999999997,315.991 925.1884999999997,405.282 835.8974999999998,315.991" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
82
- <text x="925.1884999999997" y="315.991" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A" dy="4.55">detect diagram type</text>
83
- </g>
84
- <g class="node" data-id="REG" data-label="FamilyPlugin registry
85
- detect · parse · layout · renderSvg · renderAscii
86
- serialize · mutate · verify" data-shape="rectangle">
87
- <rect x="758.9774999999997" y="453.28200000000004" width="332.42199999999997" height="70.7" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
88
- <text x="925.1884999999997" y="488.63200000000006" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A"><tspan x="925.1884999999997" dy="-12.350000000000001">FamilyPlugin registry</tspan><tspan x="925.1884999999997" dy="16.900000000000002">detect · parse · layout · renderSvg · renderAscii</tspan><tspan x="925.1884999999997" dy="16.900000000000002">serialize · mutate · verify</tspan></text>
89
- </g>
90
- <g class="node" data-id="L1" data-label="source-context layout hook
91
- parse → config middleware → layout" data-shape="rectangle">
92
- <rect x="495.8599999999998" y="672.2819999999999" width="241.27899999999997" height="53.800000000000004" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
93
- <text x="616.4994999999998" y="699.1819999999999" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A"><tspan x="616.4994999999998" dy="-3.9000000000000012">source-context layout hook</tspan><tspan x="616.4994999999998" dy="16.900000000000002">parse → config middleware → layout</tspan></text>
94
- </g>
95
- <g class="node" data-id="CTX" data-label="RenderContext
96
- positioned · colors · options" data-shape="rectangle">
97
- <rect x="512.5324999999998" y="765.6320000000001" width="207.934" height="53.800000000000004" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
98
- <text x="616.4994999999998" y="792.532" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A"><tspan x="616.4994999999998" dy="-3.9000000000000012">RenderContext</tspan><tspan x="616.4994999999998" dy="16.900000000000002">positioned · colors · options</tspan></text>
99
- </g>
100
- <g class="node" data-id="O1" data-label="SVG string" data-shape="rectangle">
101
- <rect x="564.0319999999998" y="867.432" width="104.93499999999999" height="36.900000000000006" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
102
- <text x="616.4994999999998" y="885.8820000000001" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A" dy="4.55">SVG string</text>
103
- </g>
104
- <g class="node" data-id="L2" data-label="renderAscii hook" data-shape="rectangle">
105
- <rect x="852.7139999999997" y="672.2819999999999" width="144.949" height="36.900000000000006" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
106
- <text x="925.1884999999997" y="690.732" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A" dy="4.55">renderAscii hook</text>
107
- </g>
108
- <g class="node" data-id="GRID" data-label="grid geometry
109
- AsciiGraph · Canvas · A* pathfinder" data-shape="rectangle">
110
- <rect x="797.1389999999998" y="765.6320000000001" width="256.09899999999993" height="53.800000000000004" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
111
- <text x="925.1884999999997" y="792.532" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A"><tspan x="925.1884999999997" dy="-3.9000000000000012">grid geometry</tspan><tspan x="925.1884999999997" dy="16.900000000000002">AsciiGraph · Canvas · A* pathfinder</tspan></text>
112
- </g>
113
- <g class="node" data-id="O2" data-label="text grid" data-shape="rectangle">
114
- <rect x="880.8719999999997" y="867.432" width="88.633" height="36.900000000000006" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
115
- <text x="925.1884999999997" y="885.8820000000001" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A" dy="4.55">text grid</text>
116
- </g>
117
- <g class="node" data-id="VD" data-label="ValidDiagram · DiagramBody
118
- structured | opaque" data-shape="rectangle">
119
- <rect x="1113.2379999999998" y="672.2819999999999" width="212.37999999999997" height="53.800000000000004" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
120
- <text x="1219.4279999999999" y="699.1819999999999" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A"><tspan x="1219.4279999999999" dy="-3.9000000000000012">ValidDiagram · DiagramBody</tspan><tspan x="1219.4279999999999" dy="16.900000000000002">structured | opaque</tspan></text>
121
- </g>
122
- <g class="node" data-id="RL" data-label="RenderedLayout" data-shape="rectangle">
123
- <rect x="1148.0649999999998" y="765.6320000000001" width="142.726" height="36.900000000000006" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
124
- <text x="1219.4279999999999" y="784.0820000000001" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A" dy="4.55">RenderedLayout</text>
125
- </g>
126
- <g class="node" data-id="FAM" data-label="12 diagram families
127
- flowchart · sequence · class · er · gantt
128
- pie · journey · timeline · quadrant · xychart · architecture · state" data-shape="rectangle">
129
- <rect x="40" y="40" width="419.8599999999998" height="70.7" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
130
- <text x="249.9299999999999" y="75.35" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A"><tspan x="249.9299999999999" dy="-12.350000000000001">12 diagram families</tspan><tspan x="249.9299999999999" dy="16.900000000000002">flowchart · sequence · class · er · gantt</tspan><tspan x="249.9299999999999" dy="16.900000000000002">pie · journey · timeline · quadrant · xychart · architecture · state</tspan></text>
131
- </g>
132
- <g class="node" data-id="CORE" data-label="shared core types · types.ts
133
- NodeShape · EdgeStyle · MermaidGraph · RouteClass" data-shape="rectangle">
134
- <rect x="67.78749999999991" y="158.7" width="364.28499999999997" height="53.800000000000004" rx="0" ry="0" fill="#f9f9f9" stroke="#d4d4d4" stroke-width="0.75" />
135
- <text x="249.9299999999999" y="185.6" text-anchor="middle" font-size="13" font-weight="500" fill="#27272A"><tspan x="249.9299999999999" dy="-3.9000000000000012">shared core types · types.ts</tspan><tspan x="249.9299999999999" dy="16.900000000000002">NodeShape · EdgeStyle · MermaidGraph · RouteClass</tspan></text>
136
- </g>
137
- </svg>
@@ -1,351 +0,0 @@
1
- # Layout guarantees and robustness — what we can promise, and how
2
-
3
- A literature + industry synthesis answering one question: **which layout
4
- invariants can we guarantee in 100% of inputs and keep robust under fuzzing, and
5
- which are provably impossible to guarantee — so we must optimize-and-certify
6
- instead?** It was produced by a fan-out of research sub-agents over the academic
7
- graph-drawing / map-labeling literature and the engineering practice of yFiles,
8
- Graphviz, ELK, OGDF, Adaptagrams/libavoid, cola.js, tldraw, Excalidraw, and
9
- draw.io/mxGraph. Citations are at the end.
10
-
11
- This doc is the *map*. The route-engine details live in
12
- [`route-contracts.md`](./route-contracts.md); the quality metrics in
13
- [`layout-rubric.md`](./layout-rubric.md).
14
-
15
- ## TL;DR
16
-
17
- The field partitions drawing properties into two kinds, and we must treat them
18
- differently:
19
-
20
- | Kind | Examples | Best achievable | Our use |
21
- | --- | --- | --- | --- |
22
- | **Conventions / feasibility** (membership predicates) | orthogonality, port-exactness, no node overlap, monotone flow, axis-alignment, determinism, lane-distinctness | **100%, by construction**, usually polynomial | the **hard** rubric invariants (must be 0) |
23
- | **Aesthetic optima** | min crossings, min bends (free embedding), min area, max symmetry | **NP-hard — no 100% guarantee**; optimize then certify the value achieved | the **soft** rubric metrics (ratcheted) |
24
- | **Label placement** (in between) | place every label cleanly without moving nodes | **NP-hard** (Kakoulis–Tollis ELP; Marks–Shieber: poly ⇔ P=NP). Algorithms **maximize placed labels and may drop/overlap some** | `findLabelSlot` + certify-or-fallback |
25
-
26
- So "100% + fuzz-robust" is reachable **only when reframed**: not "always produce
27
- the optimal/clean drawing" (impossible for the NP-hard ones) but *"always satisfy
28
- the hard conventions — by construction, or by a checker that vetoes and falls
29
- back — while optimizing the soft aesthetics and honestly certifying the value we
30
- hit."* That is the architecture we already have; the research says where to
31
- tighten it.
32
-
33
- ## The robustness mechanism (why fuzzing keeps finding 1–2px bugs)
34
-
35
- Our recurring failures — labels grazing nodes, collinear edges merging, endpoints
36
- just off a port at 1–2px — are the textbook symptom of **floating-point
37
- geometric predicates returning inconsistent signs near degeneracy** (Kettner,
38
- Mehlhorn, Pion, Schirra, Yap 2008). The cure is the Exact-Geometric-Computation
39
- paradigm, **not** more fuzzing (Dijkstra: testing shows presence, never absence):
40
-
41
- 1. **Exact discrete predicates.** Evaluate the *decisions* — does this label pill
42
- overlap this node? is this endpoint on this port? are these two segments
43
- collinear-and-overlapping? does this segment pass through this shape? — in
44
- **integer arithmetic on snapped coordinates with one fixed tie-break**
45
- (Simulation of Simplicity), not against scattered ε. The *coordinates* being
46
- slightly off is harmless; the *branch decisions* being wrong is catastrophic
47
- and self-reinforcing. This collapses the near-degenerate class fuzzing keeps
48
- surfacing and makes producer and checker bit-identical. (Yap EGC; Shewchuk
49
- adaptive predicates; CGAL's "exact predicates, inexact constructions";
50
- Edelsbrunner–Mücke; Hobby snap-rounding.) Today these decisions are spread
51
- across tolerances (`EPS`, `GRAZE`, `TOL`, `BOUNDS_TOL`, `PORT_TOLERANCE`) — the
52
- symptom, not the cure.
53
- 2. **One independent, total checker on every output** that re-derives each hard
54
- invariant from rendered geometry alone and *vetoes* a violating layout,
55
- falling back to a safe route. [`layout-rubric.ts`](../../../src/layout-rubric.ts)
56
- already does this right for outlines (it reimplements each shape's outline so a
57
- port regression can't hide itself); the **route** checker is weaker — its audits
58
- reuse the producer's own `directLaneBlockers`/`tryStraighten`, so a bug there is
59
- invisible to it. (Certifying algorithms: McConnell–Mehlhorn–Näher–Schweitzer
60
- 2011; checker-only formal verification: Alkassar–Böhme–Mehlhorn–Rizkallah 2011.)
61
- 3. **Exhaustive small-scope enumeration** (all non-isomorphic graphs ≤ 5–6 nodes ×
62
- shapes × 4 directions) is a *complete* proof in-scope — the real "ever" — with
63
- fuzzing relegated to the large-graph tail (small-scope hypothesis, Jackson 2006).
64
-
65
- ## The three problems, with verdicts
66
-
67
- ### 1. A label displaces the node off its port → 100% solvable by construction
68
-
69
- Industry is **unanimous**: every hand-authored editor — tldraw, Excalidraw,
70
- draw.io/mxGraph, yFiles' generic labeler — **decouples labels; node positions are
71
- never perturbed by a label.** The two systems that reserve in-band label space
72
- (Graphviz's `label` dummy-node; yFiles' integrated mode) *both document it as
73
- distorting the layout* — Graphviz's FAQ: edge labels as dummy nodes "can
74
- dramatically distort the layout," and `xlabel` (post-layout placement) is offered
75
- as the escape hatch. That `xlabel` is our `APL_DECOUPLE_LABELS`.
76
-
77
- **Verdict: making "a label can never move a node" a structural invariant is
78
- correct, and the literature says make decoupling the default.** Already built and
79
- validated (fixes the sym A→B port and the minimal repro, zero corpus-quality cost,
80
- deterministic). The only blocker to default-on is problem 2.
81
-
82
- ### 2. Label on a shared trunk (the bent-duplicate regressions) → split verdict
83
-
84
- Two problems under one error code:
85
-
86
- - **(a) the two edges share a trunk** — the universal industry solution is a
87
- *dedicated duplicate-edge spreading pass*: mxParallelEdgeLayout (bucket by a
88
- **direction-independent edge key**, fan into lanes by perpendicular offset,
89
- default spacing 20), yFiles' ParallelEdgeRouter (leading-edge + parallel
90
- reinsertion). With **distinct fixed ports per parallel edge** (Spönemann's
91
- FIXED_POS port-constraint hierarchy — which `allocateRoutePorts` already plans
92
- slots for) the edges become non-collinear at both ends **by construction**.
93
- 100%-achievable; the current pass just carves out *labeled* bent duplicates —
94
- exactly the fuzz regression.
95
- - **(b) the label finding a private segment** — the NP-hard half. We **cannot**
96
- guarantee a clean placement always *exists* (Kakoulis–Tollis: maximize placed
97
- labels, may drop some). But we **can enforce the invariant** as
98
- *certify-or-fallback*: if no edge-private labelable segment survives laning, the
99
- route contract **vetoes that geometry and falls back** (reserved label corridor /
100
- boundary-label leader à la Bekos et al. / suppress). The *output* invariant "no
101
- label on a shared trunk" becomes total via the checker's veto.
102
-
103
- **Verdict: port-exactness + lane separation = 100% by construction;
104
- clean-label-placement = not guaranteed (NP-hard) but enforceable as
105
- certified-or-safe-fallback.** Extend the duplicate-lane assignment to cover
106
- labeled bent duplicates (keyed by unordered pair), then veto-and-fallback for the
107
- residue. This unblocks decoupling-by-default.
108
-
109
- ### 3. Bundling adds bends without removing crossings → can never be 100%; gate it
110
-
111
- The visualization literature is flat: edge bundling (Holten 2006; Holten–van Wijk
112
- 2009) **reduces visual clutter but does not reduce the number of crossings, and
113
- adds curvature/ambiguity.** Bundling an already-crossing-free fan is all cost, no
114
- benefit (our observed defect: `bundleEdgePaths` on shared-hub fans, +bends, 0
115
- crossings removed). Bundling is irreducibly a heuristic — never a 100% guarantee.
116
-
117
- **Verdict: add a net-benefit gate** (the hyperedge-routing cost view): only keep a
118
- bundle when it does not increase total bends without removing a crossing; never
119
- bundle a crossing-free fan. The `simplifyPolyline` bend count + a member-vs-member
120
- crossing count make a heuristic *safe* ("bundling never worsens crossings or
121
- bends"), which itself *is* a 100%-guaranteeable property.
122
-
123
- ### 3a. The justified / symmetric bend — not every bend is a defect
124
-
125
- The aesthetic hierarchy distinguishes a *justified* bend from an *unjustified*
126
- one. A bend that is part of a **symmetric convergence** — a fan-out/fan-in bundle,
127
- or a **co-ranked mixed-label fan-in**'s converging dogleg — is "as good as" a
128
- straight line and is **not penalized**: the bend is structurally necessary to
129
- converge (N spokes cannot merge into one node without a turn), and the symmetry it
130
- buys offsets the small bend cost — the idiom every reference layered drawer uses,
131
- and the one our own fan-out emitter (`applySymmetricFanoutEmissions`) already
132
- relies on. Only *unjustified / lone* bends cost.
133
-
134
- The rubric encodes this exactly: a bend on a `bundle`-certified edge is excluded
135
- from `totalBends`/`maxBendsPerEdge` — the **same** edges `findRouteHitches` skips
136
- — so the soft bend penalty and the HARD hitch-invariant agree on what is
137
- justified, while an off-lane jog with a clear straight lane (`hitches`) or a bend
138
- on a `straight`-certified edge (`unexplainedBends`) stays a HARD violation.
139
-
140
- This dissolves an apparent conflict. A **mixed-label fan-in** (a hub fed by both a
141
- labelled and an unlabelled edge) used to land asymmetric: ELK reserves an
142
- inline-label dummy rank for the labelled edge only, so its source ranked one layer
143
- early and the hub could not be squared up. The fix (default; `APL_NO_CORANK_FANIN`
144
- to disable) gives each unlabelled sibling a layout-only balancing label so all the
145
- sources **co-rank**, then centres the hub on their barycentre; the spokes converge
146
- as symmetric doglegs (`markCorankFanInBundles` re-routes them port-to-port and
147
- marks them bundle-owned). That *bends the labelled spoke*, which the older
148
- "labelled source exits straight at its mid-port" contract forbade — but under the
149
- symmetric-bend principle that is a **corrected contract, not a regression**: the
150
- spoke still exits at the source mid-port, it just bends to converge. The
151
- labelled-source-straightening pass (`alignLabeledSourcePort`) accordingly *yields*
152
- to a fan-in hub and still straightens only a labelled source into a single-input
153
- target.
154
-
155
- ## The bigger architectural opportunity (larger scope, separate track)
156
-
157
- Much of the 16-pass whack-a-mole re-derives by hand what an exact solver one stage
158
- upstream already owns:
159
-
160
- - ELK already runs **Brandes–Köpf** (correct-by-construction coordinate
161
- assignment), then we override it with **6 node-moving heuristic passes**.
162
- Switching to `NETWORK_SIMPLEX` placement + `nodeFlexibility: PORT_POSITION` (or
163
- BK + `edgeStraightening: IMPROVE_STRAIGHTNESS`) folds **port-exactness +
164
- straightness into the placement solve** — potentially retiring several passes.
165
- - An **exact orthogonal router** (libavoid: A\* over an orthogonal visibility
166
- graph, *provably* bend-and-length-optimal per connector, object-avoiding by
167
- construction — Wybrow–Marriott–Stuckey 2009) would make
168
- `diagonalSegments`/`edgeThroughNode`/`unexplainedBends` zero **by construction**.
169
- - **Constraint solvers** (VPSC / IPSep-CoLa) guarantee non-overlap + alignment +
170
- directed-flow as *hard* constraints — but only when satisfiable; over-constrained
171
- systems degrade (silently, in WebCola). Net: they convert open-ended
172
- geometry-repair bugs into *one* characterizable failure mode (constraint
173
- infeasibility) you fuzz once.
174
- - **Exact ILP/SAT/SMT is disqualified** for us: NP-hard, tens of nodes, runtime
175
- *nondeterministic* (one SAT layout solver's UNSAT proofs: median 4 min, max
176
- 23 h) — fatal to deterministic real-time. Lone exception: Tamassia
177
- min-cost-flow bend-minimization is poly + deterministic but only for a *fixed*
178
- embedding (a full Topology-Shape-Metrics rewrite).
179
-
180
- ## Per-invariant verdict table
181
-
182
- | Invariant | Status | Mechanism |
183
- | --- | --- | --- |
184
- | Determinism | **Guaranteed by construction** | pure functions, fixed orderings, integer predicates |
185
- | Port-exactness | **Guaranteeable by construction** (currently optimize-and-certify) | emit endpoints from `shapePorts`/`diamondFacetPorts` + grid-snap; FIXED_POS ports |
186
- | Axis-alignment / no diagonals | **Guaranteed by construction** | emit only axis-aligned segments |
187
- | No edge-through-node / no hitch | **Optimize-and-certify** (feasible ⇒ achievable) | straighten then independent checker; on reject keep the ELK route |
188
- | No node overlap | **Guaranteeable by construction** | separation constraints (VPSC) — when satisfiable |
189
- | No-label-occlusion | **Optimize-and-certify** (NP-hard) | maximize placed; veto-and-fallback (never draw occluding) |
190
- | No-label-on-shared-trunk | **Optimize-and-certify** (NP-hard) | duplicate-lane construction + veto-and-fallback |
191
- | Min crossings / bends / area | **Provably impossible to guarantee** | NP-hard; certify "no worse than input, count = N", never "minimum" |
192
-
193
- ## Prioritized roadmap
194
-
195
- 1. **Minimal (recommended first):** extend duplicate-lane repair to labeled bent
196
- duplicates + veto-and-fallback → flip `APL_DECOUPLE_LABELS` to default-on; add
197
- the net-benefit gate to `bundleEdgePaths`. Retires problems 1 and 3, enforces
198
- problem 2. Lowest risk; ships the validated decoupling win.
199
- 2. **Robustness hardening:** exact integer predicates on snapped coordinates +
200
- one independent total checker run on every output. Attacks the 1–2px fuzz class
201
- at the root.
202
- 3. **Upstream re-architecture:** ELK placement strategy + libavoid-style exact
203
- router + a VPSC post-pass. Biggest payoff, biggest scope.
204
-
205
- ## Honest bottom line on "100%"
206
-
207
- - **Achievable and worth driving to zero by construction + checking:**
208
- determinism, port-exactness, axis-alignment, no-edge-through-node,
209
- no-unexplained-bend, no-hitch, no-node-overlap (these are *conventions /
210
- feasibility*).
211
- - **Achievable only as "certified-clean-or-explicit-fallback":**
212
- no-label-occlusion, no-label-on-shared-trunk (NP-hard placement — you cannot
213
- have fixed-position-AND-always-clean for every input).
214
- - **Provably impossible to guarantee as a minimum:** crossings, bends, area, edge
215
- length (NP-hard). Saying so plainly is part of dimension-7 "trust."
216
-
217
- The path to "no fuzz-surfaced geometric violation, ever" runs through **exact
218
- predicates + an independent, mandatory checker + exhaustive small-scope
219
- verification**, with fuzzing relegated to adversarial tail-coverage — not through
220
- a search for a complete construction that the literature proves does not exist.
221
-
222
- ## Citations
223
-
224
- **Aesthetic invariants & complexity.** Di Battista, Eades, Tamassia, Tollis,
225
- *Graph Drawing*, Prentice Hall 1999; Tamassia (ed.), *Handbook of Graph Drawing
226
- and Visualization*, CRC 2013. Garey & Johnson, "Crossing Number is NP-Complete,"
227
- *SIAM J. Alg. Disc. Meth.* 4(3), 1983. Eades & Wormald, "Edge crossings in
228
- drawings of bipartite graphs," *Algorithmica* 11, 1994. Tamassia, "On embedding a
229
- graph in the grid with the minimum number of bends," *SIAM J. Comput.* 16(3),
230
- 1987. Garg & Tamassia, "On the computational complexity of upward and rectilinear
231
- planarity testing," *SIAM J. Comput.* 31(2), 2001. Sugiyama, Tagawa, Toda, *IEEE
232
- TSMC* SMC-11(2), 1981. Brandes & Köpf, "Fast and simple horizontal coordinate
233
- assignment," GD 2001 (LNCS 2265; erratum arXiv:2008.01252). Purchase, "Metrics for
234
- graph drawing aesthetics," *JVLC* 13(5), 2002.
235
-
236
- **Label placement.** Kakoulis & Tollis, "Labeling Algorithms," ch. 15 in the
237
- Handbook (CRC 2013); "On the Complexity of the Edge Label Placement Problem,"
238
- *Comput. Geom.* 18(1), 2001 (ELP NP-hard, reduction from 3-SAT); "A Unified
239
- Approach to Automatic Label Placement," *IJCGA* 13(1), 2003 (conflict-graph +
240
- bipartite matching, maximize placed). Marks & Shieber, "The Computational
241
- Complexity of Cartographic Label Placement," Harvard TR-05-91, 1991 (NP-complete;
242
- optimal ⇔ P=NP). Formann & Wagner, SoCG 1991. van Kreveld, Strijk, Wolff, "Point
243
- labeling with sliding labels," *Comput. Geom.* 13, 1999 (slider models, PTAS).
244
- Bekos, Kaufmann, Symvonis, Wolff, "Boundary Labeling," *Comput. Geom.* 36(3), 2007
245
- (crossing-free, all-labels, poly-time for one-/two-opposite-sided — the escape
246
- hatch); Kindermann et al., "Multi-Sided Boundary Labeling," *Algorithmica* 76(1),
247
- 2016. Binucci et al., "Orthogonal drawings of graphs with vertex and edge labels,"
248
- *Comput. Geom.* 32(2), 2005 (ILP, no-overlap by enlarging the drawing).
249
-
250
- **Routing, ports, parallel edges.** Wybrow, Marriott, Stuckey, "Orthogonal
251
- Connector Routing," GD 2009 (libavoid; per-connector bend/length optimal);
252
- "Orthogonal Hyperedge Routing," Diagrams 2012. Spönemann et al., "Port Constraints
253
- in Hierarchical Layout of Data Flow Diagrams," GD 2009 (FREE/FIXED_SIDE/
254
- FIXED_ORDER/FIXED_POS). Rüegg et al., "Size- and Port-Aware Horizontal Node
255
- Coordinate Assignment," GD 2015. Gansner, Koutsofios, North, Vo, "A Technique for
256
- Drawing Directed Graphs," *IEEE TSE* 19(3), 1993 (edge label = virtual node).
257
- Holten, "Hierarchical Edge Bundles," *IEEE InfoVis* 2006; Holten & van Wijk,
258
- "Force-Directed Edge Bundling," *EuroVis* 2009 (bundling does not reduce
259
- crossings).
260
-
261
- **Constraint-based layout.** Dwyer, Koren, Marriott, "IPSep-CoLa," *IEEE TVCG*
262
- 12(5), 2006 (hard separation constraints by gradient projection); Dwyer, Marriott,
263
- Stuckey, "Fast Node Overlap Removal," GD 2005 (VPSC, O(n log n)); Dwyer & Koren,
264
- "Dig-CoLa," InfoVis 2005; Hoffswell, Borning, Heer, "SetCoLa," EuroVis 2018
265
- (WebCola constraints degrade silently when infeasible).
266
-
267
- **Robustness / exactness / verification.** Kettner, Mehlhorn, Pion, Schirra, Yap,
268
- "Classroom examples of robustness problems in geometric computations," *Comput.
269
- Geom.* 40(1), 2008. Yap & Dubé, "The exact computation paradigm," 1995. Shewchuk,
270
- "Adaptive precision floating-point arithmetic and fast robust geometric
271
- predicates," *DCG* 18(3), 1997. Edelsbrunner & Mücke, "Simulation of Simplicity,"
272
- *ACM TOG* 9(1), 1990. Hobby, "Practical segment intersection with finite precision
273
- output," *Comput. Geom.* 13, 1999. Fabri & Pion, "CGAL," ACM SIGSPATIAL 2009
274
- (EPICK/EPECK). McConnell, Mehlhorn, Näher, Schweitzer, "Certifying algorithms,"
275
- *Computer Science Review* 5(2), 2011. Alkassar, Böhme, Mehlhorn, Rizkallah,
276
- "Verification of certifying computations," CAV 2011. Chen, Cheung, Yiu,
277
- "Metamorphic testing," HKUST-CS98-01, 1998. Jackson, *Software Abstractions*, MIT
278
- Press, 2006 (small-scope hypothesis).
279
-
280
- **Industry practice surveyed.** yFiles (integrated vs. generic labeling;
281
- `integratedEdgeLabeling` default false; ParallelEdgeRouter), Graphviz (`label`
282
- dummy-node vs. `xlabel`/`forcelabels`; `concentrate`), ELK (`LabelDummyInserter`/
283
- `Switcher`/`Remover`; BK vs. NETWORK_SIMPLEX placement), OGDF (ELabelInterface),
284
- Adaptagrams/libavoid + cola.js, tldraw (`normalizedAnchor`/`isPrecise`/elbow
285
- arrows), Excalidraw (`FixedPointBinding`), draw.io/mxGraph (`exitX`/`entryX` fixed
286
- connection points; `mxParallelEdgeLayout` spacing).
287
-
288
- ## Empirical addendum — what we actually measured
289
-
290
- The roadmap above lists three theory-backed candidate fixes. We implemented and
291
- measured each against our own rubric (`bun run track`, corpus-wide column totals;
292
- the bar is **HARD must stay 0** and a soft net-improvement). **All four levers we
293
- could test as bounded changes were neutral-or-regressive on this corpus** — the
294
- current pipeline is already near a local optimum. Reference (current shipping,
295
- Brandes–Köpf BALANCED + the 6 node passes): **HARD 0, offCardinal 70, bends 351,
296
- strtDeficit 74, crossings 1** over 74 tracked diagrams.
297
-
298
- | Experiment | offCardinal | bends | strtDeficit | crossings | Verdict |
299
- | --- | --- | --- | --- | --- | --- |
300
- | **HEAD** (BK BALANCED + 6 passes) | 70 | 351 | 74 | **1** | reference |
301
- | Bundling net-benefit gate (bends+crossings) | — | — | — | — | wash; trades bend wins for `offCardinal`/sym regressions → reverted |
302
- | Flip `APL_DECOUPLE_LABELS` default | (6↑ / 23↓ vs baseline incl. **+2 crossings**) | | | | net-regressive; opt-in confirmed correct |
303
- | **Network-simplex** + `favorStraightEdges` | 64 | 354 | 71 | **3** | lateral: cardinal/straight ↓ but **+2 crossings** |
304
- | Network-simplex + `nodeFlexibility=PORT_POSITION` | 64 | 354 | 71 | 3 | **no-op** — inert against our `FIXED_SIDE` ports |
305
- | BK + `bk.edgeStraightening=IMPROVE_STRAIGHTNESS` | 70 | 351 | 74 | 1 | **no-op** — already BK's default |
306
- | Independent hard-invariant gate (corpus + fuzz) | 70 | 351 | 74 | 1 | **shipped** — additive test, zero geometry change |
307
- | Exact integer-snap predicate in `simplifyPolyline` | 70 | **349** | 75 | **3** | **HARD 0→1** (off circle outline) + crossings → reverted |
308
-
309
- **Conclusions.**
310
-
311
- 1. **No ELK placement strategy beats the current pipeline.** Network-simplex
312
- reorders enough to add crossings (1→3) on an already-near-crossing-free corpus;
313
- `PORT_POSITION` flexibility is inert because our ports are `FIXED_SIDE` with an
314
- explicit index. The 6 downstream node passes are doing real, near-optimal work
315
- that no placement config replicates.
316
- 2. **The decoupling default-flip and the bundling gate both regress the rubric** —
317
- the band-aids the research recommended are net-negative *here*, because our
318
- post-ELK passes already extract the straightness/symmetry/cardinality that
319
- decoupling and naive bundling give up.
320
- 3. **The "sandy ε foundation" hypothesis was wrong — measured.** Converting the
321
- shared collinearity predicate in `simplifyPolyline` to an exact integer-snapped
322
- orientation determinant (the EGC recommendation) *regressed*: it broke a hard
323
- invariant (an endpoint flattened off a **circle outline**) and added crossings,
324
- because a fixed 1px decision grid is a *scale-independent* predicate while the
325
- existing `|cross| < EPS` is *scale-appropriate* (it only removes float-noise
326
- collinearity, ~1e-4 px on long segments) — and our curved-shape endpoints carry
327
- load-bearing sub-pixel precision. The scattered ε's are not actually
328
- inconsistent in value (the axis test is `0.01` everywhere); the heuristic
329
- "fighting" is genuine multi-objective tension (straightness vs symmetry vs
330
- cardinality — NP-hard trade-offs), not predicate inconsistency. So exact
331
- predicates do **not** unblock the symmetry/decoupling regressions.
332
- 4. **The one delivered win is the independent hard-invariant gate**
333
- (`property-hard-invariants.test.ts`): the rubric oracle run over the full
334
- flowchart corpus + fuzz, asserting zero hard violations. It is purely additive
335
- (no geometry change) and is the safety net that lets new placement/routing
336
- heuristics be added aggressively — any hard-invariant regression now fails
337
- loudly and immediately. The symmetry/port fix itself remains a **placement
338
- heuristic on the pipeline** (as `12ba4e6` already did for fan-out D/E
339
- equalization), now protected by that gate — not a foundation rewrite.
340
- 5. **The genuine remaining structural win is still the exact-router rewrite**
341
- (libavoid-style A\* over an orthogonal visibility graph) — but its upside is
342
- bounded (corpus already at crossings = 1) against a multi-week, high-risk
343
- rewrite, so it is a deliberate future bet, not a quick fix.
344
-
345
- **Bottom line:** the pipeline is at a well-tuned local optimum; every bounded
346
- "improve/exactify/re-architect" lever we measured was neutral-or-regressive. The
347
- durable value is (a) this map of what does and doesn't work, and (b) the independent
348
- gate that makes the next targeted placement heuristic safe to add.
349
-
350
- Method/scripts for reproduction live in the session scratchpad; re-run
351
- `bun run track` and sum the `off/bend/strt/xing` columns to reproduce the table.