Elicit.js

Legend pickers & editing

A legend can take input as well as label a scale. Click a swatch to set a categorical field, drag a ramp handle to set a continuous value, or double-click to edit the scale's domain. With more than one row, a picker writes to the selected rows.

API reference

edit.legend.category()

Turn legend swatches into click targets that set a categorical field on the legend’s target rows.

edit.legend.category(options?)
Returns / emits

An Edit for a legend. It takes the universal edit options and none of its own. The legend’s row option names the rows a click writes. With no row, it writes the selection, or the sole row of a one-row table. With neither, a click writes nothing.

edit.legend.value()

Add a draggable handle to a continuous gradient colour ramp.

edit.legend.value(options?)
Returns / emits

An Edit for a legend. It takes the universal edit options and none of its own. The handle writes the same target rows as edit.legend.category(): the legend’s row, else the selection, else the sole row of a one-row table.

edit.scale.categories()

Inline add, rename, and remove affordances for the scale domain.

edit.scale.categories(options?)
Options
OptionType · defaultDescription
mode
"rescale" | "grow"default"rescale"
"rescale" compresses items to keep chart size fixed; "grow" widens the chart when categories are added.

Categorical swatch pickers

Pass edit: edit.legend.category() to make each swatch a click target. A click sets the channel's field on the target row and recolours the mark.

Click a swatch to set category

A one-row answer whose category is set from the legend.

const chart = Elicit({
width: 340, height: 200,
margins: { top: 20, right: 16, bottom: 20, left: 20 },
axes: false,
data: [ { status: "Active" } ],
schema: {
status: { type: "categorical", domain: ["Active", "Paused", "Archived"] },
},
marks: [
point({
size: 40,
channels: {
x: { value: 100 },
y: { value: 100 },
fill: { field: "status" },
},
}),
legendColor({
anchor: "right",
edit: edit.legend.category(),
}),
],
});
mount(chart.dom());
Try: Click a swatch to change the status.

Targeting selected rows

With several rows, a picker needs a row to write. Its row target defaults to the selection: click a mark, then a swatch, and that mark updates.

With edit.select({ multi: true }), one swatch click updates every selected row at once.

Select bars, then pick a group

Click a bar to select it (or Shift-click for multiple), then click a swatch to reassign its group.

const chart = Elicit({
width: 380, height: 220,
margins: { top: 20, right: 16, bottom: 30, left: 40 },
data: [
{ name: "A", value: 12, group: "North" },
],
schema: {
name: { type: "categorical", domain: ["A", "B", "C", "D"] },
group: { type: "categorical", domain: ["North", "South", "East", "West"] },
value: { type: "quantitative", domain: [0, 16] },
},
marks: [
barY({
channels: {
x: { field: "name" },
y: { field: "value" },
fill: { field: "group" },
},
edits: [edit.select({ multi: true })],
}),
legendColor({
anchor: "right",
edit: edit.legend.category(),
}),
],
});
mount(chart.dom());
Try: Click a bar, Shift-click another, then click a legend swatch.

Continuous ramp sliders

For a continuous field, edit: edit.legend.value() adds a draggable handle to the colour ramp. Dragging it writes that value to the row.

Drag the gradient ramp

Dragging the ramp handle updates the numeric temperature value.

const chart = Elicit({
width: 320, height: 210,
margins: { top: 20, right: 16, bottom: 20, left: 20 },
data: [ { temp: 18 } ],
schema: { temp: { type: "quantitative", domain: [0, 30] } },
axes: false,
marks: [
point({
size: 35,
channels: {
x: { value: 80 },
y: { value: 95 },
fill: { field: "temp" },
},
}),
legendColor({
anchor: "right",
edit: edit.legend.value(),
}),
],
});
mount(chart.dom());
Try: Drag the handle up and down along the gradient ramp.

Authoring categories on the scale

A swatch picker writes to a row. edit.scale.categories() writes to the scale's domain.

It adds three controls to the legend: double-click a swatch to rename its category, click the × to delete it, and double-click the + to add a category. A rename updates matching rows, and a delete removes them.

Rename, remove, and add categories

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

const chart = Elicit({
width: 380, height: 220,
margins: { top: 20, right: 16, bottom: 28, left: 40 },
data: [
{ cat: "Alpha", val: 30 },
],
schema: {
cat: { type: "categorical", domain: ["Alpha", "Beta", "Gamma"] },
val: { type: "quantitative", domain: [0, 60] },
},
marks: [
barY({
channels: {
x: { field: "cat" },
y: { field: "val" },
fill: { field: "cat" },
},
}),
legendColor({
anchor: "right",
edit: edit.scale.categories(),
}),
],
});
mount(chart.dom());
Try: Double-click the + icon to add a category · double-click a label to rename it.