Skip to content

Crossfilter ​

A histogram of each measure of Seattle's weather, in gray for every day and in blue for the days that the brushes of the other histograms select, so brushing one filters the others, but not itself. Each brush sets the clause of its field in one shared selection, which its own histogram excepts, and the clauses intersect. The bins are a count of thresholds over the extent of every day, so they stay put as the brushes move. Drag across a histogram to brush. After Vega-Lite.

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().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));