Combining diagrams
One file can hold more than a flowchart. Sequence diagrams, timelines, charts, git histories and the other diagram types are panels: blocks that sit next to the graph and share its title, theme and footer. And a diagram can be split over files with import.
Panels
A panel is a block with a kind, an id, an optional title and props:
title: Sign in
subtitle: the flow and the conversation behind it
web "Web" [blue] -> api "API" [blue] -> db "Postgres" [cylinder, amber]
sequence login "Sign in" [numbered] {
actor user "Customer" [purple]
participant web, api, db
user -> web: open /login
web -> api: POST /login
api -> db: find user
db --> api: row
note api: compares the **bcrypt** hash
--- session ---
api --> web: 200 + cookie
web -> web: store token
}The body belongs to the panel plugin: graph syntax does not apply inside it. The block ends at a line that is only }.
Arranging
panels sets how the graph and the panels line up. The graph comes first. panel-gap sets the space between them (default 48).
| setting | result |
|---|---|
panels: row | side by side (default) |
panels: column | stacked |
panels: grid | a near-square grid |
panels: wrap | graph on top, panels in rows as wide as the graph |
A file without nodes is fine. It is then just its panels:
panels: grid
chart traffic "Traffic by region" [type: donut, unit: %] {
EU: 46
US: 31
APAC: 23
}
chart latency "Latency p95" [unit: ms] {
checkout: 120
search [green]: 48
login: 80
}
chart deploys "Deploys" [type: column] {
Mon: 4
Tue: 7
Wed: 3
Thu: 9
Fri: 2
}
chart users "Users" [type: line] {
Jan: 120
Feb: 180
Mar: 160
Apr: 260
}Connecting panels
An edge may name a panel id instead of a node. It runs from or to the panel's border, like an edge between nodes:
api "API" [blue]
api -> plan: schedules
timeline plan "Plan" {
2024: beta
2025: launch
}
chart sales "Sales" [type: column] {
Q1: 4
Q2: 7
}
plan -> sales: drives
sales --> api: reportsPanels are placed after the graph, so these edges do not move them. Set exit and enter on an edge to pick the sides it leaves and enters by.
Panel style
Every panel takes these props for its box, next to its own:
| prop | result |
|---|---|
color: teal | tints the box, the border and the title |
theme: midnight | draws this panel in another theme |
background: #0f172a | box fill (none for no fill) |
border: orange | border colour, a width (border: 2) or none |
border-width: 2 | border width |
border-style: dashed | solid, dashed or dotted |
radius: 4 | corner radius |
shadow | a drop shadow |
frame: false | no box at all |
width: 480 | the smallest frame width; wider frames stretch their content |
height: 300 | the smallest frame height |
edge-color: slate | colour of the panel's lines: sequence messages, Gantt arrows |
edge-width: 2 | width of those lines |
text: indigo | title colour |
font-size: 16 | base font size: the title and all text inside scale with it |
font-weight: 800 | title weight |
italic | italic title |
panels: row
chart night "Night shift" [theme: midnight, shadow] {
api: 42
jobs: 18
}
chart draft "Draft numbers" [background: lightyellow, border: orange, border-style: dashed, radius: 4] {
api: 30
jobs: 12
}Every panel takes color to colour its box and frame: false to drop it. Parts take a colour too: a timeline event (Q2 [green]: Launch), a chart item ("Search" [teal]: 48), a sequence participant, message or note, and a git branch or commit ([pink]). Any colour may be a palette name, #hex, rgb(), hsl() or a CSS name. On timeline, chart, gantt and quadrant lines the bracket may also end the line: Q2: Launch [green], "Search": 48 [teal]. A bracket at the end of free text counts only when it is a colour, so Q2: Launch [beta] keeps its text. The editor keeps a colour where you wrote it. The visual editor lists every part of a selected panel with a colour picker.
Panel kinds
Each kind has its own page with its syntax, props and examples:
| kind | page |
|---|---|
sequence | Sequence |
timeline | Timeline |
chart | Chart |
git | Git |
mindmap | Mind map |
treeview | Tree view |
gantt | Gantt |
quadrant | Quadrant |
kanban | Kanban |
Imports
import pulls another file into this one: its classes, nodes, groups, edges, and panels. Settings such as theme: stay in their own file unless the file exports them, see settings across files.
// shared/services.yu
.svc [blue]
.store [amber, cylinder]
web "Web" .svc
sub: Next.js
api "API" .svc
db "Postgres" .storeimport "./shared/services.yu"
title: Checkout
direction: right
api [purple] // restyle an imported node
web -> api
api -> db: SQL- The importing file wins: its settings, class props and node props override the imported ones.
- Paths are relative to the importing file. Imports may import other files. A file imported twice is merged once; a cycle is an error.
- An imported file's
layout { }block is ignored; itsranklines are kept. - Errors inside an imported file are reported on the
importline, with the file and line.
Where the files come from depends on where you render:
| where | how |
|---|---|
CLI, yuhwa md | from disk, relative to the input file |
| VitePress fence (these docs) | from disk at build time |
<yuhwa-diagram src="..."> | fetched next to the src file before rendering (embedding) |
| visual editor | from the editor's other file tabs (editor) |
| JavaScript | pass resolve and file, see the API |
Exports and selective imports
A file can say what it offers with export. Without any export line, everything is importable.
// shared/styles.yu
.svc [blue]
.store [amber, cylinder]
.internal [red] // private: not in the export list
export .svc, .store// services.yu
export orders, payments // a list, anywhere in the file
export search "Search" .svc // or in front of a declaration
group orders "Orders" {
orders-api "Orders API" .svc
orders-db .store
}
payments "Payments" .svcFor a large deck, keep one kit file with the shared look and building blocks:
// kit.yu
export $brand: violet
export .svc [color: $brand, rounded]
export .store [amber, cylinder]
export def service(id, label) {
$id "$label" .svc
${id}_db .store
$id -> ${id}_db
}// checkout.yu
import "./kit.yu"
title: Checkout
service(cart, "Cart")
service(orders, "Orders")
cart -> ordersAn importer takes everything that is exported, or names what it wants:
import "./shared/styles.yu" // .svc and .store
import { orders, payments as billing } from "./services.yu"
import { .svc as .service } from "./shared/styles.yu"- Classes carry their leading dot:
.svc. Variables carry their$:$brand. Panels are picked by id, components by name. - A component brings the classes its body names and can still call the components of its own file.
- Picking a group brings its members. An edge comes along when both of its ends are picked. Classes come along when something picked uses them.
asrenames a node, group, panel, class, variable or component. Edges follow the new name.- Naming something that is not exported is an error that lists the exports.
exportof a name the file does not declare gives a warning. importandexportare top-level only.
Settings across files
Settings (theme, direction, title, curve, ...) belong to the file that writes them. Importing a file takes its nodes and classes, never its title: or theme:. So every file can have its own theme, and it shows when that file is rendered on its own.
To share a setting, export it:
// kit.yu
export theme: midnight
export curve: orthogonal
export .svc [blue, rounded]// checkout.yu
import "./kit.yu" // takes theme: midnight and curve: orthogonal
title: Checkout
api "API" .svc -> db// admin.yu
import "./kit.yu"
theme: paper // its own setting wins over the import- A plain
importtakes every exported setting. A selective import takes the ones it names:import { theme, .svc } from "./kit.yu". A setting keeps its name, soasis an error. - The importing file's own setting always wins.
- An exported setting does not close the file: without other
exportlines, its nodes and classes stay importable. - Exported settings do not pass through. If
admin.yuimports the kit, a file importingadmin.yudoes not get the kit's theme. Import the kit there too. - One global theme for a project: put
export theme: ...in a kit file and import it everywhere. A host theme (--theme, thethemeoption) still overrides all of them.
Mixing kinds
Imports and panels combine. Keep the architecture in one file, then build a release page from it: the graph, the branch history and the numbers.
// release.yu
import "./shared/services.yu"
title: Release 2.0
panels: grid
web -> api
api -> db: SQL
git branches "Branches" {
commit "v1" [tag: v1.0]
branch checkout-v2
commit "new cart"
checkout main
merge checkout-v2 [tag: v2.0]
}
chart errors "Errors after deploy" [type: line] {
Mon: 12
Tue: 4
Wed: 2
}