This project demonstrates a smooth transition animation between a waffle chart and a tiled bar chart using React and D3. The animation is triggered by scrolling.
- Waffle Chart: A grid-based visualization where each square represents a portion of the data
- Tiled Bar Chart: A bar chart where each bar is composed of individual squares
- Smooth Transition: Animated morphing between the two chart types
- Scroll-Triggered Animation: The transition is controlled by the user's scroll position
- React Spring Animation: Physics-based animations for natural-feeling transitions
- Node.js (v14 or higher)
- npm or yarn
-
Clone the repository:
git clone <repository-url> cd chart-transition -
Install dependencies:
npm install # or yarn install -
Start the development server:
npm start # or yarn start -
Open your browser and navigate to
http://localhost:3000
src/- Source codeApp.jsx- Main application componentcomponents/- React componentswaffle-bar-scrolly.jsx- Component that handles the scroll-based animationanimated-rectangles.jsx- Component that renders the morphing animationtiled-bar.jsx- Standalone tiled bar chart componentwaffle-chart.jsx- Standalone waffle chart component
utils.js- Utility functions for data processing and calculationsconfig.js- Configuration settings for charts and animations
-
Data Preparation: The
buildWaffleBarSquaresfunction inutils.jscreates a dataset with both waffle and bar positions for each square. -
Scrollama Integration: The
WaffleBarScrollycomponent uses the Scrollama library to track scroll position and update the animation progress. -
Spring Animation: The
AnimatedRectanglescomponent uses React Spring to create smooth, physics-based animations between the two chart types. -
Configuration: All chart settings are centralized in
config.jsand passed down as props to the components.
The project includes several standalone chart components that can be used independently:
- WaffleBarScrolly: The main component that demonstrates the transition animation
- TiledBarChart: A standalone bar chart where each bar is composed of individual squares
- WaffleChart: A standalone grid-based visualization where each square represents a portion of the data
The project includes a simplified version of the default Scrollama example. To use this demo:
- Open
src/App.jsx - Uncomment the
Democomponent in the return statement - Comment out the other chart components
This provides a simpler starting point for understanding how Scrollama works with basic animations.
You can customize the charts by modifying the configuration objects in config.js:
CHART_CONFIG: Settings for the morphing animationWAFFLE_CONFIG: Settings specific to the waffle chartTILED_BAR_CONFIG: Settings specific to the tiled bar chartSCROLLAMA_CONFIG: Settings for the scrollama behavior
- React
- D3
- React Spring
- React Scrollama
- D3.js for data visualization
- React Spring for animations
- React Scrollama for scroll-based interactions