Introduction
The mosaickit package assembles two-dimensional diagrams from small,
immutable pieces. A scene is an ordered list of layers (paths, filled regions,
markers, text, arrows, labels, braces). Each layer names a semantic role, a
theme maps roles to styles, and a renderer produces PNG, SVG or PDF.
The package is domain-neutral. Domain packages such as principle-viz
and utility-viz define their own models and role names, then pass
mosaickit the layers to draw. Curve construction and TikZ export
belong to geometry packages such as bezierkit.
Design
Four ideas run through the package.
/ Immutable values: Layers, scenes, styles, themes and specifications
are frozen dataclasses. A Canvas is a fluent builder around an immutable
Scene; snapshot(), copy() and bind() never change a scene another
object holds.
/ Sparse styles: Every style field may be None, meaning inherit.
A layer's explicit style sits on top of canvas overrides, configuration
overrides, the theme and the primitive defaults (Themes and configuration).
/ Roles, not colors: Layers name what they are ("primary",
"axes.note", "mypkg.boundary"); themes decide how that looks, and
colors are palette names resolved when a canvas renders (Styles and colors).
/ Placement that covers nothing: Region labels, point labels, braces
and axis annotations are placed after everything else is drawn, by pure
geometry in display pixels, so that text touches no line, marker, region
or other text (Layout geometry, Region and point labels).
Mathematics and proofs
Automatic placement uses computational geometry: orientation tests, the even-odd rule, distances to a polygon's boundary, a best-first search for the point deepest inside a region, and the least-squares packing that keeps axis text apart. The chapters state what each routine guarantees as numbered definitions, lemmas, propositions and theorems; the proofs are collected in Proofs, so the chapters can be read for the API alone. The same treatment covers the algebra of styles and themes (sparse merging, role resolution) and parameter binding. The standard references are {de Berg} (2008) for the geometry and Barlow (1972) for the order-restricted least squares behind Spreading is optimal.
Reading guide
| Topic | Contents | Section |
|---|---|---|
| Building | Canvases, specifications, scenes | Canvases and scenes |
| Paths, fills, markers, text, axes | Layers and axes | |
| Axis marks, notes and braces | Axis annotations | |
| Placement | Layout geometry | Layout geometry |
| Region and point labels | Region and point labels | |
| Appearance | Styles, colors, palettes | Styles and colors |
| Themes, roles, configuration | Themes and configuration | |
| Output | Parameters and grids | Parameters and grids |
| Renderers, caches, saving | Rendering |
Start with Quick start, Canvases and scenes and Layers and axes. Every
figure in this manual is mosaickit output, drawn by the canvas or
grid it illustrates and saved as PDF at the printed size.
The scripts that draw the figures of this manual come as one zip, sorted by topic: mosaickit-examples.zip.