Widgets
Widgets are ready-made elicitation interfaces for survey questions. Each one returns an ElicitSpec built from ordinary marks, edits and constraints, with its chrome drawn as guides. Render one with Elicit(widgets.likert({…})). A design sets how all thirteen are drawn, and you choose one with theme. The Likert scale below appears both as a widget and as the plain-API spec it expands to.
API reference
widgets.likert · multipleChoice · slider · matrix · lineCone · ranking · allocation · …
Import widgets from elicitjs. Each returns an ElicitSpec; pass it straight to Elicit. The chart draws one dataset, so getData() reads the answer.
likert({ question, options, value, onChange }) → ElicitSpec
multipleChoice({ question, options, maxChoices, value, onChange }) → ElicitSpec
slider({ question, domain, step, value, format, onChange }) → ElicitSpec
thermometer({ question, domain, step, value, onChange }) → ElicitSpec
matrix({ question, questions, options, value, onChange }) → ElicitSpec
ranking({ question, items, onChange }) → ElicitSpec
allocation({ question, categories, total, value, onChange }) → ElicitSpec
histogram({ question, bins, domain, value, onChange }) → ElicitSpec
probabilityTokens({ question, bins, maxTokens, onChange }) → ElicitSpec
interval({ question, category, value: { mean, lo, hi }, domain, symmetric, onChange }) → ElicitSpec
region({ question, domain: { x, y }, value: { x1, x2, y1, y2 }, onChange }) → ElicitSpec
lineCone({ question, x, y, value: { r, spread }, render, samples, seed, onChange }) → ElicitSpec
labeledValue({ question, input, value, domain, label, onChange }) → ElicitSpec| Option | Type · default | Description |
|---|---|---|
question | stringdefaultper widget | The prompt, drawn into the top margin so it travels with the chart. |
onChange | (data) => | Called with the committed answer. Hover previews never fire it. |
width / height / stage / theme | default per widget | |
options | any[]default[] | The response choices, on a band scale — likert, multipleChoice, matrix. |
value | any | The starting answer, on every widget that takes one. One value for likert, slider, thermometer and labeledValue. A list for multipleChoice and matrix, and one number per category for allocation and histogram. An object for interval ({ mean, lo, hi }), region ({ x1, x2, y1, y2 }) and lineCone ({ r, spread }); a key you leave out keeps its default. ranking and probabilityTokens take none. |
maxChoices | numberdefault∞ | multipleChoice: how many picks are allowed. A pick over the limit is rejected. |
domain / step | [min, default[0, | The value range, on every widget that has one: slider, thermometer, labeledValue, interval, and histogram’s count axis (default [0, 40]). region takes one per axis, { x, y } (default [0, 10] each). step is the increment a slider or thermometer answer snaps to. |
format | string | defaultauto | slider: how the end labels read. |
questions | any[]default[] | matrix: the rows, one question each. |
items | any[]default['A', | ranking: what is being put in order. |
categories / total | any[] / numberdefault['A', | allocation: what the budget is split between, and how much there is. Drag one bar and the others give way to keep the total. |
bins / maxTokens | any[] / numberdefault— / 20 | histogram and probabilityTokens: the buckets, and how many tokens there are to place. |
category | stringdefault'estimate' | interval: what is being estimated. Its starting estimate and bounds are value, which defaults to 50%, 30% and 70% of the domain. |
symmetric | booleandefaultfalse | interval: drag one cap and the other mirrors it about the mean. It adds constraints.symmetric to the widget’s follow, ordering and clamp. |
x / y | stringdefault'x' / 'y' | lineCone: the two variable names labelled on the quadrant frame. The starting correlation and its width are value, 0 and 0 by default. |
render / samples / seed | string / numberdefault'samples' / 60 / 7 | lineCone: how the spread is drawn, how many sample lines it uses, and the seed that keeps them stable across renders. |
input / label | 'number' | default'number' / 'value' | labeledValue: which editor the answer takes, and the name beside it. |
An ElicitSpec — an ordinary spec, so you can read it, change one key, and pass it on. The chrome each widget draws itself with is a guide: guides.prompt, guides.options, guides.cellGrid, guides.sliderTrack, guides.quadrants. The plain-API twins below use those same guides, so each block stands alone.
theme.widget
The widget tokens, set through theme on a widget, on Elicit or with setTheme. design names the design; the others are the colours and sizes it reads. A widget takes its theme when it is built.
theme: "survey" | "surveyBlocks" | "surveyLines"
theme: { extends: "survey", widget: { design, accent, corner, … } }| Option | Type · default | Description |
|---|---|---|
design | "ring" | default"ring" | How the widgets are drawn: a built-in design, or one you registered. |
accent / onAccent | stringdefault"#2563eb" / "#ffffff" | A committed answer, and the text and ticks drawn on it. |
tint | stringdefault"#e9f0fe" | A chosen option's wash in the box design, and a grabbed card's in the block design. |
surface / soft / stroke | stringdefaultwhite / light grey / grey | An option box or a card, a filled block or a bar's track, and the edge of a box or a card. |
ring / track | stringdefault"#cbd5e1" / "#e2e8f0" | An empty control, and a track or a hairline. |
cellFill / cellStroke | stringdefault"#f8fafc" / "#e2e8f0" | A matrix cell in the ring design. |
label / question | stringdefault"#334155" / "#0f172a" | An option's label, and the prompt. |
grip / shadow | stringdefaultgrey / translucent black | A ranking card's drag handle, and the shadow under a lifted card. |
labelSize / itemSize | numberdefault12 / 13 | The text size of an option's label, and of a list row or a card. |
questionSize / questionWeight | numberdefault13 / 400 | The prompt's size and weight. |
radius | numberdefault11 | The radius of a ring or a radio, and half a checkbox's side. |
corner | numberdefault10 | The corner radius of a box, a block or a card. |
gap | numberdefault8 | The space between options and between cards. |
optionHeight / rowHeight | numberdefault74 / 40 | The height of an option in a row of boxes, and of a list row or a card. |
authoring.registerDesign(name, design)
Adds a design. Every widget then draws with it when theme.widget.design names it. State the parts you change; the rest come from extends. See Add a design.
authoring.registerDesign(name, { extends, list, tiles, option, answer, grid, track, thumb, card, slots, bar, theme })
authoring.designNames() → string[]
authoring.labelNode(text, x, y, tokens, { width, anchor, fill, fontSize, fontWeight }) → node
authoring.checkNode(cx, cy, tokens) → node
authoring.controlNodes(cx, cy, control, selected, tokens) → node[]| Option | Type · default | Description |
|---|---|---|
extends | stringdefault"ring" | The design to take the unstated parts from. |
list / tiles | booleandefaultfalse | list stacks multiple choice as a list. tiles sizes the plot to the options from optionHeight, rowHeight and gap. |
option | (option, defaultfrom extends | Draws one option: its box, its empty control and its label. |
answer | (option, defaultfrom extends | The answer's ink: a dot or a square on the control, or a block that fills the option. |
grid / slots | (box, defaultfrom extends | Chrome around a whole matrix, and the lines between a ranking list's slots. |
track / thumb | (track, defaultfrom extends | A slider's track, and its handle. |
card | (card, defaultfrom extends | A ranking card's parts, back to front: body, badge, rank, label, grip. Each takes left or right and its paint. |
bar | (tokens) => defaultfrom extends | A bar in the widgets drawn on chart axes. |
theme | ThemeSpec | Registers a named theme under the design's name, with widget.design set to it. |
Likert scale — widget & plain API
A point on a band of options, a create({ pick: "probe" }) edit, and count({ max: 1, strategy: "replace" }). Hover to preview the answer, and click to set it. The plain-API version uses the same mark, edit and constraint, and draws the same look with inline guides.custom helpers.
As a widget
Rings, track and labels come from the guide layer.
const chart = Elicit(widgets.likert({question: "This tool is easy to use",options: ["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"],}));mount(chart.dom());
The same thing, plain API
Same mark, edit, and constraint — rings/prompt defined inline as guides. This is what widgets.likert expands to.
const options = ["Strongly disagree","Disagree","Neutral","Agree","Strongly agree"];const radius = 11;const prompt = (text) => guides.custom(() => [{type: "text", x: 0, y: -18, text,textAnchor: "start", fontSize: 13, fill: "#20555A",}]);const rings = () => guides.custom((ctx) => {const cats = ctx.scales.x.domainConfig || [];const cy = ctx.height / 2;const cxOf = (c) => ctx.scales.x.encode(c);const nodes = [];for (let i = 0; i < cats.length - 1; i++) {nodes.push({type: "line",x1: cxOf(cats[i]) + radius, y1: cy,x2: cxOf(cats[i + 1]) - radius, y2: cy,stroke: "#D9E2E9", strokeWidth: 3, background: true,});}for (const c of cats) {nodes.push({type: "circle", cx: cxOf(c), cy, r: radius,fill: "none", stroke: "#BCC9D4", strokeWidth: 1.5,});nodes.push({type: "text", x: cxOf(c), y: cy + 30, text: String(c),textAnchor: "middle", fontSize: 12, fill: "#20555A",});}return nodes;});const chart = Elicit({width: 560, height: 130,margins: { top: 34, right: 60, bottom: 44, left: 60 },axes: false,data: [],schema: { choice: { type: "ordinal", domain: options } },scales: { x: { type: "band" } },constraints: [ count({ max: 1, strategy: "replace" }) ],guides: [ prompt("This tool is easy to use"), rings() ],marks: [point({id: "likert",size: radius - 3,fill: "#50AEB7",channels: { x: { field: "choice" } },edits: [ create({ pick: "probe", channels: ["x"], advance: false }) ],}),],});mount(chart.dom());
Multiple choice
toggle() combines create and remove in one gesture. Click an empty option to pick it, and click your pick to take it back. maxChoices caps the number of picks with count().
Multiple choice (pick ≤ 2)
The hover shows whether a click will pick or un-pick.
const chart = Elicit(widgets.multipleChoice({question: "Which apply?",options: ["Fast","Cheap","Reliable","Simple"],maxChoices: 2,}));mount(chart.dom());
Slider
A single knob that follows the pointer and settles when you click or release a drag: move({ pick: "probe" }). snap() lands it on steps.
Slider
Track, end caps and value labels are guides.
const chart = Elicit(widgets.slider({question: "How likely is it? (%)",domain: [0, 100], step: 5, value: 40,}));mount(chart.dom());
Question matrix
Questions on a band y, options on a band x. toggle() on (x, y) picks a cell, and unique({ field: "question", strategy: "replace" }) keeps one answer per row.
Question matrix
The cell grid is a guide, so it never swallows the click.
const chart = Elicit(widgets.matrix({question: "Rate each aspect",questions: ["Speed","Cost","Support"],options: ["Poor","OK","Good","Great"],}));mount(chart.dom());
Line + Cone
A two-step correlation question. Aim the line and click, then open the cone and click. getData() returns [{ r, spread }], and on("stage") reports which question you are on (2 = both answered).
It is a preset over trendBand and trend on one dataset. A pinned intercept: { datum: 0 } channel and two clamp constraints state the correlation. The trend page has the same spec written out. The inner plot is square, so the line’s screen angle reads as r.
Line + Cone
Crosshair frame and high/low variable labels are guides.
const chart = Elicit(widgets.lineCone({question: "What is the relationship?",x: "Exercise amount", y: "Body weight",}));mount(chart.dom());const out = document.createElement("div");out.style.cssText = "font:12px ui-monospace,monospace;color:#6F8294";const show = () => {const d = chart.getData()[0];out.textContent = "stage " + chart.getStage() +" · r=" + d.r.toFixed(2) + " spread=" + d.spread.toFixed(2);};chart.on("change", show); chart.on("stage", show); show();mount(out);
Ranking
Each item is a card. Drag one to reorder the list: rank() on the card's body writes the new order as you cross each slot, and the other cards shift by one place. The card follows the pointer, the others ease into their slots, and the card eases into its own when you let go. With reduced motion on, cards step from slot to slot.
The card is a composite: a rect body that carries the rank() edit, with the rank and the label drawn on it. motion: true on the glyph eases its parts when the order changes. Along the rank channel, whose scale is a band of slots, it draws the grabbed card at the pointer. motion: true works on any mark, and spec.motion sets the duration.
Ranking
A card per item. The whole card is the handle.
const chart = Elicit(widgets.ranking({question: "Rank these priorities",items: ["Cost", "Speed", "Quality", "Risk"],}));mount(chart.dom());
The same thing, plain API
A composite card, rank() on its body, and motion: true.
// What widgets.ranking expands to: one card per row, a rank edit on its body,// and motion: true on the glyph.const items = ["Cost", "Speed", "Quality", "Risk"];const chart = Elicit({width: 420,height: 238,margins: { top: 34, right: 16, bottom: 4, left: 16 },axes: false,schema: {item: { type: "categorical", domain: items },rank: { type: "ordinal", domain: [1, 2, 3, 4] },},// The band runs down the plot, so rank 1 is at the top.scales: { y: { type: "band", padding: 0.17, range: [0, 200] } },data: items.map((item, i) => ({ item, rank: i + 1 })),effects: {hovered: { outline: false, stroke: "#94a3b8" },grabbed: {stroke: "#2563eb",strokeWidth: 1.5,cursor: "grabbing",filter: "drop-shadow(0 6px 9px rgba(15, 23, 42, 0.18))",},},marks: [composite({id: "card",motion: true,channels: {},parts: [// The body spans the plot and takes the drag.rect({height: 40, cornerRadius: 10, fill: "#ffffff", stroke: "#d5dbe5",channels: { y: { field: "rank", edit: rank({ cursor: "grab" }) } },}),// The rank and the label are inert, so a press on them reaches the body.text({fill: "#2563eb", fontWeight: 600,channels: { x: { value: 20 }, y: { field: "rank" }, text: { field: "rank" } },}),text({fill: "#0f172a", fontSize: 13,channels: {x: { value: 40 }, y: { field: "rank" },text: { field: "item" }, textAnchor: { value: "start" },},}),],}),],});mount(chart.dom());
Designs
A design sets how every widget is drawn: its options, the answer inside them, a slider's track, a ranking card, a bar. Four ship with the library. ring is the default and draws rings on a track. The other three come with a named theme.
- The default theme draws
ring: rings on a track, and the answer is a filled dot. theme: "survey"drawsbox: each option is an outlined box holding a radio or a checkbox.theme: "surveyBlocks"drawsblock: options are soft blocks, and the chosen one turns solid.theme: "surveyLines"drawsline: controls and hairlines, with nothing boxed.
Pass the theme to a widget, or call setTheme("survey") once to draw every widget that way. The three form designs stack multiple choice as a list. The gestures, the data and the constraints are the same in every design.
theme: "survey"
Outlined boxes, each with a checkbox.
// theme: "survey" draws each option as an outlined box holding a checkbox,// and stacks them as a list.const chart = Elicit(widgets.multipleChoice({question: "Which apply?",options: ["Fast", "Cheap", "Reliable", "Simple"],maxChoices: 2,value: ["Fast"],theme: "survey",}));mount(chart.dom());
theme: "surveyBlocks"
Soft blocks. The chosen one turns solid.
// theme: "surveyBlocks" draws options as soft blocks. The chosen one turns solid.const chart = Elicit(widgets.likert({question: "This tool is easy to use",options: ["Strongly disagree", "Disagree", "Neutral", "Agree", "Strongly agree"],value: "Agree",theme: "surveyBlocks",}));mount(chart.dom());
theme: "surveyLines"
Radios and hairlines.
// theme: "surveyLines" draws controls and hairlines, with nothing boxed.const chart = Elicit(widgets.matrix({question: "Rate each quality",questions: ["Easy to learn", "Fast", "Reliable"],options: ["Poor", "Fair", "Good", "Great"],value: [{ question: "Fast", option: "Great" }],theme: "surveyLines",}));mount(chart.dom());
Customizing styles
Every widget accepts a theme, which restyles the answer ink, chrome and affordances together. See Theming. The widget tokens live in theme.widget: design names the design, and the rest are the colours and sizes it reads. Start from a named theme with extends and change the tokens you need.
The design and the colours are separate tokens, so any theme takes any design: theme: { extends: "dark", widget: { design: "block" } } draws blocks in the dark theme's colours.
For a one-off change to a single widget, edit the plain-API version: repaint the answer mark or swap a guide. The edits and constraints stay the same.
Change a design's tokens
extends: "survey", with its own accent, corner and row height.
// Start from a design and change its tokens: the accent, the corner, the row height.const chart = Elicit(widgets.ranking({question: "Rank these priorities",items: ["Cost", "Speed", "Quality", "Risk"],theme: {extends: "survey",widget: { accent: "#0f766e", tint: "#dff3f0", corner: 4, rowHeight: 36 },},}));mount(chart.dom());
Restyle with a theme
widgets.slider({ …, theme: themes.survey }) — one object restyles the instrument.
// The same slider, restyled by themes.survey — answer ink, track, and labels// all follow the theme. See /theming.const chart = Elicit(widgets.slider({question: "How confident are you?",domain: [0, 100],value: 60,theme: themes.survey,}));mount(chart.dom());
Add a design
authoring.registerDesign(name, design) adds a design. A design is an object of drawers, one per part. Each drawer takes the box to draw in and the widget tokens, and returns scene nodes in plot pixels. State the parts you change and name the design to start from in extends. Every widget then draws with it.
A design may state these parts:
option(o, t)draws one option.ois its box (x,y,width,height,cx,cy) withlabel,selected,control("radio"or"check") andlayout("row","list"or"cell"for a matrix).answer(o, t)describes the answer's ink:{ shape: "dot" | "square" | "block", size, corner, left, top }. Ablockfills the option.leftandtopplace a dot or a square on the control.grid(g, t)draws chrome around a whole matrix, andslots(l, t)the lines between a ranking list's slots.track(s, t)draws a slider's track fromx1,x2,yandat(the value's pixel).thumb(t)describes its handle.card(c, t)lists a ranking card's parts, back to front:body,badge,rank,labelandgrip. Place each withleftorright, measured from the card's edge. Thebodytakes the drag, and itshoveredandgrabbedstyles become the chart's effects.bar(t)describes a bar in the widgets drawn on chart axes:{ corner, fillOpacity, track }.liststacks multiple choice as a list.tilessizes the plot to the options fromoptionHeight,rowHeightandgap.themeregisters a named theme with the design, sotheme: "pill"selects both.
Take colours and sizes from the tokens t, so a theme can change them. authoring.labelNode, authoring.checkNode and authoring.controlNodes draw the label, the tick and the empty control the built-in designs share. A design holds functions, so register it in JavaScript. A JSON spec then names it like any other: "theme": "pill".
A pill design
Two drawers and a theme, extending box.
// A design states the parts it changes. The rest come from the design it extends.authoring.registerDesign("pill", {extends: "box",// One option: a pill with its label inside.option: (o, t) => [{ type: "rect", x: o.x, y: o.y, width: o.width, height: o.height,rx: o.height / 2, fill: t.surface,stroke: o.selected ? t.accent : t.stroke, strokeWidth: 1 },authoring.labelNode(o.label, o.cx, o.cy, t, {width: o.width - 12,fill: o.selected ? t.onAccent : t.label,}),],// The answer's ink: a block that fills the chosen pill, under its label.answer: (o, t) => ({ shape: "block", corner: o.height / 2 }),// Registers theme: "pill" with the design's own tokens.theme: {extends: "survey",widget: { accent: "#0f766e", optionHeight: 40, gap: 6 },},});const chart = Elicit(widgets.likert({question: "How often do you cycle to work?",options: ["Never", "Rarely", "Sometimes", "Often", "Daily"],value: "Often",theme: "pill",}));mount(chart.dom());
More instruments
Allocation, tokens, intervals, histograms, regions, thermometers and labelled values. Each accepts question, onChange, stage and theme. Every widget takes its starting answer as value and its range as domain: interval starts from value: { mean, lo, hi }, region from value: { x1, x2, y1, y2 } inside domain: { x, y }.
interval is three move() handles over one row, coupled by constraints. follow carries the caps with the mean, ordering keeps lo ≤ mean ≤ hi, and clamp holds all three inside domain. symmetric: true adds symmetric, so dragging one cap mirrors the other about the mean.
Allocation
Bars that redistribute to keep a fixed sum.
const chart = Elicit(widgets.allocation({question: "Allocate 100 points",categories: ["A", "B", "C", "D"],total: 100,}));mount(chart.dom());
Region
rect + brushRect for a 2-D region.
const chart = Elicit(widgets.region({ question: "Where do you expect the outcome?", })); mount(chart.dom());
Interval / CI
Drag the mean to translate the whole interval; drag a cap to resize one end.
const chart = Elicit(widgets.interval({question: "Your estimate and range",value: { mean: 50, lo: 30, hi: 70 },}));mount(chart.dom());
Symmetric interval
widgets.interval({ symmetric: true }) — one cap mirrors the other.
const chart = Elicit(widgets.interval({question: "Your estimate, ± the same either way",value: { mean: 50, lo: 35, hi: 65 },symmetric: true,}));mount(chart.dom());
Thermometer
A single value as a vertical bar — probe drag, snap to step.
const chart = Elicit(widgets.thermometer({question: "How likely is rain tomorrow?",domain: [0, 100],step: 5,value: 40,}));mount(chart.dom());
Histogram
Editable frequency bins — drag each bar to its count.
const chart = Elicit(widgets.histogram({question: "How many cups of coffee per day?",bins: ["0", "1", "2", "3", "4+"],domain: [0, 40],}));mount(chart.dom());
Probability tokens
Discrete mass as stacked tokens — probe-create a ghost token, click to drop; alt-click removes.
const chart = Elicit(widgets.probabilityTokens({question: "Spread 20 tokens over the outcomes you expect",bins: ["Low", "Med", "High"],maxTokens: 20,}));mount(chart.dom());
Labelled value
A draggable numeric readout — the number is the mark.
const chart = Elicit(widgets.labeledValue({question: "Your point estimate",value: 42,domain: [0, 100],}));mount(chart.dom());