Elicit.js

Line

line draws a connected path through ordered points, with a draggable handle on each point once the line carries an edit. One mark covers a you-draw-it curve, a multi-series chart and a connected scatter: series groups rows into lines, order or connect orders them, and edit.line.anchor / newSeries / draw create them. lineY/lineX fix the value axis; path defaults to connect: "sequence".

API reference

line(options) · lineY(options) · lineX(options) · path(options) · polygon(options)

Import plot from elicitjs. One non-interactive connector path per series, drawn under one draggable circle handle per datum. lineY/lineX pin the value axis; path defaults to connect: "sequence".

line({ channels, orientation, curve, connect, handles, handleSize, handleColor, edits, id }) → Mark
lineY(options) → Mark   // value on y (time series)
path(options) → Mark   // connect: "sequence"
polygon(options) → Mark   // path with closed: true
Options
OptionType · defaultDescription
channels
objectdefault{}
Channel map — see Channels.
orientation
'vertical' | 'horizontal'defaultauto
Which axis the value runs along ('vertical' = y). Inferred from a band scale or the lone bound channel; lineY / lineX pin it.
channels.series
channeldefaultauto
The column grouping points into lines. A channel, because it names a column. Defaults to fill’s field (then stroke’s), so a coloured chart auto-groups.
channels.order
channel
The column each series is sorted by. Also a channel — a route’s stop number orders the line and encodes nothing, so there is no other channel to point at.
connect
'domain' | 'sequence'default'domain'
How points connect when no order channel is given: sorted by the domain axis, or as drawn. The mode only — it names no column.
closed
booleandefaultfalse (true on polygon)
Join each line’s last point to its first and fill the inside: the fill you give, or a tint of the stroke. edit.line.moveSeries() drags the region by its inside.
curve
stringdefault'linear'
Interpolation between handles (e.g. "catmullRom", "step").
handles
boolean | 'hit'defaulttrue with an edit
true draws a grabbable circle per datum. 'hit' keeps the grab target but draws nothing. false is neither drawn nor grabbable, so a sweep or nearest pick has nothing to target. The default is true when the mark carries an edit and false otherwise.
handleSize
numberdefault5
Pixel radius of each handle.
handleColor
stringdefaulttheme
Handle fill. Defaults to the series’ stroke, so each handle matches its line; the ring is the theme’s handleStroke.
edits, id
As on every mark. Line authoring edits live under edit.line.*.
Channels
ChannelTypeDescription
x
linear | band | time
Domain or value axis (per variant / inference).
y
linear | band | time
The other axis; the value axis carries the handle edit.
stroke
const | field
Line colour; a field here also becomes the default series grouping.
strokeWidth, opacity
const | field
Standard style surface for the connector + handles.
strokeDash
const | field
Dash pattern. A constant is an SVG dash array ('4 2'); a field maps each category onto a dash vocabulary through an ordinal scale. Takes legend: true.
Returns / emits

A mark with supportsSeries: true. Emits one path per series (pointerEvents:"none") plus one indexed circle handle per datum, each tagged with its series.

A line & its curve

lineY draws a value on y over a domain on x (the usual time series). curve sets the interpolation between handles.

curve: "catmullRom"

A smooth line through the points. Try "linear" or "step" for other shapes.

const chart = Elicit({
width: 400, height: 240,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ x: 0, y: 40 }, { x: 1, y: 62 }, { x: 2, y: 48 },
{ x: 3, y: 78 }, { x: 4, y: 60 }, { x: 5, y: 84 },
],
schema: {
s: { type: "categorical" }, // the series key; declared so create() mints it
x: { type: "quantitative", domain: [0, 5] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
lineY({
stroke: "#50AEB7", strokeWidth: 3, curve: "catmullRom",
channels: {
x: { field: "x" },
y: { field: "y" },
},
}),
],
});
mount(chart.dom());

Missing values

A row whose value is null, undefined or NaN breaks the line there. The segments on either side draw on their own, and the missing row gets no handle.

A gap where a value is missing

The row at x = 3 has y: null, so the line stops and starts again.

const chart = Elicit({
width: 400, height: 240,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ x: 0, y: 40 }, { x: 1, y: 52 }, { x: 2, y: 48 },
],
schema: {
x: { type: "quantitative", domain: [0, 6] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
lineY({
stroke: "#50AEB7", strokeWidth: 3,
channels: {
x: { field: "x" },
y: { field: "y", edit: move() },
},
}),
],
});
mount(chart.dom());
Try: Drag a handle on either side of the gap.

Dashed lines

strokeDash sets the dash pattern. A constant is an SVG dash array (strokeDash: '4 2'). A field maps each category onto a dash pattern (solid, dashed, dotted, dash-dot, long dash), as stroke maps one onto a colour. Add legend: true to the channel for a key of dashed segments.

