Du Bois's wrapped bars
W. E. B. Du Bois's charts for the 1900 Paris Exposition fold a bar that is too long for the page back on itself, so a large value and a small one share one scale. This page builds the Du Bois wrapped bar chart step by step, then rebuilds two of his charts the same way: a track draws each bar as a length along a route, and move() on its length writes the value. His coil and his spiral are on the next page.
Step by step: a wrapped bar chart
The Du Bois wrapped bar chart (Karduni et al., CHI 2020) turns his fold into a rule. A bar runs to a threshold, turns down, and runs back. Here every lane runs the full width, so each one holds the threshold.
1. Declare the answer. One row per bar. The schema gives value its type and domain.
data: [{ name: "A", value: 3000 }, { name: "B", value: 1750 }, /* … */],schema: {name: { type: "categorical" },value: { type: "quantitative", domain: [0, MAX] },},
2. Choose the threshold and the wrap. The first lane holds THRESH. Each lane after it runs back to WRAP * THRESH, so it holds LANE. With WRAP = 0 a lane runs back to zero and holds THRESH. A wrap steps down STEP of a row.
const THRESH = 1500, WRAP = 0, MAX = 6000;const LANE = (1 - WRAP) * THRESH; // 1,500const STEP = 0.3;
3. Map data units to pixels. Two linear scales do it: x maps [0, THRESH] across the plot, and y gives each level one row. x is linear, so every lane has the same pixels per unit.
const x = (v) => X0 + (v / THRESH) * W;const y = (level) => TOP + level * ROW;
4. Give each row its level. A row starts below the rows before it, plus the steps their wraps take. The level reads the live rows, so when a bar wraps into another lane, the rows below it move down.
const wraps = (v) => (v > THRESH ? Math.ceil((v - THRESH) / LANE - 1e-9) : 0);const levelOf = (i, rows) =>rows.slice(0, i).reduce((level, d) => level + 1 + STEP * wraps(d.value), 0);
5. Write the route. The route is the longest bar a row allows, as an SVG path. Each M starts a lane. The route runs right to THRESH, steps down, runs back to WRAP * THRESH, and repeats until it holds MAX. Only lanes hold value, so the steps between them count for nothing.
function routeOf(i, rows) {let level = levelOf(i, rows), from = 0, to = THRESH, held = THRESH;let d = `M${x(from)},${y(level)}L${x(to)},${y(level)}`;while (held < MAX) {level += STEP;[from, to] = [to, to === THRESH ? WRAP * THRESH : THRESH];d += `M${x(from)},${y(level)}L${x(to)},${y(level)}`;held += LANE;}return d;}
6. Draw the bar along the route. A track takes the route as path. Its length channel binds value: the schema's domain spans the whole route, so 6,000 fills all four lanes and 750 half of the first. join: "round" draws each step down as a half circle that bulges outward. stroke colours the bar by its value, from teal to red.
track({path: (d, i, rows) => routeOf(i, rows),join: "round",channels: {length: { field: "value", edit: move() },stroke: { field: "value", scale: { range: ["teal", "red"] } },strokeWidth: { value: 7 },},}),
7. Drag the end of the bar. move() on length puts the end of the bar at the point of the route nearest the pointer. It follows the route from where the bar ends, so drag round a turn to carry the bar into the next lane. You can press anywhere on a row's route, even where no bar is drawn, so a bar at zero can still be grabbed. Every redraw reads the new value, so the bar, its colour and the rows below follow it.
constraints: [snap({ step: 1 })] keeps each answer a whole number.
8. Add the axis. A guides.custom draws the x axis over [0, THRESH].
A wrapped bar chart
Eight categories on one scale. A value over 1,500 turns down and runs back, and the rows below it move down.
// ── This chart's route: a bar that wraps at a threshold ─────────────────// In data units, X is the value and Y is a level (one per row). A bar runs// right to THRESH, steps down, runs back left to WRAP * THRESH, steps down,// and so on. Each `M` starts a lane; the steps between lanes hold no value.const THRESH = 1500, WRAP = 0, MAX = 6000;const LANE = (1 - WRAP) * THRESH; // what each lane after the first holdsconst STEP = 0.3; // how far down a wrap steps, in levels// Two linear scales map the route to pixels: x from [0, THRESH], y one row per level.const X0 = 70, W = 470, TOP = 30, ROW = 36;const x = (v) => X0 + (v / THRESH) * W;const y = (level) => TOP + level * ROW;// How many times a value wraps, and so how many levels its row takes.const wraps = (v) => (v > THRESH ? Math.ceil((v - THRESH) / LANE - 1e-9) : 0);// The level a row starts on: the rows before it, plus their wraps. It changes// as you drag, so the rows below a wrapping bar move down.const levelOf = (i, rows) =>rows.slice(0, i).reduce((level, d) => level + 1 + STEP * wraps(d.value), 0);// The longest bar a row allows, as one lane per `M`. It holds MAX.function routeOf(i, rows) {let level = levelOf(i, rows), from = 0, to = THRESH, held = THRESH;let d = `M${x(from)},${y(level)}L${x(to)},${y(level)}`;while (held < MAX) {level += STEP;[from, to] = [to, to === THRESH ? WRAP * THRESH : THRESH];d += `M${x(from)},${y(level)}L${x(to)},${y(level)}`;held += LANE;}return d;}// The x axis over [0, THRESH].const xAxis = guides.custom(() =>[0, 250, 500, 750, 1000, 1250, 1500].flatMap((v) => [{ type: "line", x1: x(v), x2: x(v), y1: TOP - 14, y2: 420, stroke: "#dddddd", strokeWidth: 0.75, background: true },{ type: "text", x: x(v), y: 432, text: v.toLocaleString("en-US"), fontSize: 10, fill: "#555555", textAnchor: "middle" },]),);const chart = Elicit({width: 640, height: 450,margins: { top: 0, right: 0, bottom: 0, left: 0 },data: [{ name: "A", value: 3000 }, { name: "B", value: 1750 }, { name: "C", value: 500 },],schema: {name: { type: "categorical" },value: { type: "quantitative", domain: [0, MAX] },},constraints: [snap({ step: 1 })],guides: [xAxis],marks: [track({path: (d, i, rows) => routeOf(i, rows),join: "round",channels: {length: { field: "value", edit: move() },stroke: { field: "value", scale: { range: ["teal", "red"] } },strokeWidth: { value: 7 },},}),text({ channels: {x: { value: X0 - 16 }, y: { fn: (d, i, rows) => y(levelOf(i, rows)) },text: { field: "name" }, textAnchor: { value: "end" },fontSize: { value: 13 }, fill: { value: "#333333" },} }),text({ channels: {x: { value: X0 + W + 16 }, y: { fn: (d, i, rows) => y(levelOf(i, rows)) },text: { fn: (d) => d.value.toLocaleString("en-US") }, textAnchor: { value: "start" },fontSize: { value: 11 }, fill: { value: "#555555" },} }),],});mount(chart.dom());
Du Bois's charts
The two charts below use the same track and the same move() on length. Drag the end of a bar along its route. Only the route changes. Both are wrapped bars in data units, with WRAP = 0 and a row per level.
Every row's route holds the same length, so the rows share one scale.
A bar that folds back and forth
A wrapped bar with a threshold of 900 students and three lanes. The bar runs right, turns down through a half circle, runs left, and turns again. The turns hold no students. Industrial, at 2,252, fills two lanes and part of a third.
Courses of study
Du Bois's count of Black students in each course of study in Georgia schools. A bar longer than one lane folds back.
// ── This chart's route: lanes that fold back and forth ──────────────────// In data units, X is students along a lane and Y is a level (one per row).// A lane holds 900. Each `M` starts a lane; the turns hold no value.const THRESH = 900, MAX = 2700;const STEP = 0.35; // how far down a turn steps, in levels// Two linear scales map the route to pixels: x from [0, THRESH], y one row per level.const X0 = 190, W = 400, TOP = 28, ROW = 74;const x = (v) => X0 + (v / THRESH) * W;const y = (level) => TOP + level * ROW;// The longest bar a row allows: three lanes, right, left, right.function routeOf(i) {let d = "";for (let lane = 0; lane < MAX / THRESH; lane++) {const [from, to] = lane % 2 === 0 ? [0, THRESH] : [THRESH, 0];const level = i + lane * STEP;d += `M${x(from)},${y(level)}L${x(to)},${y(level)}`;}return d;}const chart = Elicit({width: 640, height: 470,margins: { top: 0, right: 0, bottom: 0, left: 0 },theme: { background: "#ecdcc6" },// Number of Black students taking each course of study in Georgia schools.data: [{ course: "Business", students: 12 },],schema: {course: { type: "categorical" },students: { type: "quantitative", domain: [0, MAX] },},constraints: [snap({ step: 1 })],marks: [track({path: (d, i) => routeOf(i),join: "round",channels: {length: { field: "students", edit: move() },stroke: { value: "#5c4a3d" }, strokeWidth: { value: 9 },},}),text({ channels: {x: { value: 20 }, y: { fn: (d, i) => y(i) },text: { fn: (d) => d.course.toUpperCase() },textAnchor: { value: "start" }, fontSize: { value: 12 }, fill: { value: "#3b2f27" },} }),text({ channels: {x: { value: X0 - 14 }, y: { fn: (d, i) => y(i) },text: { field: "students" },textAnchor: { value: "end" }, fontSize: { value: 12 }, fill: { value: "#3b2f27" },} }),],});mount(chart.dom());
A tight turn
The same route with two lanes. A lane holds 85,000 men, and the turn is 12px across, so the returning lane sits between two rows. Du Bois bracketed fifteen smaller trades together. The last row is their sum.
Du Bois's other charts wind in place of folding. The next page writes a coil and a spiral as routes in pixels.
Occupations of Georgia men
Black men over ten in Georgia by occupation, 1890. Agricultural laborers run past the lane and turn back under it.
// ── This chart's route: one lane, then a tight turn back ────────────────// In data units, X is men along a lane and Y is a level (one per row). A lane// holds 85,000. The bar turns down and runs back under itself.const THRESH = 85000, MAX = 170000;const STEP = 0.375; // how far down the turn steps, in levels// Two linear scales map the route to pixels: x from [0, THRESH], y one row per level.const X0 = 236, W = 380, TOP = 22, ROW = 32;const x = (v) => X0 + (v / THRESH) * W;const y = (level) => TOP + level * ROW;// The longest bar a row allows: right, then back left one step down.const routeOf = (i) =>`M${x(0)},${y(i)}L${x(THRESH)},${y(i)}` +`M${x(THRESH)},${y(i + STEP)}L${x(0)},${y(i + STEP)}`;const chart = Elicit({width: 640, height: 290,margins: { top: 0, right: 0, bottom: 0, left: 0 },theme: { background: "#ecdcc6" },// Occupations of Black men over ten in Georgia, 1890. The last row is the// fifteen smaller trades Du Bois bracketed together, summed.data: [{ occupation: "Agricultural laborers", men: 98400 },],schema: {occupation: { type: "categorical" },men: { type: "quantitative", domain: [0, MAX] },},constraints: [snap({ step: 1 })],marks: [track({path: (d, i) => routeOf(i),join: "round",channels: {length: { field: "men", edit: move() },stroke: { value: "#d1213f" }, strokeWidth: { value: 7 },},}),text({ channels: {x: { value: 14 }, y: { fn: (d, i) => y(i) },text: { fn: (d) => d.occupation.toUpperCase() },textAnchor: { value: "start" }, fontSize: { value: 10 }, fill: { value: "#3b2f27" },} }),text({ channels: {x: { value: X0 - 10 }, y: { fn: (d, i) => y(i) },text: { fn: (d) => d.men.toLocaleString("en-US") },textAnchor: { value: "end" }, fontSize: { value: 10 }, fill: { value: "#3b2f27" },} }),],});mount(chart.dom());