WIP Multidimensional Filtering in React
✓ Published0🌍 Public
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 descriptionIris 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
- React manages state and lifecycle –
useStatetracks the current brush intervals for each column;useEffectre-runs the D3 rendering logic whenever dimensions or brush state change. - A
ResizeObserverhook (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. - 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 thehistogram()function inhistogram.js. - Cross-filtering –
brushedIntervalsis 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