Elicit.js

Waffle

A waffle shows a quantity per category as a block of countable cells. One cell is worth unit of the field, so value / unit cells fill, laid out multiple across the band. The count channel holds the value. Edit it with edit.waffle.fill(), which fills up to the cell under the pointer, so the value is always a whole number of cells.

API reference

waffle(options) · waffleY(options) · waffleX(options)

Import plot from elicitjs. waffleY grows blocks upward (category on x), waffleX rightward (category on y). Bare waffle reads the direction from the channel map: the category's axis is the band, and count runs along the other one.

waffleY({ channels, orientation, unit, multiple, shape, showEmpty, emptyFill, gap, edits, id }) → Mark
Options
OptionType · defaultDescription
channels
objectdefault{}
One band (category) axis — x or y — plus count, the magnitude. Put edit: edit.waffle.fill() on count; it fills up to the exact cell under the pointer, for both drag and click.
image
string | (d) => string | ChannelSpec
The shape's background image: a URL painted inside each shape in place of the fill. Takes fit, position and repeat as channel params, as in CSS. See Image.
orientation
'vertical' | 'horizontal'defaultfrom the channel map
Which way the blocks grow. waffleY / waffleX set it; otherwise it follows the positional channel you bound. Same option bar takes.
unit
numberdefault1
The quantity one cell represents. value / unit cells fill; raise it for large counts, lower it (>0) for fine fractions.
multiple
numberdefaultauto
Cells across the band. Defaults to whatever makes cells square given the band width and scale; each row then spans multiple · unit.
shape
'square' | 'circle'default'square'
Cell shape: square cells or dots, as on point. A symbol channel draws a glyph in each cell instead.
showEmpty
booleandefaulttrue
Draw the unfilled cells (the value track). Set false to hide them; they stay as invisible drag targets, so dragging up to raise the count still works.
emptyFill
stringdefault'#eee'
Colour of the unfilled cells when shown (filled cells use the standard style surface).
gap
numberdefault1
Pixel gap between cells.
Channels
ChannelTypeDescription
x / y
band
The category axis. Bind one of them; the count runs along the other.
count
linear
The magnitude, in data units, on its own count axis — not on x or y. One cell is worth one unit of the field.
xOffset / yOffset
band
A second category nested inside the category axis: one block per value, side by side.
Returns / emits

A mark emitting one cell node (rect or circle) per cell; every cell carries the datum, so the whole block is one drag/click target.

Counting quantities

A waffle over four categories. Each cell is 10 fruit, so count the cells and multiply by the unit to read an amount.

Fruit counts

Static waffle; count domain 0–320, one cell = 10 fruit (32 cells), multiple picked automatically.

const cats = ["apples","bananas","oranges","pears"];
const chart = Elicit({
width: 460, height: 300,
margins: { top: 16, right: 12, bottom: 28, left: 34 },
data: [
{ cat: "apples", value: 210 }, { cat: "bananas", value: 200 },
{ cat: "oranges", value: 310 }, { cat: "pears", value: 40 },
],
schema: {
cat: { type: "categorical", domain: cats },
value: { type: "quantitative", domain: [0, 320] },
},
scales: { x: { type: "band" } },
marks: [
waffleY({
fill: "#50AEB7",
channels: {
x: { field: "cat" },
count: { field: "value" },
},
unit: 10,
}),
],
});
mount(chart.dom());

Picking a proportion

One category over a 0–1 domain. Each cell is 1/50, so 50 cells fill the block. Click or drag, and edit.waffle.fill() fills up to the cell under the pointer.

Proportion picker

click or drag; unit = 1/50 makes 50 countable cells, edit.waffle.fill lands exactly on the cell you point at.

const chart = Elicit({
width: 220, height: 300,
margins: { top: 16, right: 12, bottom: 24, left: 34 },
data: [{ cat: "belief", value: 0.4 }],
onChange: (d) => console.log("proportion:", d[0].value.toFixed(2)),
schema: {
cat: { type: "categorical", domain: ["belief"] },
value: { type: "quantitative", domain: [0, 1] },
},
scales: { x: { type: "band" } },
marks: [
waffleY({
fill: "#2B5D87",
unit: 1/50,
channels: {
x: { field: "cat" },
count: { field: "value", edit: edit.waffle.fill() },
},
// click sets the count to the clicked cell too
edits: [ edit.waffle.fill({ channels: ["count"], gesture: "click" }) ],
}),
],
});
mount(chart.dom());
Try: click a cell, or drag up/down.

Dots, click-to-set & hidden track

shape: "circle" draws a dot in each square cell. A click gesture sets the count to the clicked cell in one tap. showEmpty: false hides the empty cells, and they stay grabbable.

Click a dot to set the count

circle cells, one = 5; uniform dots pack tightly (gap: 0). Click any dot to fill up to and including it, or drag.

