Relations
Under --- relations, each line is one statement:
verb[#id][.class…] targets {properties}
Relations are hard: they say what layout must hold, and they win over the sketch. There are four verbs: stack and box arrange tokens, and arrow and line connect them.
Targets and groups
Targets are references. Each […] is a group, and a statement draws one relation per group: box [A B] [C D] draws two boxes. Without brackets, all the targets form one group. The {properties} apply to every group, and an #id with several groups is an error (use a class).
An indented line continues the statement above it, so long groups can wrap:
1 2 3
4 5 6
--- relations
box.row
[1..3]
[4..6]
--- styles
.row: fill=#f0f9ff rx=8
stack
stack spaces its targets gap apart, edge to edge (default 10), and centers them on the other axis. Its direction comes from the sketch: targets written on one row stack horizontally, otherwise vertically.
Mercury
A B C D
--- relations
stack [A..D] {gap=50}
stack [Mercury A] {gap=30}
--- styles
A..D: circle r=20 fill=#dbeafe ::text hidden
The anchor rule: targets that an earlier relation already placed stay where they are, and the others move around them. If none is placed yet, the first target keeps its sketch position. Here A is placed by the first stack, so Mercury moves to it. Two relations placing the same axis of the same token is an error that names both.
box
box draws a box around its targets, padding away (default 10), beneath what it surrounds. Over tokens, it surrounds the tokens. Over positions, such as a whole column, it surrounds those cells, so boxes over equal columns are equally tall:
Plan Build Measure
"Goals" "Ship it" "Metrics"
--- relations
box.card [@c1] [@c2] [@c3] {padding=12}
--- styles
Plan, Build, Measure: font-weight=bold
.card: fill=#f8fafc stroke=#cbd5e1 rx=10
Boxes don't make room: where boxes sit close, widen the gaps in config. A box with an id can be an arrow's target (arrow c #t0).
arrow
arrow goes from its first target to its last; three or more targets make a chain. Its ends meet the outlines of the tokens' shapes: a circle where it's round, a rounded rectangle at its corners.
Empty cells are waypoints: the path passes through them, with no arrowhead. Name them relative to the tokens beside them, so they follow the tokens:
. . Start
. . "Is it?"
. OK . End
. Rethink
--- relations
arrow Start "Is it?"
arrow "Is it?" OK {label=Yes}
arrow "Is it?" End {label=No}
arrow OK Rethink Rethink@c-1 "Is it?"@c-2 "Is it?"
--- styles
Start, End: rect rx=999
"Is it?": polygon points="50,0 100,50 50,100 0,50" viewBox="0 0 100 100" width=110 height=64
OK, Rethink: rect
--- config
row-gap=40
Messages: an arrow between empty cells on one row, with a token between its ends, takes that token as its label and runs just below it. That row grows to make room. This is how a sequence diagram's messages work:
Alice . John
. "Hello John" .
. Great! .
--- relations
arrow "Hello John"@c-1 "Hello John"@c+1
arrow Great!@c+1 Great!@c-1
Self-loops: an arrow from a token to itself is a small loop, on the side of the token with room for it and its label:
. .
A B
--- relations
arrow A B
arrow B B {label=again}
--- styles
A, B: circle r=16
--- config
row-gap=50
column-gap=50
line
line is an arrow without heads. A whole row, column or range runs from its first cell to its last, and an empty cell at the end of a row or column is met at its outer edge, so the line spans it all. Lines run through the tokens between their ends: wires through gates, an axis through dots.
2019 . 2022
• • •
. 2020 .
--- relations
line.axis [@r2] {extend=30}
--- styles
•: circle r=8 fill=#6366f1 stroke=white ::text hidden
.axis: stroke=#94a3b8 stroke-width=4 z-index=-1
Properties
Only layout goes in {}, and each verb takes only its own properties; any other is an error. Looks go in styles, through the relation's #id or .class.
| Property | Verbs | Default | Meaning |
|---|---|---|---|
gap=N | stack | 10 | Space between neighbors, edge to edge |
padding=N | box | 10 | Space between the box and what it surrounds |
extend=N | arrow, line | 0 | Lengthen past both ends (deepens a self-loop) |
label="…" | arrow, line | Text beside the middle of the longest segment |
A label sits above its segment (to the right of a vertical one, on the bow side of a curve). If that crosses a token, another label, a line (its own arrowhead included) or a box's border, it tries the other side, then the next segment, then slides along the line. A label may still sit inside a box.
What relations don't do
- Arrows and lines never move tokens.
- Relations never change the grid, except that a message's row grows to fit it.
- There's no routing. A path is straight unless you give it waypoints, or curved with the
curvedstyle. A curve chooses only how deep it bows, to clear the tokens in its way.