Elicit.js

Trend + Band

trend elicits a parametric line from one row { intercept, slope }, drawn as y = intercept + slope·x across the plot. An intercept handle at anchor (x = 0 by default) moves the line up and down. A slope grip at each end rotates it about the anchor. trendBand draws the uncertainty around it: a range on the intercept, a range on the slope, and every line between them.

API reference

trend(options)

Import plot from elicitjs. A single-datum parametric line; the line itself is non-interactive and each handle is a draggable circle claimed by its own parameter.

trend({ channels, anchor, grip, probe, handles, handleSize, handleColor, id }) → Mark
Options
OptionType · defaultDescription
anchor
numberdefault0 (if in x domain), else the first domain end
x position of the intercept handle and the slope-rotation pivot. 0 is the classic y-intercept.
grip
"end" | "probe"default"end"
Where the slope grips sit. end mounts a pair on the line's own ends, and a drag passes the line through the pointer — so it swings all the way round. probe pins one at x = probe, sliding vertically at that column, which caps the reachable slope at ySpan / (probe − anchor).
probe
numberdefaultthe other x-domain end
The column a pinned slope grip sits at, under grip: "probe" only. Setting it under the default grip warns.
handles
boolean | "hit"defaulttrue with an edit
Unset, the grips draw where an edit reaches the row. true always draws them, as ink on a trend with no edit. Turn them off with false when the line is driven from the plane. "hit" keeps them grabbable but invisible.
handleSize
numberdefault5
Handle circle radius.
handleColor
stringdefaultthe mark's fill
Handle circle paint.
Channels
ChannelTypeDescription
x, y
field
The plot's AXES, not columns of the datum. Declare their domains in the schema.
intercept
field | datum
The line's value at x = 0. Unscaled — a parameter in its own units, projected through y.
slope
field | datum
The line's slope, in y units per x unit. Unscaled. Pin either parameter with { datum: 0 } to make it a constant no edit can write.
Returns / emits

A mark emitting the line (edge-to-edge through the plot) plus handle circles tagged intercept / slope — one at the anchor, and one at each end of the line under the default grip. If the chart's axes is left unspecified, chart axes cross at the origin; state it explicitly with axes: { origin: true | false } either way.

trendBand(options)

Import plot from elicitjs. The uncertainty around a parametric line: every line the belief’s ranges allow, drawn as one envelope, a stack of nested envelopes, or a fan of samples. Declares no edits of its own — put them on the mark the reader grabs.

trendBand({ channels, render, levels, samples, seed, sigma, distribution, anchor, grip, probe, handles, handleSize, handleColor, id }) → Mark
Options
OptionType · defaultDescription
render
"region" | "gradient" | "samples"default"region"
One exact envelope polygon; nested envelopes stacked so the ink darkens toward the line; or individual sampled lines.
levels
numberdefault5
gradient only — how many nested envelopes. Their opacities compound to fillOpacity at the centre.
samples
numberdefault60
samples only — how many lines to draw from the family.
seed
numberdefault7
samples only — PRNG seed, so the fan is stable across re-renders.
distribution
"normal" | "uniform"default"normal"
samples only — normal treats the bounds as a sigma-wide envelope; uniform spreads flat across them.
sigma
numberdefault1.96
The envelope half-width in standard deviations when sampling normally, so ~95% of draws land inside the band that was pointed at.
grip
"end" | "probe"default"end"
As trend — end mounts the slopeSpread grips on the ends of the band's own upper edge, so opening the cone is not capped by how far one pinned column reaches.
handles
boolean | "hit"defaulttrue with an edit
A grip on each spread: the intercept's at the anchor, the slope's on the upper edge (see grip). As on trend: unset, they draw where an edit reaches the row; false hides them; "hit" keeps them grabbable but invisible.
handleSize
numberdefault5
Handle circle radius.
handleColor
stringdefaulttheme
Handle circle paint.
fillOpacity
numberdefault0.18
region / gradient — the ink of the filled envelope. Gradient divides it across levels so the stack compounds back to it.
strokeOpacity
numberdefault0.15
samples — the ink of ONE line in the fan, so raising samples darkens the overlap and lowering this thins it back out.
Channels
ChannelTypeDescription
x, y, intercept, slope
As trend — the axes, and the line the band surrounds.
interceptSpread, slopeSpread
field
HALF-WIDTHS in the field's own units: the symmetric form, and what one pointer distance sets.
intercept1 / intercept2, slope1 / slope2
field
Explicit asymmetric ranges, the same 1/2 span spelling area and rect use. These win wherever both forms are declared.
Returns / emits

