Layer maps
render_layer_map draws a layer map from a merlion-layer-map/1 JSON spec: named zones (boundaries), ordered rows inside each zone (comparison layers), and cards (items) in stable columns, with optional adjacent zones beside the main map. A layer map compares layers and boundaries, not flows: it has no edges, and its layout never reorders anything to reduce crossings. Output follows the shared SVG contract (svg-output.md): one self-contained SVG, labels as <text>, colours as CSS custom properties, role="img" with <title> and <desc>, no script, and byte-identical bytes from the native core and WASM. ADR-0016 records why layer maps take their own JSON spec.
The input rules are those of chart specs (chart.md), read by the same JSON reader:
- The input is one UTF-8 JSON document (RFC 8259) of at most
limits.input_bytes(1 MiB); a larger one fails withE004. - Invalid JSON, nesting deeper than
limits.nesting(64), an object with more than 64 members, an array with more than 10,000 items, and a duplicate member name in one object fail withE020at the byte where reading stopped. - A member the spec does not define fails with
E021naming its JSON Pointer path (/zones/0/rows/1/cards/2/colour), so a misspelt member never draws a different map. - Every spec error carries its line, column and byte span in the input.
| Member | Type | Required | Meaning |
|---|---|---|---|
layerMap |
the number 1 |
yes | Format version |
title |
text, 1–200 characters | yes | The map’s accessible name, written into <title>. The map draws no visible title: the host page draws the figure’s frame |
description |
text, 1–2,000 characters | no | The second line of the outline and <desc> |
zones |
array of 1–32 zones | yes | The main map’s zones, drawn top to bottom in array order |
adjacent |
array of 0–16 zones | no | Zones beside the main map, such as external systems, drawn top to bottom in array order (Fitting the width) |
A zone is a boundary:
| Member | Type | Required | Meaning |
|---|---|---|---|
id |
id | yes | The zone group’s data-merlion-id |
title |
text, 1–80 characters | yes | Drawn at the zone’s top-left corner |
role |
role name | no | A cluster role (Roles) |
rows |
array of 1–64 rows | yes | Drawn top to bottom in array order |
A row is a comparison layer:
| Member | Type | Required | Meaning |
|---|---|---|---|
id |
id | yes | The row group’s data-merlion-id |
title |
text, 1–80 characters | no | Drawn left of the row’s cards, or above them at narrow widths |
cards |
array of 1–32 cells | yes | Cell k is column k: a card, or null for an empty column. At least one cell is a card |
A card is one item:
| Member | Type | Required | Meaning |
|---|---|---|---|
id |
id | yes | The card group’s data-merlion-id |
label |
text, 1–80 characters | yes | The card’s title, drawn SemiBold |
detail |
text, 1–400 characters | no | Drawn below the label in smaller, muted text |
role |
role name | no | A node role (Roles) |
- A zone without rows, a row without cells, and a row whose every cell is
nullfail withE021(“needs at least one row”, “needs at least one card”). - An array longer than its limit fails with
E021at the array’s path. More than 2,000 cards in the whole map fails withE004at the first card past the limit.
Every text member is plain text: no Markdown and no <br>. **Q3** draws two asterisks on each side of Q3.
- Tab, line feed and carriage return count as spaces; runs of spaces collapse to one; leading and trailing spaces are dropped. Other control characters and U+FFFE/U+FFFF are dropped.
- Bidirectional formatting characters (U+202A–U+202E, U+2066–U+2069) are stripped with
W014(svg-output.md). - Text that is empty after these rules fails with
E021. Length limits count characters after them. - The drawing, the outline and
<desc>carry the text after these rules.
- An id is 1–64 ASCII letters, digits,
-and_; anything else fails withE021. - Zones, rows and cards share one namespace: an id that an earlier zone, row or card already uses fails with
E025at the later one, and the message names the earlier one’s path.
A role is a class name matching [A-Za-z_][A-Za-z0-9_-]{0,63} (svg-output.md); another value fails with E021. Role classes carry presentation only.
- A card’s
roleaddsmerlion-c-{role}to its group. The built-in node roles (accent,ok,warn,danger,muted,store) draw exactly as on a flowchart node (Built-in roles). - A zone’s
roleaddsmerlion-cc-{role}to its group. The built-in cluster roles (group,series-1…series-8) draw exactly as on a flowchart cluster. - Any other name has no built-in style. A page rule or a stylesheet sets its
--merlion-toneand--merlion-dash, and a baked palette carries that tone (Palette). - Automatic tones (svg-output.md): with
auto_toneon (the default), zone numbern(0-based, the main zones then the adjacent zones) without aroletakesseries-{n mod 8 + 1}andmerlion-auto. A zone with aroletakes no automatic tone; the zones after it keep their numbers. Cards and rows take no automatic tone.auto_tone: false, the CLI’s--no-auto-toneand the WASMautoTone: falseturn them off. - Rows take no role.
Layout
Section titled “Layout”All sizes are in px. The target width W is target_width clamped to 240–20,000. Text is measured with the diagram font tables (text-measurement.md), and its drawn width is its measured width times the tolerance t of the font mode, as for diagram labels: t is 1.06 for system and 1 for link and embed. A text wrapped to a drawn width w breaks where its measured width would exceed w ÷ t, except where a rule below names the measured limit itself.
| Text | Size and weight |
|---|---|
| Zone title, card label | font_size (default 14), SemiBold |
| Card detail | 0.8 × font_size, regular, below the label with the title + detail gap of svg-output.md |
| Row title | 6/7 × font_size (12 at the default), regular |
- Zones. The main zones stack top to bottom in array order, 16 apart, from (2, 2). A zone’s title sits 10 below its top and 12 from its left; its first row starts 10 below the title. Rows are 10 apart, and a zone ends 12 below its last row.
- Areas. The main zones form one area and the adjacent zones another. All zones of an area have one width and one column grid, so cards line up row by row and zone by zone.
- Columns. An area has as many columns as its longest row has cells,
nullcells included. Every card iscardwide, columns are 8 apart, and columnkstarts atzone x + 12 + gutter + k × (card + 8). An empty cell draws nothing and moves no card. - Row titles. In a gutter, the gutter is the drawn width of the area’s widest row title, at most 160, plus 12; it is 0 when no row of the area has a title. Row titles wrap at the widest title’s measured width, or at
160 ÷ twhen the cap applies, so the title that sizes the gutter never wraps. A row title starts at the zone’s left padding and is centred vertically on its row. Above the cards, a row title wraps to the zone’s inner width and sits 4 above them. - Cards. A card’s label and detail wrap at the measured limit
(card − 20) ÷ tand are centred in the card. Every card of a row is as tall as the row’s tallest label plus 16. A word whose measured width exceeds that limit breaks between characters. - The drawing is as wide and as tall as its zones plus 2 on each side.
Fitting the width
Section titled “Fitting the width”Fitting the width resizes columns and moves blocks; it never moves a card to another column, row or zone. Let fixed(area, gutter) be 24 + gutter + 8 × (columns − 1). The comfort width is the narrowest whole-pixel card width, at least 120 and at most 240, whose limit (card − 20) ÷ t holds the measured width of every word of every card label and detail; a word whose measured width exceeds 220 ÷ t breaks at any card width and does not count. The fit therefore follows from the spec, the target width and the font mode alone, and a word that sets the comfort width never breaks at it. The first of these that applies is used, and the root carries its name as data-merlion-fit:
| Fit | When | Card width | Adjacent zones | Row titles |
|---|---|---|---|---|
beside |
There are adjacent zones, and the card width that fills W with both areas side by side, floor((W − 4 − 16 − fixed(main) − fixed(adjacent)) / (main columns + adjacent columns)), is at least the comfort width |
That width | Beside the main map, 16 to its right, top-aligned with it | In the gutter |
below |
The card width that fills W with each area on its own, floor(min over the areas of (W − 4 − fixed(area)) / columns), is at least the comfort width |
That width | Below the main map, 16 under it | In the gutter |
stacked |
Otherwise | The same width with no gutter, at least 72 | Below the main map | Above their cards |
- The card width is at most 240, so a map with few columns can be narrower than
W. - At a card width of 72 the map can be wider than
W. The SVG keeps itsviewBoxand scales down in its container, so every card keeps its column.
- The root has
class="merlion merlion-layer-map",data-merlion-layer-map="1"anddata-merlion-fit.<title>holdstitle;<desc>holds the outline (Text alternative). - The embedded style is the diagram style (svg-output.md): the node, cluster, label and detail rules, the token reset, the role rules of the roles in use, and one rule of its own,
.merlion-layer-row-title, drawing row titles in--merlion-mutedat the row-title size. - No element carries
merlion-edge, and the SVG has no<a>, no hover rules and nodata-merlion-layout.
Groups and data attributes
Section titled “Groups and data attributes”Zones and titled rows are cluster groups and cards are node groups, so every rule of svg-output.md and interaction.md that reads those classes reaches them unchanged. Groups appear in authored order: each zone, the main zones first; inside it each row; inside each row its cards in column order.
| Element | Markup |
|---|---|
| Zone | <g class="merlion-cluster merlion-layer-zone"> with merlion-layer-adjacent on an adjacent zone, then its role classes, and data-merlion-id. Its children are <rect class="merlion-cluster-box"> (corner radius 4), the title <text class="merlion-cluster-title"> and the row groups |
| Titled row | <g class="merlion-cluster merlion-layer-row" data-merlion-id="…">; its first child is the title <text class="merlion-cluster-title merlion-layer-row-title">. It draws no box |
| Untitled row | <g class="merlion-layer-row" data-merlion-id="…">: not a cluster, because the viewer names a cluster by its title |
| Card | <g class="merlion-node" data-merlion-id="…" data-merlion-rank="0" data-merlion-column="{k}"> plus its role class, holding <path class="merlion-shape"> (the rounded rectangle of a flowchart A(text) node) and <text class="merlion-label"> |
- A card’s label lines and detail lines form one title + detail label (svg-output.md): each detail line is a
<tspan class="merlion-detail">with its measuredfont-size. A label with no detail has only title lines. - Zone titles and row titles are left-aligned; card labels are centred.
- Every line
<tspan>that continues a word broken at the wrap width carriesdata-merlion-join="true"(interaction.md), so the name the viewer rebuilds from the drawing equals the text in the outline. - The SVG id is the
id_prefix, orm+ 8 hex of FNV-1a 64 over the spec text, the options key andlayer-map(svg-output.md).
Text alternative
Section titled “Text alternative”The outline is returned as plain text and written into <desc>:
Layer map. How the product organisation is layered. 4 zones, 8 rows, 19 cards.Each zone is a boundary; each row compares one layer across the same three customer segments.Beside the map: External systems.Commercial context / Segments: Enterprise Annual contracts, procurement reviewCommercial context / Channels: Field salesExternal systems / Identity: Customer identity providers- The first line is
Layer map. {title}.and the counts of zones (main and adjacent), rows and cards. Then thedescription, when given, andBeside the map: {adjacent zone titles}., when there are adjacent zones. - Then one line per card in authored order:
{zone title} / {row title}: {label} {detail}, without/ {row title}for an untitled row and without{detail}for a card without one. - Every zone and every titled row appears in its cards’ lines, so the text alternative names every boundary and every layer with JavaScript off.
Viewer
Section titled “Viewer”<merlion-view> loads @fractalboxdev/merlion-view/interact for a layer map as for any Merlion SVG (viewer.md), and the module applies to it without change: the SVG has class merlion and no .merlion-edge.
- Pin. A tap on a card, or Enter on the keyboard’s current card, pins it. A card has no incident edges, so its lit set is the card alone and every other card dims. A second tap, a background tap or Esc clears the pin.
- Popover. The heading is the card’s label; the body is its detail lines, muted; the context line is its zone title and row title joined by
/, read from the cluster titles that enclose it. - Hover thickens the pointed card’s border and does nothing else.
- Keyboard. The arrow keys walk every card in outline order, which is authored order: each card’s outline line equals its viewer prefix
{cluster path}: {name}(interaction.md). Each move and each pin announces the card’s outline line in the live region, so a keyboard user hears the zone, the row, the label and the detail that a pointer user reads in the popover. - Accessible names. The host takes the map’s
titleas its name (viewer.md); a card’s announcement is its outline line, and zones and rows are named by their titles. - Collapse. A tap on a zone title collapses the zone, and a tap on a row title collapses the row, under the cluster rules (interaction.md): the cards are hidden, the title gains
+N, and Show all restores the markup byte for byte. Collapse stays because it is the cluster gesture on every Merlion diagram, and because it hides presentation only: nothing reflows, so every other card keeps its position and its column. An untitled row cannot collapse. - Clearing the pin and the keyboard’s current card restores
svg.outerHTMLbyte for byte. With JavaScript off, every label, detail, zone title and row title is drawn text, and the outline is in<desc>.
Diagnostics
Section titled “Diagnostics”| Code | Severity | Meaning |
|---|---|---|
E004 |
Error | The input exceeds limits.input_bytes, the map has more than 2,000 cards, or its fuel is exhausted |
E020 |
Error | The input is not valid JSON, exceeds a nesting, object-member or array-item limit, or repeats a member name (as for charts) |
E021 |
Error | The spec’s shape (as for charts): an unknown or missing member, a wrong type or version, an id or role outside its grammar, text empty or over its length, a zone without rows, a row without a card, an array over its limit |
E025 |
Error | An id that an earlier zone, row or card already uses |
W014 |
Warning | Bidirectional formatting characters stripped from text |
I010 |
Info | A character outside the font tables; its width is estimated |
E020 and E021 keep the meanings they have for charts because both formats are read by the same JSON reader and report shape the same way. strict promotes W014 to an error.
Limits
Section titled “Limits”| Limit | Value |
|---|---|
| Input / nesting | limits.input_bytes / limits.nesting |
| Zones | 1–32 main, 0–16 adjacent |
| Rows per zone / cells per row | 1–64 / 1–32 |
| Cards | 2,000 |
| Text | title 200, description 2,000, zone and row titles and card labels 80, detail 400 characters |
| Fuel | One unit per zone, row and card, against fuel |
Out of scope
Section titled “Out of scope”Edges or links between cards, cards spanning several columns or rows, column headers, zones inside zones, links on cards, row roles, the CSS hover layer, and layout hints. Links between cards are added only when a second use case needs them; a flowchart draws flows.
Validation
Section titled “Validation”crates/merlion-render/tests/layer_map_acceptance.rsrenders every fixture intests/fixtures/layer-map/strictly at 960, 720, 600 and 360 px; checks byte-identical repeats, authored zone, row and card order and column alignment at each width with its fit, empty cells, the minimum card width, the comfort width, a sweep of single-word row titles that each size their gutter without wrapping in thesystemandlinkfont modes, the outline and<desc>, join marks against the rebuilt card name, plain text andW014, every error code with its JSON path, line and column (one fixture per error intests/fixtures/layer-map/invalid/), every limit and fuel, the group markup the viewer reads, roles, automatic zone tones and a palette tone. It records each fixture’s SVG and outline digest (FNV-1a 64,data-merlion-versionblanked) intests/fixtures/layer-map-digests.txt.packages/merlion-wasm/test/glue.test.mjsrenders a fixture throughrenderLayerMapfrom a string and from an object, checks errors throughcheckLayerMap, and renders every fixture inlayer-map-digests.txtthrough the WASM build to the recorded native digests.crates/merlion-cli/tests/cli.rschecks thatmerlion render --layer-mapwrites the core’s SVG and outline, from a file and from standard input.bench/test/viewer.browser.mjs(Playwright, headless Chromium) taps a card and checks its lit set, popover and announcement; checks that a second tap clears; walks every card with the arrow keys in authored order, each announcing its outline line, also at a width that breaks words; pins with Enter and clears with Esc; collapses a zone and restores it with Show all; and checks thatsvg.outerHTMLafter clearing equals its value before.