const chart = Elicit({
width: 240, height: 300,
margins: { top: 16, right: 12, bottom: 24, left: 34 },
data: [{ cat: "count", value: 45 }],
onChange: (d) => console.log("count:", d[0].value),
schema: {
cat: { type: "categorical", domain: ["count"] },
value: { type: "quantitative", domain: [0, 100] },
},
scales: { x: { type: "band" } },
marks: [
waffleY({
fill: "#7DB86B",
shape: "circle",
unit: 5,
gap: 0,
channels: {
x: { field: "cat" },
count: { field: "value", edit: edit.waffle.fill() }, // drag to fill
},
edits: [ edit.waffle.fill({ channels: ["count"], gesture: "click" }) ], // click to set
}),
],
});
mount(chart.dom());
Try: click a dot, or drag up/down.

Small counts (unit = 1)

With unit: 1 each cell is one item, so small counts read directly. The grid is centred in the band and only as wide as it needs to be.

Tallies of 1–6

one cell = one item; counts of 1, 3, 6, 2 — count the cells directly.

const cats = ["A","B","C","D"];
const chart = Elicit({
width: 460, height: 260,
margins: { top: 16, right: 12, bottom: 28, left: 28 },
data: [
{ cat: "A", value: 1 }, { cat: "B", value: 3 },
{ cat: "C", value: 6 }, { cat: "D", value: 2 },
],
schema: {
cat: { type: "categorical", domain: cats },
value: { type: "quantitative", domain: [0, 6] },
},
scales: { x: { type: "band" } },
marks: [
waffleY({
fill: "#F2B94B",
shape: "circle",
unit: 1,
gap: 0,
channels: { x: { field: "cat" }, count: { field: "value" } },
}),
],
});
mount(chart.dom());

The count axis

A waffle's magnitude is the count channel, and it has its own count axis, separate from y. A waffle and a bar in one chart keep separate domains.

Ask for the axis with axes: { count: true }. The cells already make the count readable, so it is off by default. It reports data units, matching the column it reads.

One cell is worth unit of the field. With the default unit: 1, the column value is the number of cells. Pick a unit that divides the declared domain. Otherwise the top cell is a fraction and the mark logs a warning.

A count axis

axes: { count: true } — one cell is 10, so the 320 domain spans 32 cells.

const cats = ["apples","bananas","oranges","pears"];
const chart = Elicit({
width: 460, height: 300,
margins: { top: 16, right: 12, bottom: 28, left: 44 },
// The count axis is opt-in: it reserves layout space for a scale these marks
// already make countable by eye, so it sits with `legends`, not with x/y.
axes: { count: true },
data: [
{ cat: "apples", value: 210 }, { cat: "bananas", value: 200 },
{ cat: "oranges", value: 310 }, { cat: "pears", value: 40 },
],
schema: {
cat: { type: "categorical", domain: cats },
value: { type: "quantitative", domain: [0, 320] },
},
scales: { x: { type: "band" } },
marks: [
waffleY({
fill: "#50AEB7",
channels: {
x: { field: "cat" },
// The magnitude is `count`, on a count axis of its own — not `y`.
count: { field: "value" },
},
unit: 10, // one cell is worth 10, so 320 spans 32 cells
}),
],
});
mount(chart.dom());

Grouped waffles (xOffset, yOffset)

xOffset splits each category into one block per value of a second field, side by side. Each block keeps its own cells, so edit.waffle.fill() fills the block you point at. yOffset does the same for waffleX. The cells shrink to fit the narrower block.

A waffle per group

xOffset: { field: "sex" } gives each sport a block for women and one for men. One cell is 10 athletes.

const sports = ["rowing", "cycling", "judo"];
const chart = Elicit({
width: 420, height: 260,
margins: { top: 16, right: 12, bottom: 28, left: 28 },
data: sports.flatMap((sport) => [
{ sport, sex: "women", athletes: 40 },
{ sport, sex: "men", athletes: 40 },
]),
schema: {
sport: { type: "categorical", domain: sports },
sex: { type: "categorical", domain: ["women", "men"] },
athletes: { type: "quantitative", domain: [0, 200] },
},
marks: [
waffleY({
unit: 10,
channels: {
x: { field: "sport" },
xOffset: { field: "sex", scale: { padding: 0.15 } },
count: { field: "athletes", edit: edit.waffle.fill() },
fill: { field: "sex", legend: { anchor: "top", title: false } },
},
}),
],
});
mount(chart.dom());
Try: Click or drag in a block to set its count.

Orientation

Put the category on y and the blocks grow rightward. waffleY and waffleX set the direction. A bare waffle takes it from the channel map: the category's axis is the band, and count runs along the other. orientation: "horizontal" | "vertical" is the explicit form, the same option bar takes.

Blocks that grow rightward

waffleX with the category on y; the count axis sits at the bottom.

const cats = ["apples","bananas","oranges","pears"];
const chart = Elicit({
width: 460, height: 260,
margins: { top: 16, right: 16, bottom: 28, left: 72 },
axes: { count: true },
data: [
{ cat: "apples", value: 210 }, { cat: "bananas", value: 200 },
{ cat: "oranges", value: 310 }, { cat: "pears", value: 40 },
],
schema: {
cat: { type: "categorical", domain: cats },
value: { type: "quantitative", domain: [0, 320] },
},
scales: { y: { type: "band" } },
marks: [
waffleX({
fill: "#50AEB7",
channels: {
// The category is on y, so the count runs along x.
y: { field: "cat" },
count: { field: "value" },
},
unit: 10,
}),
],
});
mount(chart.dom());