Skip to content

ADR-0016: Layer maps from a JSON spec rendered by the core

  • Status: Proposed
  • Date: 2026-12-01

Some diagrams compare layers and boundaries rather than flows: a product organisation’s commercial context, delivery and offering, each with the same rows (segments, channels, services, data) compared across the same columns, and the external systems beside them. A reader compares row by row and boundary by boundary, so the positions carry the meaning: zone order, row order and column alignment must hold exactly as written, at a desktop width and on a phone.

A flowchart’s layout optimises the wrong objective for this. Layer assignment and crossing minimisation move boxes to shorten and uncross edges (layout.md); with no edges, the order inside a subgraph follows the layout’s tie-breaking, not the author’s columns. Invisible links (~~~) can pin some positions, but they state a graph that does not exist, cost one fabricated link per constraint, and still leave alignment across subgraphs to the layout. The working alternative is a hand-authored SVG, which loses Merlion’s text measurement, theme tokens, roles, outline, <desc> and viewer interaction, and must be redrawn for every width.

merlion-chart/1 (ADR-0012) shows that a versioned JSON spec rendered by the core keeps Merlion’s guarantees for a non-Mermaid form. Its members describe axes, scales and marks over data rows; none of them describes a box in a row of a zone.

The core renders a third input format, the merlion-layer-map/1 JSON spec (layer-map.md): zones of ordered rows of cards in stable columns, and adjacent zones beside the main map. It is exposed as render_layer_map and check_layer_map, the WASM exports of the same names, the JS functions renderLayerMap and checkLayerMap, and merlion render --layer-map / merlion check --layer-map. Its layout places every card by its authored zone, row and column and never reorders; fitting the width resizes columns, moves adjacent zones below the map and row titles above their cards, and past a minimum card width draws wider than the target. Zones and titled rows are emitted as cluster groups and cards as node groups, so the embedded style, roles, palettes and the viewer’s pin, popover, keyboard walk and collapse apply without a new viewer module. The spec reuses the chart’s JSON reader and its codes E020 and E021, and adds E025 for a duplicate id.

Option Buys Costs
A flowchart layout mode (a layout: grid directive) or invisible edges to pin positions One input language; existing fences render Invisible edges state a false graph and leave cross-subgraph alignment to the layered layout. A grid mode is a Merlion dialect inside the mermaid fence: GitHub, Obsidian and mermaid itself draw the same source as an ordinary flowchart with different positions, so the source means different things in different readers
A hand-authored SVG Exact control of every pixel No shared text measurement, theme tokens, roles, outline, <desc> or viewer interaction; one drawing per width; nothing validates it
Extending merlion-chart/1 with a box mark on band axes One JSON format and one entry point A chart is rows of values read through scales; a card has no value, and zones, row titles and adjacent areas have no axis. The chart spec’s member names, tests and chart: 1 contract would carry a second, unrelated model
A new JSON spec, merlion-layer-map/1, rendered by the core The spec states exactly the model (zones, rows, columns, cards); authored order is the layout; unknown members fail with a JSON Pointer path; the core’s determinism, measurement, theming, roles and accessibility apply; cards and zones reuse the node and cluster contract, so the viewer needs no change A third input format to maintain; not Mermaid, so no other renderer draws it; GitHub shows the spec as code

Fidelity to authored order, portability of the source, determinism across native and WASM, accessibility parity with diagrams, viewer budget, and maintenance. Fidelity and portability ruled out a flowchart mode or invisible edges. Accessibility and determinism ruled out a hand-authored SVG. Maintenance ruled out folding a second model into the chart spec. A separate spec whose output reuses the node and cluster markup met the viewer budget with zero bytes added to interact.js.

  • Easier: an author or an agent writes zones, rows and cards as data, and every Merlion host — the CLI, rehype, Astro, a page calling renderLayerMap — draws a map that matches its diagrams’ fonts, colours, themes and interaction. Keyboard and screen-reader users read each card’s zone, row, label and detail from its announcement.
  • Harder: three input formats share the core. Layer-map layout, its tests, its fixtures and its digests are maintained alongside charts and diagrams, and changes to the node or cluster markup must keep layer maps working in the viewer.
  • Expensive to reverse: the member names, the id and role grammars, the classes and data-merlion-* attributes in layer-map.md, the outline line format the keyboard walk matches, and the JS names renderLayerMap and checkLayerMap. Breaking changes need layerMap: 2.
  • Unmeasured: the fit thresholds (120 px comfort width, 72 px minimum, 240 px maximum) come from fixture review, not from a reader study, and no automated accessibility scan (axe-core) runs on layer maps.
  • E. R. Tufte. Envisioning Information. Graphics Press, 1990 — small multiples and comparison within the eyespan: aligned positions carry the comparison.
  • W3C. WAI-ARIA 1.2, the img role, whose children are presentational — why the viewer announces outline lines rather than referencing SVG descendants.