A mark emitting one path (region), levels paths (gradient), or samples lines — all inert and painted in the background layer — plus the optional spread handles.

edit.trend.*

The trend-scoped edits. Each inverts the pointer through x/y and solves for the parameter it owns, writing the column that parameter’s channel names. A pinned parameter is never written.

edit.trend.intercept({ anchor, probe, ...EditOptions }) → Edit
edit.trend.slope({ anchor, probe, ...EditOptions }) → Edit
edit.trend.interceptSpread({ anchor, probe, ...EditOptions }) → Edit
edit.trend.slopeSpread({ anchor, probe, ...EditOptions }) → Edit
Options
OptionType · defaultDescription
anchor
numberdefaultthe mark's anchor
The pivot: the x whose value a rotation holds, and where an intercept drag places the line.
probe
numberdefaultthe mark's probe
The x a PINNED handle drag measures at (one drawn under grip: "probe"). An end-mounted grip, and a gesture carrying no node at all (a plane or probe pick), use the pointer's own x instead, so the line follows the cursor.
Returns / emits

An Edit with scope: "trend", claiming the handle tagged with its own channel. trend() generates the first two for you; declare them yourself to restage them, retarget them, or drive them from the plane.

Its channels name the axes, not the columns

A trend's x and y channels name the plot's axes, not columns of its row. Declare their domains in the schema. Domains that span both sides of zero put the intercept in the middle of the frame.

When axes is unset, a chart with a trend crosses its axes at the origin. Set axes: { origin: true | false } to state the frame yourself. origin: false gives the ordinary left/bottom frame. See Axis, Grid & Rule.

Trend can't be created by a gesture

A trend line is parametric. Its position comes from intercept and slope, and a click has no x/y to invert into them, so a plane create can't add one. See the create matrix. Set a trend by editing its parameters.

Inert until an edit names the column

trend() with no edit draws the line without handles and writes nothing. Like every mark, it stays a view until an edit names the column a gesture sets: edit.trend.intercept() on the intercept channel, edit.trend.slope() on the slope channel. Set a stage on the edit, as elsewhere: edit.trend.slope({ stage: 1 }).

No edit, no writes

The line draws without handles, and the data never moves.

const chart = Elicit({
width: 360, height: 260,
margins: { top: 16, right: 16, bottom: 28, left: 34 },
schema: {
x: { type: "quantitative", domain: [-10, 10] },
y: { type: "quantitative", domain: [-10, 10] },
intercept: { type: "quantitative" },
slope: { type: "quantitative" },
},
data: [{ intercept: 2, slope: 0.5 }],
marks: [
// No edit anywhere: the line draws without handles, and nothing you do to
// it changes the data. A mark is a VIEW until an edit names the column a
// gesture writes — trend is no exception, and used to be.
trend({
channels: {
intercept: { field: "intercept" },
slope: { field: "slope" },
},
}),
],
});
mount(chart.dom());
Try: drag the line. Nothing changes.

Intercept, then slope

Stage 0: drag the intercept handle to set the level. Stage 1: drag either end grip to set the slope, rotating the line about the anchor.

The parameters are channels. Rename a column with channels: { slope: { field: "r" } }, or pin it to a constant with { datum }. They are unscaled: each stays in its own units and is projected through x and y.

axes moves only the axis spines. The handles follow anchor and probe. anchor is 0 when 0 lies in the x domain, and the domain's start otherwise. Over a domain starting at 0 or above, that puts the intercept handle on a left/bottom y-axis. Pair it with grip: "probe" for a single slope handle at the domain's far end. The default pair of grips would put one on top of the intercept handle.

Trend line

Axes cross at the origin automatically; the line runs edge-to-edge through the plot.

