Skip to content

Sankey Chart

React SVG sankey diagram: node columns laid out from the links, gradient ribbons, a node's flows lit on hover or focus, and a hidden data table.

src/registry/ui/sankey-chart.tsx/r/sankey-chart.json

Installation

bash
npx shadcn@latest add @minidev/sankey-chart

MiniDev UI is in the shadcn registry directory, so the short form works with no setup. Older CLI versions can use the full URL: npx shadcn@latest add https://ui.minidev.pro/r/sankey-chart.json

Usage

tsx
import { SankeyChart } from "@/components/ui/sankey-chart"

export function Example() {
  return (
    <SankeyChart />
  )
}

API reference

SankeyChart props
PropTypeDefault
nodesOptional node order, labels and colours. Unknown ids found in links are added automatically.SankeyNodeInput[]SAMPLE_NODES
align"left" puts each node one column after its furthest source; "justify" also pushes nodes with no outgoing links to the last column."left""justify""left"
titlestring"Where signups come from"
captionstring"Last 30 days, visitors to paid plan"
heightChart height in px. The width follows the container.number320
nodeWidthnumber10
nodePaddingVertical gap between nodes in a column, in px.number14
formatFormats values in labels, the tooltip text and the table.(value: number) => stringdefaultFormat
unitUnit word for accessible labels, e.g. "visitors".string"visitors"
classNamestring-

Keyboard interactions

Keyboard interactions
KeyAction
TabMoves focus into the diagram. All nodes share one Tab stop.
ArrowRightorArrowDownMoves focus to the next node and highlights its flows.
ArrowLeftorArrowUpMoves focus to the previous node.
HomeorEndMoves focus to the first or last node.

Accessibility

  • The chart is a <figure> labelled by its title; the SVG is role="group" named with the node and flow counts.
  • Each node is a focusable role="img" whose label reads its total and every flow in and out, such as "Signed up: 3,480 visitors. From Organic search 1,400, … To Starter 1,640, …". unit supplies the word "visitors".
  • A visually hidden <table> lists every flow with From, To and Value columns; the ribbons are aria-hidden.
  • Highlighting is an opacity change on a 140ms CSS transition, which the kit's stylesheet cuts under reduced motion.

Frequently asked questions

Why do sample nodes like "Starter" show up next to my own data?

nodes defaults to the sample node list, and every listed node is drawn even if no link uses it. When you pass your own links, also pass nodes (to set labels and colours) or nodes={[]}.

How are SankeyChart columns decided?

From the links alone: each node goes one column after its furthest source. With align="justify", nodes that have no outgoing links move to the last column, so every end state lines up on the right. Links from a node to itself and links with a value of 0 or less are dropped.

Can the data contain a cycle, like users who come back?

The layout will not hang: nodes caught in a cycle are placed one column after their placed sources. A sankey reads best without loops, so model returns as a separate node, such as "Returned".

How do I size it?

Set height in pixels (default 320); the width follows the container through a ResizeObserver. Labels in middle columns hide when fewer than five characters fit, but each node keeps its full spoken label.

Examples

Custom flows and labels

links reference node ids; nodes adds display labels and colours, and format and unit rewrite every number for a budget in thousands.

Justified columns

align justify pushes nodes with no outgoing flow to the last column, so visitors who left line up with the plans instead of sitting mid chart.

All chart components

Learn more