Diagram format¶
A diagram is one YAML file. It says what exists (groups, nodes, edges) and, optionally, what happens (a scenario). Colours, fonts and sizes live in the theme, not here. To try any of it without installing diagr, paste it into the playground.
version: 1 # format version; see Versions
title: Order processing
description: One sentence, used as the accessible label.
theme: default # built-in name or a path to a theme file
icons: [./icons] # extra icon folders, searched before the core set
grid: {col: 200, row: 170} # cell size in px
direction: right # automatic layout flows right (default) or down
align: true # line up the edges of neighbouring boxes that nearly line up (default)
step_list: true # numbered badges and the step list in static output
The files a diagram builds are named after it: order-flow.yml writes order-flow.html, order-flow-light.svg
and order-flow-dark.svg. A file called diagram.yml is named after its folder instead, so
order-flow/diagram.yml writes the same files.
Every id (of a group, a node, a component, an instance, a scenario or a view) is letters, digits, _ and -,
starting with a letter or _ and not ending in -, which would run into an arrow: a-->b could be a- to b or a
dashed edge.
Groups¶
groups:
back: {title: Backend, sub: one region, icon: cloud, tone: teal}
bi: {title: Reporting, tone: neutral, at: [5, 0], span: [1, 3]}
lake: {title: Landing zone, title_at: top, tone: violet}
etl: {title: Data processing, sub: "ETL: raw to clean", title_at: middle, tone: blue}
A group is a tinted box with its title (by default its id) at the bottom left; title_at moves it: top or bottom centres it along
that edge, top-left puts it in the top corner, and middle makes it a heading, larger and bolder, centred top to
bottom just right of the box's own nodes, with sub on the line below as a description (a card with an icon on the
left and its name beside it). A box that fits its contents leaves room for the title on the side it is on. Without
at it fits around its member nodes. With at (top-left cell) and span (cells wide and tall) it covers a fixed
area, which is how you make several groups the same height. Placed automatically, layer: first or last puts a
group before or after everything else in its parent. Tones come from the theme: neutral, blue, teal, violet,
amber, green, orange.
Tones without tone. A group that leaves out tone gets one. A group that holds other groups is neutral, a
frame around them; the others take the theme's tones in turn, in the order the file has them, never their parent's.
A component's group takes one tone in all its instances. Set tone when the colour means something, such as orange,
neutral and amber for bronze, silver and gold.
Alignment. Neighbouring boxes with the same parent that nearly line up are lined up: boxes one above the other
share their left and right edges when those are within a grid column of each other, boxes side by side share their
top and bottom edges within a row. Boxes only grow, so what they hold stays inside, and a side moves only when the
grown box covers no node or box it did not cover already. A box with at keeps its cells. A diagram placed
automatically with nothing pinned is not lined up: the placer sizes its boxes itself. Child boxes that sat flush with a side that moves move with
it, so they keep filling their parent. What a grown box holds keeps its place relative to the box: its pinned nodes
and the child boxes that did not grow with it move by the shift of its middle, so a centred node stays centred. That
move is skipped on an axis where it would bend an edge running straight along it to a node outside the box, or an
edge with its own route or via; nodes placed automatically stay where they were placed. It happens level by
level, inner boxes first, so a parent fits around children already lined up. A group with boxes stacked
behind it lines up by the outline of the whole stack, so the stack never sticks out past its
neighbours. A box much narrower than its neighbour is left as it is: give it at and span to make it as wide.
align: false on the diagram turns it off.
What a group holds¶
groups:
back:
title: Backend
tone: teal
nodes:
api: {at: [1, 0], icon: function, title: API}
queue: {at: [2, 0], icon: queue, title: Order queue}
groups:
data:
title: Data
tone: amber
nodes:
db: {at: [3, 0], icon: database, title: Orders}
A group holds its own nodes and groups, to any depth, so the file has the shape of the picture. Writing a node or
group inside a box is the only way to put it there. Ids stay global: edges and scenarios name db, not back/data/db.
Nested groups¶
A fitted parent surrounds its own nodes and its child groups, with room for its title below them. A child with at keeps its fixed area and must lie inside its
parent. Each level adds a margin around the one inside it, so deeply nested groups reach a little past their columns:
leave a fractional column (at: [2.2, 0]) between them and their neighbours. show, hide and focus on a group
affect only its box.
Stacked boxes¶
groups:
compute: {title: prod workspace, behind: {compute-dev: dev workspace}, tone: neutral}
edges:
deploy-dev -> compute-dev: dev workspace
deploy-prod -> compute: prod workspace
behind stacks boxes behind a group, for the same thing in several places (a dev and a prod workspace, say), nearest
first. Each is a copy of the group's box, 24px further left and 28px further up for each step back, with its own id
and its title in the strip along its top that the box in front leaves showing. Every title in a stack, the front
box's included, sits at the top left in the same style (centred along the top with title_at: top), and a stack that
fits its contents leaves room above them for it. The nodes and child groups stay on the front box, and a parent fits
around the whole stack.
An edge can end at a box behind like at any box. If its path meets a box in front first, it stops there without a
tip, as if it went on underneath; one that reaches the box on a side that shows (its top or left strip) ends on it
with a tip. An edge from a box behind starts where it comes out from behind. The boxes behind follow the group's
show, hide and focus.
Nodes¶
nodes:
api: {at: [1, 0], icon: function, title: API, sub: validates}
worker: {at: [3, 0], icon: server, title: Workers, sub: [three replicas, autoscaled], stack: 3}
nb: {at: [2, 0], icon: notebook, title: Notebook, cells: [ingest, clean, join]}
bus: {at: [2.5, 1], junction: true}
Nodes go under nodes at the top level, or in the nodes of the group they are in. A node can also be just its
title (api: API) or nothing at all (web:), and a node that no nodes declares but an edge names is a plain node
at the top level:
edges:
web -> api -> db: [POST /orders, write]
is a whole diagram of three nodes. An edge end that is not declared but is close to an id that is (wrker next to
worker) is a warning, since it is more likely a typo than a new node. An instance's ids (a/db) are never made up
this way.
| Key | Meaning |
|---|---|
at |
Grid cell [col, row]. Fractions are allowed ([2.5, 1]). Leave it out to have the node placed for you, see Automatic layout. |
title, sub |
Text under the icon; title defaults to the node's id, and title: "" leaves it out. sub is a string or a list of lines. |
icon, tone |
Icon name; tone recolours a generated tile (blue, teal, green, violet, amber, orange, slate, red). Without icon the node is a tile with its initials (Web app is WA, API stays API), in a colour picked from its id and different from the nodes it has edges to; tone picks it instead. |
junction |
A dot where edges meet, for a bus or fan-out. No icon or text. |
cells |
A strip of progress squares. A list of names (each shows as the caption while active) or a count. |
stack |
Draw the icon as a stack of N, for "N workers". |
mark |
new, removed or changed, for as-is versus to-be diagrams. |
hidden |
Start hidden; a scenario brings it out by showing, drawing or activating it. Hidden elements are left out of static SVGs. |
tooltip |
Hover text. |
align_x, align_y |
Another node's id: line this node up with it, one above the other (align_x, same x) or side by side (align_y, same y), wherever each sits. See Row and column layout. |
layer |
first or last: placed automatically, the node goes before or after everything else in its group. See Automatic layout. |
Edges¶
The key is the edge. The value is the label, a mapping, or nothing.
edges:
web -> api: POST /orders
queue --> dlq: after 3 tries
bus -> monitor:
pipe -> refresh: {label: last step, route: [down, right]}
dispatcher -> jobs: {label: send, route: [right 70px, up, right]}
jobs@bottom+15 -> dlq: {label: three failures, route: [down, right]}
dlq --> jobs@bottom-15 as redrive: {route: [right 0.45, down 0.45, left, up]}
One key can make several edges:
edges:
web -> api -> queue -> db: [POST /orders, enqueue, write] # a chain: one edge per arrow
(mobile web) -> gateway: HTTPS # one from each
bus -> (stock search notify): # one to each
warehouse <-> dashboards: [data, {label: query, dashed: true}]
- Chains and fans.
a -> b -> cisa -> bandb -> c. Ids in parentheses, separated by spaces, are side by side:(a b) -> cis an edge from each,a -> (b c)one to each, and ports work inside ((a@top b) -> c). A label or mapping applies to every edge the key makes; a list gives one each, in order (arrow by arrow, and within an arrow from each source in turn), and must have as many items as there are edges.nullin the list is an edge with nothing on it. -->is a dashed edge, the same asdashed: true.-
<->is a pair:a -> bandb -> a, running side by side 10px either side of the middle of the sides they use, so they do not draw over each other. A list gives the first value toa -> band the second tob -> a. -
Default path. Nodes on the same row or column get a straight edge. Otherwise the edge goes sideways, then up or down.
routeis a list of moves from the start node:up,down,left,right, each with an optional length in cells (right 0.5) or px (up 40px). Moves without a length on the same axis share what is left, so[down, right]is an L and[right, down, right]is a Z with the bend halfway. The first move picks the side the edge leaves from, the last move the side it enters.- Ports.
node@sideforces a side (left,right,top,bottom), and+15or-15shifts the point along that side in px. Use it when two edges share a side. vialists explicit waypoints in grid cells, as an escape hatch.- Boxes as ends. Either end can be a group id instead of a node, or a box stacked behind one:
deploy -> workspace: dev,api -> data. When the two ends line up, the edge goes straight across: at the node's own x or y, at the named port, or in the middle of where two boxes overlap. Otherwise it goes to a side the usual way, andgroup@side+40picks the side and the point (offsets are from the side's middle). Aflowpath can pass through a box, which has no active or done state of its own;drawworks as for any edge. An edge between a node and a group it is in is an error. as namegives the edge an id, for a key that makes one edge. The default id isa->b; a second edge between the same pair needs a name.- Other keys:
dashed,mark,label_at(0 to 1 along the path; by default the label goes where it covers nothing, see Automatic layout),hidden,tooltip, andconstraint: falseto leave the edge out when placing nodes.
Automatic layout¶
Nodes without at are placed for you, so most diagrams need no coordinates at all:
groups:
back:
title: Backend
tone: teal
nodes:
api: {icon: api, title: API}
users: {icon: database, title: Users}
nodes:
web: {icon: browser, title: Web app}
mail: {icon: mail, title: Welcome email}
edges:
web -> api: sign up
api -> users: insert
api -> mail: send
When no node or group has at, diagr lays the diagram out in layers, the way Graphviz does. The layers are the
whole diagram's, like columns, so nodes in boxes side by side line up. Across the flow it goes one box at a time from
the inside out: each group's contents first, then the group as one block inside its parent, over the layers it spans.
So boxes never overlap, and a box is only as big as what it holds.
- Layers. Edges point along the flow (
direction:right, the default, ordown), each at least one layer long, and as short as they can all be together. A box (or node) that an edge goes into starts after the box (or node) it comes from, among what one box holds, so the two sit side by side. An edge that would close a loop is drawn back against the flow. - Order. Within each layer, nodes and boxes are sorted by where their neighbours sit, sweeping forward and back and keeping the order with the fewest crossings; a box keeps one place in every layer it spans. An edge that skips layers keeps a lane open in each layer it passes, so it never runs through a node, and an edge that leaves a box has a lane to the box's edge.
- Straight lines. Each node and box then moves across the flow to where its edges run straight, keeping its order and its distance from its neighbours. A chain comes out as a straight line, a node fanning out to several sits in the middle of them, and a node with one edge in and several out stays in line with the one coming in.
- Spacing. Each layer is as thick as its biggest node. The gap after it, between the boxes that end in it and
those that start in the next, is wide enough for the labels of the edges crossing it and for the edges that turn
there;
gridscales the gaps and the padding inside boxes. - Dashed edges are side links (replication, a dead-letter queue, a wake-up call). One sets the layer of the node it
leads into only when no solid edge does, and
a/db --> b/dbleaves the replica where its own writes put it. A node hanging off another by its only edge, dashed or hidden, such asqueue --> dlqor something a scenario reveals, goes right beside it in the same layer, with the edge running straight across; so does a node whose only edges are dashed ones out of it, such as a scheduler or a health check. - Hidden edges pull a quarter as hard as the others, so what only a scenario shows does not bend the picture as it first appears.
- A node that no edge places, joined only by dashed edges out of it, goes in the layer of what it is joined to: a governance box of separate services spreads along under the platform they serve, each service by what it serves.
- Edges follow their lanes and turn only in the gaps between layers. Edges that turn in one gap turn side by side; those from one node leave it as one trunk, a dashed one beside a solid one. Edges that meet a node on one side meet it side by side, in the order they come from, and an edge that runs straight on keeps the middle.
- Labels go on their edge where they cover nothing: they move along the path off nodes, other labels, group
titles and other edges' lines.
label_aton an edge puts its label where you say.
Three keys steer the layout without coordinates:
| Key | On | Meaning |
|---|---|---|
layer: first, layer: last |
node, group | Before or after everything else in the box it is in (the diagram, for a top-level node or group): an actor or a side system at one end of the picture. Edges into a first item or out of a last one are drawn back against the flow. |
constraint: false |
edge | Drawn, but left out when placing: for a long edge back to the start, or a side link that should not pull its ends together. |
align_x, align_y |
node | Line the node up with another one, see Row and column layout. |
The examples are all laid out this way: the only layout key in them is layer: last on the two
users of the data platform.
- Pinning. A node with
atkeeps its cell. When some nodes are pinned, the rest are placed around them by a simpler placer: in layers, with every group in its own band and placed nodes moving aside rather than landing on a pinned one. A group with a fixed area (atandspan) needs its nodes pinned.layeronly applies when nothing is pinned, anddiagr checksays so. - Pinning everything.
diagr expand FILEwrites every computed position asatand every computed path as aroute, so the output draws the same picture with nothing left to place. Start from it to fine-tune by hand. Its views become crops of the pinned diagram. diagr build --html --debuglabels each placed node with the cell it got ([2, 1] auto).
Row and column layout¶
Instead of cells, a box can arrange what it holds the way CSS flexbox does: one after another, in the order they appear in the file, each as big as its contents.
layout: {direction: row, gap: 24, align: stretch} # the diagram itself: main column, then dashboarding
groups:
main:
title: main
box: false
layout: {direction: column, align: stretch}
groups:
compute:
title: Compute
layout: {direction: column, gap: 24, align: stretch}
groups:
pipeline:
title: Orchestration
title_at: middle
layout: row
nodes:
orchestrator: {icon: pipeline, title: Data Pipeline} # no at
ci: {title: Development & CI/CD, layout: {direction: row, justify: space-between}}
layoutisroworcolumn, or a mapping:direction,gap(px between items, default 24),alignacross the direction (start,center(the default),end, orstretchto make child boxes as wide in a column, or as tall in a row, as the box) andjustifyalong it, for space left over (start(the default),center,end,space-betweenorspace-around).growon a group inside such a box gives it a share of the space left over along the direction, likeflex-grow:grow: 1on one child makes it fill the rest, and on two splits it evenly. Growing comes beforejustify.- It works on a group, or on the whole diagram at the top level. Everything inside a box with
layoutis laid out too: a child group withoutlayoutis a column. A node or group inside one cannot haveatorspan; the outermost box withlayoutcan takeatfor where it starts. box: falsemakes a group that only arranges what it holds and draws nothing, like a plaindiv, for rows and columns that need no frame.- In a row, nodes line up by their icons, whatever the length of their labels, so edges between them stay straight. Centring places what shows, the icon and its labels, in the middle; a row whose nodes are clear of a bottom title centres on the whole box rather than above the title's band.
align_xandalign_yon a node line it up with a node in another box, which a row or column alone cannot do:align_x: deploy-devputs a key straight under the step it feeds, so the edge between them is straight. Only that axis moves, the node stays inside its box (its padding included), anddiagr checkreports an unknown node, a node naming itself, or a loop.- A box is as big as its contents plus 20px inside, more on the side its title is on; a
title_at: middleheading takes its place after the box's nodes. Edges are routed afterwards as usual: an edge between two boxes that line up goes straight across where it misses their titles, or jogs through the gap between them when titles cover the whole overlap.
Components¶
A component is a block of groups, nodes and edges defined once; instances puts named instances of it in the diagram.
components:
region:
params: {name: {required: true}, role: primary} # a value is the default
groups:
region:
title: $name
sub: $role
tone: neutral
nodes:
db: {at: [1, 0], icon: database, title: Orders, sub: $role}
groups:
cluster:
title: Cluster
tone: blue
nodes:
api: {at: [0, 0], icon: api, title: Checkout API}
edges:
api -> db: write
instances:
a: {component: region, at: [2, 0], with: {name: Region A}}
b: {component: region, at: [2, 2], with: {name: Region B, role: standby}, in: cloud}
edges:
a/db -> b/db: replication
- Names. Inside a component, ids are local (
api,db). Each instance prefixes them with its own name, so the rest of the file refers toa/apiandb/db: in edges (lb -> a/api@left), effects (fail a/api,b/db.sub: primary,draw a/api->a/db),step.atandtrigger.at. Edge ids follow:a/api->a/db, ora/<name>for an edge declared withas <name>. - Positions. A component's cells are relative; the instance's
atmoves all of them, fixed group areas andviapoints included. A component whose nodes have noatis placed automatically, like any other node. - Parameters.
$paramin titles, sub text, labels, tooltips and the text of its actions is replaced by the instance'swithvalue or the default fromparams;{required: true}instead of a default makes every instance set it. It needs no quotes (title: $name,sub: schema v$version). Write$$for a literal$before a letter;$5needs nothing. Parameters are text only: ids, positions and numbers cannot be parameters. inon an instance puts its outermost groups and nodes inside an existing group. It is the one placeinis written: an instance has nowhere to be nested.- A component's nodes and edges can only use its own groups and nodes. A problem in a component's definition (an
unknown
$param, an edge to a node it does not have) is reported once; a problem that depends on the instance, like an overlap, names the instance's ids (a/api). - Components cannot contain other components, and scenarios stay at the top level; a component's actions say what it does in them.
diagr expand FILEprints the file with every instance written out as plain groups, nodes and edges, to check what a component turned into, and every call of a component's action written out as the effects it plays. Its ids keep theinstance/idform, which the format accepts.
Scenarios¶
scenario:
trigger: {at: web, label: Place order} # a button under a node that plays the scenario
ready: Press Place order to follow one order.
end: Order stored.
steps:
- Validate and queue:
at: api # the node that gets the step's number badge
status: Validating # status line while the step plays; default: the title
text: The API checks the order and puts it on the queue.
do:
- activate api 400ms
- api.sub: order is valid
- flow api -> queue
- Store:
at: db
focus: [queue, worker, db] # dim the rest while the step plays
do: [flow queue -> worker 1200ms -> db 600ms done]
- Confirm: [run mail 800ms] # a step with nothing to say but its title
triggerputs a button under the nodeat, withlabelon it, that plays the scenario. A node carries one trigger at most.focuson a step dims everything but the nodes, edges and groups it lists, and the edges between the nodes it lists, while the step plays, and clears when the step ends.- Steps. A step's title is its key, so the titles read down the left like a table of contents. Under it go the
step's effects (
Title: [effects]), or a mapping of its other keys:at,text,status,focusanddo. A title with:in it needs quotes, like any YAML key.
A scenario compiles to a list of frames. Each frame only assigns values (node api is active, edge api->queue is
drawn, a text is replaced), and the state at frame k is all assignments up to k. That is what makes step back,
scrub and replay exact: the player jumps to any frame and the page shows the same thing it shows when playing up to
it.
scenario is a diagram's one scenario. For several, scenarios maps ids to scenarios instead, and title on each
names it in the player's picker; a file has one key or the other. With more than one, the HTML page gets a picker;
switching resets the diagram and shows that scenario's steps and badges. Each scenario's trigger plays it:
scenarios:
checkout: {title: Checkout, trigger: {at: user, label: Place order}, steps: [...]}
failover: {title: Failover, trigger: {at: health, label: Fail region A}, steps: [...]}
The scenario under scenario has the id main, for the views and scripts that name it.
A static SVG can only show one scenario, so it shows the first one's badges and step list. From a script,
diagr.scenario("failover") switches and diagr.scenarios lists the ids.
loop: true on a scenario makes it replay forever: it holds its last frame for two seconds, then starts again. The
first looping scenario starts on its own when the page loads, which suits a diagram on a screen nobody touches. Any
input from the viewer (pause, a step, the scrubber, the picker or a trigger) stops the loop, and Play starts it again.
A loop does not start on its own for viewers who ask for reduced motion, and it waits while the diagram is scrolled
out of view or the tab is in the background.
Effects¶
An effect is verb targets [duration]. The duration is how long the frame holds before the next one.
Targets are written the way edge keys are. A node, group or named edge is its id, (a b) is several side by side,
and arrows between them name the edges along the way: draw a -> b -> c draws a->b and b->c,
draw (orders clicks stock) -> bus draws one edge from each, and draw a <-> b both edges of a pair. --> names
the same edge as ->, and spaces around arrows are optional (draw a->b). Targets with no arrow between them are
separate: done a b and draw a->b c->d.
| Effect | Meaning | Default |
|---|---|---|
activate a [b ...] |
Node starts working: pulsing ring, spinner badge | 0 ms |
done a [b ...] |
Node finished: check badge | 0 ms |
fail a [b ...] |
Node failed: red ring and cross. An active cell fails too | 0 ms |
run a [b ...] [ms] |
Node works for a while, then finishes: activate a ms, then done a |
0 ms |
draw a -> b [c -> d ...] |
The accent line draws along the edge, then its arrow turns accent | 1400 ms |
flow a -> b -> c |
Follow a path, see below | |
cells n [2..4] [ms] |
Fill the cells one by one. A range by position (2..4, or 3 for one cell) or by name (build..test, canary) fills only those; a range that stops early leaves its last cell active, and the next range completes it |
1040 ms per cell |
spin n, spin n off |
Rotate the node's glyph | 0 ms |
show x, hide x |
Reveal or hide a node, edge or group | 0 ms |
focus x y, focus none |
Dim everything except the targets and the edges between them; a step's own focus does this for the step |
0 ms |
wait 400ms |
Pause | |
n.sub: text |
Replace text: n.title, n.sub (every line), n.sub.1 (one line), a -> b.label |
0 ms |
status: text |
Replace the status line | 0 ms |
parallel: [...] |
Effects that play together, in lockstep: each frame plays the next frame of every effect and lasts as long as the slowest, so flows advance one hop at a time, cells fill side by side, a repeat runs its rounds alongside and a nested parallel plays its own lockstep as one lane |
longest |
repeat 3: [...] |
Unrolled at build time; $i in text becomes the round number |
|
[...] |
A list inside a list plays one effect after another, as one lane of a parallel |
Drawing or activating something hidden brings it out, along with the ends of an edge it draws, so a node or edge that
starts hidden needs no show before the effect that uses it. show is for bringing one out without animating it.
Text. A text change is a mapping from what changes to the new text, with an optional duration before the colon:
api.sub 400ms: order is valid. Several in one mapping change together, in one frame:
do:
- a/worker.sub: v2
b/worker.sub: v2
- status: Both regions run v2.
YAML needs quotes around text that contains : or, inside [...], a comma or braces: b/db.sub: "replica, in
sync". Quoting the whole item works too ("nb.sub: stages 1 to 9: passed").
Durations are ms or s. Generated tiles marked spins (the core refresh icon) rotate while their node is
active.
Flow¶
flow follows a path the way a request travels it:
- flow web -> api # activate web, draw web->api, done web
- flow queue -> worker 1200ms -> db 600ms done
- flow bus -> (stock search notify) done
- Each stop is activated, the edge to the next stop is drawn, and the stop is done. A stop that is already active, with no duration, is not activated again.
- A duration after a stop is how long it stays active:
worker 1200msworks for 1.2 s before the edge on todbdraws. - The last stop is left as it is, so the next step can pick it up. With a duration it is activated for that long
and left active;
doneat the end finishes it. - Stops side by side, in parentheses, play together:
a -> (b c)draws both edges at once, and(b c) -> dactivatesbandctogether before drawing both edges intod. - A box on the path is passed through: it has no active or done state of its own;
drawworks as for any edge.
Actions¶
An action is a list of effects with a name, called in do by that name:
actions:
refresh: [draw warehouse -> dashboards, dashboards.sub: refreshed, done dashboards]
scenario:
steps:
- Publish: [flow marts -> warehouse, refresh]
A component's actions use its own ids and are called with the instances they run on. Several instances play side
by side, in lockstep, as in a parallel:
components:
feed:
# groups, nodes and edges with src, ingest and check
actions:
pull: [flow src -> ingest]
validate: [flow ingest -> check 800ms done]
scenario:
steps:
- Pull the feeds: [pull orders clicks stock]
- Validate: [validate orders clicks stock]
Inside a component's action, another action of the same component is called by its name alone and runs on the same
instance, and $param in text is the instance's value. An action cannot call itself, and it cannot have the name of
an effect.
Views¶
A view is a part of the diagram built as its own images and page, for the slide or the doc section that only needs that part. The whole diagram is still built too.
views:
ingestion: {title: Ingestion, include: [ingestion, bus], exclude: [quarantine]}
serving: {include: [serving, analyst, access], scenarios: [query]}
- Files. Each view is written next to the diagram's files as
<name>-<view>-light.svg,<name>-<view>-dark.svgand<name>-<view>.html, where<name>is what the diagram's own files are named. includelists group and node ids; a group brings everything inside it, nested groups included. Withoutincludethe view starts from every node.excludetakes ids out again in the same way.- An edge is kept when both its ends are, and a group when it holds a kept node, so the parents of what you include come along with it.
- Layout. Nodes that were placed automatically are placed again for the view, so it closes up. Pinned nodes keep their cells, which makes a view of a hand-placed diagram a crop of it.
scenarioslists the scenarios the view keeps; by default it keeps none, and a trigger that would play a dropped scenario is left out. A kept scenario must only use what the view shows; if it does not,diagr checkreports the step, prefixed with the view's name.titlereplaces the diagram's title on the view's page.diagr expandpins every position, so in the expanded file a view of automatically placed nodes is a crop of the whole rather than laid out again.
The data platform example has two views and the event-driven example one, each laid out again.
Dynamic views¶
A dynamic view shows one scenario as a numbered story, like a dynamic view in the C4 model: only the parts the scenario uses, with each edge numbered by the step that draws it.
views:
checkout-flow: {title: Checkout request, scenario: checkout}
- What it shows.
scenariopicks the nodes and edges the scenario uses: those it flows along, draws, activates, shows, focuses or changes the text of, and each step'satnode, with the groups around them. Edges the scenario never touches are left out, even between nodes it shows. includeadds context the story does not touch, such as a node and the edges between it and the other included nodes.excludetakes nodes out as usual.- Numbers. Each edge the scenario flows along or draws gets a badge with the number of the step that does it, the
same number as in the step list and on the node badges. Edges used in one step share its number, whether in one
flow or in parallel; an edge used again later shows both numbers (
1,3). Withstep_list: falsethere are no badges. - The badge sits beside the edge's label when the run has room, otherwise on the label's line or just before the
arrow.
diagr checkwarns if it covers another label or a node. - The view keeps its scenario, first, so its page plays the story;
scenarioscan keep others as well.
The multi-region example and the event-driven example each have a dynamic view.
Formatting¶
diagr fmt FILE lines the file up into columns, and the playground's Format button does the same:
nodes:
api: {icon: function, title: API, sub: validates}
queue: {icon: queue, title: Order queue}
worker: {icon: server, title: Workers, sub: three replicas, stack: 3}
edges:
web -> api: POST /orders
api -> queue: enqueue
queue --> dlq: after 3 tries
- One-line mappings side by side at one indent, such as nodes, start their values in one column, and each item in one column while every line with an item after it has the same key there.
- Edges under
edges:start their arrows in one column, and their labels too. One key much longer than the others, such as a long chain, keeps its label one space after it rather than pushing every label to the right. - A blank line or a comment ends a run, so related lines can be grouped. Comments, quoting, blank lines and everything else stay as written, and every line stays on its line.
--checkchanges nothing and fails if a file would change, for CI.
Versions¶
version says which version of the format a file is written in; a file without it is version 1, the current one.
diagr init and diagr expand write it.
When a later version changes the format in a way that breaks older files, diagr will keep reading them: it upgrades
each file as it reads it, and warns at each place it rewrote with what the new version writes there, so
diagr check lists what to change.
Validation¶
diagr check reports problems as file:line:col: error: message: unknown keys, nodes, groups, edges, icons and
scenarios (each with a "did you mean" suggestion for typos), duplicate keys and ids, unknown tones, edges from a node to itself without a route or via, routes that cannot reach their target, diagonal segments, two
nodes on one cell, nodes outside their group, groups outside their parent or inside themselves, triggers at an unknown
node or on a node that already has one, effects that reference nothing, actions that call themselves, unknown components
or parameters, and broken theme or icons.yml files. Overlapping nodes, labels over nodes or over other labels,
overlapping groups, nodes over a group they are not in, nodes or child groups over a group's title, edges through a node
they do not connect or across a group's title, hidden nodes or edges that nothing shows, draws or activates, visible
edges into hidden nodes, and edge ends that are not declared but look like a typo of an id that is are warnings; --strict makes them fail.
Python¶
import diagr
d = diagr.load_file("diagram.yml")
d.nodes["nb"].cells = ["ingest", "clean", "join"] # e.g. stage names read from another file
p = diagr.prepare(d)
prepare validates, lays out and compiles; diagr.render.svg.render_static(p.scene(), p.theme, "dark") and
diagr.render.html.render_html(p) return the outputs as strings. d.scenarios maps scenario ids to scenarios,
and p.scenarios holds each one compiled to frames.