Skip to content

Animated Crossfilter ​

The crossfilter of Seattle's weather with transitions: as a brush moves, the blue bars of the other histograms grow and shrink to their new counts. Drag across a histogram to brush.

js
const days = await d3.csv("/data/seattle-weather.csv", d3.autoType);
const brush = cm.selection({resolve: "intersect"});

function histogram(field) {
  const renderer = cm.svg({width: 640, height: 160});
  const root = cm.flow({transition: {duration: 250}}).renderer(renderer);
  root
    .data(() => [
      ...days.map((d) => ({...d, layer: "all"})),
      ...days
        .filter((d) => brush.test({datum: d}, {except: field, empty: true}))
        .map((d) => ({...d, layer: "selected"})),
    ])
    .transform(cm.encode, {x: field, fill: "layer"})
    .transform(cm.binX, {y: "count", thresholds: 20})
    .transform(cm.plane, {y: {grid: true}, fill: {domain: ["all", "selected"], range: ["#ddd", "steelblue"]}})
    .add(cm.rect, cm.insetX(0.5))
    .add(cm.brushX, {as: brush, source: field});
  root.render();
  return renderer.node();
}

document.body.append(...["precipitation", "temp_max", "wind"].map(histogram));