Skip to main content
100%

WIP Multidimensional Filtering in React

✓ Published0🌍 Public
CCurran Kelleher
Last edited Mar 13, 2026
Created on Mar 13, 2026

This example shows the Iris dataset rendered as four linked histograms, one for each numeric column. Brushing any histogram cross-filters the other charts, with highlighted bars showing data points that fall within all active brush selections. The visualization is built with React managing state and lifecycle via `useState` and `useEffect`, while D3 v7 handles SVG rendering, `brushX` interactions, and animated bar transitions. A `ResizeObserver` hook tracks container dimensions for responsive re-rendering.

AI-generated description

Iris Histogram with React and D3

This project visualizes the Iris dataset as a series of linked histograms using React and D3.

Features

  • One brushable histogram per numeric column in the dataset: sepal_length, sepal_width, petal_length, petal_width
  • Brushing on any histogram cross-filters all other histograms, highlighting only the data points that fall within every active brush selection
  • Animated bar enter/update/exit transitions powered by D3

How It Works

  1. React manages state and lifecycle – useState tracks the current brush intervals for each column; useEffect re-runs the D3 rendering logic whenever dimensions or brush state change.
  2. A ResizeObserver hook (useResizeObserver) watches the container <div> and stores its pixel dimensions in React state, causing the chart to re-render responsively whenever the window is resized.
  3. D3 renders the SVG – inside useEffect, D3 selects the <svg> element via a React ref and draws one <g class="histogram"> per column. Each histogram is rendered by the histogram() function in histogram.js.
  4. Cross-filtering – brushedIntervals is a plain object mapping column name → [min, max]. The filtered dataset is recomputed on every render by checking each data row against every active interval.

Project Structure

File Purpose
index.html HTML shell with import map
index.jsx React app entry point; state, resize hook, D3 orchestration
histogram.js Pure D3 function that draws a single brushable histogram
MIT Licensed

Similar vizzes