Rows group into lines by series. Without it, they group by the field on fill, stroke or strokeDash, so a strokeDash field alone also splits the lines.

Observed and forecast

strokeDash: { field: "kind" } draws the forecast dashed; series: { field: "kind" } splits the two lines.

const chart = Elicit({
width: 420, height: 250,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
axes: { x: { tickFormat: "d" } },
data: [
{ year: 2020, v: 42, kind: "observed" }, { year: 2021, v: 48, kind: "observed" },
],
schema: {
year: { type: "quantitative", domain: [2020, 2026] },
v: { type: "quantitative", domain: [0, 100] },
kind: { type: "categorical", domain: ["observed", "forecast"] },
},
marks: [
lineY({
stroke: "#1B3F60", strokeWidth: 2.5,
channels: {
x: { field: "year" },
y: { field: "v", edit: move() },
series: { field: "kind" },
// A field picks a dash pattern per category: solid, then dashed.
strokeDash: { field: "kind" },
},
}),
],
});
mount(chart.dom());
Try: Drag a forecast point.

You-draw-it (sweep)

Put edit: move({ pick: "sweep" }) on the value channel for a you-draw-it line. Press and sweep horizontally to paint each point's y as the pointer crosses its column. The x positions stay fixed.

Sweep to draw the curve

The value channel carries a sweep; guide: true shows the paint guide.

const chart = Elicit({
width: 420, height: 260,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ x: 0, y: 50 }, { x: 1, y: 50 }, { x: 2, y: 50 }, { x: 3, y: 50 },
{ x: 4, y: 50 }, { x: 5, y: 50 }, { x: 6, y: 50 }, { x: 7, y: 50 },
],
schema: {
s: { type: "categorical" }, // the series key; declared so create() mints it
x: { type: "quantitative", domain: [0, 7] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
lineY({
stroke: "#50AEB7", strokeWidth: 3, curve: "catmullRom",
channels: {
x: { field: "x" },
y: { field: "y",
edit: move({ pick: "sweep", guide: true }) },
},
}),
],
});
mount(chart.dom());
Try: Sweep left-to-right across the chart — or drag a single handle.

Hiding the handles

By default, handles draw only where an edit can move the row. A line with no edit has none, and neither does a locked or context row, or a line whose edits wait for a later stage. handles: true draws them on every row, with or without an edit. handles: 'hit' keeps them grabbable but invisible, so a sweep or nearest pick still finds the line. handles: false removes them entirely; a proximity edit then has nothing to target and logs a warning. handleSize sizes them when shown.

A clean line, still sweepable

handles: 'hit' hides the dots; the sweep edit still works.

const chart = Elicit({
width: 400, height: 240,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ x: 0, y: 50 }, { x: 1, y: 50 }, { x: 2, y: 50 }, { x: 3, y: 50 },
{ x: 4, y: 50 }, { x: 5, y: 50 }, { x: 6, y: 50 }, { x: 7, y: 50 },
],
schema: {
s: { type: "categorical" }, // the series key; declared so create() mints it
x: { type: "quantitative", domain: [0, 7] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
lineY({
stroke: "#8A78C0", strokeWidth: 3, curve: "catmullRom",
handles: 'hit', // hide the anchor dots (still editable)
channels: {
x: { field: "x" },
y: { field: "y",
edit: move({ pick: "sweep", guide: true }) },
},
}),
],
});
mount(chart.dom());
Try: Sweep across — no handles, but the line still responds.

Multiple lines (series)

The series channel groups points into separate lines, so one mark holds many series. Without series, the field on fill, stroke or strokeDash groups them. A stroke field both groups and colours the lines from the ordinal palette. A sweep locks onto the nearest line when the drag starts and paints only that one.

Two series, swept independently

stroke: { field: "g" } both groups and colours the lines.

const chart = Elicit({
width: 420, height: 260,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ g: "plan", x: 0, y: 30 }, { g: "plan", x: 1, y: 45 }, { g: "plan", x: 2, y: 40 }, { g: "plan", x: 3, y: 60 },
{ g: "actual", x: 0, y: 70 }, { g: "actual", x: 1, y: 62 }, { g: "actual", x: 2, y: 75 }, { g: "actual", x: 3, y: 68 },
],
schema: {
s: { type: "categorical" }, // the series key; declared so create() mints it
x: { type: "quantitative", domain: [0, 3] },
y: { type: "quantitative", domain: [0, 100] },
g: { type: "categorical" }, // a group identifier, not an ordered scale
},
marks: [
lineY({
strokeWidth: 3, curve: "catmullRom",
channels: {
x: { field: "x" },
y: { field: "y",
edit: move({ pick: "sweep", guide: true }) },
stroke: { field: "g" }, // groups AND colours the lines
},
}),
],
});
mount(chart.dom());
Try: Sweep over one line to reshape it; the other stays put.

