Skip to content

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:

Sign inSign inEdit
yuhwa
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).

settingresult
panels: rowside by side (default)
panels: columnstacked
panels: grida near-square grid
panels: wrapgraph on top, panels in rows as wide as the graph

A file without nodes is fine. It is then just its panels:

yuhwa diagramyuhwa diagramEdit
yuhwa
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:

yuhwa diagramyuhwa diagramEdit
yuhwa
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: reports

Panels 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:

propresult
color: tealtints the box, the border and the title
theme: midnightdraws this panel in another theme
background: #0f172abox fill (none for no fill)
border: orangeborder colour, a width (border: 2) or none
border-width: 2border width
border-style: dashedsolid, dashed or dotted
radius: 4corner radius
shadowa drop shadow
frame: falseno box at all
width: 480the smallest frame width; wider frames stretch their content
height: 300the smallest frame height
edge-color: slatecolour of the panel's lines: sequence messages, Gantt arrows
edge-width: 2width of those lines
text: indigotitle colour
font-size: 16base font size: the title and all text inside scale with it
font-weight: 800title weight
italicitalic title
yuhwa diagramyuhwa diagramEdit
yuhwa
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:

kindpage
sequenceSequence
timelineTimeline
chartChart
gitGit
mindmapMind map
treeviewTree view
ganttGantt
quadrantQuadrant
kanbanKanban

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.

yuhwa
// shared/services.yu
.svc [blue]
.store [amber, cylinder]

web "Web" .svc
  sub: Next.js
api "API" .svc
db "Postgres" .store
CheckoutCheckout
yuhwa
import "./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; its rank lines are kept.
  • Errors inside an imported file are reported on the import line, with the file and line.

Where the files come from depends on where you render:

wherehow
CLI, yuhwa mdfrom 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 editorfrom the editor's other file tabs (editor)
JavaScriptpass 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.

yuhwa
// shared/styles.yu
.svc [blue]
.store [amber, cylinder]
.internal [red]           // private: not in the export list

export .svc, .store
yuhwa
// 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" .svc

For a large deck, keep one kit file with the shared look and building blocks:

yuhwa
// 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
}
yuhwa
// checkout.yu
import "./kit.yu"
title: Checkout
service(cart, "Cart")
service(orders, "Orders")
cart -> orders

An importer takes everything that is exported, or names what it wants:

yuhwa
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.
  • as renames 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. export of a name the file does not declare gives a warning.
  • import and export are 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:

yuhwa
// kit.yu
export theme: midnight
export curve: orthogonal
export .svc [blue, rounded]
yuhwa
// checkout.yu
import "./kit.yu"          // takes theme: midnight and curve: orthogonal
title: Checkout
api "API" .svc -> db
yuhwa
// admin.yu
import "./kit.yu"
theme: paper                   // its own setting wins over the import
  • A plain import takes every exported setting. A selective import takes the ones it names: import { theme, .svc } from "./kit.yu". A setting keeps its name, so as is an error.
  • The importing file's own setting always wins.
  • An exported setting does not close the file: without other export lines, its nodes and classes stay importable.
  • Exported settings do not pass through. If admin.yu imports the kit, a file importing admin.yu does 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, the theme option) 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.

yuhwa
// 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
}

Released under the MIT License.