Elicit.js
Elicit.js is a grammar for visual elicitation. It gives you a concise way to build visualisations that work as elicitation interfaces: charts people can change to tell you what they think.
Alpha: pre-1.0 and under active development, so expect breaking changes.
ESM-only, with d3 v7 as a peer dependency.
Turn a chart into a question
Scroll down to learn what you can build with Elicit.js. Things are interactive so feel free to touch the bars when it looks like it is interactive!
Draw a chart
A chart is a spec. data holds the rows, schema says what each field means, and marks draw the rows. This one draws four causes of rising house prices, each with a share.
const chart = Elicit({data: […],{ cause: "Interest rates", share: 30 },{ cause: "Immigration", share: 20 },{ cause: "Investors", share: 25 },{ cause: "Too few homes", share: 25 },],schema: {…},cause: { type: "categorical" },share: {type: "quantitative",domain: [0, 100],},},marks: […],barY({channels: {x: { field: "cause" },y: { field: "share" },},}),],});
Let people answer by dragging
Put an edit on a channel and the mark takes input. move() on y turns a drag into a new share. The drag is read back through the same scale that drew the bar.
const chart = Elicit({data: […],{ cause: "Interest rates", share: 30 },{ cause: "Immigration", share: 20 },{ cause: "Investors", share: 25 },{ cause: "Too few homes", share: 25 },],schema: {…},cause: { type: "categorical" },share: {type: "quantitative",domain: [0, 100],},},marks: […],barY({channels: {x: { field: "cause" },y: { field: "share" },y: { field: "share", edit: move() },},}),],});
Show the answer in more than one channel
A field can drive several channels. With fill on share, a bar darkens as it grows. The drag writes share once, and every channel that reads it redraws.
const chart = Elicit({data: […],{ cause: "Interest rates", share: 30 },{ cause: "Immigration", share: 20 },{ cause: "Investors", share: 25 },{ cause: "Too few homes", share: 25 },],schema: {…},cause: { type: "categorical" },share: {type: "quantitative",domain: [0, 100],},},marks: […],barY({channels: {x: { field: "cause" },y: { field: "share", edit: move() },fill: { field: "share" },},}),],});
Add a mark that reacts
Marks share the rows, so a second mark follows the first. This text mark puts an emoji on each bar. It reads share for its position and its size, so it rides up and grows as you drag the bar under it.
const chart = Elicit({data: […],{ cause: "Interest rates", share: 30 },{ cause: "Immigration", share: 20 },{ cause: "Investors", share: 25 },{ cause: "Too few homes", share: 25 },],schema: {…},cause: { type: "categorical" },share: {type: "quantitative",domain: [0, 100],},},marks: […],barY({channels: {x: { field: "cause" },y: { field: "share", edit: move() },fill: { field: "share" },},}),text({dy: -18,channels: {x: { field: "cause" },y: { field: "share" },text: { fn: (d) => ICON[d.cause] },fontSize: {field: "share",scale: { range: [14, 40] },},},}),],});
Keep the answer adding up
The four shares split one rise in prices, so they have to add up to 100. A constraint on the dataset checks every change. maintainSum repairs it, so raising one bar lowers the others, and clamp stops a share going below 0.
const chart = Elicit({data: […],{ cause: "Interest rates", share: 30 },{ cause: "Immigration", share: 20 },{ cause: "Investors", share: 25 },{ cause: "Too few homes", share: 25 },],schema: {…},cause: { type: "categorical" },share: {type: "quantitative",domain: [0, 100],},},constraints: […],clamp({ field: "share", min: 0 }),maintainSum({ field: "share", total: 100 }),],marks: […],barY({channels: {x: { field: "cause" },y: { field: "share", edit: move() },fill: { field: "share" },},}),text({dy: -18,channels: {x: { field: "cause" },y: { field: "share" },text: { fn: (d) => ICON[d.cause] },fontSize: {field: "share",scale: { range: [14, 40] },},},}),],});
Read the answer
The answer is the data. getData() returns the rows as they stand, and on("change") calls you after every edit. The panel under the chart is what your app reads.
const chart = Elicit({data: […],{ cause: "Interest rates", share: 30 },{ cause: "Immigration", share: 20 },{ cause: "Investors", share: 25 },{ cause: "Too few homes", share: 25 },],schema: {…},cause: { type: "categorical" },share: {type: "quantitative",domain: [0, 100],},},constraints: […],clamp({ field: "share", min: 0 }),maintainSum({ field: "share", total: 100 }),],marks: […],barY({channels: {x: { field: "cause" },y: { field: "share", edit: move() },fill: { field: "share" },},}),text({dy: -18,channels: {x: { field: "cause" },y: { field: "share" },text: { fn: (d) => ICON[d.cause] },fontSize: {field: "share",scale: { range: [14, 40] },},},}),],});chart.on("change", () => {save(chart.getData());});
Ask it as one bar
Change the mark and the question changes with it. Stacked into one bar, the four shares read as parts of a single rise. You drag the edge between two segments, so every answer weighs one cause against its neighbour. Your answer carries over, because the data never belonged to the mark.
const chart = Elicit({data: […],{ cause: "Interest rates", share: 30 },{ cause: "Immigration", share: 20 },{ cause: "Investors", share: 25 },{ cause: "Too few homes", share: 25 },],schema: {…},cause: { type: "categorical" },share: {type: "quantitative",domain: [0, 100],},},constraints: […],clamp({ field: "share", min: 0 }),maintainSum({ field: "share", total: 100 }),],elements: [legendColor({ anchor: "bottom" })],marks: […],barY({channels: {x: { field: "cause" },y: { field: "share", edit: move() },fill: { field: "share" },},}),text({dy: -18,barX({edits: [edit.stack.edge()],channels: {x: { field: "cause" },y: { field: "share" },text: { fn: (d) => ICON[d.cause] },fontSize: {field: "share",scale: { range: [14, 40] },},x: { field: "share" },stack: { field: "cause" },fill: { field: "cause" },},}),],});chart.on("change", () => {save(chart.getData());});
Hand out 100 squares
A waffle draws each share as squares, one per percentage point. You paint squares to give each cause its part. The rows and the rule stay the same.
const chart = Elicit({data: […],{ cause: "Interest rates", share: 30 },{ cause: "Immigration", share: 20 },{ cause: "Investors", share: 25 },{ cause: "Too few homes", share: 25 },],schema: {…},cause: { type: "categorical" },share: {type: "quantitative",domain: [0, 100],},},constraints: […],clamp({ field: "share", min: 0 }),maintainSum({ field: "share", total: 100 }),],elements: [legendColor({ anchor: "bottom" })],marks: […],barX({edits: [edit.stack.edge()],waffleY({multiple: 5,channels: {x: { field: "share" },stack: { field: "cause" },x: { field: "cause" },count: {field: "share",edit: edit.waffle.fill(),},fill: { field: "cause" },},}),],});chart.on("change", () => {save(chart.getData());});
Make the mark anything
A composite builds a new mark from ordinary ones, placed in its own frame. Each house here is a few rects, a roof shape and two labels. The walls’ height reads share, and the roof sits on the same field, so dragging the roof or the walls raises the house. A window lights up on each floor it reaches.
const chart = Elicit({data: […],{ cause: "Interest rates", share: 30 },{ cause: "Immigration", share: 20 },{ cause: "Investors", share: 25 },{ cause: "Too few homes", share: 25 },],schema: {…},cause: { type: "categorical" },share: {type: "quantitative",domain: [0, 100],},},constraints: […],clamp({ field: "share", min: 0 }),maintainSum({ field: "share", total: 100 }),],axes: false,marks: […],waffleY({multiple: 5,channels: {x: { field: "cause" },count: {field: "share",edit: edit.waffle.fill(),},fill: { field: "cause" },},composite({channels: { x: { field: "cause" } },parts: [// the walls: their top is the answerrect({ channels: {y1: { frame: -0.95 },y2: { field: "share", frame: [-0.5, 2.5],edit: move() },} }),// the roof rides on the wallsshape({ symbol: ROOF, channels: {y: { field: "share", frame: [-0.14, 2.86],edit: move() },} }),// a lit window on each floor it reaches...FLOORS.map((y) => rect({ channels: {y1: { frame: y }, y2: { frame: y + 0.3 },fill: { fn: (d) => lit(d, y) },} })),// the labeltext({ channels: {y: { frame: -1.32 },text: { field: "cause" },} }),],}),],});chart.on("change", () => {save(chart.getData());});
Write it as JSON
Every spec has a JSON form in the same grammar. compile(json) turns { "type": "barY" } into barY(). A language model can write this JSON, show the chart to a person in a conversation, and read the rows back.
const chart = Elicit({data: [{ cause: "Interest rates", share: 30 },{ cause: "Immigration", share: 20 },{ cause: "Investors", share: 25 },{ cause: "Too few homes", share: 25 },const json = {"data": […],{ "cause": "Interest rates", "share": 30 },{ "cause": "Immigration", "share": 20 },{ "cause": "Investors", "share": 25 },{ "cause": "Too few homes", "share": 25 }],schema: {cause: { type: "categorical" },share: {type: "quantitative",domain: [0, 100],},"schema": {…},"cause": { "type": "categorical" },"share": {"type": "quantitative","domain": [0, 100]}},constraints: [clamp({ field: "share", min: 0 }),maintainSum({ field: "share", total: 100 }),],axes: false,marks: [composite({channels: { x: { field: "cause" } },parts: [// the walls: their top is the answerrect({ channels: {y1: { frame: -0.95 },y2: { field: "share", frame: [-0.5, 2.5],edit: move() },} }),// the roof rides on the wallsshape({ symbol: ROOF, channels: {y: { field: "share", frame: [-0.14, 2.86],edit: move() },} }),// a lit window on each floor it reaches...FLOORS.map((y) => rect({ channels: {y1: { frame: y }, y2: { frame: y + 0.3 },fill: { fn: (d) => lit(d, y) },} })),// the labeltext({ channels: {y: { frame: -1.32 },text: { field: "cause" },} }),],}),"constraints": […],{ "type": "clamp", "field": "share", "min": 0 },{ "type": "maintainSum", "field": "share","total": 100 }],});"marks": [{"type": "barY","channels": {"x": { "field": "cause" },"y": { "field": "share","edit": { "type": "move" } },"fill": { "field": "share" }}}]};chart.on("change", () => {save(chart.getData());});const chart = Elicit(compile(json));
const chart = Elicit({data: […],{ cause: "Interest rates", share: 30 },{ cause: "Immigration", share: 20 },{ cause: "Investors", share: 25 },{ cause: "Too few homes", share: 25 },],schema: {…},cause: { type: "categorical" },share: {type: "quantitative",domain: [0, 100],},},marks: […],barY({channels: {x: { field: "cause" },y: { field: "share" },},}),],});
Ask with any mark
Pick a chart from the grid to try it large. The large chart and its small copy share one dataset, so the small one follows your answer.