recharts-sankey-chart
evilcharts/recharts-sankey-chartFreeComponent
Sankey chart component for visualizing flow data with nodes and links
Install it
npx shadcn@latest add https://evilcharts.com/r/recharts-sankey-chart.jsonSource
1"use client";23import {4 Sankey as RechartsSankey,5 Layer,6 type SankeyProps,7 type SankeyNodeProps,8 type SankeyLinkProps,9 type SankeyData,10 type SankeyNode as RechartsSankeyNode,11} from "recharts";12import {13 Children,14 createContext,15 isValidElement,16 use,17 useCallback,18 useId,19 useMemo,20 useState,21 type FC,22 type ReactElement,23 type ReactNode,24} from "react";25import {26 ChartTooltip,27 ChartTooltipContent,28 type TooltipRoundness,29 type TooltipVariant,30} from "@/registry/ui/recharts-tooltip";31import {32 type ChartConfig,33 ChartContainer,34 getColorsCount,35 LoadingIndicator,36} from "@/registry/ui/recharts-chart";37import { ChartBackground, type BackgroundVariant } from "@/registry/ui/recharts-background";38import { motion } from "motion/react";3940// Constants41const LOADING_ANIMATION_DURATION = 2000; // full loading cycle duration in milliseconds42const DEFAULT_NODE_WIDTH = 10;43const DEFAULT_NODE_PADDING = 10;44const DEFAULT_LINK_CURVATURE = 0.5;45const DEFAULT_ITERATIONS = 32;4647type LinkVariant = "gradient" | "solid" | "source" | "target";48type NodeLabelPosition = "inside" | "outside";4950// ─────────────────────────────────────────────────────────────────────────────51// Shared context52// ─────────────────────────────────────────────────────────────────────────────5354/**55 * Shared state for every part of the chart. Lifted into <EvilSankeyChart /> so56 * that <Node />, <Link />, and <Tooltip /> can read it without prop drilling.57 * A sankey chart's data is rigid — the root passes `nodes`/`links` straight to58 * Recharts — so the parts here configure how those nodes and links render.59 */60type SankeyChartContextValue = {61 data: SankeyData; // the nodes + links rendered by the chart62 config: ChartConfig; // colors + labels keyed by node name63 chartId: string; // colon-free id scoping this chart's SVG defs64 isLoading: boolean; // whether the chart shows its loading skeleton65 selectedNode: string | null; // currently selected node name, or null when none66 selectNode: (nodeName: string | null) => void; // sets the selected node67};6869const SankeyChartContext = createContext<SankeyChartContextValue | null>(null);7071// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from EvilCharts
All 271 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| echarts-area-chartecharts-area-chart | EvilCharts | Components | Free | 2 deps | |
| echarts-bar-chartecharts-bar-chart | EvilCharts | Components | Free | 2 deps | |
| echarts-brushecharts-brush | EvilCharts | Components | Free | 1 dep | |
| echarts-chartecharts-chart | EvilCharts | Components | Free | 1 dep | |
| echarts-composed-chartecharts-composed-chart | EvilCharts | Components | Free | 2 deps | |
| echarts-dotecharts-dot | EvilCharts | Components | Free | 1 dep | |
| echarts-legendecharts-legend | EvilCharts | Components | Free | no deps | |
| echarts-line-chartecharts-line-chart | EvilCharts | Components | Free | 2 deps |