const chart = Elicit({
width: 360, height: 300,
margins: { top: 16, right: 16, bottom: 28, left: 34 },
schema: {
x: { type: "quantitative", domain: [-10, 10] },
y: { type: "quantitative", domain: [-10, 10] },
intercept: { type: "quantitative" },
slope: { type: "quantitative" },
},
data: [{ intercept: 0, slope: 0.6 }],
marks: [
// A trend draws its line and two handles, but writes nothing until an edit
// names the column each handle sets. Staging goes on the edit, like any other:
// the intercept is live in stage 0, the slope in stage 1.
trend({
channels: {
intercept: { field: "intercept", edit: edit.trend.intercept({ stage: 0 }) },
slope: { field: "slope", edit: edit.trend.slope({ stage: 1 }) },
},
}),
],
});
mount(chart.dom());
const btn = document.createElement("button");
btn.textContent = "Next: set the slope";
btn.style.marginTop = "8px";
btn.onclick = () => { chart.nextStage(); btn.disabled = true; };
mount(btn);
Try: drag the centre (intercept) dot; press Next; drag an end dot.

Both handles at once

Omit the stages (default null) to leave both handles always active.

const chart = Elicit({
width: 360, height: 300,
margins: { top: 16, right: 16, bottom: 28, left: 34 },
schema: {
x: { type: "quantitative", domain: [-10, 10] },
y: { type: "quantitative", domain: [-10, 10] },
intercept: { type: "quantitative" },
slope: { type: "quantitative" },
},
data: [{ intercept: 2, slope: 0.5 }],
marks: [
// Unstaged: both handles live at once. Each edit claims its own handle, so
// dragging the intercept never moves the slope and vice versa.
trend({
channels: {
intercept: { field: "intercept", edit: edit.trend.intercept() },
slope: { field: "slope", edit: edit.trend.slope() },
},
}),
],
});
mount(chart.dom());

Left/bottom frame

axes: { origin: false }, plus a domain starting at 0 and grip: "probe" — the intercept handle sits on the y-axis, the one slope handle on the right edge.

const chart = Elicit({
width: 360, height: 300,
margins: { top: 16, right: 16, bottom: 28, left: 34 },
// Without this, axes here would still cross at zero — a trend mark is
// present and axes was otherwise unspecified. origin: false states the
// ordinary left/bottom frame explicitly instead of leaving it inferred.
axes: { origin: false },
schema: {
// A domain that doesn't need to span negative values, so trend's default
// anchor (0, whenever 0 lies in the x domain — here that's the domain's
// own start) lands exactly where the y-axis is drawn, instead of
// floating mid-plot the way it would over a domain like [-10, 10].
x: { type: "quantitative", domain: [0, 20] },
y: { type: "quantitative", domain: [0, 20] },
intercept: { type: "quantitative" },
slope: { type: "quantitative" },
},
data: [{ intercept: 2, slope: 0.5 }],
marks: [
trend({
// grip: "probe" mounts a single slope handle at the domain's far end.
// The default pair (grip: "end") would put its near-end grip on the
// same point as the intercept handle now that anchor sits at x = 0.
grip: "probe",
channels: {
intercept: { field: "intercept", edit: edit.trend.intercept() },
slope: { field: "slope", edit: edit.trend.slope() },
},
}),
],
});
mount(chart.dom());

Rotating the line

The slope grips sit on the line’s ends. Dragging one passes the line through the pointer, so the line rotates a full turn: drag an end up and over the anchor, and the line swings past vertical and down the other side. Both ends carry the same edit, and each stays inside the plot at every angle.

A vertical line has no slope. The gesture holds while the pointer is in the anchor’s column, and slope grows without bound as you approach it. Bound it with a clamp on the column, as for any field.

grip: "probe" pins a single grip at x = probe instead, sliding vertically at that column. Reachable slope is then capped at ySpan / (probe − anchor).

Swing it round

Both parameters live, with slope clamped to ±20.

