Elicit.js

Core concepts

The model behind every elicitation interface: a dataset, marks that encode it, and edits that write it back.

Marks are views over one dataset

A chart draws one dataset. Each mark is a view over that dataset: it encodes some fields onto visual channels, and where a channel carries an edit, it writes them back. Two marks over the same rows stay in sync — an edit on one commits to the shared data, and the other re-renders from it. Several charts can share one dataset in the same way; see Datasets & linked charts.

Two marks, one dataset

Bars and points share the dataset and schema. The point mark carries the drag edit and writes the 'n' field over the y channel, the bar mark updates when the data commits.

const chart = Elicit({
width: 380, height: 240,
margins: { top: 16, right: 16, bottom: 28, left: 34 },
data: [
{ cat: "A", n: 30 }, { cat: "B", n: 55 },
{ cat: "C", n: 22 }, { cat: "D", n: 44 },
],
schema: {
cat: { type: "categorical", domain: ["A", "B", "C", "D"] },
n: { type: "quantitative", domain: [0, 60] },
},
marks: [
// Both marks read the same rows — neither owns data.
bar({
fill: "#EDF7F8",
channels: {
x: { field: "cat" },
y: { field: "n" },
},
}),
point({
fill: "#50AEB7", size: 7,
channels: {
x: { field: "cat" },
y: { field: "n", edit: move() },
},
}),
],
});
mount(chart.dom());
Try: Drag a point — both marks update from the same rows.

The schema owns type and domain

Elicitation often starts from an empty chart, so the data can't tell you what a field is or how wide its axis runs. The schema states this once: each field's type (quantitative, categorical, ordinal, or temporal) and its domain. A mark may name the scale a field encodes through; when it doesn't, the scale is inferred from the type. See Data schema and Scales & channels.

Schema owns the domain

Nothing names a scale. Schema says cat is categorical and n is quantitative; the bar needs an interval for discrete data — band and linear fall out.

const chart = Elicit({
width: 380, height: 240,
margins: { top: 16, right: 16, bottom: 28, left: 34 },
// Type + domain live here — once. Marks never declare a domain.
schema: {
cat: { type: "categorical", domain: ["A", "B", "C", "D"] },
n: { type: "quantitative", domain: [0, 60] },
},
data: [
{ cat: "A", n: 34 }, { cat: "B", n: 58 },
{ cat: "C", n: 22 }, { cat: "D", n: 47 },
],
marks: [
bar({
fill: "#50AEB7",
channels: {
x: { field: "cat" }, // categorical + bar → band
y: { field: "n", edit: move() }, // quantitative → linear
},
}),
],
});
mount(chart.dom());
Try: Drag a bar — the edit inverts through the derived scale.

Channels

A mark encodes data onto channels — x, y, fill, stroke, size, and so on. Every mark exposes the same channel set, plus top-level style shorthands. A channel takes one of four serializable forms:

  • { field: "n" } — a field, mapped through its scale.
  • { value: 25 } — a visual-space constant; on y it is pixel 25, skipping the scale.
  • { datum: 25 } — a data-space constant, mapped through the scale; on y it lands where the value 25 sits.
  • { field: "n", scale: null } — a raw field, used as-is with no scale.

Field-driven colour (ordinal palette)

channels: { fill: { field: "kind" } } — a category drives fill through the ordinal palette.

const chart = Elicit({
width: 340, height: 240,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ cat: "A", n: 34, kind: "low" }, { cat: "B", n: 58, kind: "high" },
{ cat: "C", n: 22, kind: "low" }, { cat: "D", n: 47, kind: "high" },
],
schema: {
cat: { type: "categorical", domain: ["A", "B", "C", "D"] },
n: { type: "quantitative", domain: [0, 60] },
kind: { type: "categorical", domain: ["low", "high"] },
},
marks: [
bar({
channels: {
x: { field: "cat" },
y: { field: "n" },
fill: { field: "kind" },
},
}),
],
});
mount(chart.dom());

Constant style shorthands

stroke, strokeWidth, opacity as top-level shorthands on a point — a constant channel needs no scale.

const chart = Elicit({
width: 340, height: 240,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ x: 12, y: 40 }, { x: 30, y: 22 }, { x: 48, y: 55 },
{ x: 66, y: 33 }, { x: 80, y: 68 }, { x: 22, y: 60 },
],
schema: {
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 80] },
},
marks: [
point({
fill: "#F2B94B", opacity: 0.85,
size: 9,
channels: {
x: { field: "x" },
y: { field: "y" },
},
}),
],
});
mount(chart.dom());

value vs datum

Solid teal rule: y: { datum: 40 } (data units, through the scale). Dashed gold: y: { value: 28 } (pixel 28, skips the scale).

const chart = Elicit({
width: 380, height: 240,
margins: { top: 16, right: 16, bottom: 28, left: 34 },
data: [
{ cat: "A", n: 30 }, { cat: "B", n: 55 },
{ cat: "C", n: 22 }, { cat: "D", n: 44 },
],
schema: {
cat: { type: "categorical", domain: ["A", "B", "C", "D"] },
n: { type: "quantitative", domain: [0, 60] },
},
marks: [
bar({
fill: "#EDF7F8",
channels: {
x: { field: "cat" },
y: { field: "n" },
},
}),
// datum: data units → through the scale (lands where n = 40 is)
ruleY({
stroke: "#50AEB7", strokeWidth: 2,
channels: { y: { datum: 40 } },
}),
// value: visual units → skips the scale (pixel 28 from the top of the plot)
ruleY({
stroke: "#F2B94B", strokeWidth: 2, strokeDash: "4 3",
channels: { y: { value: 28 } },
}),
],
});
mount(chart.dom());

