Follow guest → cashier → barista, then switch from Normal to Out of milk. Open the coffee shop or copy its HTML and JSON.
Save this source map as map.json. There are no coordinates:
{
"format": 3, "id": "coffee", "title": "Coffee shop", "direction": "right",
"layers": {"process": {"label": "Process"}},
"nodes": {
"guest": {"label": "Guest", "layer": "process"},
"cashier": {"label": "Cashier", "layer": "process"},
"barista": {"label": "Barista", "layer": "process"}
},
"edges": {
"order": {"from": "guest", "to": "cashier", "label": "Order"},
"ticket": {"from": "cashier", "to": "barista", "label": "Make coffee"},
"ready": {"from": "barista", "to": "guest", "label": "Coffee ready"},
"empty": {"from": "barista", "to": "cashier", "label": "Out of milk"},
"offer": {"from": "cashier", "to": "guest", "label": "Offer americano"}
},
"scenarios": [
{
"id": "normal", "label": "Normal",
"steps": [
{"id": "order", "title": "Place an order", "text": "The guest orders a coffee.", "show": ["guest", "cashier"], "current": ["cashier"], "edges": ["order"]},
{"id": "brew", "title": "Make coffee", "text": "The cashier sends the order to the barista.", "show": ["barista"], "current": ["barista"], "edges": ["ticket"]},
{"id": "serve", "title": "Serve coffee", "text": "The guest receives the coffee.", "show": [], "current": ["guest"], "edges": ["ready"]}
],
"flow": [{"node": "guest", "step": "order", "log": []}, {"node": "cashier", "step": "order", "log": ["Order received."], "edge": "order"}, {"node": "barista", "step": "brew", "log": ["Making coffee."], "edge": "ticket"}, {"node": "guest", "step": "serve", "log": ["Coffee served."], "edge": "ready"}]
},
{
"id": "out-of-milk", "label": "Out of milk",
"steps": [
{"id": "order", "title": "Order a cappuccino", "text": "The barista receives an order for a cappuccino.", "show": ["guest", "cashier", "barista"], "current": ["barista"], "edges": ["order", "ticket"]},
{"id": "empty", "title": "Check the milk", "text": "The barista tells the cashier there is no milk.", "show": [], "current": ["barista"], "edges": ["empty"]},
{"id": "offer", "title": "Offer an alternative", "text": "The cashier offers an americano.", "show": [], "current": ["guest"], "edges": ["offer"]}
],
"flow": [{"node": "guest", "step": "order", "log": []}, {"node": "cashier", "step": "order", "log": [], "edge": "order"}, {"node": "barista", "step": "order", "log": [], "edge": "ticket"}, {"node": "cashier", "step": "empty", "log": ["No milk left."], "edge": "empty"}, {"node": "guest", "step": "offer", "log": ["Offer an americano."], "edge": "offer"}]
}
]
}Load the stylesheet, one module script and one element on an HTML page:
<link
rel="stylesheet"
href="https://esm.sh/@metronforge/concept-map@0.5.0/css"
/>
<script
type="module"
src="https://esm.sh/@metronforge/concept-map@0.5.0/element"
></script>
<concept-map src="./map.json" layout="dagre"></concept-map>Serve the files over HTTP, for example with python3 -m http.server 8000.
The complete page adds a title, navigation and host styling.
The element fetches the JSON, loads dagre when needed and provides scenarios,
steps, an animated whole-map flow, keyboard controls and reduced-motion support.
Ready maps with geometry do not download a layout engine.
- Plain HTML: use
<concept-map>as above. It also accepts inline JSON or amapproperty and can hydrate server-rendered figures. Selectlayout="elk"for ELK, or supply anelement.layoutfunction. - Browser code:
mount(element, resolvedMap)from@metronforge/concept-map/domrenders an empty host or hydrates matching markup and returns a player. Callplayer.destroy()when removing the host. - Server rendering:
renderFigure(resolvedMap)from@metronforge/concept-mapreturns complete figure markup. Mount it in the browser to add interaction.
The last two accept resolved maps. For source maps, call layout(source, engine)
from @metronforge/concept-map/layout first. See integration
and automatic layout.
Framework examples: React, Vue, and Svelte.
Generate light and dark palettes or check host colours with the independent
@metronforge/concept-map/color entry. It emits CSS custom
properties without loading the player, layout engines or Zod.
All ten examples and 18 of 23 book maps use at most four layers. The measured lane labels pass text contrast, but some layer pairs and layer–accent pairs become hard to tell apart under simulated colour vision deficiencies. The generator checks all four vision models. Its two- through six-layer palettes beat the book's existing colours, including when the book accent stays fixed. See the comparison and measured distances. Applying a palette is an explicit host choice; lane labels and CSS defaults are unchanged.
Install the optional engine with npm install @dagrejs/dagre. Read the source
map, resolve its geometry, then render the complete figure:
import { readFile } from "node:fs/promises";
import { layout } from "@metronforge/concept-map/layout";
import { dagreEngine } from "@metronforge/concept-map/layout/dagre";
import { renderFigure } from "@metronforge/concept-map";
const map = JSON.parse(await readFile("map.json", "utf8"));
const resolvedMap = await layout(map, dagreEngine);
const html = renderFigure(resolvedMap);dagreEngine is an object, not a function: pass it directly to layout, without
calling it. Include html in the server response and load the package stylesheet.
Use mount in the browser to add interaction.
Pass onUnsupportedHints to layout to receive preferred hints the engine
cannot apply: layout(map, dagreEngine, { onUnsupportedHints: console.warn }).
Each item retains the hint and its source path, with reason: "unsupported"
for an engine capability refusal. The exported UnsupportedHint type also
reports reason: "contradiction" and ordered conflicts paths for dropped
same-rank groups. Both engines support same-rank alignment through an on-demand
solver. Unsafe stretched routes report reason: "unsupported" with arrow ids.
Required unsupported, contradictory or unroutable hints throw. See hint diagnostics.
Layout hints also accept pin with a node id and box-centre coordinates;
placement support is still in progress.
check(source, resolved) judges any laid-out map, whether an engine, a hand
drawing or an edited file produced it. It reports separate facts, not a score:
import { check } from "@metronforge/concept-map/layout";
const report = check(map, resolvedMap);
report.hard; // contacts that are clearly defects
report.labels.lines; // arrow labels crossed by a line
report.steps.steps; // step numbers on top of each other
report.crossings.count;
report.reading.share; // first scenario's arrows that point down or rightEach contact is tight or defect; clear ones are not listed. Thresholds are
fractions of the arrow-label text size, so scaling a map does not change its
report. layout(map, dagreEngine, { strict: true }) runs the same check and
throws an error carrying the report when there are hard defects. Text is
measured with built-in font tables; pass measureLabel to use your own.
- Door: a finite state machine — states, guarded transition labels and a self-transition. Authoring notes.
- Euclid's algorithm — a recorded loop with repeat badges and values in the log. Authoring notes.
- Layout comparison — manual geometry, dagre and ELK side by side.
Each example is a standalone HTML page plus a source JSON file. Its README records what the author had to work around; these notes inform the next release.
npm install @metronforge/concept-map zodESM only, Node ≥ 22.14. zod 4 is a peer dependency. MIT.
Install @dagrejs/dagre or elkjs when a bundled application uses that engine.
When arrow labels still collide after browser refinement, the player shows
their text beside step numbers in the panel. Whole-map mode groups the labels
by step. It checks again after resizing and restores labels to drawings that
have room. Hand-drawn boxes and routes stay fixed. See
labels in the panel.
Load @metronforge/concept-map/css separately; host colours and fonts use the
custom properties in docs/CSS.md.
Maps declare their own layers and use plain text with inline code, emphasis and
strong marks. HTML is escaped. SourceMapSchema validates maps without geometry;
ResolvedMapSchema validates geometry for playback. layout() checks semantic
references before running an engine. See the format guide.
The exported schemas use Zod Mini. parse() and safeParse() still work;
compose schemas with zod/mini and use its functional helpers instead of
classic schema methods. Check validation errors through issues (or package
errors through kind), not instanceof a classic ZodError. Map data and
validation messages are unchanged. See the format guide.
Before 1.0 any minor version may change the API. The data format has its own
number (format: 3); format 2 is no longer accepted. The planned
changes are in docs/ARCHITECTURE.md and
docs/DEBT.md.
| Entry | Contents |
|---|---|
@metronforge/concept-map |
schemas, model and server renderers |
@metronforge/concept-map/dom |
mount, MapPlayer, concepts and browser ports |
@metronforge/concept-map/element |
registers <concept-map> |
@metronforge/concept-map/layout |
layout, check and measureLabel |
@metronforge/concept-map/css |
the player stylesheet |
@metronforge/concept-map/source-map.schema.json |
JSON Schema of the source map |
@metronforge/concept-map/resolved-map.schema.json |
JSON Schema of the resolved map |
