An interactive Sankey diagram visualization built with D3.js that supports progressive disclosure and customizable styling.
- Progressive Disclosure: Start with root nodes and click to reveal connected nodes and flows
- Interactive Exploration: Click on nodes to expand the diagram progressively
- Customizable Styling: Adjust node colors, sizes, link opacity, and other visual properties
- Gradient Links: Beautiful gradient colors for flow connections
- SVG Icons: Custom SVG icons for each node type
- Responsive Design: Works on desktop and mobile devices
- Tooltips: Hover over nodes and links for detailed information
- Smooth Animations: Elegant transitions when revealing new elements
- Clone or download the project files
- Place the files in a web server directory (local or remote)
- Open
index.htmlin a web browser - The diagram will load automatically with sample energy flow data
interactive-sankey/
├── index.html # Main application file
├── data.json # Data file containing nodes and links
└── README.md # This file
The visualization uses a JSON format that defines nodes, links, and interaction rules:
{
"nodes": [
{
"id": "unique_id",
"name": "Display Name",
"level": 0,
"style": {
"color": "#color_code",
"icon": "<svg>...</svg>"
},
"visible": true,
"description": "Node description"
}
],
"links": [
{
"id": "link_id",
"source": "source_node_id",
"target": "target_node_id",
"value": 100,
"style": {
"gradient": {
"start": "#start_color",
"end": "#end_color"
}
}
}
],
"interactionRules": {
"initiallyVisible": ["node_id"],
"progressiveDisclosure": {
"parent_node": ["child_node1", "child_node2"]
}
}
}The interface includes several customization controls:
- Node Width: Adjust the thickness of nodes
- Node Padding: Control spacing between nodes
- Node Color: Change the default node color
- Link Opacity: Adjust transparency of flow connections
- Animation Speed: Control transition timing
- Modify
data.json: Edit the data file to include your own nodes and links - Node Styling: Each node can have custom colors and SVG icons
- Link Gradients: Define custom gradient colors for each connection
- Interaction Rules: Set which nodes are initially visible and define progressive disclosure paths
Replace the icon field in node definitions with your own SVG code:
{
"style": {
"icon": "<svg viewBox='0 0 24 24' width='20' height='20'><path d='...' fill='white'/></svg>"
}
}- Initial State: Only the root nodes specified in
interactionRules.initiallyVisibleare shown - Progressive Disclosure: Click on any visible node to reveal its connected nodes
- Flow Visualization: Links between nodes show the flow relationships with gradient colors
- Interactive Exploration: Continue clicking to explore deeper levels of the data
- Chrome (recommended)
- Firefox
- Safari
- Edge
- Modern mobile browsers
- D3.js v7 (loaded from CDN)
- d3-sankey plugin (loaded from CDN)
The included sample data demonstrates an energy flow visualization with:
- Energy sources (coal, natural gas, renewables)
- Renewable breakdowns (solar, wind, hydro)
- Electricity grid distribution
- End-use consumption (residential, commercial, industrial)
MIT License - feel free to use and modify for your projects.
Feel free to submit issues and enhancement requests!