Derived channels

A fifth form computes the channel from a function, one datum at a time: fill: { fn: d => d.x > 50 ? "red" : "blue" } (the shorthand fill: d => … desugars to it). The function runs in visual space — its return value is used as-is (on y, a pixel), never through a scale.

A derived channel is read-only. It is opaque to the edit layer, so it can't carry an edit; put the edit on the source field instead (here x). Every mark re-derives from the committed rows on each render, so the colour recomputes live during the drag. On a line or area, a paint function (fill/stroke) runs once per series, against that series' first row.

Threshold fill (derived)

fill: { fn: d => d.x > 50 ? "#dc2626" : "#2563eb" } — the drag writes x; the colour re-derives on every render.

const chart = Elicit({
width: 420, height: 260,
margins: { top: 16, right: 16, bottom: 32, left: 40 },
data: [{ x: 25, y: 50 }, { x: 75, y: 50 }],
schema: {
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
// Dashed threshold at x = 50 (data units, through the scale).
ruleX({
stroke: "#94A5B3", strokeWidth: 1.5, strokeDash: "4 3",
channels: { x: { datum: 50 } },
}),
point({
size: 10,
channels: {
x: { field: "x", edit: move() },
y: { field: "y" },
// Derived channel: computed per datum in VISUAL space (a colour, used
// as-is). Read-only — the drag lives on x; fill re-derives on commit.
fill: { fn: (d) => d.x > 50 ? "#EE7B5E" : "#50AEB7" },
},
}),
],
});
mount(chart.dom());
Try: Drag a point across the dashed line — its colour flips.

Marks, elements, and guides

Three kinds of thing draw on an interface, and each views something different.

| Kind | Namespace | Spec key | One node per | Writes | | --- | --- | --- | --- | --- | | mark | plot.* | marks | a row | rows | | element | elements.* | elements | a tick or swatch | the schema's domain | | guide | guides.* | guides | a derived statement | nothing |

A mark draws the data. An element — axisX, gridY, legendColor — draws a scale, so it takes a singular channel rather than a channels map, and an edit on it reshapes that field's domain. A guide draws the rule and the state: a target line, the range you should stay inside, how much of a budget is left.

A guide is read-only. Every guide option takes a literal or a function of the chart context, so guides.rule({ y: ({ data }) => d3.mean(data, d => d.y) }) follows the rows — but a guide has no table, no channels and no edit. A guide differs from a derived channel: a derived channel is per-row and its mark can still be edited, while a guide's expressions run once per render and never write.

guides.remaining({ field: "y" }) reads its target from a maintainSum constraint when you don't pass one, so the total you enforce and the total you show stay the same number.

Edits

An edit is the inverse of an encoding. Encoding maps data → visual; an edit maps a gesture → data, back through the same scale. Put it on a channel (y: { field, edit: move() }) to write one field, or at mark level (edits: [...]) for a gesture that writes several at once. Full catalogue on Editing.

Mark-level drag (x and y together)

edits: [move({ channels: ["x", "y"] })] — one gesture writes both fields.

const chart = Elicit({
width: 380, height: 240,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [{ x: 20, y: 30 }, { x: 50, y: 62 }, { x: 78, y: 40 }],
schema: {
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
point({
fill: "#50AEB7", opacity: 0.85,
size: 9,
channels: {
x: { field: "x" },
y: { field: "y" },
},
// Joint gesture: one drag writes both channels.
edits: [ move({ channels: ["x", "y"] }) ],
}),
],
});
mount(chart.dom());
Try: Drag a point in two dimensions.

Constraints

A constraint is a pure rule over the dataset. It holds no matter which edit fired it or which mark it was aimed at, which is why it is declared once on the spec rather than inside a mark. A constraint can reject a proposed edit or repair it by returning corrected rows. Catalogue on Constraints.

Clamped drag

clamp keeps n in [10, 50]. guide: true draws the live bound while you drag.

const chart = Elicit({
width: 380, height: 240,
margins: { top: 16, right: 16, bottom: 28, left: 34 },
data: [
{ cat: "A", n: 30 }, { cat: "B", n: 55 },
{ cat: "C", n: 22 }, { cat: "D", n: 44 },
],
schema: {
cat: { type: "categorical", domain: ["A", "B", "C", "D"] },
n: { type: "quantitative", domain: [0, 60] },
},
// Dataset invariant — holds for every edit from every mark.
constraints: [ clamp({ field: "n", min: 10, max: 50 }) ],
marks: [
bar({
fill: "#50AEB7",
channels: {
x: { field: "cat" },
y: { field: "n", edit: move({ guide: true }) },
},
}),
],
});
mount(chart.dom());
Try: Drag a bar — it stops at 10 and 50.

Where next

  • Marks — every mark factory, from bars and points to glyphs and geo.
  • Editing — drag, create/remove, pick modes, stages, history; drive named edits from outside the chart with control().
  • Scales & data — derived scales, schema, and constraints in depth.
  • Widgets — survey instruments built on the same API.
  • Authoring SDK — custom marks, edits, and drivers when the built-ins aren’t enough.