Elicit.js

Needle

needle draws a tapered pointer and hub for a gauge or dial. Its value is on the theta channel, and the theta scale's range sets the sweep in degrees: the default [180, 0] runs left to right through the top. A companion axisRadial draws the same theta scale, so give it the needle's range. x/y place the pivot, for many small needles in one chart.

API reference

needle(options)

Import plot from elicitjs. One needle (+ hub) per datum.

needle({ channels, length, handles, handleSize, handleColor, baseWidth, tipWidth, id }) → Mark
Options
OptionType · defaultDescription
channels
objectdefault{}
Must include theta — the polar angular position. (angle is a mark’s rotation in place and is not read here.) Optional x/y place the pivot (default: plot centre).
length
numberdefault40% of min(w,h)
Needle length in px. Or drive via the size channel.
handles
boolean | 'hit'defaulttrue
The hub always draws. true paints it as a handle. false or 'hit' paints it in the needle’s own fill and stroke.
handleSize
numberdefault5
Hub circle radius in px. The hub is the needle's handle.
handleColor
stringdefaulttheme
Hub fill. Defaults to the theme’s handle colour.
baseWidth
numberdefault10
Width of the needle base in px.
tipWidth
numberdefault0
Width of the needle tip in px. 0 tapers to a point. Set it equal to baseWidth for a bar of even width, such as a limb you grab far from its pivot.
Channels
ChannelTypeDescription
theta
linear | point (deg)
The elicited value, mapped to degrees by its scale. Default range [180, 0].
x / y
linear | point
Optional pivot position — categorical or quantitative.
fill / stroke
style
Needle colour.
Returns / emits

A mark emitting a filled needle path and hub circle per datum.

Semicircle gauge + centre text

A gauge combines axisRadial for the ticks, needle, and text. The default range [180, 0] puts 0 on the left and the maximum on the right.

Quantitative gauge

Domain [0, 100] maps to [180°, 0°] (left → right). Drag the needle.

const chart = Elicit({
width: 320, height: 200,
margins: { top: 24, right: 16, bottom: 16, left: 16 },
axes: false,
data: [{ n: 62 }],
schema: { n: { type: "quantitative", domain: [0, 100] } },
marks: [
composite({
id: "gauge",
parts: [
axisRadial({
outerRadius: 100, ticks: 5,
channels: { theta: { field: "n", scale: { range: [180, 0] } } },
}),
needle({
length: 90, fill: "#50AEB7",
channels: {
theta: {
field: "n",
scale: { range: [180, 0] },
edit: rotate({ pivot: "mark", fold: false, pick: "direct" }),
},
},
}),
text({
fontSize: 22, dy: 28,
format: ".0f",
channels: {
text: { field: "n" },
textAnchor: { value: "middle" },
lineAnchor: { value: "middle" },
},
}),
],
}),
],
});
mount(chart.dom());
Try: Drag the needle left or right.

Right-facing

Same data; the needle and axisRadial share the theta range [-90, 90].

const chart = Elicit({
width: 240, height: 280,
margins: { top: 16, right: 28, bottom: 16, left: 16 },
axes: false,
data: [{ n: 62 }],
schema: { n: { type: "quantitative", domain: [0, 100] } },
marks: [
axisRadial({
outerRadius: 100, ticks: 5,
channels: { theta: { field: "n", scale: { range: [-90, 90] } } },
}),
needle({
length: 90, fill: "#50AEB7",
channels: {
theta: {
field: "n",
scale: { range: [-90, 90] },
edit: rotate({ pivot: "mark", fold: false, pick: "direct" }),
},
},
}),
],
});
mount(chart.dom());

Many needles on x × y

Each row is a pivot: x is categorical, y quantitative, and theta a third numeric answer. Drag a needle to write that row only.

Small needles in a scatter of pivots

Group on x, layer on y, answer on theta. Cartesian axes frame the pivots.