const chart = Elicit({
width: 340, height: 300,
margins: { top: 16, right: 16, bottom: 28, left: 40 },
schema: {
x: { type: "quantitative", domain: [-10, 10] },
y: { type: "quantitative", domain: [-10, 10] },
intercept: { type: "quantitative" },
slope: { type: "quantitative" },
},
data: [{ intercept: 0, slope: 0.6 }],
// The slope grows without bound as the line approaches vertical. Bound it the
// same way you bound any other column.
constraints: [clamp({ field: "slope", min: -20, max: 20 })],
marks: [
trend({
channels: {
intercept: { field: "intercept", edit: edit.trend.intercept() },
slope: { field: "slope", edit: edit.trend.slope() },
},
}),
],
});
mount(chart.dom());
const out = document.createElement("div");
out.style.cssText = "font:12px ui-monospace,monospace;margin-top:6px;color:#6F8294";
const show = () => {
const d = chart.getData()[0] || {};
out.textContent = "intercept " + d.intercept.toFixed(2) +
" slope " + d.slope.toFixed(2);
};
chart.on("change", show); show();
mount(out);
Try: drag an end dot up and across the middle of the plot — the line keeps turning.

The band around the line

trendBand takes the same two parameters plus a spread on each: interceptSpread and slopeSpread, half-widths in the field’s own units. It draws every line those ranges allow. The envelope is exact: piecewise linear, with one kink where x crosses zero and only the intercept range is left.

The two marks are views of one dataset. Put a plane or probe edit on the band or on the line, not both, or it runs twice per gesture. The band's spread channels take edit.trend.interceptSpread() and edit.trend.slopeSpread(), shown below.

For an asymmetric band, name the ends instead: intercept1/intercept2 and slope1/slope2, the same 1/2 spelling area and rect use. Where both forms are declared, the range form wins. Pair it with ordering to keep the ends in order.

A band around the line

Every line whose intercept is within aSd and whose slope is within bSd.

const chart = Elicit({
width: 360, height: 300,
margins: { top: 16, right: 16, bottom: 28, left: 34 },
schema: {
x: { type: "quantitative", domain: [-10, 10] },
y: { type: "quantitative", domain: [-10, 10] },
// The band's four elicited columns. Every column of the dataset belongs in
// the schema — that is the contract of what this chart elicits.
intercept: { type: "quantitative" },
slope: { type: "quantitative" },
aSd: { type: "quantitative" },
bSd: { type: "quantitative" },
},
data: [{ intercept: 1, slope: 0.4, aSd: 1.5, bSd: 0.25 }],
marks: [
trendBand({
fill: "#50AEB7",
channels: {
interceptSpread: { field: "aSd" },
slopeSpread: { field: "bSd" },
},
}),
// Drag either handle to move the line; the band above re-derives from the same
// two parameters, so it follows without carrying an edit of its own.
trend({
stroke: "#50AEB7",
channels: {
intercept: { field: "intercept", edit: edit.trend.intercept() },
slope: { field: "slope", edit: edit.trend.slope() },
},
}),
],
});
mount(chart.dom());

Editing the band

The spread edits put a grab on each spread: the intercept's at the anchor, the slope's on the ends of the band's upper edge.

const chart = Elicit({
width: 360, height: 300,
margins: { top: 16, right: 16, bottom: 28, left: 34 },
schema: {
x: { type: "quantitative", domain: [-10, 10] },
y: { type: "quantitative", domain: [-10, 10] },
intercept: { type: "quantitative" },
slope: { type: "quantitative" },
aSd: { type: "quantitative" },
bSd: { type: "quantitative" },
},
data: [{ intercept: 1, slope: 0.4, aSd: 2, bSd: 0.3 }],
marks: [
// The band is a VIEW. It draws the spreads; the handles below write them.
trendBand({
fill: "#8A78C0",
channels: {
interceptSpread: { field: "aSd", edit: edit.trend.interceptSpread() },
slopeSpread: { field: "bSd", edit: edit.trend.slopeSpread() },
},
}),
trend({
stroke: "#8A78C0",
channels: {
intercept: { field: "intercept", edit: edit.trend.intercept() },
slope: { field: "slope", edit: edit.trend.slope() },
},
}),
],
});
mount(chart.dom());
Try: drag either band handle, then drag the line's own handles underneath.

Three readings of one band

