Elicit.js

A face, a plant and an hourglass

Three elicitation interfaces built from existing marks and edits: a face whose colour you slide, a plant you grow, and an hourglass you fill. Each follows the same steps: declare the fields, draw the parts, then put an edit on each channel a gesture should write.

The steps

  1. Declare the answer. One field per thing you ask. The schema gives each field its type and domain.
  2. Draw the glyph. A composite in box mode places every part in the glyph's own units: x and y from -1 to 1, y up. The composite's size sets the box's half-size, so the whole glyph scales with it.
  3. Bind the fields. A channel with a field and a frame: [lo, hi] range maps the field's domain onto that slice of the box. Two parts that read the same field and range always line up.
  4. Add the gestures. An edit on a channel writes that channel's field: move for a position, slide for a size, colour or angle. A drag passes through any part with no edit.

A face that changes colour

face() already draws a head, eyes, brows and a mouth. Its fill channel colours the head, so binding it to a field adds a question with no new parts.

feeling runs from -1 (anger) to 1 (disgust). A diverging scale maps it from red through yellow to green. slide({ axis: "x" }) on the head writes it, so you drag the head left for anger and right for disgust. slide works on a colour ramp because it moves along the field's domain. The mouth keeps its own slide on valence, so the two answers come from two different parts.

Anger or disgust

The emotion preset's mouth, plus a head colour bound to a field: red for anger, green for disgust.

const chart = Elicit({
width: 320, height: 320,
margins: { top: 12, right: 12, bottom: 28, left: 12 },
data: [{ valence: -0.4, feeling: 0 }],
schema: {
valence: { type: "quantitative", domain: [-1, 1] },
// -1 is anger, +1 is disgust, 0 is neither.
feeling: { type: "quantitative", domain: [-1, 1] },
},
marks: [
face({
channels: {
// The mouth bends with valence, as in the emotion preset.
mouthCurve: { field: "valence", edit: slide({ axis: "y", increase: "up" }) },
// The head's colour is a field too: a diverging scale runs red → yellow → green,
// and a sideways slide on the head writes it.
fill: {
field: "feeling",
scale: { type: "diverging", range: ["#d62728", "#ffd666", "#2ca02c"] },
edit: slide({ axis: "x", increase: "right" }),
},
},
}),
text({ channels: { x: { value: 20 }, y: { value: 304 }, text: { value: "← anger" }, textAnchor: { value: "start" }, fill: { value: "#d62728" } } }),
text({ channels: { x: { value: 288 }, y: { value: 304 }, text: { value: "disgust →" }, textAnchor: { value: "end" }, fill: { value: "#2ca02c" } } }),
],
});
mount(chart.dom());
Try: Drag the head left or right to colour it · drag the mouth up or down.

A plant that grows

Three answers about your week, one plant: energy is how tall it grows, joy how big it blooms, and support how full its leaves are.

The stem's top and the flower both read energy over the same range, frame: [-0.15, 0.65], so the flower always sits on the stem. Drag the flower up or down: move({ channels: ["y"] }) writes energy. Drag it sideways: a slide on its size writes joy. Each edit reads its own direction of the drag, so one drag can set both.

Each leaf's centre and width both read support. As the leaf widens, its centre moves out by the same amount, so its inner edge stays on the stem. Drag a leaf outward to make it fuller.

How is your week going?

A ruleX stem, two ellipse leaves, a rect pot and a point flower, each placed in the glyph's own units.

