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.6.0/css"
/>
<script
type="module"
src="https://esm.sh/@metronforge/concept-map@0.6.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.
Both built-in engines support same-rank alignment and required box-centre
pin hints through a shared solver. Preferred pins guide sketch order and
distance; they do not promise exact centres. The four stated relation hints
(relation, align, between, equalSpacing) also use a shared placement
stage. Placement is a settling heuristic near the engine drawing, with no
guarantee of a globally nearest or most compact solution.
Pass onUnsupportedHints to receive preferred hints that were not applied:
layout(map, dagreEngine, { onUnsupportedHints: console.warn }).
Each item retains the hint and its source path. The exported UnsupportedHint
type includes reason: "unsupported" for capability or routing refusals,
reason: "contradiction" for a checked conflict, and reason: "undecided"
when placement found no answer. Conflict diagnostics can include ordered
source paths and arrow ids in conflicts. A conflict involving a preference
does not prove that the required source constraints are contradictory.
Required hints that cannot be applied throw. For stated relations,
isStatedRelationsError(error) identifies an error whose data.status is
contradiction, branch, undecided or routing. A contradiction certificate
proves infeasibility in the recorded exact 1/64-grid model, including measured
box sizes; it is not a claim about every possible drawing. A branch failure
means the source model has a checked grid placement but the engine's choices
did not yield one. Undecided proves nothing about feasibility; routing means
boxes were placed but arrows could not be routed. A feasible candidate does
not establish uniqueness. See hint syntax and support
and placement limits and errors.
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; // clear contact defects, overlapping boxes and broken required constraints
report.constraints; // per-hint and lane verdicts; free hints have holds: null
report.labels.lines; // arrow labels crossed by a line
report.overlaps; // pairs of boxes that overlap, with the shared area
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. Two boxes
overlap when they share more than 1/128 unit in both directions; touching
edges do not count, and each overlapping pair is one hard defect. Contact
thresholds are fractions of the arrow-label text size rather than fixed pixel
distances. This is a check of the specified geometric contract, not a
comparison of all semantic content in the two maps. Its tolerant drawing
verdicts differ from exact grid synthesis: a drawing can pass even when no exact
grid solution was found. A zero hard-defect count does not prove visual
quality; crossings and reading direction are separate facts.
layout(map, dagreEngine, { strict: true }) runs the same check and throws an
error carrying the report when there are hard defects. Successful layout
without strict does not promise a drawing free of hard defects. Text is
measured with built-in font tables; pass measureLabel to use your own.
Check again with the actual fonts in the browser before accepting a drawing.
- 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 |
