Skip to content

ADR-0014: Single-cycle subgraphs and components are drawn as rings

  • Status: Proposed
  • Date: 2026-11-29

Flywheels, PDCA loops, growth loops and release cycles are cycles, and the cycle is what the author means to show. The layered engine (layout.md) breaks every cycle by reversing one edge, so a six-step loop becomes a column of six nodes with one long edge running back from the last to the first. Two linked loops become two such columns. Authors who want a wheel then place the geometry by hand in SVG, which loses everything Merlion guarantees: theming, measured labels, the outline and determinism.

Mermaid 12.0.0 has no circular layout for flowcharts; config.layout selects dagre or elk, both layered. Merlion’s compatibility contract is the graph (nodes, edges, labels, clusters, directions), not positions (parser.md), so a different drawing of the same graph stays compatible.

A flowchart subgraph with no nested subgraph and no direction of its own, holding 3 to 16 nodes whose edges are exactly one directed cycle, is drawn as a ring; so is a connected component of 3 to 16 nodes outside every subgraph that is exactly one cycle (layout.md). The layered engine lays out the rest of the chart with each ring replaced by one node of the ring’s size. Each ring is then turned to face the nodes its other edges reach, and those edges run straight when nothing is in the way. config.merlion.rings: false and a subgraph’s own direction keep the layered drawing. State diagrams keep it always.

Option Buys Costs
Detect single-cycle subgraphs and components No syntax: the same Mermaid source renders as a ring in Merlion and as the same graph everywhere else; models and authors write nothing new Changes the drawing of every existing diagram with such a cycle (none of the 391 diagrams in the compat corpus); an author who wants the chain must opt out
New syntax: direction ring or a ring shape keyword Explicit; nothing changes unasked A dialect: the source fails to parse on GitHub, in Obsidian and in mermaid itself, the failure ADR-0012 rejected for charts
An opt-in key, config.merlion.layout: ring Mermaid-compatible and explicit Front matter applies to the whole diagram, not one subgraph, and an author or model has to know the key before the feature exists for them
A circular or force-directed layout for the whole graph Covers graphs that are not one cycle Drops what the layered engine gives the rest of the diagram: container fit, stable layout, dominator layering, clusters and orthogonal routes
A ring layout with a router of its own for the whole chart One routing model inside each ring and outside it A second complete router to keep deterministic and fuel-bounded, for diagrams that are mostly layered

Portability of the source, author effort, and reuse of the layered engine’s guarantees. Portability ruled out new syntax. Author effort ruled out the opt-in key. Reuse ruled out the whole-graph and whole-chart layouts. Detection kept all three; its cost, a changed drawing for diagrams that already hold such a cycle, is bounded by the opt-outs and measured at zero in the compat corpus.

  • Easier: a flywheel, or two linked flywheels, is a plain Mermaid flowchart. The ring keeps every flowchart guarantee: themed, measured, outlined, and byte-identical native and WASM (the rings determinism corpus).
  • Harder: a flowchart can hold two drawing styles. Edges that meet a ring run straight or detour round it, beside the engine’s orthogonal routes, and that routing has its own obstacle tests and fuel.
  • Harder: a ring is sized before container fit runs, so narrower label wrapping does not shrink it, and every slot is sized for the largest member. A ring’s members are placed by the cycle order and the turn, so the stable-layout hint covers only the first member.
  • Expensive to reverse: diagrams written to render as rings.
  • Unmeasured: ring drawings have fixture coverage (tests/fixtures/rings/) and invariant tests, no reader study, and no benchmark against another renderer, since none draws flowchart cycles as rings.