const chart = Elicit({
width: 420, height: 280,
margins: { top: 16, right: 16, bottom: 36, left: 40 },
data: [
{ g: "A", layer: 1, belief: 35 },
],
schema: {
g: { type: "categorical", domain: ["A", "B", "C"] },
layer: { type: "quantitative", domain: [0.5, 2.5] },
belief: { type: "quantitative", domain: [0, 100] },
},
axes: {
x: { title: "group" },
y: { title: "layer", ticks: 2 },
},
marks: [
// A mini radial axis rings each pivot, so every needle shows the 0→100 span
// it encodes. Same x/y channels as the needle → one ring per row.
axisRadial({
outerRadius: 22, ticks: 0, tickSize: 0, tickPadding: 6, fontSize: 7,
stroke: "#BCC9D4",
channels: {
x: { field: "g" },
y: { field: "layer" },
theta: { field: "belief", scale: { range: [180, 0] } },
},
}),
needle({
length: 24, handleSize: 3, baseWidth: 6,
channels: {
x: { field: "g" },
y: { field: "layer" },
theta: {
field: "belief",
scale: { range: [180, 0] },
edit: rotate({ pivot: "mark", fold: false, pick: "direct" }),
},
fill: { field: "g" },
},
}),
],
});
mount(chart.dom());
Try: Drag any small needle to change that cell’s answer.

Full-circle dial

For a full 360° knob, set the theta range to [-180, 180] on the needle and on axisRadial. rotate({ fold: false }) lets the needle travel the whole circle.

Quantitative dial

Rotate anywhere around the hub.

const chart = Elicit({
width: 280, height: 280,
margins: { top: 20, right: 20, bottom: 20, left: 20 },
axes: false,
data: [{ n: 0.35 }],
schema: { n: { type: "quantitative", domain: [0, 1] } },
marks: [
axisRadial({
outerRadius: 95, ticks: 8,
channels: { theta: { field: "n", scale: { range: [-180, 180] } } },
}),
needle({
length: 80, fill: "#20555A",
channels: {
theta: {
field: "n",
scale: { range: [-180, 180] },
edit: rotate({ pivot: "mark", fold: false, pick: "direct" }),
},
},
}),
text({
fontSize: 18, format: ".0%",
channels: {
text: { field: "n" },
textAnchor: { value: "middle" },
lineAnchor: { value: "middle" },
},
}),
],
});
mount(chart.dom());
Try: Drag around the dial.

Ableton-style knob

A software knob is a composite of a ring (a dark track and a value fill) and a thin needle on the same theta scale. arc and donut divide a total among rows, but a knob's fill is one value swept from the arc's start, so the ring is a small custom mark built on authoring.arcPath. The needle carries rotate({ pivot: "mark", fold: false, pick: "direct" }). The ring has no edit and re-derives as you drag.

The span is a 270° arc with a gap at the bottom: start: 225 (about 7 o'clock) to end: -45 (about 5 o'clock). Set the needle's scale.range to the same span.

Compress knob

Ring fill + needle over one quantitative field. Drag the needle — the cyan slice follows.

