# Sankey chart

Where things flow, step by step: ribbons blend from one step's color to the next, and pointing at a step lights every flow through it with dots traveling the way things move.

Also called: flow diagram, alluvial chart.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: Sankey chart. A week of support chats from channel to intent to outcome. Point at Bug report to see where bugs end up. Preview: https://chatcn.dev/preview/sankey-chart-demo

## Installation

```bash
npx shadcn@latest add @chatcn-pro/sankey-chart
```

## Usage

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

<SankeyChart
  title="Where support chats went this week"
  columns={["Channel", "Intent", "Outcome"]}
  nodes={[
    { id: "web", label: "Web" },
    { id: "bug", label: "Bug report" },
    { id: "ai", label: "Answered by AI", tone: "good" },
    { id: "left", label: "Left unanswered", tone: "bad" },
  ]}
  links={[
    { source: "web", target: "bug", value: 1380 },
    { source: "bug", target: "ai", value: 1240 },
    { source: "bug", target: "left", value: 140 },
  ]}
  unit="chats"
/>
```

Steps are placed in columns by their longest path from a source, so every flow runs left to right, and ribbons are stacked in the order of the step at their other end so they cross as little as they can. Every step takes a palette color in reading order (`--chatcn-chart-1` onward) unless it has its own `color` or a `tone`, and each ribbon blends from the color of the step it leaves to the step it reaches, so you can read where a flow came from and where it went. Give outcomes a tone (`good`, `bad`, `warn`, `neutral`) and they read by meaning without a legend. Names of the first and last columns sit outside the plot in gutters sized to fit, so they never sit on a ribbon. Everything rests as a quiet tint: point at a step and every flow on a path through it lights, upstream and down, with dots traveling the way things move; point at a ribbon and a card follows the pointer with its amount, its share of where it came from and its share of everything. The plot keeps a minimum width of 520 px and scrolls sideways inside its card below that. The table button shows every link as a table, and a screen reader table is always there.

## Examples

### States

Example: States. Two columns of spend, loading, empty and a failed load. Preview: https://chatcn.dev/preview/sankey-chart-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `nodes` | `SankeyNode[]` | `{ id, label, color?, tone? }`; tone is `good`, `bad`, `warn` or `neutral` |
| `links` | `SankeyLink[]` | `{ source, target, value }` |
| `title`, `description` | `ReactNode` | The caption |
| `headline` | `ReactNode` | A large number under the title, such as a `ChartHeadline` |
| `columns` | `string[]` | Names over the columns, left to right |
| `linkColor` | `"gradient" | "source" | "target"` | How ribbons take color. Default `gradient` |
| `flow` | `"hover" | "always" | "off"` | Dots along the lit ribbons. Default `hover`; off under reduced motion |
| `nodeValue` | `"value" | "share" | "none"` | What follows each name. Default `value` |
| `unit`, `valueFormat` | `string`, `DataValueFormat` | How amounts read |
| `height` | `number` | Default 320 |
| `loading`, `error`, `onRetry` |  | Loading keeps the final height |
| `labels` | `Partial<SankeyChartLabels>` | Every string, for translation |

## Keyboard

| Key | Action |
| --- | --- |
| Tab | Focus the chart; the first step is read out |
| Arrow up, down | Previous or next step in the column |
| Arrow left, right | The nearest step in the column before or after |
| Escape | Clear the highlight |

## Accessibility

- The chart is an image summarized in words, with a table of every flow for screen readers.
- The readout above the plot says what is pointed at or focused, in words and numbers.
- Color is never the only cue: steps and amounts are labelled.

## Motion

Flows draw in from the left once, over 900 ms with the kit's ease out, and steps grow from their baseline. Highlights fade over 200 ms. On lit ribbons, dots travel along the flow (stroke dash offset only) to show direction. Under reduced motion it appears drawn and nothing travels.

Source: https://chatcn.dev/docs/components/sankey-chart