Elicit.js

Editing

An edit writes a gesture back to the data, through the same scale that encodes it. It sets a gesture (drag, click, dblclick, commit or wheel), a pick such as direct, nearest, plane, probe or sweep, and optionally when, constrain and guide; its apply performs the inversion. Declare it on a channel (channels.y.edit), at mark level (edits: [...]), or on a legend or axis.

API reference

The Edit descriptor

Every edit factory (edit.*) returns this shape, built by makeEdit. The named factories are presets over it: each fixes a gesture and an apply — the inversion that turns the gesture back into data. apply(ctx) is pure: given the context it returns a datum (direct edit), a full array (whole-dataset edit), or undefined (no-op).

Options17
OptionType · defaultDescription
gesture
'drag'|'click'|'dblclick'|'commit'|'wheel'default'drag'
The raw gesture that triggers the edit. 'commit' is a value arriving from an inline editor or an external control. 'wheel' is a wheel tick over the plot.
channels
string[] | nulldefaultnull
Channel names it governs; null injects the channel it was placed on.
when
(ctx) => booleandefaultnull
Arbitration — whether this edit claims the gesture (e.g. only on Shift). A drag is asked once, at the press, and keeps its answer until the release. See edit.when.
pick
'direct'|'nearest'|'plane'|'probe'|'sweep'|'draw'|'brush'|'brushRect'|'moveSeries'|'slide'|'pan'|stringdefault'direct'
How the gesture selects its target. Everything but direct and plane routes through a driver; register your own with authoring.registerDriver and name it here. Each edit takes the picks that fit it; another logs a warning and the edit keeps its default.
threshold
numberdefault40
Proximity radius (px) for nearest-style picks. edit.line.moveSeries defaults to 6, and an axis handle to 14.
scope
null | 'line' | 'stack' | 'waffle' | 'trend' | 'network' | 'geo' | 'axis' | 'legend' | 'scale'defaultnull
The mark capability this edit needs. A mismatch warns instead of silently doing nothing.
constrain
Constraint[]default[]
Per-edit constraint sugar; the canonical home is the spec’s constraints (the dataset’s invariants).
guide
booleandefaultnull
Self-draw this edit’s guide (constraint bounds + snap ring).
name
stringdefaultnull
The handle an external control addresses this edit by — chart.control(name). See External controls. Unnamed edits stay pointer- and keyboard-driven.
channel
string
The single-channel spelling of channels. Every factory takes either; the singular wins, so it overrides a factory’s own default.
Returns / emits

An Edit. The engine matches gesture + pick, builds an EditContext, then calls apply(ctx). Three more keys — cardinality, inverts and inline — declare what a new edit does to the dataset; see Authoring.

EditContext (ctx)

The object handed to apply(ctx) and when(ctx) — and to custom(fn)'s one argument. It is the gesture already resolved into plot space plus the mark/scale state needed to invert it. Built once per edit invocation in the engine; read it, don’t mutate it.

Options
OptionTypeDescription
pointer
{ x, y }
Pointer position in plot pixels (origin at the plot’s top-left, inside the margins). Invert with ctx.scales.y.invertValue(ctx.pointer.y).
datum
object | undefined
The row being edited. Set for direct/nearest picks; absent for plane creates that append.
index
number | null
Index of datum in data. Returning a plain object splices it back at this index.
data
Datum[]
The full current dataset (read-only). Return a new array from apply for whole-dataset edits (create/remove).
scales
ScaleMap
Live scales by channel name (ctx.scales.x, .y, …). Each has invertValue(pixel) / encode(value).
channels
ResolvedChannel[]
This edit’s governed channels, each { name, field, scale }. Empty when the edit named none (typical for bare custom).
markChannels
object
The mark’s full channel map (name → ChannelSpec). Use to look up a sibling field the edit didn’t declare.
event
Event
The raw DOM event (for modifiers like shiftKey). Prefer edit.when for arbitration when you can.
node
FeatureNode | null
The scene node the edit acts on: the one under the pointer, or the one a nearest, sweep or probe pick chose. Null when the gesture names no row (plane).
value
any
Non-pixel gesture payload — e.g. the typed string from editText’s commit. Undefined for pointer gestures.
schema, width, height
Dataset schema (for minting rows) and the plot’s inner pixel size (for plane-relative geometry like rotate).
Returns / emits

