Authoring SDK
Extend Elicit.js with new marks, edits and gestures. Marks use authoring.encodeChannel and resolveStyle. Edits use authoring.makeEdit and invertChannel. Multi-event lifecycles register with authoring.registerDriver. Edits go on a channel (y: { field, edit: move() }) or in a mark's edits: [...]. For the model these extend, see Core concepts. For the stock edits, see Editing.
API reference
Mark SDK
Shared foundation every mark factory uses. Import as authoring.encodeChannel (or the bare name in these docs). A mark never owns data or a domain — Elicit owns both.
authoring.normalizeMarkOptions(options) → options
authoring.encodeChannel(scales, channels, name, datum, fallback) → any
authoring.encodeAngle(scales, channels, datum, fallback?) → number
authoring.resolveStyle(scales, channels, datum, defaults?) → style| Option | Type · default | Description |
|---|---|---|
build(data, | required | Emit FeatureNode[] (circle / rect / line / path / text). Resolve every position and style through encodeChannel / resolveStyle — never call scale(d[key]) by hand. A mark that joins another table reads it from ctx: tables, schema and its own table. |
authoring.normalizeMarkOptions | fn | Call at the top of the factory. Desugars top-level shorthands ( fill, size, …) into channels.*.value. |
discreteScale | 'band' | | What the mark needs for discrete data (bar → band interval; point/line → tick). Leave unset for span-only marks (rule). |
channels / edits / id | passthrough | Accept them on the factory and pass them through. A mark that drops edits can’t be edited. Constraints go on the spec: a mark given constraints logs a warning. |
xKey / yKey | stringdefaultfrom channels | Field names the edit/constraint layer reads back — usually the channel’s field. |
pointerEvents | per-nodedefaultengine | Don’t silence the whole mark — leave unset so the engine can. Set per-node on glyph chrome (a path over handles) so chrome doesn’t swallow drags. |
A feature object the engine consumes. Line-family marks also set seriesKey, order, and supportsSeries: true.
Edit SDK
Build descriptors and reuse the same invert/pick helpers the stock edits use. Prefer the ladder: stock edit → custom → makeEdit → registerDriver.
makeEdit(spec) → Edit
custom(fn, options) → Edit
invertChannel(ch, pointer, center?) → value
recenterSpan(node, chA, chB, pointer) → { a, b }
markCenter(node) → { x, y }
schemaDefaults(schema) → Datum
nearestMark(marks, x, y, threshold) → index | null
registerDriver({ name, onEvent, sessionKeys?, options?, wants?, selects? })| Option | Type · default | Description |
|---|---|---|
makeEdit(spec) | → Edit | Normalize a partial spec into a full descriptor. Defaults: gesture: "drag", pick: "direct", channels: null (inject the channel it’s placed on). Keys the descriptor doesn’t know pass through onto the edit — the sanctioned way a custom driver carries per-edit options (the built-ins’ edgeInset works the same way). |
apply(ctx) | fn | Pure given ctx. Return a datum (splice at index), a full array (whole-dataset rewrite), or undefined (no-op). Never mutate ctx.data. |
EditContext | ctx | data, datum, index, pointer, node, event, resolved channels, markChannels, scales, schema, marks, … |
cardinality | 'append' | | Tell constraints which row is active when the dataset’s shape changes (create/remove). |
inverts | booleandefaultfalse | Declares that this edit runs a pointer back through a channel’s scale, so that scale must be invertible. Set it on any edit that reads ctx.pointer; the dead-drag guard reads this rather than a list of type names. |
inline | booleandefaultfalse | Declares that this edit opens an inline text editor over the mark. It is what wires the double-click lifecycle — type, then Enter or blur commits and Escape cancels — and what editText sets. |
name | stringdefaultnull | Stable handle for chart.control(name). See External controls. |
scope | 'line' | defaultnull | Mark family the edit needs. Put the family in the API name ( edit.line.*); the engine warns on a mismatch. |
invertChannel | fn | Pointer → data for one resolved channel — the same path stock move uses. Prefer this over hand-rolled scale.invert. |
Descriptors the engine routes. Multi-event lifecycles belong in a driver, not an if (pick === …) branch in the engine.
Drivers — authoring.registerDriver
A driver owns a multi-event plane lifecycle (hover / drag / click, …). Built-ins cover nearest, sweep, draw, brush, probe, plane, …. Register a new one when stock pick values aren’t enough.
registerDriver({ name, onEvent(ctx), sessionKeys?, options?, wants?(edit), selects? })| Option | Type · default | Description |
|---|---|---|
wants(edit) | → boolean | Claim edits — usually edit.pick === name. |
onEvent(ctx) | → boolean | Return whether anything changed (commit or redraw). ctx has event, edits, marks, session, preview, runEdit, previewEdit. |
runEdit / previewEdit | (edit, | Commit through constraints + undo, or park an uncommitted hover preview. |
selects | booleandefaultfalse | If true, the driver writes a selection into session so guide: true can draw the snap ring / highlight. |
Replaces a built-in of the same name, or adds a new pick. No engine fork required.
A custom mark
A mark is a view over the chart’s dataset. The factory returns a feature object, and its only required method is build(data, scales, width, height, ctx?).
- Call
normalizeMarkOptionsfirst. - Resolve every channel through
encodeChannelandresolveStyle. - Spread
authoring.markCommon(opts)to passid,edits,table,tipandclipthrough unchanged. - Set
discreteScalewhen discrete data needs a band or a point scale. - Set
typeon the feature. Every feature carries one; the example uses"square". - Leave mark-wide
pointerEventsto the engine.
To let a datum’s derived channels ({ fn }) see their row index and the dataset, pass the optional index and data arguments when you resolve per datum: authoring.resolveStyle(scales, channels, d, defaults, i, data).
A custom square mark
authoring.normalizeMarkOptions → encodeChannel / resolveStyle → FeatureNode[]. Stock drag still works because the nodes carry data and index.
// A minimal mark factory — same contract as point/bar.function square(options = {}) {const opts = authoring.normalizeMarkOptions(options, { mark: "square", allow: [] });const { channels = {} } = opts;return {// id / edits / table / tip / clip, passed through verbatim....authoring.markCommon(opts),type: "square",channels,discreteScale: "point",xKey: channels.x && channels.x.field,yKey: channels.y && channels.y.field,build(data, scales, width, height) {return data.map((d, i) => {const style = authoring.resolveStyle(scales, channels, d, { fill: "#50AEB7" });const cx = authoring.encodeChannel(scales, channels, "x", d, width / 2);const cy = authoring.encodeChannel(scales, channels, "y", d, height / 2);const r = authoring.encodeChannel(scales, channels, "size", d, 8);const side = Math.max(0, r * 2);return {type: "rect",x: cx - side / 2, y: cy - side / 2,width: side, height: side,...style, data: d, index: i,};});},};}const chart = Elicit({width: 380, height: 240,margins: { top: 14, right: 14, bottom: 26, left: 30 },data: [{ x: 25, y: 40 }, { x: 55, y: 70 }, { x: 80, y: 35 }],schema: {x: { type: "quantitative", domain: [0, 100] },y: { type: "quantitative", domain: [0, 100] },},marks: [square({size: 9,channels: {x: { field: "x" },y: { field: "y" },},edits: [ move({ channels: ["x", "y"] }) ],}),],});mount(chart.dom());
The edit ladder
Reach for the smallest tool that fits:
- Stock edit —
move,resize,create, … when the behaviour already exists. custom(fn)— one-offapply, same gesture/pick defaults.makeEdit(spec)— full descriptor control (type,pick,cardinality,name, …).registerDriver— multi-event lifecycle / a newpickvalue.
apply is pure: return a new datum, a new array, or undefined. Prefer invertChannel over hand-rolled scale.invert.
custom(fn) — a one-off apply
custom wraps fn as apply. Drag rewrites y from the pointer; x still uses stock move().
// Level B — custom(fn): one-off apply, stock gesture/pick defaults.const bumpY = custom((ctx) => {if (!ctx.datum) return undefined;const y = ctx.scales.y.invertValue(ctx.pointer.y);return { ...ctx.datum, y: Math.round(y) };});const chart = Elicit({width: 380, height: 240,margins: { top: 14, right: 14, bottom: 26, left: 30 },data: [{ x: 30, y: 40 }, { x: 70, y: 65 }],schema: {x: { type: "quantitative", domain: [0, 100] },y: { type: "quantitative", domain: [0, 100] },},marks: [point({fill: "#1B3F60", size: 9,channels: {x: { field: "x", edit: move() },y: { field: "y" },},edits: [ bumpY ],}),],});mount(chart.dom());
makeEdit + invertChannel
Full descriptor: invert y, then snap to the nearest 10. Same idea as custom, with an explicit type and channels list.
const snapDrag = authoring.makeEdit({type: "snapDrag",gesture: "drag",channels: ["y"],apply: (ctx) => {const ch = ctx.channels[0];const v = authoring.invertChannel(ch, ctx.pointer);if (v === undefined || !ctx.datum) return undefined;return { ...ctx.datum, [ch.field]: Math.round(v / 10) * 10 };},});const chart = Elicit({width: 360, height: 240,margins: { top: 16, right: 16, bottom: 28, left: 34 },data: [ { cat: "A", n: 40 } ],schema: {cat: { type: "categorical", domain: ["A"] },n: { type: "quantitative", domain: [0, 100] },},marks: [point({fill: "#50AEB7", size: 10,channels: { x: { field: "cat" }, y: { field: "n" } },edits: [ snapDrag ],}),],});mount(chart.dom());
When apply returns a full array
Most edits return one datum, which replaces the row at index. Whole-dataset edits, such as reorder, create and remove, return a new array. rank() is the built-in example: drag swaps discrete rank slots.
rank() — array-returning apply
Point scale over ranks; drag swaps with the nearest slot. Your makeEdit can return [...ctx.data] the same way.
const chart = Elicit({width: 360, height: 260,margins: { top: 16, right: 16, bottom: 28, left: 80 },data: [{ item: "A", rank: 1 },],schema: {item: { type: "categorical", domain: ["A", "B", "C"] },rank: { type: "ordinal", domain: [1, 2, 3] },},marks: [point({fill: "#1B3F60", size: 9,channels: {x: { value: 40 },y: { field: "rank", edit: rank() },},}),text({fontSize: 13,channels: {x: { value: 56 },y: { field: "rank" },text: { field: "item" },textAnchor: { value: "start" },},}),],});mount(chart.dom());
Register a driver
Stock pick values (direct, nearest, plane, probe, sweep, …) cover most lifecycles. For a new one, register a driver. An edit reaches a driver by naming it, as in pick: "clickNearest", and each edit reaches exactly one driver. wants(edit) claims an edit by capability, such as a relative slide, and doesn't re-test pick.
onEvent handles hover, click and drag. runEdit and previewEdit commit or preview through the same constraint and undo path as stock edits. Declare sessionKeys. Every driver on the mark shares the per-feature session, and the session.clear() you receive nulls only your keys. Declare options for any setting your driver reads off the edit, or the engine reports it as an unknown option. Set selects: true if guide: true should draw a snap ring. Set targetsRow: true if the driver only chooses a row, so that chart.control(name, index) can run its edits on a given row.
clickNearest — hover, then click to bump
registerDriver + makeEdit({ pick: "clickNearest" }). Hover highlights; click adds 10 to y.
// A tiny driver: hover highlights the nearest mark; click bumps its y.authoring.registerDriver({name: "clickNearest",// The keys this driver owns in the shared per-feature session; clear() nulls them.sessionKeys: ["px", "py", "threshold", "hoverIndex"],selects: true,onEvent({ event, edits, marks, session, runEdit }) {const threshold = 48;if (event.type === "hover") {session.set({px: event.x, py: event.y, threshold,hoverIndex: authoring.nearestMark(marks, event.x, event.y, threshold),});return true;}if (event.type === "hoverout") {session.clear();return true;}if (event.type === "click") {const index = authoring.nearestMark(marks, event.x, event.y, threshold);if (index == null) return false;let changed = false;for (const e of edits) {if (e.gesture === "click" && runEdit(e, index)) changed = true;}return changed;}return false;},});const bump = authoring.makeEdit({type: "bump",pick: "clickNearest",gesture: "click",channels: ["y"],guide: true,apply: (ctx) => {if (!ctx.datum) return undefined;const field = ctx.channels[0].field;return { ...ctx.datum, [field]: Math.min(100, (ctx.datum[field] || 0) + 10) };},});const chart = Elicit({width: 380, height: 240,margins: { top: 14, right: 14, bottom: 26, left: 30 },data: [{ x: 25, y: 30 }, { x: 55, y: 55 }, { x: 80, y: 40 }],schema: {x: { type: "quantitative", domain: [0, 100] },y: { type: "quantitative", domain: [0, 100] },},marks: [point({fill: "#50AEB7", size: 9,channels: {x: { field: "x" },y: { field: "y" },},edits: [ bump ],}),],});mount(chart.dom());
Glyphs: prefer a group of marks
If a glyph’s handles map to distinct fields of a row, build it as a composite: ordinary marks over the same rows. Direct picks then keep each handle to its own field. Use node.channel with a when guard only when several handles must live on one feature over one datum, because their positions are derived rather than stored as fields.
Put a whole-dataset plane gesture (create, rotate, …) on exactly one mark. Two marks with the same plane edit fire twice per click.
Helpers to reuse
Reuse these for proximity and minting:
invertChannel/recenterSpan/markCenter: pointer ↔ data for positional editsschemaDefaults(schema): mint a row with every field set to its default (ornull)authoring.nextSeriesKey(data, seriesField, schema?): the next free series id for a new linenearestMark/nearestSeries/nearestMarkOnAxis: shared distance pickers
To restyle the built-in widgets, register a design: authoring.registerDesign.
For a custom edit that creates rows, set cardinality: "append" so constraints know which row is new. For an edit that runs the pointer back through a scale, set inverts: true so the dead-drag guard can check the channel. To drive an edit from external UI, give it a name and call chart.control(name).
Where next
- Marks — reference implementations (
point,bar,rule) to mirror. - Editing — stock gestures, pick modes, stages, history.
- Composite — multi-handle glyphs as grouped marks.
- Constraints — dataset rules your
applymust respect. - Gestures · Custom — more
custom(fn)patterns withwhen.