Components

Sankey Chart

Trace quantities through branching and recombining flows.

Loading chart…

Configured energy allocation (MWh)
FlowSource IDTarget IDMWh
solar-homessolarhomes35
solar-industrysolarindustry25
wind-homeswindhomes15
wind-industrywindindustry25

Usage

SankeyChart validates balanced directed flows and delegates layout to Recharts. Share nodeConfig with SankeyLegend for default node/source-link colors and static metadata.

Composition
<Chart.ResponsiveContainer width="100%" height={250}>
  <Chart.SankeyChart
    data={data} nodeConfig={nodeConfig}
    animate={{ revealDurationMs: 900 }}
  >
    <Tooltip isAnimationActive={false} />
  </Chart.SankeyChart>
</Chart.ResponsiveContainer>
<Chart.SankeyLegend config={nodeConfig} />

Sankey needs no Root or axes. nodeConfig maps every node ID, including isolated/zero-only nodes, to a label and color. Default nodes use their own color; solid links use the source color. Import Tooltip from Recharts.

Identities and selection

Compose native node/link callbacks when labels, gradients or interaction need custom rendering.

Loading chart…

Illustrative energy allocation (MWh)
FlowSource IDTarget IDMWh
solar-northsolarnorth30
solar-centralsolarcentral20
solar-southsolarsouth10
wind-northwindnorth20
wind-centralwindcentral30
wind-southwindsouth30
hydro-northhydronorth20
hydro-centralhydrocentral10
hydro-southhydrosouth10
north-homesnorthhomes35
north-industrynorthindustry25
north-servicesnorthservices10
central-homescentralhomes15
central-industrycentralindustry30
central-servicescentralservices15
south-homessouthhomes10
south-industrysouthindustry15
south-servicessouthservices25

Give nodes and links unique nonempty string IDs. Endpoints accept IDs or original-array integer indices; numeric-looking strings remain IDs. Use renderer payload.id for stable application identity.

Click or press Enter/Space to select a ribbon; Escape clears it. Selection changes paint, not quantities. A hidden SankeyTable retains all routes; narrow diagrams scroll horizontally.

Intermediate inflow must equal outflow. Model losses/gains as explicit boundary links. This example carries 180 MWh per stage.

Flow finishes

Choose plain, paper, clay or glow with finish; material="gradient" resolves source and target colors from the same nodeConfig. Explicit color and targetColor remain overrides. Labels remain consumer-owned outside the filters.

Loading chart…

Illustrative energy allocation (MWh)
FlowSource IDTarget IDMWh
solar-northsolarnorth30
solar-centralsolarcentral20
solar-southsolarsouth10
wind-northwindnorth20
wind-centralwindcentral30
wind-southwindsouth30
hydro-northhydronorth20
hydro-centralhydrocentral10
hydro-southhydrosouth10
north-homesnorthhomes35
north-industrynorthindustry25
north-servicesnorthservices10
central-homescentralhomes15
central-industrycentralindustry30
central-servicescentralservices15
south-homessouthhomes10
south-industrysouthindustry15
south-servicessouthservices25

Motion and geometry

Entrance reveals supported link paint along fixed paths; widths and node positions stay unchanged. Interaction, data/layout/renderer changes or resize finish it; reduced motion skips it.

Recharts owns coordinates, control points and widths. Kind preserves computed geometry against presentation overrides. Small frames show a status when the padding budget cannot fit.

API reference

Focused public props; native SVG presentation and Recharts layout options remain available.

SankeyChart

