Skip to content

Waffle in the Terminal ​

The catch of six lakes as waffles of ■ cells, a unit per fish, on the terminal renderer. The rows of units are snapped to whole rows, so none is left out.

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

const renderer = cm.terminal({width: 640, height: 400, units: "pixels"});
const root = cm.flow().renderer(renderer);

root
  .data(seafood)
  .transform(cm.encode, {x: "lake", y: "count", fill: "species"})
  .transform(cm.spreadX)
  .transform(cm.unitY)
  .transform(cm.spreadY, {chunk: 5})
  .transform(cm.spreadX)
  .transform(cm.plane, {y: {axis: null}})
  .add(cm.rect, {fill: (d) => `cell(■, ${d.fill})`});

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