const chart = Elicit({
width: 320, height: 340,
margins: { top: 10, right: 10, bottom: 10, left: 10 },
// How is your week going? Three answers, one plant.
data: [{ energy: 0.5, joy: 0.4, support: 0.5 }],
schema: {
energy: { type: "quantitative", domain: [0, 1] }, // how tall it grows
joy: { type: "quantitative", domain: [0, 1] }, // how big it blooms
support: { type: "quantitative", domain: [0, 1] }, // how full its leaves are
},
marks: [
// Every part is placed in the glyph's own units: x and y run from -1 to 1, y up.
composite({
channels: { size: { value: 150 } },
parts: [
// The stem's top is `energy`; the flower below sits on the same field
// and range, so the two always meet.
ruleX({ channels: {
x: { frame: 0 }, y1: { frame: -0.55 },
y2: { field: "energy", frame: [-0.15, 0.65] },
stroke: { value: "#4d7c0f" }, strokeWidth: { value: 6 },
} }),
// Two leaves. A leaf's centre and its width both read `support`, so its
// inner edge stays on the stem as it grows.
ellipse({ channels: {
x: { field: "support", frame: [-0.08, -0.3] }, y: { frame: -0.3 },
rx: { field: "support", frame: [0.06, 0.28],
edit: slide({ axis: "x", increase: "left" }) },
ry: { frame: 0.07 }, angle: { value: -25 },
fill: { value: "#65a30d" },
} }),
ellipse({ channels: {
x: { field: "support", frame: [0.08, 0.3] }, y: { frame: -0.3 },
rx: { field: "support", frame: [0.06, 0.28],
edit: slide({ axis: "x", increase: "right" }) },
ry: { frame: 0.07 }, angle: { value: 25 },
fill: { value: "#65a30d" },
} }),
// The pot.
rect({ channels: {
x1: { frame: -0.3 }, x2: { frame: 0.3 }, y1: { frame: -0.95 }, y2: { frame: -0.55 },
fill: { value: "#b45309" },
} }),
// The flower: drag it up or down to set `energy`, sideways to set `joy`.
point({ channels: {
y: { field: "energy", frame: [-0.15, 0.65], edit: move({ channels: ["y"] }) },
size: { field: "joy", frame: [0.08, 0.3],
edit: slide({ axis: "x", increase: "right" }) },
fill: { value: "#db2777" },
} }),
point({ channels: {
y: { field: "energy", frame: [-0.15, 0.65] },
size: { field: "joy", frame: [0.03, 0.11] },
fill: { value: "#fde047" },
} }),
],
}),
],
});
mount(chart.dom());
Try: Drag the flower up to grow the plant, sideways to open the bloom · drag a leaf outward.

An hourglass you fill

How long will this work take? The timer holds 12 weeks of sand. The top bulb holds your estimate and the bottom holds the rest.

Each pile of sand is a rect, drawn as a plain bar. The top pile's upper edge, y2, reads weeks over frame: [0, 0.8]. The bottom pile reads the same field over the mirrored range, [0, -0.8], so as the top drains the bottom fills. Both carry move({ mode: "relative" }), so you can drag either pile and its surface stays under the pointer. snap({ step: 1 }) rounds the answer to whole weeks.

The glass is a shape drawn from an SVG path. A second shape is a mask: a box with the glass cut out of it, painted over the sand in the background colour. It trims each bar to the curve of its bulb. Neither shape carries an edit, so a drag passes through them to the sand.

How long will this take?

Two bars on one field with mirrored ranges, trimmed to the glass by a masking shape and snapped to whole weeks.

// The glass, as an SVG path in its own units (y down, as in SVG): two curved
// bulbs meeting at a narrow neck. `shape` scales a path to fit, so its half-height
// (0.8) is the `size` it is drawn at.
const GLASS = "M-0.42,-0.8 L0.42,-0.8 C0.42,-0.3 0.05,-0.12 0.05,0 C0.05,0.12 0.42,0.3 0.42,0.8 " +
"L-0.42,0.8 C-0.42,0.3 -0.05,0.12 -0.05,0 C-0.05,-0.12 -0.42,-0.3 -0.42,-0.8 Z";
// A mask: a box with the glass cut out of it. Painted over the sand in the
// background colour, it trims each bar to the shape of its bulb.
const MASK = "M-0.46,-0.82 L-0.46,0.82 L0.46,0.82 L0.46,-0.82 Z " + GLASS;
const chart = Elicit({
width: 320, height: 340,
margins: { top: 10, right: 10, bottom: 10, left: 10 },
// How long will this work take? The timer holds 12 weeks of sand; the top
// bulb holds your estimate and the rest has run through.
data: [{ weeks: 4 }],
schema: { weeks: { type: "quantitative", domain: [0, 12] } },
// Whole weeks only.
constraints: [snap({ step: 1 })],
marks: [
composite({
channels: { size: { value: 140 } },
parts: [
// Top sand: a bar from the neck up to `weeks`.
rect({ channels: {
x1: { frame: -0.42 }, x2: { frame: 0.42 }, y1: { frame: 0 },
y2: { field: "weeks", frame: [0, 0.8], edit: move({ mode: "relative" }) },
fill: { value: "#eab308" },
} }),
// Bottom sand: the same field over the mirrored range, so as the top
// drains the bottom fills. It is a handle too.
rect({ channels: {
x1: { frame: -0.42 }, x2: { frame: 0.42 }, y1: { frame: -0.8 },
y2: { field: "weeks", frame: [0, -0.8], edit: move({ mode: "relative" }) },
fill: { value: "#eab308" },
} }),
// The mask, then the glass outline over it.
shape({ symbol: MASK, channels: { size: { frame: 0.82 }, fill: { value: "#ffffff" }, stroke: { value: "none" } } }),
shape({ symbol: GLASS, channels: {
size: { frame: 0.8 }, fill: { value: "none" },
stroke: { value: "#64748b" }, strokeWidth: { value: 2.5 },
} }),
// The wooden caps.
rect({ channels: {
x1: { frame: -0.52 }, x2: { frame: 0.52 }, y1: { frame: 0.8 }, y2: { frame: 0.88 },
cornerRadius: { value: 4 }, fill: { value: "#78350f" },
} }),
rect({ channels: {
x1: { frame: -0.52 }, x2: { frame: 0.52 }, y1: { frame: -0.88 }, y2: { frame: -0.8 },
cornerRadius: { value: 4 }, fill: { value: "#78350f" },
} }),
// The answer, read off the same field.
text({ channels: {
y: { frame: 1 },
text: { fn: (d) => `${d.weeks} week${d.weeks === 1 ? "" : "s"}` },
fontSize: { value: 18 }, fill: { value: "#334155" },
} }),
],
}),
],
});
mount(chart.dom());
Try: Drag either pile of sand up or down: the other pile moves the opposite way.

