Elicit.js

Data schema

A schema declares the output dataset: each field's type, domain, and creation default. It is the source of truth for a field's scale, so an elicitation interface resolves scales, draws axes, and mints data with zero starter data. structure says which tables that dataset has: one by default, a network of nodes and links, or a hierarchy.

API reference

schema — Record<field, FieldSchema>

Required on Elicit — marks never own domains. Each field maps to a spec that fixes its measurement type, range and creation default — the source of truth a scale and a minted datum both read.

schema: { [field]: { type, domain?, default?, open?, key? } }
schema: { structure, tables: { [name]: { role?, fields } } }
Options
OptionType · defaultDescription
type
'quantitative'|'categorical'|'ordinal'|'temporal'|'ref'
The field’s measurement type — picks the scale family (quantitative→linear, categorical→band/ordinal, temporal→time). ref means the value names a row of another table by its key; it scales as a category, and its domain comes from the column it points at.
domain
any[]
The field’s data range or category list; feeds the resolved scale and the axis.
open
booleandefaultfalse
Is the domain a ceiling or a starting set? Closed (the default) means the declared categories are the whole vocabulary: edit.stack.cut() hands out the unused ones and refuses once they run out, and a seed value outside the domain is reported. open: true lets a cut append a new category and skips that check. A field with no domain is open either way — its domain is inferred from the data.
key
booleandefaultfalse
This field is the table’s identity — the column a ref points at, and the one create writes a fresh value into when it mints a row. One per table. Pair it with open: true so a gesture can mint an identity without asking you to type; a closed domain caps how many rows may exist.
to
stringdefaultthe nodes table’s key
On a ref field, which column it points at: "id" for a column of the nodes table, "links.id" for another table’s. You rarely need it.
structure
'table' | 'network' | 'hierarchy'default'table'
Which tables the dataset has. "table" is one, and its schema is the bare field map above. "network" is two, under tables — see Network. "hierarchy" is a nodes table and a nesting table, with an optional links table — see Hierarchy.
tables
Record<name, table>
Under a multi-table structure, the tables by name — and the name is the key you seed data with and read getData() back by. A table whose value is a bare field map takes its role from its own name.
role
stringdefaultthe table's name
Which role in the structure this table fills (nodes, links, nesting). Separate from the name, so an argument map can call its tables claims and supports and marks still find them.
default
anydefaultnull
The value a newly-created datum gets for this field (null = present but unset, editable later).
Returns / emits

With a schema, a mark resolves scales and draws axes from no starter data; create seeds every declared field before the pointer places the positional ones.

An empty chart that knows its axes

With no data, the axes come from the schema. Every created point carries all declared fields, from the pointer or the field's default, so it is editable at once.

Elicit from nothing

schema declares age / belief / class; create mints fully-formed data.

const chart = Elicit({
width: 380, height: 260,
margins: { top: 16, right: 16, bottom: 30, left: 36 },
schema: {
age: { type: "quantitative", domain: [0, 100] },
belief: { type: "quantitative", domain: [0, 1], default: 0.5 },
class: { type: "categorical", domain: ["A", "B", "C"] },
},
axes: { x: { title: "age" }, y: { title: "belief" } },
data: [], // start from nothing
onChange: (d) => console.log("elicited", d),
marks: [
point({
size: 7,
channels: {
x: { field: "age" }, y: { field: "belief" },
fill: { field: "class" },
},
edits: [
create({ gesture: "dblclick" }),
move({ channels: ["x", "y"] }),
cycle({ channel: "fill", gesture: "click" }),
],
}),
],
});
mount(chart.dom());
Try: Double-click to create · drag to move · click to cycle the class colour.

How many tables

structure says which tables the dataset has. Leave it out and you get one, whose columns are the schema itself:

schema: {
age: { type: "quantitative", domain: [18, 80] },
belief: { type: "quantitative", domain: [0, 1] },
}

structure: "network" gives two tables under tables, filling the roles nodes and links. Each has its own columns, so a node and a link both carry their own attributes.

schema: {
structure: "network",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
links: {
source: { type: "ref" },
target: { type: "ref" },
},
},
}

data is keyed by table name, and so are getData(), onChange and setData. Omit a table and it starts empty.

Give a table a role to name it for your data — claims and supports rather than nodes and links. Marks and edits find their table by role, so nothing else in the spec changes. See Network for the marks and gestures that draw one.

The links table also takes directed, which says whether source → target is ordered:

links: {
role: "links",
directed: true,
fields: { source: { type: "ref" }, target: { type: "ref" } },
}