render sets how the family is drawn. region (the default) is one polygon: the exact envelope. gradient stacks levels nested envelopes, so the ink darkens toward the line. samples draws individual lines from the family. Its distribution is normal (the bounds are a sigma-wide envelope, so about 95% of draws land inside) or uniform (every line in the range equally likely).

The filled forms use fillOpacity (default 0.18). samples uses strokeOpacity (default 0.15) for each line, so the fan gets denser as you raise samples. Lower strokeOpacity to thin it out.

region, gradient, samples

One band, three renderings of the same answer.

const belief = [{ intercept: 1, slope: 0.4, aSd: 1.5, bSd: 0.25 }];
const spreads = { interceptSpread: { field: "aSd" }, slopeSpread: { field: "bSd" } };
const lineParams = {
intercept: { field: "intercept", edit: edit.trend.intercept() },
slope: { field: "slope", edit: edit.trend.slope() },
};
for (const render of ["region", "gradient", "samples"]) {
mount(Elicit({
width: 200, height: 170,
margins: { top: 10, right: 10, bottom: 22, left: 26 },
schema: {
x: { type: "quantitative", domain: [-10, 10] },
y: { type: "quantitative", domain: [-10, 10] },
intercept: { type: "quantitative" },
slope: { type: "quantitative" },
aSd: { type: "quantitative" },
bSd: { type: "quantitative" },
},
data: belief,
marks: [
trendBand({ render, levels: 6, samples: 80, fill: "#1B3F60", stroke: "#1B3F60", channels: spreads }),
// Three renderings of the SAME belief, so all three share one edit set.
trend({ stroke: "#1B3F60", channels: lineParams }),
],
}).dom());
}

A correlation is a pinned trend

To elicit a correlation, pin the intercept at the origin and limit the slope to [-1, 1]. Pin with a constant channel, intercept: { datum: 0 }, which names no column, so no edit writes it. Limit with a clamp.

Stage 0 aims the line. Under probe the line follows the pointer's x, and a click sets it and advances. Stage 1 opens the band: slopeSpread is how far the line through the pointer tilts from the committed one, so the fan's edge sits under the cursor.

Both axes span [-1, 1] over a square plot, so the line's screen angle reads as r. This interface ships as widgets.lineCone.

Line + Cone, from the general marks

Two clicks: aim the line, then open the cone.

const chart = Elicit({
width: 300, height: 300,
margins: { top: 14, right: 14, bottom: 14, left: 14 },
axes: false,
schema: {
// Standardized units, matched on both axes, so a slope of 1 is a 45° line.
x: { type: "quantitative", domain: [-1, 1] },
y: { type: "quantitative", domain: [-1, 1] },
r: { type: "quantitative", domain: [-1, 1], default: 0 },
spread: { type: "quantitative", domain: [0, 1], default: 0 },
},
data: [{ r: 0, spread: 0 }],
// What makes it a CORRELATION rather than a free trend — declared, not baked in.
constraints: [
clamp({ field: "r", min: -1, max: 1 }),
clamp({ field: "spread", min: 0, max: 1 }),
],
marks: [
trendBand({
render: "samples",
samples: 80,
channels: {
intercept: { datum: 0 }, // pinned at the origin
slope: { field: "r" },
slopeSpread: { field: "spread" },
},
}),
trend({
handles: false,
stroke: "#F2B94B",
strokeWidth: 5,
channels: {
intercept: { datum: 0 },
slope: { field: "r", edit: edit.trend.slope({ pick: "probe", stage: 0 }) },
slopeSpread: { field: "spread", edit: edit.trend.slopeSpread({ pick: "probe", stage: 1 }) },
},
}),
],
});
mount(chart.dom());
const out = document.createElement("div");
out.style.cssText = "font:12px ui-monospace,monospace;margin-top:6px;color:#6F8294";
const show = () => {
const d = chart.getData()[0] || {};
out.textContent = "stage " + chart.getStage() +
" · r=" + (d.r ?? 0).toFixed(2) + " spread=" + (d.spread ?? 0).toFixed(2);
};
chart.on("change", show); chart.on("stage", show); show();
mount(out);
Try: move the mouse, click, move again, click.