// Ableton-style knob: a donut-slice ring (track + value fill) plus a needle.
// The ring is a tiny mark over authoring.arcPath; the needle carries rotate().
// Stock arc/donut partition a total among rows — a knob's fill is one value
// swept from the arc's start, so the ring is a short authoring mark instead.
const START = 225; // ~7 o'clock
const END = -45; // ~5 o'clock — 270° clockwise through the top
function knobArc(options = {}) {
const opts = authoring.normalizeMarkOptions(options, {
mark: "knobArc",
allow: ["outerRadius", "innerRadius", "start", "end", "track"],
});
const {
channels = {},
outerRadius = 90,
innerRadius = 78,
start = START,
end = END,
track = "#14283A",
} = opts;
return {
...authoring.markCommon(opts),
type: "knobArc",
channels,
build(data, scales, width, height) {
const cx = width / 2, cy = height / 2;
return data.flatMap((d, i) => {
const deg = authoring.encodeAngle(scales, channels, d, start, i, data);
const style = authoring.resolveStyle(
scales, channels, d, { fill: "#2B5D87" }, i, data,
);
const nodes = [];
const trackD = authoring.arcPath(cx, cy, outerRadius, start, end, { innerRadius });
if (trackD) {
nodes.push({
type: "path", d: trackD, fill: track, stroke: "none",
data: d, index: i, pointerEvents: "none",
});
}
const fillD = authoring.arcPath(cx, cy, outerRadius, start, deg, { innerRadius });
if (fillD) {
nodes.push({
type: "path", d: fillD, ...style, stroke: "none",
data: d, index: i, pointerEvents: "none",
});
}
// Max tick — the small end-cap Ableton puts at 5 o'clock.
const tip = authoring.polarToXY(cx, cy, (outerRadius + innerRadius) / 2, end);
nodes.push({
type: "circle", cx: tip.x, cy: tip.y, r: 2.5,
fill: track, stroke: "none",
data: d, index: i, pointerEvents: "none",
});
return nodes;
});
},
};
}
const chart = Elicit({
width: 260, height: 280,
margins: { top: 40, right: 24, bottom: 44, left: 24 },
axes: false,
theme: { background: "#14283A", ink: "#94A5B3" },
data: [{ level: 25 }],
schema: { level: { type: "quantitative", domain: [0, 100] } },
marks: [
composite({
id: "knob",
parts: [
text({
fontSize: 13, dy: -108,
channels: {
text: { value: "Compress" },
fill: { value: "#94A5B3" },
textAnchor: { value: "middle" },
lineAnchor: { value: "middle" },
},
}),
knobArc({
outerRadius: 88, innerRadius: 76,
start: START, end: END,
track: "#14283A",
channels: {
theta: { field: "level", scale: { range: [START, END] } },
fill: { value: "#2B5D87" },
},
}),
needle({
length: 70, baseWidth: 2.5,
handles: "hit",
fill: "#14283A", stroke: "#14283A",
channels: {
theta: {
field: "level",
scale: { range: [START, END] },
edit: rotate({ pivot: "mark", fold: false, pick: "direct" }),
},
},
}),
text({
fontSize: 14, dy: 108,
format: (v) => `${Math.round(v)} %`,
channels: {
text: { field: "level" },
fill: { value: "#94A5B3" },
textAnchor: { value: "middle" },
lineAnchor: { value: "middle" },
},
}),
],
}),
],
});
mount(chart.dom());
Try: Drag the needle around the ring.

Categorical needle

A discrete theta field uses a point scale, so a drag snaps to the nearest category. axisRadial({ bands: true }) draws the coloured bands.

Likelihood gauge

Seven ordered categories across a top-facing arc.

const chart = Elicit({
width: 360, height: 220,
margins: { top: 40, right: 70, bottom: 20, left: 70 },
axes: false,
// Let the long band labels ("VERY LIKELY D" …) spill into the margin instead of
// being clipped by the plot edge.
overflow: "visible",
data: [{ chance: "LEANING D" }],
schema: {
chance: {
type: "ordinal",
domain: ["VERY LIKELY D", "LIKELY D", "LEANING D", "TOSSUP",
"LEANING R", "LIKELY R", "VERY LIKELY R"],
},
},
marks: [
axisRadial({
outerRadius: 110, bands: true, bandWidth: 22,
tickSize: 0, tickPadding: 18, fontSize: 8,
channels: {
theta: { field: "chance", scale: { range: [180, 0] } },
// ColorBrewer RdBu is red→blue; reverse so D (left) is blue and R (right)
// is red — a proper 7-class diverging categorical palette.
fill: { field: "chance", scale: { scheme: "dddiverging", reverse: true } },
},
}),
needle({
length: 95, fill: "#EE7B5E",
channels: {
theta: {
field: "chance",
scale: { range: [180, 0] },
edit: rotate({ pivot: "mark", fold: false, pick: "direct" }),
},
},
}),
text({
fontSize: 14, dy: 32,
channels: {
text: { field: "chance" },
textAnchor: { value: "middle" },
lineAnchor: { value: "middle" },
},
}),
],
});
mount(chart.dom());
Try: Drag the needle across categories.