View specs¶
A view spec is the exact form a description compiles to (see
Descriptions and specs). This page is section 4 of
spectacular-specifications.md,
the full guide for programs and agents, included here as it stands in the repository.
Its § numbers refer to that guide: §7 is embedding with mount(), §8 driving the
commands, §8.6 Python.
The contract itself is packages/viz/src/spec.ts, and sp.schema() returns its JSON
Schema.
4.1 Top level¶
| Property | Type | Required | Meaning |
|---|---|---|---|
version |
"spectacular/v0" |
no | If present, it must be exactly this. Include it. |
$schema |
string | no | Ignored by the renderer. Point it at spectacular.schema.json for editor checking. |
title |
string | no | Heading above the views. |
description |
string | no | Not displayed; use it for provenance. |
theme |
"auto" | "light" | "dark" | "paper" |
no | Default "auto": follow the page's colour scheme (in a notebook, the notebook's theme). "paper" is for print: white, no panel borders, darker axes. |
data |
object | yes | §4.2. |
fields |
object | no | Field types, axis titles, category orders and colours, §4.3. |
key |
string | no | A field whose values identify rows. Selections then name rows by it, and rows can be selected from outside by it (§7, §8.6). It loads as a category and uses one crossfilter dimension. |
views |
array | yes | At least one view, §4.5. |
layout |
object | no | { "columns": n }, n an integer from 1 to 12. The default is the smaller of 3 and the number of views. |
output |
object | no | { "interactive": bool, "figure": { "format": "svg" \| "pdf" \| "png", "width": n, "unit"?: "mm" \| "in" \| "px", "dpi"?: n } }. figure sets the default size for spectacular render (§8.3). interactive is accepted and not yet used. |
Any other property is an error.
4.2 data: give exactly one of these¶
| Form | Use |
|---|---|
{ "url": "file.csv", "format"?: ..., "pointer"?: ... } |
A file. Relative URLs resolve against the spec. |
{ "values": [ { "a": 1, "k": "x" }, ... ] } |
Inline rows, for small tables. |
{ "columns": "external" } |
Columns passed by the program calling mount() (§7). The fast path for large data. |
With url:
- format is "csv", "tsv" or "json". The default comes from the extension:
.json and .jsonld read as JSON, .tsv as TSV, anything else as CSV. Set it when
the URL has no telling extension, such as an API endpoint.
- pointer is a JSON Pointer, as defined in Request for Comments (RFC) 6901, to the
array of row objects inside a JSON document. Without it, the document itself must be
that array. A run log or JSON for Linked Data (JSON-LD) record usually nests its rows: { "url": "run.jsonld", "pointer": "/executions" }
reads the objects in the document's executions array as rows. Escape / in a key as
~1 and ~ as ~0.
- Each row's fields must be plain values. A nested object or array in a field is not
flattened; give the program that writes the file a flat column for anything to plot.
Only the fields that views use, or that fields declares, are loaded. Other columns
are ignored.
Size guidance. Parsing CSV in the browser is the slowest step. Keep url and
values data to about a million rows. For more, pass typed arrays as external columns.
4.3 fields¶
"fields": { "<name>": { "type": "quantitative" | "nominal", "title": "axis label", "domain": [...], "palette": [...] } }
- Type inference when
typeis omitted: a field isquantitativeif every non-empty value parses as a finite number, andnominalotherwise. Declare the type whenever you know it. A numeric code such as a detector id is nominal: declare it, or it will be inferred as quantitative. - Missing values. An empty quantitative cell becomes NaN, and NaN rows are excluded
by any active range brush on that field. An empty nominal cell becomes the category
"". titlelabels axes. It defaults to the field name.domainlists a nominal field's categories in order, each once. Every view of the field draws them in that order, also a category with no rows (bars keep its band, a sankey its place). Values the list does not name follow it, in order of first appearance.palettegives a nominal field's colours, used by every view that draws the field's categories: bars, split bars, a scatter or strip coloured by it, and sankey and layers nodes. Either a list (1 to 32 colours, in the order ofdomain, or of first appearance) or category name to colour; categories it does not name take the default colours in turn. A view's ownpalettewins over it. Colours belong to categories, so a category keeps its colour when filters remove others.- A field with a
domainor apaletteis nominal; declaring itquantitativeas well is an error.
4.4 Field types each view needs¶
| View | Quantitative | Nominal | Either |
|---|---|---|---|
scatter |
x, y |
color |
|
histogram |
field |
||
bars |
field, color |
||
density |
x, y |
||
scatter3d |
x, y, z |
color |
|
strip |
x |
y |
color |
matrix |
x, y |
||
interval |
low, high |
label |
color |
arc, sankey, network3d, layers |
source, target |
4.5 Views¶
Every view has id (required, unique, a non-empty string), type (required), and
optional title (defaults to id), height (plot height in CSS pixels) and span
(grid columns occupied, capped at layout.columns; default 1).
type |
Properties | Brush | Defaults |
|---|---|---|---|
scatter |
x, y, color?, brush?, pointSize?, fill?, palette? |
"xy" (rectangle) or "none" |
brush "xy", height 320 |
histogram |
field, bins?, brush?, fill? |
"x" (range) or "none" |
bins 60, brush "x", height 200 |
bars |
field, color?, brush?, palette? |
"select" (click a category to toggle it) or "none" |
brush "select", height 22 px per category, between 120 and 420 |
density |
x, y, bins? ([xBins, yBins]) |
none | bins [128, 128], height 300 |
scatter3d |
x, y, z, color?, pointSize?, fill?, palette? |
none (drag to orbit, scroll to zoom) | height 360 |
strip |
x (the value), y (the category), color?, brush?, pointSize?, fill?, palette? |
"x" (range of the value) or "none" |
brush "x", height 30 px per category, between 120 and 480 |
matrix |
x, y, brush? |
"select" (click a cell, or a row or column label) or "none" |
brush "select", height 26 px per y category, between 80 and 480 |
interval |
low, high, label?, color?, scale? ("shared" or "label"), brush?, fill?, palette? |
"x" (rows overlapping a range) or "none"; none with scale: "label" |
scale "shared", brush "x", height 8 px per row, between 120 and 520 |
arc |
source, target, order? ("count", "name" or "data"), brush? |
"select" (click an arc or a node) or "none" |
order "count", brush "select", height 300 |
sankey |
source, target, brush? |
"select" (click a flow, or a node on either side) or "none" |
brush "select", height 360 |
network3d |
source, target, brush? |
"select" (click a node) or "none"; drag to orbit, scroll to zoom |
brush "select", height 420 |
layers |
source, target, brush? |
"select" (click a flow or a node) or "none" |
brush "select", height 360 |
Constraints:
- bins: an integer from 1 to 10,000 for histograms; each of the pair an integer
from 1 to 1,024 for density.
- height, span and pointSize: positive numbers.
- fill: one colour for the marks when no color field is given (for a histogram,
its bars): "#rrggbb", "#rgb" or a CSS colour name such as "steelblue".
- palette: 1 to 10 such colours for the categories, in order of first appearance;
they repeat beyond that. It colours a color field's categories, and a bar chart's bars.
- Brushes: only scatter, histogram, bars, arc, sankey and network3d
accept a brush property. On any other view it is an error.
What each view draws:
- scatter: rows that pass every brush are drawn coloured, on top of the rest in
grey. When fewer than 20,000 rows are selected, selected points are drawn twice as
large. Axes are rounded outward ("niced") from the data extent.
- histogram: equal-width bins over the field's minimum to maximum. Bars count rows
passing every other view's brush. Light context bars behind them show the
unfiltered distribution while it fits on the same axis; they are hidden when it would
not fit. The count axis follows the filtered counts.
- bars: one horizontal bar per category, in order of first appearance in the data,
coloured from Tableau 10 (repeating after 10). It counts like a histogram.
- density: a grid of counts over the rows passing every brush, coloured with
inferno on a log scale. Empty bins are transparent. Prefer it to scatter for
hundreds of thousands of rows or more, where points saturate into a solid blob.
- scatter3d: each axis is scaled separately to fill a cube, so the aspect ratio is
not preserved. It shows the selection made in other views.
- Edge views (arc, sankey, network3d): each row is one edge from source to
target. Rows with the same pair are one edge, weighted by how many of them pass every
other view's brush. Each edge view has one crossfilter dimension over the pairs, so
clicking a node selects every edge that touches it, which a filter on either field
alone cannot express. Selections are reported as "source → target" values.
- arc: nodes on one line, ordered by the rows touching them unless order says
otherwise; every edge is an arc above the line, as thick as its rows. Light context
arcs show the unfiltered edges while another view filters.
- sankey: sources on the left and targets on the right, ordered by their totals;
each flow is as wide as its rows. A node that is both appears on both sides. Labels
are shown where a node is tall enough; every node names itself on hover.
- network3d: nodes placed by a three-dimensional force layout that starts from a
fixed arrangement, so the same data always gives the same picture. Nodes are sized
by the rows that touch them; edges fade as the filters empty them. The 24 busiest
nodes are labelled.
barswithcolor: each bar split into the categories of a second nominal field, stacked in that field's colours, with a key. Clicking a bar still selects its whole category; the selection reports categories offield.strip: one band per category ofy, each row a point at its value ofx, spread across the band so equal values stay visible. Withoutcolorit is coloured by its category when that field declares apalette.matrix: one cell per pair of categories that occurs, shaded by the rows holding it after the other views' filters (light to dark, square-root scale), with the count written in cells large enough. A cell emptied by filters keeps a faint outline.interval: each row a line fromlowtohighon a lane of its own, grouped in bands bylabeland ordered by low end within a band; rows missing either end are left out. Withscale: "label"each band has its own scale, for quantities in different units, with its ends printed at the band's corners. A brush keeps the rows whose interval overlaps the range (low end at or below its top, high end at or above its bottom), reported asoverlaps.layers: a directed graph left to right: each node one layer after the furthest node leading to it, nodes ordered within a layer to keep flows short, flows as wide as their rows. An edge that closes a cycle (found by depth-first search) loops back under the graph, dashed. For pipelines of steps and rows passing between them.
color: a nominal field uses Tableau 10 by category, or the field's palette; a quantitative field uses
viridis over the field's extent. Without color, points use one colour. A key under the
view's title names the colours: swatches for up to 12 categories (then "+N more"), or the
viridis ramp between the field's minimum and maximum. A density view's key shows its
inferno ramp from 1 to the fullest bin's count.
Axes. Every 2D view has light gridlines under its data, tick labels sized to read
(integers without decimals, values from 10,000 up as 12k or 3.4M), and axis titles
centred along each axis. Titles come from fields.<name>.title, else the field name.
4.6 Limits¶
- 32 crossfilter dimensions per spec. The validator reports a spec that needs more.
- 2: a scatter or an interval with a brush, and density.
- 1: histogram, bars, a strip with a brush, matrix, arc, sankey, network3d, layers, and
a
key. - 0: scatter3d, and a scatter, strip or interval without a brush.
- Memory. Each dimension holds its own copy of its field: 8 bytes per row for numbers, 4 for category codes, plus 4 bytes per row for the sort order. On top of that come 5 bytes per row of filter state, and the page's own copies for drawing. Measured: 10 million rows with four dimensions used 631 MiB of WASM memory. Budget views accordingly at that scale.
- Rows: at most 4,294,967,295 (the crossfilter indexes rows with 32 bits). The demo's synthetic generator caps itself at 20 million.