Demo
Energy flow
Documented in SankeyChart.
Energy flow
A SankeyChart of energy sources to consumers with gradient links, a node legend, adjacent highlight on hover and keyboard navigation between nodes and flows.
Sankey chart, 8 nodes, 8 flows, 3 columns. Coal to Grid: 30; Gas to Grid: 25; Solar to Grid: 15; Wind to Grid: 20; Gas to Industry: 10; Grid to Homes: 40; Grid to Industry: 35; Grid to Transport: 15.
| Source | Target | Value |
|---|---|---|
| Coal | Grid | 30 |
| Gas | Grid | 25 |
| Solar | Grid | 15 |
| Wind | Grid | 20 |
| Gas | Industry | 10 |
| Grid | Homes | 40 |
| Grid | Industry | 35 |
| Grid | Transport | 15 |
Clicked: none
Demo.tsx
'use client';
import { useState } from 'react';
import { SankeyChart } from '@salmonui/charts/sankey-chart';
const nodes = [
{ id: 'coal', label: 'Coal' },
{ id: 'gas', label: 'Gas' },
{ id: 'solar', label: 'Solar' },
{ id: 'wind', label: 'Wind' },
{ id: 'grid', label: 'Grid' },
{ id: 'homes', label: 'Homes' },
{ id: 'industry', label: 'Industry' },
{ id: 'transport', label: 'Transport' },
];
const links = [
{ source: 'coal', target: 'grid', value: 30 },
{ source: 'gas', target: 'grid', value: 25 },
{ source: 'solar', target: 'grid', value: 15 },
{ source: 'wind', target: 'grid', value: 20 },
{ source: 'gas', target: 'industry', value: 10 },
{ source: 'grid', target: 'homes', value: 40 },
{ source: 'grid', target: 'industry', value: 35 },
{ source: 'grid', target: 'transport', value: 15 },
];
export default function SankeyChartBasicDemo() {
const [last, setLast] = useState('none');
return (
<div className="demo-stack">
<SankeyChart title="Energy flow (TWh)" nodes={nodes} links={links} height={380} linkColor="gradient" legend onNodeClick={(n) => setLast(n.label)} onLinkClick={(l) => setLast(`${l.source.label} → ${l.target.label}`)} />
<p className="demo-status" aria-live="polite">
Clicked: <code>{last}</code>
</p>
</div>
);
}
Hover a node or a flow to highlight its neighbours. Tab to the chart: arrow keys move between nodes in a column and across columns, Enter steps into the focused node's flows and Escape returns.