Layout and routing¶
Side-by-side comparisons. The Guide explains each option.
Layouts¶
Four groups, four arrangements: step-by-step, grid, column and circle.
# SPDX-FileCopyrightText: 2026 Reza Jelveh
#
# SPDX-License-Identifier: CC-BY-4.0
graph dir=LR layout=row gap=40
css "theme.css"
group layered "layout=layered" layout=layered dir=TB {
a -> b, c; b -> d; c -> d
}
group grid "layout=grid cols=2" layout=grid cols=2 {
g1; g2; g3; g4
}
group col "layout=column" layout=column {
r1; r2; r3
}
group radial "layout=radial" layout=radial center=hub {
hub; s1; s2; s3; s4; s5
hub -> s1, s2, s3, s4, s5
}
Routing styles¶
The same fan-out with curved, bent, right-angle and straight edges.
# SPDX-FileCopyrightText: 2026 Reza Jelveh
#
# SPDX-License-Identifier: CC-BY-4.0
# Same fan-out, four routing styles side by side
graph dir=LR layout=row gap=40
group curve "route=curve" layout=layered dir=TB {
default edge route=curve
a1 "source"; a1 -> b1, c1, d1
}
group bend "route=bend" layout=layered dir=TB {
default edge route=bend
a2 "source"; a2 -> b2, c2, d2
}
group bend2 "bend radius=24 stub=8" layout=layered dir=TB {
default edge route=bend radius=24 stub=8
a3 "source"; a3 -> b3, c3, d3
}
group ortho "route=ortho" layout=layered dir=TB {
default edge route=ortho radius=10
a4 "source"; a4 -> b4, c4, d4
}
Diagonals¶
When a bent edge only needs a small sideways step, it can slant instead of turning twice.
# SPDX-FileCopyrightText: 2026 Reza Jelveh
#
# SPDX-License-Identifier: CC-BY-4.0
# Diagonal policy demo: same graph, three settings side by side.
# p and q share child y, so y sits between them: short sideways offsets (p->y, q->y)
# next to long ones (p->x, q->z).
graph dir=LR layout=row gap=40
css { group { font-size: 11px; } }
group auto "bend (default: diagonal=40)" dir=TB route=bend {
p1 "p"; q1 "q"
x1 "x"; y1 "shared y"; z1 "z"
p1 -> x1, y1
q1 -> y1, z1
}
group never "diagonal=none" dir=TB route=bend diagonal=none {
p2 "p"; q2 "q"
x2 "x"; y2 "shared y"; z2 "z"
p2 -> x2, y2
q2 -> y2, z2
}
group always "diagonal=always" dir=TB route=bend diagonal=always {
p3 "p"; q3 "q"
x3 "x"; y3 "shared y"; z3 "z"
p3 -> x3, y3
q3 -> y3, z3
}
Arrow styles¶
Solid, thick, dashed, two-way and no arrowhead.
# SPDX-FileCopyrightText: 2026 Reza Jelveh
#
# SPDX-License-Identifier: CC-BY-4.0
graph dir=LR rank-gap=140 node-gap=18
css "theme.css"
a1 -> b1 "->"
a2 ==> b2 "==>"
a3 ..> b3 "..>"
a4 <-> b4 "<->"
a5 -- b5 "--"
Annotations¶
Second lines, numbered steps, a bracket, a legend, a caption, sideways panel titles and a box lined up with one in another panel. See Annotations.
# SPDX-FileCopyrightText: 2026 Reza Jelveh
#
# SPDX-License-Identifier: Apache-2.0
# Annotations tour: every feature added since 0.2, in one small request-flow diagram.
#
# sub="..." second line under a label (nodes and groups)
# steps=auto / step=N numbered circles on edges
# legend / caption a key and a figure caption under the diagram
# accent-bar, title-fill CSS: a coloured side strip, a band behind a panel title
# label-position: left CSS: a panel title turned sideways
# align=stretch equal-height panels (in a row) or equal-width tiers (in a column)
# align-x=ID line a box up with one in another panel
# bracket a, b "note" a curly bracket with a note beside a range of boxes
#
# Render: pdg examples/annotations.pdg -o annotations.svg
graph layout=column align=stretch gap=12 theme=hami steps=auto caption="A request, from the browser to the database"
# Panels in a column with align=stretch are all as wide as the widest one.
group edge "Edge" layout=row gap=40 .tier {
browser "Browser" sub="sends GET /orders"
cdn "CDN" sub="caches static files" .blue
}
group app "Application" layout=row gap=40 .tier {
api "API gateway" sub="checks the token" .green
orders "Orders service" sub="builds the response" .green
}
group data "Data" layout=row .tier {
# align-x puts the database right under the Orders service, so the arrow is straight.
# (It moves a box only within its own panel's free space.)
db "PostgreSQL" sub="all orders" shape=cylinder align-x=orders
}
# steps=auto numbers these in file order: 1, 2, 3 ...
browser -> cdn
cdn -> api "cache miss"
api -> orders
orders -> db "query"
# A bracket spans from the top of the first box to the bottom of the last one.
bracket api, db "runs in our\ncluster"
legend "Key"
legend .green "our services"
legend .blue "third party"
css {
group.tier { label-position: left; title-fill: none; }
#edge { fill: #eff6ff; color: var(--blue); stroke: none; }
#app { fill: #f0fdf4; color: var(--green); stroke: none; }
#data { fill: #f8fafc; color: var(--muted); stroke: none; }
}