Components/SankeyChart

SankeyChart

Flow diagrams on the d3-sankey layout: gradient links, node value labels, drill affordances and slot tooltips.

VerifiedSince 0.1.0

SankeyChart

Basic Usage

nodes is the node array; links connect nodes by index (source/target index into nodes). Node color precedence: node.color > defaultNodeColor > the categorical palette by index. Links blend source → target colors by default; link-color="gray" switches to a flat gray. Value labels turn on automatically when any node carries a value (showNodeValues forces either way).

Traffic distribution

Gradient links + tooltip

Hover nodes for value and tooltipData rows; drillable nodes get a pointer cursor.

Loading demo...

Inline labels + gray links

Small nodes read better with the inline 'value name' layout.

Loading demo...

Resilience

Circular links make d3-sankey throw — the component catches that, renders an empty state and logs a dev warning instead of crashing the host page.

API

SankeyChart Props

PropTypeDefaultDescription
nodesSankeyNodeData[]{ name, color?, value?, tooltipData?, isDrillable?, childCount? }.
linksSankeyLinkData[]{ source, target, value, isDrillable? }, index references.
heightnumber400Pixel height.
widthnumbermeasuredExplicit width (SSR/tests).
nodeWidthnumber8Node bar width.
nodePaddingnumber10Vertical gap between nodes in a column.
showNodeValuesboolean | 'auto''auto''auto' enables labels when any node has a value.
nodeLabelLayout'stacked' | 'inline''stacked'Value above the name / on one line.
formatValue(v: number) => stringtoLocaleStringValue formatter.
showTooltipbooleantrueHover tooltip.
defaultNodeColorstringFallback before the categorical palette.
left / rightnumber | string'5%'Layout insets (px or percent).
linkColor'gradient' | 'gray''gradient'Link fill mode.
linkOpacitynumber0.5Gradient link opacity.

SankeyChart Events

EventPayloadDescription
node-click(node: SankeyNodeData)Node clicked; the original datum.
link-click(link: SankeyLinkData)Link clicked; the original datum.

SankeyChart Slots

SlotScopeDescription
tooltip{ params: SankeyTooltipParams }Replaces the tooltip body; params.type is 'node' | 'link'.

Differences from kumo

  • tooltipFormatter (HTML strings + manual XSS escaping) → the tooltip slot (VNodes).
  • kumo throws on circular input; this degrades to an empty render with a dev warning.