Glyphs as points

A glyph's own x and y place it on the chart's scales, like a point. Give the composite a field for each, and you get one glyph per row: a scatter plot when both are quantitative, a grid when both are categories. The positions are data you already have, and the glyphs are the answers. Every part keeps its edit, so each glyph is answered on its own.

With x and y on band scales, each glyph fills its cell by default. On a continuous scale, set size to fix the box's half-size in pixels.

A move on the composite's x moves the whole glyph, writing both position fields. Its press would compete with the parts' edits, so when splits the gestures by modifier:

  • move({ channels: ["x", "y"], pick: "nearest", when: when.shift }) takes a Shift-drag and moves the nearest glyph.
  • Every part's own edit takes when: when.noShift, so a plain drag still answers with the part you grab.

On a categorical axis the move snaps to the nearest category, so a plant dragged with Shift lands in another cell.

How does each person feel?

face() with x and y bound to fields: one face per person, placed by hours slept and worked. Shift-drag moves a face.

const chart = Elicit({
width: 400, height: 340,
axes: { x: { title: "Hours slept" }, y: { title: "Hours worked" } },
// How does each person feel? Where each face sits is data you already have:
// hours slept against hours worked. The face is the answer.
data: [
{ name: "Ana", slept: 8, worked: 4, valence: 0.6, feeling: 0 },
],
schema: {
name: { type: "categorical" },
slept: { type: "quantitative", domain: [4, 10] },
worked: { type: "quantitative", domain: [0, 12] },
valence: { type: "quantitative", domain: [-1, 1] },
feeling: { type: "quantitative", domain: [-1, 1] },
},
marks: [
face({
channels: {
// Placed like a point: x and y are positions on the chart's scales.
// Shift-drag moves the nearest face; a plain drag answers with its parts.
x: { field: "slept", edit: move({ channels: ["x", "y"], pick: "nearest", when: when.shift }) },
y: { field: "worked" },
size: { value: 30 },
mouthCurve: { field: "valence", edit: slide({ axis: "y", increase: "up", when: when.noShift }) },
fill: {
field: "feeling",
scale: { type: "diverging", range: ["#d62728", "#ffd666", "#2ca02c"] },
edit: slide({ axis: "x", increase: "right", when: when.noShift }),
},
},
}),
],
});
mount(chart.dom());
Try: Drag a head sideways to colour that face · drag a mouth up or down · Shift-drag a face to move it.

A plant per person per week

The plant as a function of its channels, placed on an ordinal x and a categorical y.

