Skip to content

Stacked Waffles ​

Olympic athletes per 10 kg of weight, women up and men down, one square per 10 athletes. cm.unitY sums the signed counts of each bin and sex into squares, and cm.stackY with chunk stacks them in rows of 5. After Observable Plot.

js
const athletes = await d3.csv("/data/athletes.csv", d3.autoType);

const renderer = cm.svg({width: 640, height: 400});
const root = cm.flow().renderer(renderer);

root
  .data(athletes)
  .transform(cm.encode, {
    x: (d) => Math.floor(d.weight / 10) * 10,
    y: (d) => (d.sex === "female" ? 1 : -1),
    fill: "sex",
  })
  .transform(cm.spreadX)
  .transform(cm.unitY, {unit: 10})
  .transform(cm.stackY, {chunk: 5})
  .transform(cm.plane)
  .add(cm.rect);

root.render();
document.body.append(renderer.node());