true draws arrowheads and separates reciprocal links; false treats the pair as unordered, so connect refuses b → a once a → b exists. Leave it out and neither applies. See Kinds of network.

multi: true lets a pair hold more than one link, and selfLoops: true lets a link join a node to itself. Both are off by default. See Parallel links and loops.

structure: "hierarchy" gives a nodes table and a nesting table, whose rows say which node sits inside which. A links table is optional. See Hierarchy.

Keys and references

Two field declarations join one table to another. key: true marks the column that identifies a row. type: "ref" marks a column that names one.

A ref reads its domain from the key column, so you list identities once. A value that names no row is reported when you seed it, and dropped when it becomes dangling: delete a node and its links go with it.

Pair key with open: true so a creating edit can mint a fresh identity automatically. Naming is a separate act: put editText() on a text mark and write the label in place.

A closed domain on a key is a fixed roster. create hands out the declared values one at a time and stops when they run out, which caps the number of rows.

None of this needs a network. A single table can declare a key too, and every row you create gets an identity:

A keyed table

One table, a `key` column, and `create`. New rows arrive already identified.

const chart = Elicit({
width: 380, height: 240,
margins: { top: 20, right: 16, bottom: 34, left: 44 },
data: [
{ id: "r1", effort: 30, value: 70 },
{ id: "r2", effort: 65, value: 40 },
],
schema: {
id: { type: "categorical", key: true, open: true },
effort: { type: "quantitative", domain: [0, 100] },
value: { type: "quantitative", domain: [0, 100] },
},
marks: [
node({
size: 9,
fill: "#50AEB7",
edits: [create(), remove({ when: when.alt })],
channels: {
x: { field: "effort", edit: move({ channels: ["effort", "value"] }) },
y: { field: "value" },
text: { field: "id" },
},
}),
],
});
mount(chart.dom());
Try: Click empty space to add a row and watch its id. Drag a dot to move it, Alt-click to remove it.

Which table a mark draws

Every mark draws exactly one table, named by its table option. A single-table interface needs no table.

With no table, a mark draws the primary table: the only one on a structure: "table" interface, and the nodes on a network or hierarchy. link() draws the links instead.

Use table when you want an ordinary mark over another table:

barY({ table: "links", channels: { x: { field: "source" }, y: { field: "strength" } } })

An edit on that mark writes rows of that table, and getData() shows the change there. A name the schema does not declare is reported, and the mark falls back to the primary table.

Positional scales are shared across the interface. Two tables that encode different kinds of field on the same axis disagree about its type, and this is reported. Give the second mark its own chart instead.

A bar of link weights

An ordinary barY over the links table. Same channels, same edits — only `table` differs.

const chart = Elicit({
width: 380, height: 220,
margins: { top: 20, right: 16, bottom: 34, left: 44 },
schema: {
structure: "network",
tables: {
nodes: {
id: { type: "categorical", key: true, open: true },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
links: {
source: { type: "ref" },
target: { type: "ref" },
strength: { type: "quantitative", domain: [0, 1] },
},
},
},
data: {
nodes: [
{ id: "a", x: 20, y: 70 },
],
links: [
{ source: "a", target: "b", strength: 0.9 },
],
},
marks: [
barY({
table: "links",
fill: "#50AEB7",
channels: {
x: { field: "source" },
y: { field: "strength", edit: move({ channels: ["y"] }) },
},
}),
],
});
mount(chart.dom());
Try: Drag a bar. The change lands in the links table.

A temporal axis

type: "temporal" on a field. Dates place, drag, and invert like any continuous axis. A temporal column holds Dates: an ISO string or epoch number in data or setData() is stored as a Date, so getData() returns Dates.

Beliefs over time

A temporal domain drives a time scale; created points carry real Dates.

const chart = Elicit({
width: 380, height: 260,
margins: { top: 16, right: 16, bottom: 30, left: 36 },
schema: {
when: { type: "temporal", domain: ["2020-01-01", "2026-01-01"] },
belief: { type: "quantitative", domain: [0, 1], default: 0.5 },
},
axes: { x: { title: "when" }, y: { title: "belief" } },
data: [],
marks: [
point({
size: 7, fill: "#1B3F60",
channels: {
x: { field: "when" }, y: { field: "belief" },
},
edits: [
create({ gesture: "dblclick" }),
move({ channels: ["x", "y"] }),
],
}),
],
});
mount(chart.dom());
Try: Double-click to record a belief at a point in time · drag to adjust.