A line-scoped or driver-backed edit sees more — seriesKey, connect, and the driver’s own session. The TypeScript definitions carry the full shape.

Edit catalogue

Universal edits sit on edit itself (edit.move). A scoped family sits under the subject it is about, and that dotted path is also the edit’s type: edit.line.draw() is { type: "line.draw" }.

Options21
OptionType · defaultDescription
move · moveSpan · brushSpan · brushRect
dragdefaultgestures · handles
Position. move inverts the pointer on each positional channel; the other three move or resize a two-endpoint span or a 2-D box.
slide · resize · rotate
dragdefaultgestures
Magnitude and angle. The pointer’s axial distance (slide), radius (resize) or angle about a pivot (rotate) inverts to a value.
cycle · toggle
clickdefaultgestures
Discrete value. cycle advances a channel to its next domain value, and toggle flips a row in or out.
set
commitdefaultgestures · external controls
Write a value into the channel’s field. Its input is the value itself, so an external control drives it.
rank
dragdefaultgestures
Drag a row to a new place in the order.
create · remove
clickdefaultexistence
Mint a datum from the pointer, or delete the target.
editText
dblclickdefaultsticker
Open an inline editor over the mark and write the typed string back.
select
clickdefaultselection
Chart state, not a data row — which rows the chart considers selected.
custom
dragdefaultgestures
An arbitrary (ctx) => … over the full EditContext, for anything the named edits do not cover.
edit.line.*
linedefaultsweep · existence
anchor, newSeries, draw, sweep, removeSeries, moveSeries — author, reshape and move connected paths. Needs a series-grouping mark.
Returns / emits

See Gestures, Sweep, Existence and each mark’s page for a factory’s own options. There is no edit.face.*: a face is a composite of ordinary marks, so its parameters take the universal edits.

Move a value

move() inverts the pointer on each positional channel it governs. On a bar's y, a drag rewrites the value.

Drag a value (bars)

y carries edit: move(). The gesture → data path mirrors the data → height encoding.

const chart = Elicit({
width: 380, height: 260,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [
{ x: "A", y: 20 }, { x: "B", y: 45 },
{ x: "C", y: 30 }, { x: "D", y: 60 },
],
schema: {
x: { type: "categorical", domain: ["A", "B", "C", "D"] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
bar({
fill: "#50AEB7",
channels: {
x: { field: "x" },
y: { field: "y", edit: move() },
},
}),
],
});
mount(chart.dom());
Try: Drag a bar up or down.

Pick — how an edit finds its target

pick: "direct" uses the mark under the pointer. pick: "nearest" takes the closest mark within a pixel threshold, so you can grab small marks from nearby empty space. guide: true draws the snap ring.

An edit acts on the same part of a mark whichever way it finds it: edit.stack.edge() drags a boundary handle, not the segment, under direct and nearest alike. Each edit takes the picks that fit what it writes:

  • An edit that writes a row (move, cycle, remove, edit.stack.*, …) takes direct, nearest or probe. A drag that paints values (move, slide, resize) also takes sweep.
  • An edit that places a new row (create, toggle, edit.line.anchor()) takes plane or probe.
  • An edit served by one driver (edit.line.draw(), the brushes, edit.network.connect(), edit.axis.*, the legend edits) takes only its own pick.

Any other pick logs a warning, and the edit keeps its default. So does a drag gesture on a click edit such as remove or cycle.

Nearest pick from empty space

A 2D nearest drag: move near a dot to select it, drag from empty space to grab the closest.

const chart = Elicit({
width: 340, height: 240,
margins: { top: 14, right: 14, bottom: 26, left: 30 },
data: [{ x: 25, y: 35 }, { x: 55, y: 68 }, { x: 78, y: 30 }],
schema: {
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
marks: [
point({
fill: "#50AEB7",
size: 10,
channels: {
x: { field: "x" },
y: { field: "y" },
},
edits: [ move({ channels: ["x", "y"], pick: "nearest", threshold: 45, guide: true }) ],
}),
],
});
mount(chart.dom());
Try: Drag from anywhere near a dot to grab it.