Document and canvas¶
Doc¶
Doc
¶
Doc(
width: float = 600.0,
*,
height: float | None = None,
theme: Theme = DEFAULT,
pad: float = 8.0,
)
A figure under construction.
add
¶
Append blocks to the figure, top to bottom. Returns self, to chain.
describe
¶
describe(title: str, description: str = '') -> Doc
Give the figure an accessible name, emitted as
connect
¶
connect(
source: str,
target: str,
*,
color: str = "muted",
label: str = "",
heads: str = "->",
via: str = "",
) -> Doc
Draw an arrow between two named blocks, once both have been placed.
heads is one of ->, <-, <-> or --. The route is
chosen from where the boxes end up: straight when they line up on an
axis, square-cornered when they do not. via overrides that and sends
the arrow around one side of the figure — left, right, top
or bottom — which is what a back-edge across several tiers wants.
overlay
¶
Place a block against a named one, on top of everything else.
A badge on a card, a note beside a box, a stamp in a corner — anything that sits outside the flow. The block is centred on the chosen point of the box it is placed against, and takes that box's width unless it declares one of its own.
Canvas¶
Canvas
dataclass
¶
Canvas(
width: float,
height: float,
theme: Theme = DEFAULT,
parts: list[str] = list(),
markers: dict[str, str] = dict(),
rects: dict[str, Rect] = dict(),
title: str = "",
description: str = "",
)
rect
¶
rect(
box: Rect,
*,
fill: str = "none",
stroke: str = "none",
radius: float = 0.0,
stroke_width: float = 1.0,
) -> None
A rectangle filling box, with an optional corner radius.
text
¶
text(
x: float, y: float, content: str, style: TextStyle, anchor: str = "start"
) -> None
One run of text on one baseline. x is the anchor, not the left edge.
line
¶
line(
start: tuple[float, float],
end: tuple[float, float],
*,
stroke: str = "rule",
stroke_width: float = 1.0,
dash: str = "",
) -> None
A straight line; dash takes an SVG dash pattern such as "4 3".
arrow
¶
arrow(
start: tuple[float, float],
end: tuple[float, float],
*,
stroke: str = "muted",
stroke_width: float = 1.4,
) -> None
A line with an arrowhead at end. The marker is added once per colour.
circle
¶
A circle centred on cx, cy — a bullet, a node, a status dot.
image
¶
An embedded picture, centred in box and keeping its proportions.
path
¶
A path. Connectors use it; a bend needs one element, not three.
connect
¶
connect(
source: Rect,
target: Rect,
*,
stroke: str = "muted",
label: str = "",
heads: str = "->",
via: str = "",
) -> None
An arrow between two placed blocks, leaving from the facing edges.
label
¶
label(
start: tuple[float, float],
end: tuple[float, float],
text: str,
*,
stroke: str = "muted",
) -> None
A word beside a connector — alongside the line, never across it.
Set on the line and knocked out of it, a label covers whatever the line runs between as soon as the run is shorter than the word. Beside it, the worst case is that a long label reaches into its own gutter.
It is always offset towards the middle of the figure, so a connector detouring along a margin does not push its label off the page.
Rect¶
Rect
dataclass
¶
Routing¶
route
¶
route(
source: Rect, target: Rect, via: str = "", bounds: Rect | None = None
) -> list[tuple[float, float]]
Where a connector runs between two placed boxes.
Two points when the boxes line up on an axis; four when they do not, so the arrow turns square corners instead of cutting a diagonal across the figure. Diagonals are most of why a hand-laid diagram looks untidy.
via overrides all of that and sends the connector out around one side —
left, right, top or bottom.