Elicit.js

Axes and view: rescale, zoom & pan

An axis with an edit rewrites the field's domain on the schema, where a mark edit rewrites a datum. Drag a numeric axis to change its range. A categorical axis gains controls to add, rename and remove categories. The chart's view takes the edits that move the whole plot: the wheel zooms it and a drag pans it. The grid, guides and marks follow the new domain, and chart.setDomain(field, domain) does the same from a button. Read it with chart.getSchema(). The dataset is unchanged, except that removing a category deletes its rows.

API reference

edit.axis.scale(options)

Numeric / temporal axis — drag an end-handle to rescale the range. Runs through the axisDrag driver (the plane owns the gesture); apply writes the new [min,max].

edit.axis.scale({ field, mode }) → Edit
Options
OptionType · defaultDescription
field
stringdefaultall on axis
The schema field whose domain to write. Defaults to every field unioned onto the axis (e.g. an error bar's mean/lo/hi).
mode
'rescale'|'grow'default'rescale'
rescale keeps the chart size (marks compress); grow holds the data's pixels-per-unit and resizes the chart instead.
Returns / emits

An Edit with target: "domain". apply returns { domains, resize? }; the engine writes the schema (and resizes in grow mode).

edit.scale.categories(options)

Categorical / ordinal SCALE — add, rename and remove categories, from any element that draws it (an axis or a legend). Reuses the inline-typing lifecycle: double-click the "+" to add, double-click a label or swatch to rename, click its "×" to remove. Renaming and removing write every column on the scale, in every table it spans.

edit.scale.categories({ field, mode }) → Edit[]
Options
OptionType · defaultDescription
field
stringdefaultevery field on the axis
The categorical field whose domain (and rows, on rename/remove) to edit. Unset, every field on the scale is written.
mode
'rescale'|'grow'default'rescale'
rescale keeps the chart size (bands re-divide it — thinner as you add); grow keeps each band the same pixel size and grows/shrinks the chart by a step per category (e.g. a 5-point Likert extended to 7).
Returns / emits

An array of three Edits, all type: "scale.categories" and target: "domain". Each one’s action says which it is: "add", "rename" or "remove". Rename relabels matching rows; remove deletes them. In grow mode, add/remove also carry a chart resize.

view

A spec option. Holds the edits on the view itself, the x and y domains as a window: edit.view.zoom() and edit.view.pan(). It needs no axis, so it works with axes: false. On a map it moves the lon and lat domains.

Elicit({ view: { edits: [edit.view.zoom(), edit.view.pan()] }, … })
Options
OptionTypeDescription
edits
Edit[]
The view's edits. A view edit placed on a mark or an axis warns and does nothing.

edit.view.zoom(options)

The wheel narrows or widens the view about the value under the pointer. It writes the schema’s domains, never the dataset. Place it in the view: view: { edits: [edit.view.zoom()] }.

edit.view.zoom({ channels, factor, limit, minSpan, min, max, mode, when }) → Edit
Options
OptionType · defaultDescription
channels
('x' | 'y')[]default['x', 'y']
The axes it zooms. With both, one factor scales them together.
factor
numberdefault1.2
How much one wheel notch (100 px of wheel travel) scales the span. Scrolling up divides the span by it; scrolling down multiplies.
limit
'declared' | [lo, hi] | falsedefault'declared'
The widest a domain may zoom out to: the field's domain as declared in the schema, an explicit range, or false for no limit.
minSpan
number
The narrowest span a domain may zoom in to, in data units. Use it with one channel; with both, use max.
min
number
The lowest zoom level, as a multiple of the declared view. 0.5 shows twice the declared span, which also needs limit: false.
max
number
The highest zoom level, as a multiple of the declared view. 8 stops at eight times the declared size.
mode
'domain' | 'magnify'default'domain'
domain moves positions and keeps every pixel size. magnify also scales sizes, text, strokes and layout gaps with the view.
when
(ctx) => boolean
Gate the zoom on a modifier key. Two zooms, one per channel, with when.alt on one and when.noAlt on the other zoom the axes separately.
Returns / emits

An Edit scoped to view. It acts on continuous scales (numeric or temporal). A burst of wheel ticks is one undo step.

edit.view.pan(options)

Dragging the plot slides the view along. It writes the schema’s domains, never the dataset, and composes with edit.view.zoom(): view: { edits: [edit.view.zoom(), edit.view.pan()] }.

edit.view.pan({ channels, limit, when }) → Edit
Options
OptionType · defaultDescription
channels
('x' | 'y')[]default['x', 'y']
The axes it pans.
limit
'declared' | [lo, hi] | falsedefault'declared'
How far it may pan: the field's domain as declared in the schema, an explicit range, or false for no limit. At the limit the view stops and keeps its span.
when
(ctx) => boolean
Gate the pan on a modifier key, e.g. when.shift to pan only with Shift held.
Returns / emits

An Edit scoped to view. It acts on continuous scales (numeric or temporal). A press on a mark with its own edit edits the mark. One drag is one undo step.

clip

A spec option. Clips the marks to the plot area, axis to axis. Only the part of a mark inside the clip takes a press or shows a tip. Axes, legends, guides and marks with clip: false keep drawing in the margins.

Elicit({ clip: true | false, … })
Elicit({ clip: { padding: 6 }, … })
Elicit({ clip: { padding: { top: 4, bottom: 4 } }, … })
text({ clip: false, … })   // on a mark
Options
OptionType · defaultDescription
clip
boolean | { padding }defaulton with zoom or pan
On by default when the view carries edit.view.zoom() or edit.view.pan(), off otherwise. The object form turns it on.
padding
number | { top, right, bottom, left }default0
Pixels past the plot area the marks still draw: one number for every side, or a number per side.
clip (on a mark)
booleandefaultfollows the chart
false draws the mark past the clip. On a composite, it applies to every part.

chart.setDomain(field, domain, options)

Write a field’s domain from outside the chart — a zoom button, a reset control. The same commit a wheel tick or a pan makes: undoable, notified through change, and every scale reflows.

chart.setDomain("x", [20, 40])   // → true
chart.setDomain("x", null)       // restore the declared domain
chart.setDomain("weight", [0, 5], { table: "links" })
Options
OptionType · defaultDescription
field
string
The schema field to write. It writes that one field, as given.
domain
any[] | null
The new domain, or null for the domain declared in the schema. On a field declared with no domain, null takes a written domain away.
options.table
stringdefaultthe primary table
The table that declares the field.
Returns / emits

true when it wrote the domain. false, with a warning, when the table declares no such field, there is no domain to restore or take away, or the domain does not fit the field’s type: [min, max] for a numeric or temporal field, a list of distinct values for a categorical one.

Drag a numeric axis to rescale

axisX({ edit: edit.axis.scale() }) adds a draggable handle at each end of the axis. Drag a handle toward the middle to widen the range, so the data compresses into the same chart. Drag it outward to narrow the range. The opposite end stays fixed, and the dataset is unchanged.

Rescale in place

Dragging the end-handle rewrites x's schema domain; the grid follows.

const chart = Elicit({
width: 420, height: 280,
margins: { top: 16, right: 18, bottom: 40, left: 44 },
data: [{ x: 20, y: 30 }, { x: 55, y: 65 }, { x: 90, y: 20 }],
schema: {
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
axes: false,
marks: [
gridX(), axisY(),
axisX({ title: "x", edit: edit.axis.scale() }),
point({ fill: "#8A78C0", size: 7,
channels: { x: { field: "x" }, y: { field: "y" } } }),
],
});
mount(chart.dom());
Try: Drag the blue handle at either end of the x-axis.

Grow the chart instead

mode: 'grow' holds the data's scale constant and resizes the chart.

const chart = Elicit({
width: 360, height: 260,
margins: { top: 16, right: 18, bottom: 40, left: 44 },
data: [{ x: 20, y: 30 }, { x: 90, y: 55 }],
schema: {
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
axes: false,
marks: [
axisY(),
axisX({ title: "x", edit: edit.axis.scale({ mode: "grow" }) }),
point({ fill: "#315228", size: 7,
channels: { x: { field: "x" }, y: { field: "y" } } }),
],
});
mount(chart.dom());
Try: Drag the x-axis max handle — the chart itself grows/shrinks.

Add, rename & remove categories

axisX({ edit: edit.scale.categories() }) makes each category label a rename target (double-click to type). Each label gets an × to remove it, and a + at the end adds a new one. A rename relabels matching rows, and a removal deletes them, so the schema and data stay in step.

The domain belongs to the scale, so the same edit works on any element that draws it, including a legend. When one scale spans several columns or tables, it writes all of them.

Edit the category list

Double-click + to add · double-click a label to rename · click × to remove.

const chart = Elicit({
width: 420, height: 280,
margins: { top: 16, right: 18, bottom: 48, left: 44 },
data: [
{ cat: "Apples", v: 6 },
],
schema: {
cat: { type: "categorical", domain: ["Apples", "Pears", "Plums"] },
v: { type: "quantitative", domain: [0, 12] },
},
axes: false,
marks: [
axisY(),
axisX({ edit: edit.scale.categories() }),
bar({ fill: "#50AEB7",
channels: { x: { field: "cat" }, y: { field: "v" } } }),
],
});
mount(chart.dom());
Try: Double-click + to add a bar · double-click a label to rename · click × to remove.

Grow a Likert scale

mode: 'grow' keeps each band the same width and grows the chart by a step per point added — extend a 5-point scale to 7 without cramming.

const chart = Elicit({
width: 320, height: 240,
margins: { top: 16, right: 18, bottom: 46, left: 40 },
data: [
{ step: "1", n: 3 }, { step: "2", n: 6 }, { step: "3", n: 9 },
{ step: "4", n: 5 }, { step: "5", n: 2 },
],
schema: {
step: { type: "ordinal", domain: ["1", "2", "3", "4", "5"] },
n: { type: "quantitative", domain: [0, 12] },
},
axes: false,
marks: [
axisY(),
axisX({ edit: edit.scale.categories({ mode: "grow" }) }),
bar({ fill: "#2B5D87",
channels: { x: { field: "step" }, y: { field: "n" } } }),
],
});
mount(chart.dom());
Try: Double-click + to add points — the chart widens instead of the bars shrinking · click × to shrink it back.

Zoom with the wheel

Put edit.view.zoom() in the spec's view: view: { edits: [edit.view.zoom()] }. Scroll up to zoom in and down to zoom out. The value under the pointer stays where it is.

It zooms x and y by one factor. Set channels: ["x"] or channels: ["y"] to zoom one axis and leave the other alone. The view needs no axis, so a chart with axes: false zooms the same way.

The declared domain is the zoom-out ceiling, so you can always scroll back to the full view and no further. Set limit to an explicit [lo, hi] for a different ceiling, or false for none. min and max set the zoom levels it stops at, as multiples of the declared view: max: 8 stops at eight times the declared size.

A burst of wheel ticks is one step in history, so one undo restores the domain from before you scrolled. Each tick notifies change, and chart.getSchema() reads the current domain. The domain is the dataset's, so charts that share a dataset zoom together.

Zoom works on numeric and temporal axes, and on a map, where it moves the lon and lat domains. Mark edits keep working at every zoom level: drag a point and it inverts through the zoomed scale. The buttons call chart.setDomain for each axis (see below).

Zoom both axes

edit.view.zoom() in view, plus buttons that zoom about the centre.

const chart = Elicit({
width: 420, height: 280,
margins: { top: 16, right: 18, bottom: 32, left: 40 },
schema: {
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
data: [
{ x: 12, y: 20 }, { x: 24, y: 42 }, { x: 38, y: 35 }, { x: 47, y: 58 },
{ x: 55, y: 51 }, { x: 63, y: 70 }, { x: 71, y: 64 }, { x: 86, y: 82 },
],
// The wheel zooms x and y by one factor, about the value under the pointer.
view: { edits: [edit.view.zoom()] },
marks: [
point({
fill: "#8A78C0", size: 6,
channels: { x: { field: "x" }, y: { field: "y" } },
edits: [move({ channels: ["x", "y"] })],
}),
],
});
mount(chart.dom());
// Buttons zoom both axes about the centre of the view, clamped to the
// declared domains.
const DECLARED = { x: [0, 100], y: [0, 100] };
const zoomBy = (k) => {
const schema = chart.getSchema();
for (const field of ["x", "y"]) {
const [lo, hi] = schema[field].domain;
const [LO, HI] = DECLARED[field];
const half = Math.min((hi - lo) * k, HI - LO) / 2;
const mid = Math.min(Math.max((lo + hi) / 2, LO + half), HI - half);
chart.setDomain(field, [mid - half, mid + half]);
}
};
const controls = document.createElement("div");
controls.style.cssText = "display:flex;gap:8px;margin-top:10px;font:12px system-ui";
const addButton = (label, onclick) => {
const b = document.createElement("button");
b.textContent = label;
b.onclick = onclick;
b.style.cssText = "padding:4px 10px;border:1px solid #BCC9D4;border-radius:6px;background:#fff;cursor:pointer";
controls.append(b);
};
addButton("Zoom in", () => zoomBy(0.5));
addButton("Zoom out", () => zoomBy(2));
addButton("Reset", () => { chart.setDomain("x", null); chart.setDomain("y", null); });
mount(controls);
Try: Scroll over the plot or click Zoom in · drag a point at any zoom level.

Pan by dragging

Add edit.view.pan() beside the zoom. Drag the plot and the view follows the pointer, on both axes. channels: ["x"] pans along x only.

A press on a mark with an edit of its own still edits that mark. A press anywhere else on the plot pans.

Pan stops at the declared domain, keeping the span. Set limit as on zoom. One drag is one undo step.

Zoom and pan write the same domains, so they combine. Each starts from where the other left it, and you can scroll to zoom in the middle of a drag.

Zoom and pan a year of data

edit.view.zoom() and edit.view.pan() with channels: ["x"]. The buttons zoom about the centre of the view.

// A year of weekly rainfall. Zoom in, then drag the plot to pan along it.
const data = d3.range(53).map((week) => ({
week,
rain: Math.round(40 + 25 * Math.sin(week / 8) + 10 * Math.cos(week / 3)),
}));
const chart = Elicit({
width: 460, height: 260,
margins: { top: 16, right: 18, bottom: 32, left: 40 },
schema: {
week: { type: "quantitative", domain: [0, 52] },
rain: { type: "quantitative", domain: [0, 100] },
},
data,
// Zoom and pan both write the week domain, so each picks up where the
// other left off. `channels: ["x"]` leaves y alone.
view: {
edits: [
edit.view.zoom({ channels: ["x"], minSpan: 4 }),
edit.view.pan({ channels: ["x"] }),
],
},
marks: [
lineY({ stroke: "#2B5D87", strokeWidth: 2, channels: { x: { field: "week" }, y: { field: "rain" } } }),
point({
fill: "#2B5D87", size: 4,
channels: { x: { field: "week" }, y: { field: "rain", edit: move() } },
}),
],
});
mount(chart.dom());
const [LO, HI] = [0, 52]; // the declared week domain
const zoomBy = (k) => {
const [lo, hi] = chart.getSchema().week.domain;
const half = Math.max(2, Math.min((hi - lo) * k, HI - LO) / 2);
const mid = Math.min(Math.max((lo + hi) / 2, LO + half), HI - half);
chart.setDomain("week", [mid - half, mid + half]);
};
const controls = document.createElement("div");
controls.style.cssText = "display:flex;gap:8px;align-items:center;margin-top:10px;font:12px system-ui";
const addButton = (label, onclick) => {
const b = document.createElement("button");
b.textContent = label;
b.onclick = onclick;
b.style.cssText = "padding:4px 10px;border:1px solid #BCC9D4;border-radius:6px;background:#fff;cursor:pointer";
controls.append(b);
};
addButton("Zoom in", () => zoomBy(0.5));
addButton("Zoom out", () => zoomBy(2));
addButton("Reset", () => chart.setDomain("week", null));
const readout = document.createElement("span");
readout.style.color = "#6F8294";
controls.append(readout);
mount(controls);
const show = () => {
const [lo, hi] = chart.getSchema().week.domain;
readout.textContent = `weeks ${lo.toFixed(1)} – ${hi.toFixed(1)}`;
};
chart.on("change", show);
show();
Try: Scroll or click Zoom in · drag the plot to pan · drag a point to edit it.

Zoom sizes and text

Zoom changes the domain, so by default only positions move with it. A size, width, height or font size in pixels stays the same on screen at every zoom level.

edit.view.zoom({ mode: "magnify" }) scales every pixel length with the view. The sizes you write are the sizes at the declared domain. At twice the zoom a box, its text, its stroke and its corner radius all draw twice as large. Axes, legends and ui grips keep their size.

A size that is data stays data. Drag a grip at twice the zoom and 40 pixels of travel write 20 units, so the value you elicit is the same at any zoom level.

A layout reads its gap, rankGap and padding at the declared size too. Zooming in spreads the rows and grows the gaps together, and the positions the layout wrote stay as they are.

Zoom both axes, as the default does. With channels: ["x"], widths follow the zoom and heights keep their size, so shapes stretch.

Zoom a board of notes

mode: "magnify" on edit.view.zoom(), with axes: false and a layered layout.

// Steps of a process. The layout places them; the links follow.
const chart = Elicit({
width: 520, height: 380,
margins: { top: 12, right: 12, bottom: 12, left: 12 },
axes: false,
schema: {
structure: "network",
tables: {
steps: {
role: "nodes",
fields: {
id: { type: "categorical", key: true, open: true },
label: { type: "categorical", open: true },
w: { type: "quantitative", domain: [70, 220] },
x: { type: "quantitative", domain: [0, 100] },
y: { type: "quantitative", domain: [0, 100] },
},
},
flows: {
role: "links",
directed: true,
fields: { source: { type: "ref" }, target: { type: "ref" } },
},
},
},
data: {
steps: [
{ id: "ask", label: "Ask the question", w: 120 },
],
flows: [
{ source: "ask", target: "draw" },
],
},
// "magnify" scales boxes, text, strokes and the layout's gaps with the view.
// `max: 6` stops at six times the declared size.
view: {
edits: [edit.view.zoom({ mode: "magnify", max: 6 }), edit.view.pan()],
},
marks: [
link({ stroke: "#46596B", strokeWidth: 1.5, curve: "orthogonal" }),
sticker({
id: "step",
fill: "#ECF3F9", stroke: "#1D4467",
cornerRadius: 10, maxWidth: 220,
edits: [editText({ multiline: true })],
channels: {
x: { field: "x", edit: move({ channels: ["x", "y"], mode: "relative" }) },
y: { field: "y" },
// The width is data. A grip writes the same value at any zoom.
width: { field: "w", scale: { range: [70, 220] } },
text: { field: "label" },
},
}),
],
layout: [layout.network.layered({ direction: "down", gap: 18, rankGap: 26 })],
});
mount(chart.dom());
ui.attach(chart, [ui.handles({ on: { mark: "step" } })]);
// A readout of the zoom level: the declared span over the current one.
const readout = document.createElement("div");
readout.style.cssText = "margin-top:8px;font:12px system-ui;color:#6F8294";
mount(readout);
const show = () => {
const [lo, hi] = chart.getSchema().tables.steps.fields.x.domain;
readout.textContent = `zoom ${Math.round(100 / (hi - lo) * 100)}%`;
};
chart.on("change", show);
show();
Try: Scroll to zoom · drag the plot to pan · drag a note to move it, or a grip on its side to resize it.

Sizes in data units

This is a workaround for a chart that zooms in the default mode. It scales no size. It stores each shape's edges as data and draws the shape between them, and positions move with the zoom.

A rect with x1/x2 and y1/y2 spans those values on the zoomed scales, so it grows as you zoom in. A corner radius of at least half the side draws a circle. Give the plot the same pixels per unit on both axes, so a circle stays round. Text and strokes keep their pixel size.

Drag a shape with move({ channels: ["x1", "x2", "y1", "y2"], mode: "relative" }). It moves both edges by the same amount on each axis, so the shape keeps its size.

Boxes and circles in data units

rect with x1/x2 and y1/y2 from the data; zoom and pan on the view.

// A workaround, with no size scaling: each shape stores its edges as data,
// x0–x1 and y0–y1. The four edges are positions, so they move with the zoom
// and the shape grows between them.
const data = [
{ kind: "box", x0: 10, x1: 40, y0: 60, y1: 85 },
];
const chart = Elicit({
// 360 × 300 px for 120 × 100 units: 3 px a unit on both axes, so a
// square in data units is square on screen.
width: 400, height: 340,
margins: { top: 12, right: 8, bottom: 28, left: 32 },
schema: {
kind: { type: "categorical", domain: ["box", "circle"] },
x0: { type: "quantitative", domain: [0, 120] },
x1: { type: "quantitative", domain: [0, 120] },
y0: { type: "quantitative", domain: [0, 100] },
y1: { type: "quantitative", domain: [0, 100] },
},
data,
view: { edits: [edit.view.zoom({ max: 8 }), edit.view.pan()] },
marks: [
rect({
channels: {
x1: { field: "x0" }, x2: { field: "x1" },
y1: { field: "y0" }, y2: { field: "y1" },
fill: { field: "kind", scale: { range: ["#E8D3A9", "#A9CFC4"] } },
// A corner radius of at least half the side draws a circle.
cornerRadius: { fn: (d) => (d.kind === "circle" ? 999 : 6) },
},
stroke: "#5E6E7C", strokeWidth: 1,
// Relative: the shape keeps its offset from where you grabbed it.
edits: [move({ channels: ["x1", "x2", "y1", "y2"], mode: "relative" })],
}),
],
});
mount(chart.dom());
Try: Scroll to zoom · drag the plot to pan · drag a shape to move it.

Clip to the plot

A zoomed or panned chart clips its marks to the plot area, axis to axis. A mark past an axis is hidden, and only the part inside the plot takes a press or shows a tip. Axes, legends and guides keep drawing in the margins.

Clipping is on by default whenever the view carries edit.view.zoom() or edit.view.pan(). Set clip: false on the spec to turn it off, or clip: true to clip a chart with neither.

clip: { padding: 6 } clips to the plot area grown by 6 pixels, so a point on the edge of the domain draws whole. Pass one number for every side, or { top, right, bottom, left } for each side. A padding turns clipping on.

Set clip: false on a mark to draw it past the clip, such as a label in the margin. Its marks take a press and show a tip out there too. On a composite, it applies to every part.

Pad the clip, label in the margin

clip: { padding: 6 } on the spec and clip: false on the text mark.

// Daily highs that touch both ends of the scale. `padding` lets a point on the
// edge draw whole; `clip: false` keeps the latest reading's label in the margin.
const data = d3.range(30).map((day) => ({
day,
high: Math.max(0, Math.min(40, Math.round(20 + 18 * Math.sin(day / 3) + 6 * Math.cos(day)))),
}));
const W = 460, H = 260;
const margins = { top: 16, right: 72, bottom: 32, left: 40 };
const chart = Elicit({
width: W, height: H, margins,
schema: {
day: { type: "quantitative", domain: [0, 29] },
high: { type: "quantitative", domain: [0, 40] },
},
data,
// Clip to the plot, grown by 6 px on every side.
clip: { padding: 6 },
view: {
edits: [
edit.view.zoom({ channels: ["x"], minSpan: 5 }),
edit.view.pan({ channels: ["x"] }),
],
},
marks: [
lineY({ stroke: "#EE7B5E", strokeWidth: 2, channels: { x: { field: "day" }, y: { field: "high" } } }),
point({
fill: "#EE7B5E", size: 6,
channels: { x: { field: "day" }, y: { field: "high", edit: move() } },
}),
// Pinned 8 px past the plot's right edge, at the latest day's value.
// `clip: false` lets it draw in the margin.
text({
clip: false, textAnchor: "start", fontSize: 12, fill: "#B14A30",
channels: {
x: { value: W - margins.left - margins.right + 8 },
y: { field: "high" },
text: { fn: (d, i, rows) => (i === rows.length - 1 ? `${d.high}° today` : "") },
},
}),
],
});
mount(chart.dom());
Try: Scroll to zoom · drag the plot to pan · drag the last point and its label follows.

One axis at a time

A plain wheel runs every edit.view.zoom() in the view. Declare one per axis with channels, and give each a when to split them by modifier key: when.noAlt on one and when.alt on the other.

minSpan sets the narrowest the domain may zoom in to, in data units. Here time stops at three months and value at ten units.

Time with the wheel, value with Alt

Two zooms, one per channel: when.noAlt on x and when.alt on y; minSpan caps how far each zooms in.

// A forecast over 24 months. The plain wheel zooms time; Alt + wheel zooms the value.
const data = d3.range(25).map((m) => ({
month: m,
value: 50 + 20 * Math.sin(m / 4) + m * 0.8,
}));
const chart = Elicit({
width: 440, height: 260,
margins: { top: 16, right: 18, bottom: 32, left: 40 },
schema: {
month: { type: "quantitative", domain: [0, 24] },
value: { type: "quantitative", domain: [0, 100] },
},
data,
view: {
edits: [
edit.view.zoom({ channels: ["x"], when: when.noAlt, minSpan: 3 }),
edit.view.zoom({ channels: ["y"], when: when.alt, minSpan: 10 }),
],
},
marks: [
lineY({
stroke: "#1B3F60", strokeWidth: 2,
channels: {
x: { field: "month" },
y: { field: "value", edit: move() },
},
}),
],
});
mount(chart.dom());
Try: Scroll to zoom time · Alt + scroll to zoom value · drag a point on the line.

Set a domain from outside

chart.setDomain(field, domain) writes a field's domain. It takes the same path as a wheel tick or a pan: one undo step, a change notification, and every scale reflows. Pass null to restore the domain declared in the schema.

setDomain returns false and logs a warning when the table declares no such field, or when the domain doesn't fit the field's type. A numeric or temporal field takes [min, max]; a categorical or ordinal one takes a list of distinct values. Pass { table } to name a field of a table other than the primary one.

It writes the domain as given. Clamp to the declared domain yourself when zooming out, as the buttons above do:

const zoomBy = (k) => {
const [lo, hi] = chart.getSchema().week.domain;
const half = Math.min((hi - lo) * k, 52) / 2;
const mid = Math.min(Math.max((lo + hi) / 2, half), 52 - half);
chart.setDomain("week", [mid - half, mid + half]);
};