Components/SankeyChart

SankeyChart

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

VerifiedSince 0.1.0

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...

API Reference

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.
defaultNodeColorstring—Fallback 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'.

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.

Hover Highlight

Hovering a node or a link leaves only adjacent elements untouched: the non-adjacent nodes, links and labels dim together to 10% opacity, matching ECharts' emphasis.focus: 'adjacency' (blur is fromState.opacity * 0.1), switched over 300ms cubicOut. A node's neighbourhood is itself, every link touching it and the nodes at those links' other ends; a link's is itself, its two endpoint nodes and every link touching either endpoint.

Sankey has no geometry animation, which is parity with kumo rather than a missing feature: ECharts' SankeyView has neither initProps nor updateProps, so when the d3-sankey layout changes the nodes and links land on their new positions without a tween. Under prefers-reduced-motion: reduce the 300ms transition drops out and the highlight switches instantly.

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.