Blocks¶
The base¶
Block
dataclass
¶
A thing that can state its height and then draw itself into a box.
Text¶
Span
dataclass
¶
Span(
text: str,
size: float | None = None,
weight: int | None = None,
italic: bool | None = None,
fill: str | None = None,
tracking: float | None = None,
face: Font | None = None,
)
A stretch of a paragraph with a weight, colour or size of its own.
Everything left as None is inherited from the Text it sits in, so a
span says only what it changes.
Text
dataclass
¶
Text(
text: str | Sequence[str | Span],
size: float | None = None,
weight: int = 400,
italic: bool = False,
fill: str = "ink",
align: str = "left",
leading: float | None = None,
tracking: float = 0.0,
wrap: bool = True,
hyphenate: Callable[[str], Sequence[str]] | None = None,
face: Font | None = None,
*,
key: str | None = None,
grow: bool = False,
width: float | None = None,
)
A paragraph, broken by total-fit and set at the requested alignment.
lines
¶
The broken lines this text makes at width.
Containers¶
Stack
¶
Stack(
*children: Block,
gap: float | None = None,
grow: bool = False,
width: float | None = None,
)
Row
¶
Row(
*children: Block,
gap: float | None = None,
weights: Sequence[float] | None = None,
grow: bool = False,
width: float | None = None,
)
Children side by side, all stretched to the height of the tallest.
Frame
dataclass
¶
Frame(
child: Block,
fill: str = "page",
stroke: str = "rule",
pad: float | None = None,
radius: float | None = None,
stroke_width: float = 1.0,
height: float | None = None,
accent: str = "none",
valign: str = "top",
*,
key: str | None = None,
grow: bool = False,
width: float | None = None,
)
A padded panel around one child: the card, the band, the callout.
Atoms¶
Spacer
dataclass
¶
Rule
dataclass
¶
Rule(
color: str = "rule",
stroke_width: float = 1.0,
height: float = 9.0,
*,
key: str | None = None,
grow: bool = False,
width: float | None = None,
)
Draw
dataclass
¶
Image
dataclass
¶
Image(
source: Path | str,
height: float = 48.0,
align: str = "left",
*,
key: str | None = None,
grow: bool = False,
width: float | None = None,
)
A picture, embedded in the figure and keeping its own proportions.
Give it a height; the width follows from the image. align places it
across the box it was given, which matters in a row or a wide column.
Bars
dataclass
¶
Bars(
items: Sequence[tuple[str, float]],
color: str = "accent",
top: float | None = None,
bar_height: float = 18.0,
gap: float = 9.0,
label_fraction: float = 0.34,
fmt: str = "{:,.0f}",
*,
key: str | None = None,
grow: bool = False,
width: float | None = None,
)
A labelled bar chart, the workhorse of an infographic.
Composites¶
These return ordinary blocks assembled from the primitives above.
card
¶
card(
title: str, body: str, *, accent: str = "none", key: str | None = None
) -> Frame
A titled panel whose height follows its text.
band
¶
A section container: tinted ground, tracked-out title, then content.
heading
¶
heading(
text: str,
*,
size: float | None = None,
fill: str = "ink",
align: str = "left",
) -> Text
Bold text at the theme's body size unless told otherwise.