View as Markdown

Data Visualization

SankeyChart

Sankey flow diagrams from @salmonui/charts/sankey-chart with horizontal or vertical layout, node and link colors, gradient links, labels, a node legend, adjacent highlight, tooltips and node and flow keyboard navigation.

SankeyChart lives in @salmonui/charts/sankey-chart. The layout (node columns from the longest path, iterative relaxation, link bands) is computed without d3 and identically on the server and the client.

import { SankeyChart } from '@salmonui/charts/sankey-chart';
import '@salmonui/charts/sankey-chart/styles.css';

<SankeyChart nodes={[{ id: 'a', label: 'Coal' }, { id: 'b', label: 'Grid' }]} links={[{ source: 'a', target: 'b', value: 30 }]} height={320} />

Energy flow

Open demo

A SankeyChart of energy sources to consumers with gradient links, a node legend, adjacent highlight on hover and keyboard navigation between nodes and flows.

Energy flow (TWh)

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.

Energy flow (TWh)
SourceTargetValue
CoalGrid30
GasGrid25
SolarGrid15
WindGrid20
GasIndustry10
GridHomes40
GridIndustry35
GridTransport15

Clicked: none

Layout and colors

orientation is 'horizontal' (default) or 'vertical'; nodeWidth (default 16 px) and nodePadding (default 12 px) size the nodes, node.offset shifts a node along its column and curvature (0 to 1, default 0.5) bends the links. Links that close a cycle or name an unknown node are dropped. Nodes take the derived palette or node.color (a data color); linkColor is 'source' (default), 'target' or 'gradient'. getNodeStyle, getLinkStyle and formatLabel restyle and relabel; labels is true, false or { position: 'inside' | 'outside' }. format and locale format the values in labels, tooltips, announcements and the table.

Interaction

Hovering a node or a link dims everything not adjacent to it (highlight: 'adjacent' | false, default 'adjacent') and shows the tooltip (tooltip: { renderNode, renderLink }). onNodeClick(node, event) and onNodeHover(node | null) receive { index, id, label, value, column, color }; onLinkClick(link, event) and onLinkHover(link | null) receive { index, source, target, value } with both node records, and event.source is 'pointer', 'keyboard' or 'touch'. The chart has no controlled state. legend (true or { position, title }) lists the nodes; hovering an entry highlights that node's flows. onResize reports the measured size, and ref receives the instance (export, toBlob, toDataURL, toSVGString, print, focus).

Budget flow with custom tooltips

Open demo

A monthly budget SankeyChart with custom node and link tooltips, getNodeStyle and getLinkStyle colors, formatLabel value labels, onResize and SVG / PNG export through the instance.

Monthly budget. Income to spending, USD

Sankey chart, 8 nodes, 7 flows, 3 columns. Salary to Budget: $4,200; Freelance to Budget: $800; Budget to Housing: $1,700; Budget to Food: $750; Budget to Transport: $300; Budget to Leisure: $450; Budget to Savings: $1,800.

Monthly budget
SourceTargetValue
SalaryBudget$4,200
FreelanceBudget$800
BudgetHousing$1,700
BudgetFood$750
BudgetTransport$300
BudgetLeisure$450
BudgetSavings$1,800

Size: not measured yet

Keyboard and accessibility

One tab stop. Arrow keys move between the nodes of a column and to the nearest node of the next or previous column; Enter steps into the focused node's flows (arrows cycle them) and Escape returns to the node. Enter on a node and Enter or Space on a flow fire onNodeClick / onLinkClick; Space on a node fires onNodeClick without stepping in. A polite live region announces "Grid: 70, 3 incoming, 2 outgoing" or "Grid to Homes: 40". The accessible table lists source, target and value.

Server rendering

The layout is pure, so the server renders the final nodes, links, labels, legend and table. Without height (prop or CSS) the server renders the nominal size and the chart relays out once after hydration (onResize); tooltips and the entrance animation are client only. See Size, animation and RTL.

Node strokes, opacity and fonts are system-owned, not props; see Rendering and colors. Every prop is listed in the API reference.