// The plant from above, as a function of where it goes.
const plant = (channels) => composite({
channels,
parts: [
ruleX({ channels: {
x: { frame: 0 }, y1: { frame: -0.55 },
y2: { field: "energy", frame: [-0.15, 0.65] },
stroke: { value: "#4d7c0f" }, strokeWidth: { value: 3 },
} }),
ellipse({ channels: {
x: { field: "support", frame: [-0.08, -0.3] }, y: { frame: -0.3 },
rx: { field: "support", frame: [0.06, 0.28], edit: slide({ axis: "x", increase: "left", when: when.noShift }) },
ry: { frame: 0.07 }, angle: { value: -25 }, fill: { value: "#65a30d" },
} }),
ellipse({ channels: {
x: { field: "support", frame: [0.08, 0.3] }, y: { frame: -0.3 },
rx: { field: "support", frame: [0.06, 0.28], edit: slide({ axis: "x", increase: "right", when: when.noShift }) },
ry: { frame: 0.07 }, angle: { value: 25 }, fill: { value: "#65a30d" },
} }),
rect({ channels: {
x1: { frame: -0.3 }, x2: { frame: 0.3 }, y1: { frame: -0.95 }, y2: { frame: -0.55 },
fill: { value: "#b45309" },
} }),
point({ channels: {
y: { field: "energy", frame: [-0.15, 0.65], edit: move({ channels: ["y"], when: when.noShift }) },
size: { field: "joy", frame: [0.08, 0.3], edit: slide({ axis: "x", increase: "right", when: when.noShift }) },
fill: { value: "#db2777" },
} }),
point({ channels: {
y: { field: "energy", frame: [-0.15, 0.65] },
size: { field: "joy", frame: [0.03, 0.11] },
fill: { value: "#fde047" },
} }),
],
});
const people = ["Ana", "Ben", "Cai"];
const weeks = ["Week 1", "Week 2", "Week 3"];
const chart = Elicit({
width: 400, height: 360,
// One plant per person per week: both positions are categories, so each
// plant fills its cell.
data: people.flatMap((person, p) => weeks.map((week, w) => ({
person, week, energy: 0.3 + 0.2 * w, joy: 0.3 + 0.1 * p, support: 0.5,
}))),
schema: {
person: { type: "categorical", domain: people },
week: { type: "ordinal", domain: weeks },
energy: { type: "quantitative", domain: [0, 1] },
joy: { type: "quantitative", domain: [0, 1] },
support: { type: "quantitative", domain: [0, 1] },
},
marks: [plant({
// Shift-drag moves the nearest plant to another cell; a plain drag answers.
x: { field: "week", edit: move({ channels: ["x", "y"], pick: "nearest", when: when.shift }) },
y: { field: "person" },
})],
});
mount(chart.dom());
Try: Drag any flower up or down to grow its plant · Shift-drag a plant to another cell.

An estimate per task

One hourglass per task, on an ordinal x and a quantitative y.

// The hourglass from above, as a function of where it goes.
const GLASS = "M-0.42,-0.8 L0.42,-0.8 C0.42,-0.3 0.05,-0.12 0.05,0 C0.05,0.12 0.42,0.3 0.42,0.8 " +
"L-0.42,0.8 C-0.42,0.3 -0.05,0.12 -0.05,0 C-0.05,-0.12 -0.42,-0.3 -0.42,-0.8 Z";
const MASK = "M-0.46,-0.82 L-0.46,0.82 L0.46,0.82 L0.46,-0.82 Z " + GLASS;
const hourglass = (channels) => composite({
channels,
parts: [
rect({ channels: {
x1: { frame: -0.42 }, x2: { frame: 0.42 }, y1: { frame: 0 },
y2: { field: "weeks", frame: [0, 0.8], edit: move({ mode: "relative", when: when.noShift }) },
fill: { value: "#eab308" },
} }),
rect({ channels: {
x1: { frame: -0.42 }, x2: { frame: 0.42 }, y1: { frame: -0.8 },
y2: { field: "weeks", frame: [0, -0.8], edit: move({ mode: "relative", when: when.noShift }) },
fill: { value: "#eab308" },
} }),
shape({ symbol: MASK, channels: { size: { frame: 0.82 }, fill: { value: "#ffffff" }, stroke: { value: "none" } } }),
shape({ symbol: GLASS, channels: {
size: { frame: 0.8 }, fill: { value: "none" },
stroke: { value: "#64748b" }, strokeWidth: { value: 1.5 },
} }),
rect({ channels: {
x1: { frame: -0.52 }, x2: { frame: 0.52 }, y1: { frame: 0.8 }, y2: { frame: 0.88 },
fill: { value: "#78350f" },
} }),
rect({ channels: {
x1: { frame: -0.52 }, x2: { frame: 0.52 }, y1: { frame: -0.88 }, y2: { frame: -0.8 },
fill: { value: "#78350f" },
} }),
text({ channels: {
x: { frame: 0.62 },
text: { fn: (d) => `${d.weeks} wk` },
textAnchor: { value: "start" }, fontSize: { value: 11 }, fill: { value: "#334155" },
} }),
],
});
const chart = Elicit({
width: 400, height: 340,
axes: { y: { title: "Team size" } },
// How long will each task take? Tasks run along x, and the team on each sits
// on y. Each hourglass is one estimate.
data: [
{ task: "Design", team: 2, weeks: 3 },
],
schema: {
task: { type: "ordinal", domain: ["Design", "Build", "Test", "Launch"] },
team: { type: "quantitative", domain: [0, 8] },
weeks: { type: "quantitative", domain: [0, 12] },
},
constraints: [snap({ step: 1, field: "weeks" })],
marks: [hourglass({
// Shift-drag moves the nearest hourglass; a plain drag on its sand answers.
x: { field: "task", edit: move({ channels: ["x", "y"], pick: "nearest", when: when.shift }) },
y: { field: "team" },
size: { value: 30 },
})],
});
mount(chart.dom());
Try: Drag the sand in any hourglass to change that task's estimate · Shift-drag an hourglass to move it.