Elicit.js

Arc · Pie · Donut

arc and donut draw pie and donut slices. Each row's magnitude, on the theta channel, is stacked and normalised to a full circle or a partial arc. edit.stack.edge(), cut() and merge() reshape the slices while keeping the total fixed. x/y scatter one donut per value, and a radius channel gives each slice its own rim for a rose plot.

API reference

arc(options) · donut(options)

Import plot from elicitjs. donut is arc with a default inner radius. A full pie is just arc().

arc({ channels, outerRadius, innerRadius, padAngle, arc, start, end, handles, handleSize, handleColor, edits, id }) → Mark
donut(options) → Mark
Options
OptionType · defaultDescription
outerRadius
numberdefaultfits the slot
Outer radius in px, for every donut. Omit to fit the slot (a band cell, or a shrunk scatter default); or bind a size field for a per-donut radius.
innerRadius
numberdefault0
Inner radius; >0 makes a donut. A value in (0,1] is a ratio of the outer radius (so a fitted / size-driven donut stays proportional); >1 is absolute px. donut() defaults this.
padAngle
numberdefault0
Gap between slices in degrees.
arc
'semi' | 'full'default'full'
Angular span of the whole pie. 'semi' is the top half.
start / end
numberdefault-180 / 180
Explicit span in degrees, measured counter-clockwise from 3 o’clock (0° is the right, 90° the top). The span is signed: start: 90, end: -270 walks clockwise from 12 o’clock. Both given, they override arc.
edits
Edit | Edit[]
Slice editing — edit.stack.cut(), edit.stack.edge(), edit.stack.merge(). Draws a grab handle on each interior boundary (n slices → n − 1 handles; the seam is the layout's fixed anchor).
handles
boolean | 'hit'defaulttrue with a stack edit
Unset, the boundary dots draw once an edit.stack.* edit is wired. true always draws them, as ink on a pie with no edit. 'hit' keeps each boundary grabbable but draws no dot. false is neither drawn nor grabbable.
handleSize
numberdefault5
Pixel radius of each boundary handle.
handleColor
stringdefaulttheme
Handle fill. Defaults to the theme’s handle colour.
Channels
ChannelTypeDescription
theta
magnitude field
Slice size in data units; layout normalizes by the sum of rows. The polar positional channel (Vega-Lite's name for it) — not `angle`, which is a mark's rotation in place, and not `value`, which already means a visual-space constant on any channel. Read raw here: an arc normalizes its own magnitudes, so it neither implies a radial axis nor draws a fan key.
stack
categorical | ordinal field
Optional. Names each slice and orders the slices by the field's schema domain (else first appearance); without it, slices follow data order. `edit.stack.cut()` writes a new slice's category into it, so a cut needs it.
fill
ordinal | const
Slice colour.
x / y
field | const
Donut centre. Bind a field to place one donut per distinct value (a band category, or a scatter coordinate) — a grid of donuts, grouped by the encoding. Unbound → the plot centre (one donut).
size
field | const
Optional per-donut outer radius (e.g. turnout), through the size scale. Overridden by an explicit outerRadius.
radius
linear | sqrt
Per-slice outer radius (a rose plot), through a radius scale whose range runs from innerRadius to outerRadius. scale: 'sqrt' makes area proportional to the value. Takes an edit: move() drags a slice’s rim. Wins over size. Key it with axisRadial({ channel: 'radius' }).
Returns / emits

A mark emitting one filled path per row.

Pie

Full circle, zero inner radius.

Party shares

Three slices from a shared total.

const chart = Elicit({
width: 300, height: 280,
margins: { top: 20, right: 20, bottom: 20, left: 20 },
axes: false,
data: [
{ party: "D", share: 48 },
],
schema: {
party: { type: "categorical" },
share: { type: "quantitative", domain: [0, 100] },
},
marks: [
arc({
outerRadius: 100,
channels: {
theta: { field: "share" },
fill: { field: "party" },
},
}),
],
});
mount(chart.dom());

Donut

The same layout with an inner hole, which leaves room for a centre label.

Donut with centre text

Static proportions; text is a sibling mark.

const chart = Elicit({
width: 300, height: 280,
margins: { top: 20, right: 20, bottom: 20, left: 20 },
axes: false,
data: [
{ party: "D", share: 48, label: "48%" },
],
schema: {
party: { type: "categorical" },
share: { type: "quantitative", domain: [0, 100] },
label: { type: "categorical" },
},
marks: [
donut({
outerRadius: 100, innerRadius: 55,
channels: {
theta: { field: "share" },
fill: { field: "party" },
},
}),
text({
fontSize: 22,
channels: {
text: { value: "100%" },
textAnchor: { value: "middle" },
lineAnchor: { value: "middle" },
},
}),
],
});
mount(chart.dom());

Editable slice boundaries

Add edit.stack.edge() and every interior boundary gets a draggable handle, so n slices give n − 1 handles. The seam where the last slice meets the first stays fixed, since the orientation and the total are both fixed.

Dragging a boundary moves value between the two slices it separates. One grows by what the other loses, so the total is preserved.

Drag any boundary

Each handle pair-shifts the two slices it sits between; the rest of the pie holds still.

const chart = Elicit({
width: 300, height: 280,
margins: { top: 20, right: 20, bottom: 20, left: 20 },
axes: false,
data: [
{ party: "D", share: 40 },
],
schema: {
party: { type: "categorical" },
share: { type: "quantitative", domain: [0, 100] },
},
marks: [
arc({
outerRadius: 100,
edits: [edit.stack.edge()],
channels: {
theta: { field: "share" },
fill: { field: "party" },
},
}),
],
});
mount(chart.dom());
Try: Drag a dot on any slice edge.

Donut, four slices

Four slices → three handles.

const chart = Elicit({
width: 300, height: 280,
margins: { top: 20, right: 20, bottom: 20, left: 20 },
axes: false,
data: [
{ cat: "A", v: 20 },
],
schema: {
cat: { type: "categorical" },
v: { type: "quantitative", domain: [0, 100] },
},
marks: [
donut({
outerRadius: 100, innerRadius: 50,
edits: [edit.stack.edge()],
handleSize: 6,
channels: {
theta: { field: "v" },
fill: { field: "cat", scale: { scheme: "dd" } },
},
}),
],
});
mount(chart.dom());
Try: Drag any edge — the two adjacent slices rebalance.

Cutting and merging slices

A pie divides one total among its rows, as a stacked bar does along an axis. The same three gestures work on both:

  • edit.stack.cut() — click inside a slice to divide it in two at the pointer angle.
  • edit.stack.edge() — drag a boundary to move value across it.
  • edit.stack.merge() — double-click a boundary to fuse those two slices back into one.

Each preserves the pie's total, and each takes pick: "nearest" to grab a slice or boundary from close by. A cut needs a stack channel: it writes the new slice's category into that field, taking a value from its schema domain, so it needs no typing. A pie always stacks, so on arc the stack channel only names the slices and orders them by its domain. Without it, slices follow data order. A closed domain hands out the values this pie doesn't yet use, and refuses the cut once they run out. open: true lets each cut append a new one. See Slicing a stack for the bar form.

Cut a slice

One full circle to start. The category domain declares five values, so the pie takes four cuts.

const chart = Elicit({
width: 300, height: 300,
margins: { top: 20, right: 20, bottom: 20, left: 20 },
axes: false,
data: [{ category: "housing", share: 100 }],
schema: {
category: {
type: "categorical",
domain: ["housing", "food", "transport", "savings", "other"],
},
share: { type: "quantitative", domain: [0, 100] },
},
legends: true,
marks: [
arc({
outerRadius: 100,
channels: {
theta: { field: "share" },
stack: { field: "category" },
fill: { field: "category" },
},
edits: [
edit.stack.cut(),
edit.stack.edge(),
edit.stack.merge(),
],
}),
],
});
mount(chart.dom());
Try: Click inside a slice to cut it, drag a boundary to shift share, double-click one to merge.

A grid of donuts

Bind x (and optionally y) to a field and each distinct value becomes a slot with its own donut. The rows at that slot are its slices, so the encoding does the grouping. A size field scales each donut separately, and outerRadius sets one radius for all. Otherwise the radius fits the slot.

Here x: { field: 'state' } gives a band axis, so IL, NY and NC each get a donut of their own party split. A boundary drag moves share within that state only, and the other states keep their totals.

Party split per state

One donut per band-axis category; each state's boundaries redistribute within that state alone.

const chart = Elicit({
width: 520, height: 260,
margins: { top: 20, right: 20, bottom: 30, left: 20 },
data: [
{ state: "IL", party: "D", share: 55 },
],
schema: {
party: { type: "categorical" },
share: { type: "quantitative", domain: [0, 100] },
state: { type: "categorical", domain: ["IL", "NY", "NC"] },
},
marks: [
donut({
edits: [edit.stack.edge()],
handleSize: 6,
channels: {
x: { field: "state" }, // band axis → one donut per state
theta: { field: "share" }, // party's share within its state
fill: { field: "party" },
},
}),
],
});
mount(chart.dom());
Try: Drag a boundary in one state — only that state’s shares rebalance.

Rose plots (radius)

The radius channel gives each slice its own outer radius, between innerRadius and outerRadius, for a rose or radial plot. theta still sets each slice's angle. theta: { value: 1 } makes every slice the same width, so the value reads from the rim alone. With no outerRadius, the ring's extent is 40% of the smaller plot dimension.

scale: 'sqrt' makes a slice's area grow with its value; the default linear scale makes its radius grow with it. Put edit: move() on the channel to drag a slice's rim in or out. axisRadial({ channel: 'radius' }) draws concentric rings as its key.

A radius channel replaces a per-donut size and sets one ring's extent. On a grid of donuts, every slot uses that extent.

A rose you can reshape

radius: { field: "speed", scale: "sqrt", edit: move() } — eight equal slices, each rim a value.

const chart = Elicit({
width: 320, height: 300,
margins: { top: 16, right: 16, bottom: 16, left: 16 },
axes: false,
data: [
{ dir: "N", speed: 12 }, { dir: "NE", speed: 8 },
],
schema: {
dir: { type: "categorical" },
speed: { type: "quantitative", domain: [0, 30] },
},
elements: [ axisRadial({ channel: "radius", ticks: 3 }) ],
marks: [
arc({
innerRadius: 12, outerRadius: 120, padAngle: 2,
start: 112.5, end: -247.5, // clockwise, N centred at the top
fill: "#1B3F60", fillOpacity: 0.85,
channels: {
theta: { value: 1 }, // equal slices: the value lives on the radius
// sqrt: a slice's AREA grows with the value, not its radius.
radius: { field: "speed", scale: "sqrt", edit: move() },
},
}),
],
});
mount(chart.dom());
Try: Drag a slice's rim outward or inward to change its speed.