Connected scatter (connect: sequence)

With connect: "sequence", points connect in row order instead of domain order, giving a connected scatter or a free 2D path. Both axes carry a drag here, so each point moves in 2D and the links follow. edit.line.anchor() appends a point wherever you click, extending the one path in click order.

A 2D path you can reshape

path defaults to connect: "sequence"; a 2D drag moves points, anchor extends the one path in click order.

const chart = Elicit({
width: 420, height: 300,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ s: 0, x: 20, y: 30 }, { s: 0, x: 45, y: 70 },
{ s: 0, x: 70, y: 40 }, { s: 0, x: 85, y: 80 },
],
schema: {
s: { type: "categorical" }, // the series key; declared so create() mints it
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
path({
stroke: "#1B3F60", strokeWidth: 3,
channels: {
series: { field: "s" },
x: { field: "x" },
y: { field: "y" },
},
edits: [
move({ channels: ["x", "y"], pick: "nearest", threshold: 40 }),
edit.line.anchor({ into: "nearest", channels: ["x", "y"], series: "s", threshold: 80 }),
],
}),
],
});
mount(chart.dom());
Try: Drag a point anywhere, or click empty space to add the next anchor.

Closed regions (polygon)

closed: true joins a path's last point to its first and fills the inside. polygon is path with closed: true. Each vertex is a row, so move drags one by its handle and remove deletes one. edit.line.moveSeries() drags the whole region by its inside, and moves an open line when you press on it. The fill is the fill you give, or a tint of the stroke. The linear, catmullRom, basis and cardinal curves close; any other is drawn with straight sides.

A region you can reshape

Five rows, one per vertex. The region stays inside the schema's x and y domains.

const chart = Elicit({
width: 420, height: 300,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
// One row per vertex, joined in row order.
data: [
{ x: 25, y: 30 }, { x: 70, y: 22 }, { x: 82, y: 62 },
{ x: 48, y: 80 }, { x: 18, y: 60 },
],
schema: {
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
polygon({
stroke: "#50AEB7", strokeWidth: 2,
channels: {
x: { field: "x" },
y: { field: "y" },
},
edits: [
move({ channels: ["x", "y"] }), // a vertex, by its handle
edit.line.moveSeries(), // the whole region, by its inside
],
}),
],
});
mount(chart.dom());
Try: Drag a vertex to reshape · drag the inside to move the region.

Draw from scratch (samples)

newSeries seeds a whole line at once, flat at the clicked value. It places one anchor per sampled domain position: the scale's ticks by default, or a count, an explicit list, or a time interval. Double-click empty space to drop a fresh line, then sweep it.

Double-click to seed, then sweep

edit.line.newSeries({ samples: 6 }) drops six evenly-spaced anchors at the click’s value.

const chart = Elicit({
width: 420, height: 300,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [],
schema: {
s: { type: "categorical" }, // the series key; declared so create() mints it
x: { type: "quantitative", domain: [0, 10] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
lineY({
stroke: "#50AEB7", strokeWidth: 3, curve: "catmullRom",
channels: {
series: { field: "s" },
x: { field: "x" },
y: { field: "y",
edit: move({ pick: "sweep", guide: true }) },
},
edits: [ edit.line.newSeries({ along: "x", value: "y", series: "s", samples: 6 }) ],
}),
],
});
mount(chart.dom());
Try: Double-click to drop a line, then sweep to shape it.

Draw it in one drag (draw)

draw creates lines by dragging. On a domain-ordered line, a drag in empty space draws from scratch: as the pointer crosses each sample column, it lays that point down at the pointer value, so one stroke draws the curve. A later drag within threshold of the drawn line reshapes it with a sweep. A drag farther away draws another line. Pass into: "new" to always draw a fresh line.

Draw, then reshape

edit.line.draw({ samples: 8 }) on an empty line. First drag draws all eight points; a drag over the line reshapes it, a drag in empty space starts a new one.

const chart = Elicit({
width: 420, height: 300,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [],
schema: {
s: { type: "categorical" }, // the series key; declared so create() mints it
x: { type: "quantitative", domain: [0, 10] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
lineY({
stroke: "#50AEB7", strokeWidth: 3, curve: "catmullRom",
channels: {
series: { field: "s" },
x: { field: "x" },
y: { field: "y" },
},
edits: [ edit.line.draw({ along: "x", value: "y", series: "s", samples: 8 }) ],
}),
],
});
mount(chart.dom());
Try: Press and drag to draw · drag over the line to reshape · drag elsewhere for a new line.