PropTypeDefaultDescription
dataSankeyFlowDataRequiredImmutable nodes and links; validates identities, quantities, acyclicity and intermediate balance.
nodeConfigSankeyNodeConfigOffExplicit node-ID labels/colors; enables default Kind node and source-link paint.
nodeNative object, element or (props: SankeyNodeProps) => ReactNodeKind node with nodeConfig; otherwise nativeReceives computed geometry and typed node identity.
linkNative object, element or native-compatible callback using SankeyLinkPropsKind link with nodeConfig; otherwise nativeMetadata enables default Kind paint/motion; custom callbacks retain control.
animateboolean | { revealDurationMs?: number }falseFlow paint reveal; true uses 450ms. Duration must be finite and nonnegative.
emptyReactNode"No positive flows"Status for empty or all-zero data.
nodeWidthnumber10Native node rectangle width.
nodePaddingnumber10Native vertical gap between nodes.
sortbooleantrueNative node ordering; these components use false.
linkCurvaturenumber0.5Native cubic link curvature.
iterationsnumber32Native layout relaxation iterations.
margin{ top?: number; right?: number; bottom?: number; left?: number }5 each sideReserve space for consumer labels.
onClick / onMouseEnter / onMouseLeave(item, type, event) => void—Native event with typed node/link IDs; type is "node" | "link".
childrenReactNode—Native tooltip or other supported children.

Equal-value positive parallel links are rejected; distinct values are supported. Rescale extreme numeric ranges before native layout. See Recharts Sankey.

SankeyNode

PropTypeDefaultDescription
Native renderer geometry and payloadSankeyNodePropsRequiredSpread the complete callback props; computed rectangle dimensions win.
colorstringConfig color; fallback "#4f46e5"Explicit paint overrides metadata.
finish"plain" | "paper" | "clay" | "glow""plain"Static surface filter; explicit filters take precedence.
rectPropsSVGProps<SVGRectElement>—Presentation, semantics and handlers on the original rectangle.

Supply node labels as sibling SVG text. Selection and legend state remain consumer-owned.

PropTypeDefaultDescription
Native renderer geometry and payloadSankeyLinkPropsRequiredSpread the complete callback props; path and flow width stay native.
material"solid" | "gradient""solid"Single-color stroke or source-to-target gradient.
colorstringSource config color; fallback "#4f46e5"Explicit source paint override.
targetColorstringTarget config color; fallback "#06b6d4"Explicit destination override for gradient paint.
finish"plain" | "paper" | "clay" | "glow""plain"Static treatment independent of material and flow width.
pathPropsSVGProps<SVGPathElement>—Presentation, keyboard handlers and semantics on the original path; computed geometry wins.

Explicit filters bypass finishes; transformed paths bypass reveal. Custom renderers own motion. Glow changes neither quantities nor hit targets.

SankeyLegend

A standalone static list; share the exact config passed to SankeyChart. Config insertion order determines legend order. It does not toggle or infer flows.

PropTypeDefaultDescription
configSankeyNodeConfigRequiredExplicit node-ID labels/colors; extra entries remain visible in the legend.
children(item: { key: string; label: string; color: string; marker: ReactNode }) => ReactNodeLabel and markerCustom legend content; native list attributes and refs remain available.

SankeyTable

PropTypeDefaultDescription
dataSankeyFlowDataRequiredComplete input, including zero flows; validated independently.
captionstringRequiredAccessible table name.
formatValue(value: number) => stringStringConsumer-owned units.
onInspect(link: SankeyFlowLink) => void—Adds native inspection buttons receiving the original link.
activeLinkIdstring | null—Controlled selected row and button aria-pressed.

Native attributes/refs remain available. These examples hide the table; onInspect supports a visible keyboard inspector.

Flow data

PropTypeDefaultDescription
nodesreadonly SankeyFlowNode[]RequiredEach node has unique id: string and name: string; extra metadata is retained.
linksreadonly SankeyFlowLink[]RequiredEach link has unique id: string, endpoints and a value.
source / targetstring | numberRequiredNode ID or original node-array integer index.
valuenumberRequiredFinite nonnegative flow quantity.

prepareSankeyData(data) validates/copies input and resolves endpoints to indices. It does not aggregate, normalize or infer flows. Cycles, invalid endpoints/IDs and negative/nonfinite quantities throw.

Zero links remain in the table but leave plotted geometry; isolated nodes also leave the plot.

Shared components

ResponsiveContainer, Tooltip.

Sankey uses the native Recharts Tooltip for hover inspection. Path handlers and status text provide keyboard selection. Give the diagram a measurable height; these examples use a 540px minimum width.