Elicit.js

Du Bois's coil and spiral

Two of Du Bois's charts for the 1900 Paris Exposition do not fold a bar back and forth: they wind it, into a square coil and into a spiral. A coil and a spiral are geometry, so each route is written in pixels in place of data units. The chart is the same track with move() on its length as on the wrapped bars page; only the route changes. Every row's route holds the same length, so the rows share one scale.

A square coil

The route runs right along the bottom, up, back left and down, then turns inward one step and goes round again. Each side is one step shorter than the side before it on that axis. The route is one lane, so the corners hold value too, and every pixel of the coil holds about 1,750 people.

Religion of Black Americans

14,517 Catholics beside 2,659,460 Protestants. The Protestant bar coils inward to fit the page.

// ── This chart's route: a square coil ───────────────────────────────────
// Right along the bottom, up, back left, down, and inward, a step at a time.
// One lane: the corners are part of it, so every pixel of the coil holds value.
const START = 130, W = 440, H = 140, STEP = 30;
const baseY = (i) => 160 + i * 180;
function routeOf(i) {
const dirs = [[1, 0], [0, -1], [-1, 0], [0, 1]];
let [x, y] = [START, baseY(i)];
let d = `M${x},${y}`;
for (let k = 0; ; k++) {
const len = k % 2 === 0 ? W - (k / 2) * STEP : H - ((k - 1) / 2) * STEP;
if (len <= STEP) break;
x += dirs[k % 4][0] * len;
y += dirs[k % 4][1] * len;
d += `L${x},${y}`;
}
return d;
}
const COLOURS = ["#c8243b", "#1f7a45"];
const chart = Elicit({
width: 600, height: 370,
margins: { top: 0, right: 0, bottom: 0, left: 0 },
theme: { background: "#ecdcc6" },
// Religion of Black Americans, from Du Bois's chart.
data: [
{ church: "Catholics", members: 14517 },
{ church: "Protestants", members: 2659460 },
],
schema: {
church: { type: "categorical" },
members: { type: "quantitative", domain: [0, 4000000] },
},
constraints: [snap({ step: 1 })],
marks: [
track({
path: (d, i) => routeOf(i),
channels: {
length: { field: "members", edit: move() },
stroke: { fn: (d, i) => COLOURS[i] }, strokeWidth: { value: 20 },
},
}),
text({ channels: {
x: { value: 14 }, y: { fn: (d, i) => baseY(i) },
text: { field: "church" },
textAnchor: { value: "start" }, fontSize: { value: 12 }, fill: { value: "#3b2f27" },
} }),
text({ channels: {
x: { value: START - 10 }, y: { fn: (d, i) => baseY(i) - 20 },
text: { fn: (d) => d.members.toLocaleString("en-US") },
textAnchor: { value: "end" }, fontSize: { value: 11 }, fill: { value: "#3b2f27" },
} }),
],
});
mount(chart.dom());
Try: Drag the end of the green coil to wind it further in · drag the end of the red bar along the coil to grow it.

A spiral

Each year starts at the top and runs clockwise. Its radius shrinks by six bands a turn, so the turns of all six years nest without touching. The value is the length of the spiral, so an outer turn holds more than an inner one. Each year's spiral is cut to the same length, which holds $1,600,000.

Furniture owned by Black Georgians

The assessed value of household and kitchen furniture, 1875 to 1899. Each year is a band of the spiral.

// ── This chart's route: a spiral ────────────────────────────────────────
// Each year starts at the top and runs clockwise. Its radius shrinks by six
// bands a turn, so the turns of all six years nest without touching.
const CX = 330, CY = 290, R0 = 230, BAND = 12, PITCH = 6 * BAND;
// Every year's spiral is LENGTH px long, so the years share one scale.
const MAX = 1600000, LENGTH = 1227;
const radius = (i) => R0 - i * BAND;
function routeOf(i) {
let d = "", run = 0, prev = null;
for (let deg = 0; run < LENGTH; deg += 3) {
const t = (deg * Math.PI) / 180, r = radius(i) - (PITCH * deg) / 360;
const p = [CX + r * Math.sin(t), CY - r * Math.cos(t)];
if (prev) run += Math.hypot(p[0] - prev[0], p[1] - prev[1]);
d += `${prev ? "L" : "M"}${p[0].toFixed(1)},${p[1].toFixed(1)}`;
prev = p;
}
return d;
}
const COLOURS = ["#e8a2a2", "#8e9fd3", "#b39b7d", "#f0b02c", "#d6ccb8", "#dc1f45"];
const chart = Elicit({
width: 580, height: 540,
margins: { top: 0, right: 0, bottom: 0, left: 0 },
theme: { background: "#ecdcc6" },
// Assessed value of household and kitchen furniture owned by Black
// Georgians, in dollars.
data: [
{ year: 1875, value: 21186 },
],
schema: {
year: { type: "ordinal" },
value: { type: "quantitative", domain: [0, MAX] },
},
constraints: [snap({ step: 1 })],
marks: [
track({
path: (d, i) => routeOf(i),
channels: {
length: { field: "value", edit: move() },
stroke: { fn: (d, i) => COLOURS[i] }, strokeWidth: { value: 9 },
},
}),
text({ channels: {
x: { value: CX - 12 }, y: { fn: (d, i) => CY - radius(i) },
text: { fn: (d) => `${d.year} — $${d.value.toLocaleString("en-US")}` },
textAnchor: { value: "end" }, fontSize: { value: 11 }, fill: { value: "#3b2f27" },
} }),
],
});
mount(chart.dom());
Try: Drag the end of a band to wind it further round · drag the short pink band at the top clockwise to grow 1875.