Transforms & Modalities
A transform maps input to a channel's value through that channel's scale. move sets position, resize and slide set magnitude, rotate sets an angle, and cycle steps through categories. toggle adds or removes a row in a slot, set writes a value outright, rank reorders rows, and custom does anything else. A mark that takes a drag also takes the arrow keys, through the same edit and constraints.
API reference
move(options)
Position edit — inverts the pointer on each positional channel. On x+y a 2D move; on y alone a bar drag.
move({ channel, channels, mode, pick, threshold, when, guide, constrain }) → Edit| Option | Type · default | Description |
|---|---|---|
channel | stringdefaultinjected | A single channel to govern (co-located edits inject their own). |
channels | string[] | Multiple channels for a joint move (e.g. ["x","y"]). |
mode | 'absolute'|default'absolute' | absolute puts the mark’s centre at the pointer. relative moves it by the drag distance instead, so the point you grabbed stays under the pointer — use it on anything with area, such as a rect or a sticker, where an absolute move snaps the mark as soon as you press it. Relative mode is direct-pick. |
pick | 'direct'|default'direct' | Target selection; nearest grabs from anywhere within threshold. |
guide | boolean | Draw the constraint bounds + snap ring while dragging. |
when, | Shared Edit fields (see the Editing overview). |
An Edit. apply returns the datum with each governed field rewritten from the pointer.
resize(options)
Magnitude edit — the gesture radius from the mark centre inverts back to the channel value.
resize({ channel }) → Edit| Option | Type · default | Description |
|---|---|---|
channel | stringdefaultinjected | The magnitude channel, usually size. Its scale must be invertible. |
An Edit returning the datum with the channel field set from the pointer radius.
slide(options)
Magnitude edit — a linear drag along one axis maps onto the channel's domain. The linear alternative to resize (radial).
slide({ axis, increase, extent, mode, channel }) → Edit| Option | Type · default | Description |
|---|---|---|
axis | 'x' | default'x' | Which pointer coordinate drives the value. |
increase | 'left'|default'right' / 'up' | The direction that raises the value (left/right for axis x, up/down for axis y). |
extent | numberdefaultglyph radius, | Drag distance that sweeps the full domain. Inside a composite's local box it defaults to the glyph's radius, so the gesture scales with the glyph. |
mode | 'absolute' | default'relative' | relative — the value moves by the drag delta from the grab, so there is no jump. absolute — the value is read off the pointer's position on a fixed track centred on the mark; stateless, but it teleports unless the handle already sits at its value's place on that track. Both are direct-pick and coexist with a mark's other direct edits. |
An Edit returning the datum with the channel field set from the pointer's position along the axis.
rotate(options)
Angle edit — the pointer's angle about a pivot inverts back to the channel value (the scale's range is in degrees).
rotate({ pivot, fold, pick, relativeTo, channel }) → Edit| Option | Type · default | Description |
|---|---|---|
pivot | 'plot' | default'plot' | The centre the angle is measured about — the plot, or the hit mark. |
fold | booleandefaulttrue | true folds into a direction-agnostic cone; false uses full-circle degrees (a gauge/dial). |
pick | 'plane' | default'plane' | How the gesture finds its row. A gesture on a row turns that row alone ( direct, a needle handle); a plane drag with no row turns every row. |
relativeTo | string | Measure the absolute angular distance from another angular channel (the “open the cone” gesture). |
An Edit with the channel field set from the pointer angle through the channel's scale.
cycle(options)
Discrete edit — a click advances the channel to the next value in its domain. Needs a stable ordinal domain.
cycle({ channel }) → Edit| Option | Type · default | Description |
|---|---|---|
channel | stringdefaultinjected | The ordinal channel to advance, usually fill. |
An Edit (gesture click) returning the datum with the field stepped to the next domain entry.
toggle(options)
Slot edit — create and remove folded into the one gesture a checkbox has. Click an empty slot to mint a datum there; click an occupied one to take it back.
toggle({ channels, pick, when, stage }) → Edit| Option | Type · default | Description |
|---|---|---|
channels | string[]defaultinjected | The channels whose inverted values name a slot. One ( ["x"]) toggles an option on a scale; two (["x","y"]) toggle a cell of a grid. |
pick | 'plane' | default'plane' | probe previews the toggle on hover before the click commits it. |
An Edit returning the full dataset. Pairs with unique for one pick per row and count for a cap.
set(options)
Value edit — write a value straight into the channel’s field, whatever its type. Its input is the value itself, not a pixel, so it is the edit an external control drives.
set({ channel, channels, name, when, stage }) → Edit| Option | Type · default | Description |
|---|---|---|
channel / channels | string / string[]defaultinjected | Which channel's field to write. |
name | string | Address it from outside with chart.control(name).set(value). accepts() reports what the channel’s scale allows. |
An Edit (gesture commit) returning the datum with that field set.
rank(options)
Reorder by dragging along a rank axis. The pointer inverts to a rank slot, and the rows between the old slot and the new one shift by one place, so ranks stay unique. On a mark with motion: true the grabbed row follows the pointer and the others ease into place. See Ranking.
rank({ channel, channels, when, stage }) → Edit| Option | Type · default | Description |
|---|---|---|
channel / channels | string / string[]defaultinjected | The rank axis — a band, point or quantitative scale. Place it on that channel: y: { field: "rank", edit: rank() }. |
An Edit returning the full dataset, with the shifted rows rewritten.
custom(fn, options)
An arbitrary edit. fn becomes the edit’s apply; the descriptor still declares which gesture fires it.
custom((ctx) => datum | data[] | undefined, options?) → Edit| Option | Type · default | Description |
|---|---|---|
fn | (ctx) => | datum is ctx.datum, event is the raw DOM event (ctx.event), ctx is the full EditContext (see Editing overview). Return a new datum, a full dataset, or undefined to no-op — whatever fields you put on the datum become data. |
options.gesture | 'drag'|default'drag' | Which gesture runs this edit. The engine matches event.type to this; fn itself does not choose the gesture. |
options.pick, | Any shared Edit fields (see the Editing overview). |
An Edit. Default gesture: "drag", pick: "direct". Full ctx field list lives on the Editing overview under EditContext.
Position — move
move() inverts the pointer on each positional channel it governs. On x and y together it is a 2D drag. On y alone it is a 1D bar drag.
By default, the mark's centre snaps to the pointer. On marks with area, such as rect or sticker, pass mode: "relative": the mark moves by the drag distance and keeps its grab offset.
Move a point
edits: [move({ channels: ["x", "y"] })] — the pointer inverts onto both positional channels.
const chart = Elicit({width: 380, height: 260,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" },},// move() inverts the pointer on both positional channels — a 2D translate.edits: [ move({ channels: ["x", "y"] }) ],}),],});mount(chart.dom());
Keyboard modality — arrow key nudging
Press Tab to focus a mark, then press the arrow keys to nudge its value by 1% of the scale domain. Shift+arrow nudges by 10%.
A nudge runs through the same edit, clamping and constraints as a drag. It works for move(), slide() or resize() with a direct, nearest or sweep pick, for a rotate() about its own mark, for a stack's boundaries (edit.stack.edge()), and for the brush edits. Set focusOutline: true to show the browser's native focus ring.
Arrow keys move a point
A mark configured with move() accepts arrow keys automatically. Domain clamps hold for both modalities.
const chart = Elicit({width: 420, height: 260,margins: { top: 16, right: 16, bottom: 32, left: 40 },focusOutline: true,schema: {effort: { type: "quantitative", domain: [0, 100] },value: { type: "quantitative", domain: [0, 100] },},data: [{ effort: 25, value: 70 },{ effort: 60, value: 45 },],constraints: [clamp({ min: 0, max: 100, field: "effort" }),clamp({ min: 0, max: 100, field: "value" }),],marks: [point({size: 8, fill: "#50AEB7",channels: {x: { field: "effort", edit: move() },y: { field: "value", edit: move() },},}),],});mount(chart.dom());
Magnitude — resize (radial)
resize() inverts the pointer's distance from the mark's centre into the channel's value (size: { edit: resize() }). Stroke widths stay constant as the mark grows.
Drag outward to grow
resize() maps the gesture radius back to the size field.
const chart = Elicit({width: 380, height: 260,margins: { top: 14, right: 14, bottom: 26, left: 30 },data: [{ x: 25, y: 50, mag: 3 }, { x: 55, y: 50, mag: 7 }, { x: 82, y: 50, mag: 11 },],schema: {x: { type: "quantitative", domain: [0, 100] },y: { type: "quantitative", domain: [0, 100] },mag: { type: "quantitative", domain: [0, 14] },},constraints: [ clamp({ field: "mag", min: 1, max: 14 }) ],marks: [point({fill: "#8A78C0",channels: {x: { field: "x" },y: { field: "y" },size: { field: "mag", edit: resize() },},}),],});mount(chart.dom());
Magnitude — slide (linear)
slide() is the linear counterpart to resize. It maps the pointer's travel along one axis onto the value's domain. Set axis to 'x' or 'y', and increase to 'left', 'right', 'up' or 'down'.
The default mode: "relative" changes the value by the distance dragged since the press. extent sets the drag distance that covers the full domain.
Slide along an axis
size: { edit: slide({ axis: "x", increase: "left" }) } — dragging left increases the value.
const chart = Elicit({width: 380, height: 260,margins: { top: 14, right: 14, bottom: 26, left: 30 },data: [{ x: 50, y: 50, mag: 7 },],schema: {x: { type: "quantitative", domain: [0, 100] },y: { type: "quantitative", domain: [0, 100] },mag: { type: "quantitative", domain: [0, 14] },},constraints: [ clamp({ field: "mag", min: 1, max: 14 }) ],marks: [point({fill: "#50AEB7",channels: {x: { field: "x" },y: { field: "y" },size: { field: "mag", edit: slide({ axis: "x", increase: "left" }) },},}),],});mount(chart.dom());
Angle — rotate
rotate() inverts the pointer's angle about a pivot into degrees. Set pivot: "mark" to rotate about the mark's centre, or pivot: "plot" for the plot's centre. Set fold: false for a full 360° dial, or fold: true for a directional cone.
Rotate a box
Pointer angle inverts onto theta relative to the mark centre.
const chart = Elicit({width: 380, height: 260,margins: { top: 20, right: 20, bottom: 20, left: 20 },schema: {x: { type: "quantitative", domain: [0, 100] },y: { type: "quantitative", domain: [0, 100] },theta: { type: "quantitative", domain: [0, 360] },},data: [ { x: 50, y: 50, theta: 20 } ],marks: [rect({channels: {x: { field: "x" },y: { field: "y" },width: { value: 110 },height: { value: 70 },fill: { value: "#50AEB7" },stroke: { value: "#37919B" },// rotate() inverts the pointer's angle about the mark centre onto theta.angle: {field: "theta",scale: { range: [0, 360] },edit: rotate({ pick: "direct", pivot: "mark", fold: false }),},},}),],});mount(chart.dom());
Discrete — cycle, and combining gestures
cycle() steps an ordinal channel to the next value in its domain on a click. When several edits share a mark, when picks which one fires by modifier key. A drag is decided at the press: pressing or releasing Shift mid-drag does not switch edits.
Move · Shift-resize · click-cycle
when.noShift and when.shift split the drag; cycle() advances the fill category.
const chart = Elicit({width: 380, height: 260,margins: { top: 14, right: 14, bottom: 26, left: 30 },data: [{ x: 24, y: 70, mag: 5, team: "A" },],schema: {x: { type: "quantitative", domain: [0, 100] },y: { type: "quantitative", domain: [0, 100] },mag: { type: "quantitative", domain: [0, 14] },team: { type: "categorical", domain: ["A", "B", "C"] },},constraints: [ clamp({ field: "mag", min: 1, max: 14 }) ],marks: [point({channels: {x: { field: "x" },y: { field: "y" },size: { field: "mag" },fill: { field: "team", edit: cycle() },},edits: [move({ channels: ["x", "y"], when: when.noShift }), // plain drag = moveresize({ channel: "size", when: when.shift }), // shift-drag = resize],}),],});mount(chart.dom());
Custom transforms
custom(fn) sets fn as the edit's apply. It fires on a gesture (drag by default). fn receives an EditContext (ctx.datum, ctx.event, ctx.pointer, ctx.scales). Return a new datum, or an array of data; the fields you set are written back.
Invert y directly
ctx.pointer contains plot pixels; scales.y.invertValue maps them back to data.
const chart = Elicit({width: 380, height: 260,margins: { top: 14, right: 14, bottom: 26, left: 30 },data: [{ x: 30, y: 30 }, { x: 70, y: 70 }],schema: {x: { type: "quantitative", domain: [0, 100] },y: { type: "quantitative", domain: [0, 100] },},marks: [point({fill: "#50AEB7",size: 8,channels: {x: { field: "x" },y: { field: "y" },},edits: [// default gesture: "drag" — pass { gesture: "click" } to change itcustom((ctx) => ({...ctx.datum,y: ctx.scales.y.invertValue(ctx.pointer.y),touched: true, // becomes data; omit if you only want to rewrite y})),],}),],});mount(chart.dom());