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).
| Option | Type · default | Description |
|---|---|---|
gesture | 'drag'|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[] | defaultnull | Channel names it governs; null injects the channel it was placed on. |
when | (ctx) => defaultnull | 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'|default'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 | 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. |
cursor | stringdefaultfrom the edit | The CSS cursor over the edit’s marks. The default follows the edit: a drag along x shows ew-resize, along y ns-resize, on both move; a click shows pointer; a typed edit shows text. Set it to override, e.g. move({ cursor: "grab" }). |
stage | numberdefaultnull | Only active when the chart is on this stage. See Stages. |
advance | booleandefaulttrue | Whether a settled probe click moves to the next stage. Set false to commit repeatedly within one stage. |
table | stringdefaultthe mark's table | Which table this edit writes to, by role (nodes, links, nesting) or by name, as a constraint's table. A name that matches no table warns, and the edit writes its mark's table. Only meaningful on a multi-table schema. |
target | 'domain' | Write the schema rather than the dataset. Set by edit.axis.* and edit.scale.*; see Editing the scale. |
type | string | The edit’s kind, as its dotted path ( move, line.draw, geo.brush). Each factory sets its own. |
apply | (ctx) => | The edit itself — maps the gesture to data through the same scale. Never mutate ctx.data; return a new datum or array. |
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.
| Option | Type | Description |
|---|---|---|
pointer | { x, | 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 | | The row being edited. Set for direct/nearest picks; absent for plane creates that append. |
index | number | | 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 | | 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, | Dataset schema (for minting rows) and the plot’s inner pixel size (for plane-relative geometry like rotate). |
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" }.
| Option | Type · default | Description |
|---|---|---|
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. |
edit.axis.scale | axisdefaultaxis | Reshape a positional domain rather than the dataset: drag an axis end to rescale it. |
edit.view.zoom · pan | viewdefaultview | Move the view rather than the dataset: zoom with the wheel, or drag the plot to pan. Declared in the spec’s view. See Zoom & pan. |
edit.scale.categories | scaledefaultaxis · legend | Add, rename and remove categories, on an axis or a legend. categories() returns three edits — spread it. |
edit.legend.category · edit.legend.value | legenddefaultlegend | Turn a legend into an input: click a swatch, or drag the ramp handle. |
edit.stack.cut · edge · merge | stackdefaultsweep · handles | Divide a whole among rows: split a segment, move value across a boundary, fuse two back into one. |
edit.trend.* | trenddefaulttrend | intercept, slope, interceptSpread, slopeSpread — edit a parametric line by its parameters. |
edit.waffle.fill | waffledefaultwaffle | Fill up to the exact cell under the pointer. |
edit.network.connect · rewire · reverse | networkdefaultnetwork | Build a network's topology. Nodes themselves are plain create / remove. |
edit.hierarchy.nest | dragdefaulthierarchy | Drag a node into a container, or out of one. It writes the nesting table. |
edit.geo.* | geodefaultgeo | move, create, draw, moveSeries, brush, createRect — the universal edits on a map’s lon/lat channels, placed through the chart’s projection. |
edit.when | predicatedefaultgestures | Not an edit — the arbitration predicates for an edit’s when (when.shift, when.alt, …). |
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());
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.*, …) takesdirect,nearestorprobe. A drag that paints values (move,slide,resize) also takessweep. - An edit that places a new row (
create,toggle,edit.line.anchor()) takesplaneorprobe. - 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());