@acronis-platform/ui-react 5.2.0 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/dist/components/ui/area-chart/area-chart.js +107 -107
  2. package/dist/components/ui/area-chart/area-chart.js.map +1 -1
  3. package/dist/components/ui/bar-chart/bar-chart.js +162 -162
  4. package/dist/components/ui/bar-chart/bar-chart.js.map +1 -1
  5. package/dist/components/ui/category-bar/category-bar.js +50 -50
  6. package/dist/components/ui/category-bar/category-bar.js.map +1 -1
  7. package/dist/components/ui/chart/chart.js +53 -40
  8. package/dist/components/ui/chart/chart.js.map +1 -1
  9. package/dist/components/ui/composed-chart/composed-chart.js +146 -146
  10. package/dist/components/ui/composed-chart/composed-chart.js.map +1 -1
  11. package/dist/components/ui/confidence-cone/confidence-cone.js +97 -97
  12. package/dist/components/ui/confidence-cone/confidence-cone.js.map +1 -1
  13. package/dist/components/ui/funnel-chart/funnel-chart.js +120 -120
  14. package/dist/components/ui/funnel-chart/funnel-chart.js.map +1 -1
  15. package/dist/components/ui/histogram/histogram.js +58 -58
  16. package/dist/components/ui/histogram/histogram.js.map +1 -1
  17. package/dist/components/ui/line-chart/line-chart.js +91 -91
  18. package/dist/components/ui/line-chart/line-chart.js.map +1 -1
  19. package/dist/components/ui/pie-chart/pie-chart.js +92 -92
  20. package/dist/components/ui/pie-chart/pie-chart.js.map +1 -1
  21. package/dist/components/ui/radar-chart/radar-chart.js +37 -37
  22. package/dist/components/ui/radar-chart/radar-chart.js.map +1 -1
  23. package/dist/components/ui/radial-bar-chart/radial-bar-chart.js +112 -112
  24. package/dist/components/ui/radial-bar-chart/radial-bar-chart.js.map +1 -1
  25. package/dist/components/ui/sankey-chart/sankey-chart.js +78 -78
  26. package/dist/components/ui/sankey-chart/sankey-chart.js.map +1 -1
  27. package/dist/components/ui/scatter-chart/scatter-chart.js +57 -57
  28. package/dist/components/ui/scatter-chart/scatter-chart.js.map +1 -1
  29. package/dist/components/ui/treemap/treemap.js +87 -87
  30. package/dist/components/ui/treemap/treemap.js.map +1 -1
  31. package/dist/index.js +111 -111
  32. package/dist/llms.txt +1 -1
  33. package/dist/react.js +111 -111
  34. package/dist/src/components/ui/chart/chart.d.ts +1 -0
  35. package/dist/src/components/ui/chart/index.d.ts +1 -1
  36. package/dist/src/components/ui/radial-bar-chart/radial-bar-chart.d.ts +3 -2
  37. package/dist/src/components/ui/sankey-chart/sankey-chart.d.ts +1 -1
  38. package/dist/src/components/ui/treemap/treemap.d.ts +3 -2
  39. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"radial-bar-chart.js","names":[],"sources":["../../../../src/components/ui/radial-bar-chart/radial-bar-chart.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport {\n Cell,\n Label,\n LabelList,\n PolarAngleAxis,\n PolarGrid,\n RadialBar,\n RadialBarChart as RechartsRadialBarChart,\n} from 'recharts';\n\nimport type { LegendPayload } from 'recharts/types/component/DefaultLegendContent';\n\nimport { cn } from '@/lib/utils';\nimport {\n ChartContainer,\n ChartLegendContent,\n ChartTooltip,\n ChartTooltipContent,\n resolveAnimation,\n resolveChartColors,\n resolveLabelFillClass,\n CHART_DEFAULT_PALETTE,\n CHART_LABEL_FONT_SIZE,\n type ChartConfig,\n type ChartPalette,\n type ChartAnimationProps,\n type ChartDataLabelProps,\n type ChartTooltipContentProps,\n type PolarLabelPosition,\n type ResolvedAnimation,\n type TickFormatter,\n} from '../chart';\n\n// A typed recharts composition over the shared `Chart` primitives (a polar/radial\n// type). Rows become concentric arcs sized by `dataKey`, each colored from its\n// `--color-<name>` var; `dataKeys` switches to one arc per metric instead. Like\n// ScatterChart/ComposedChart there's no CVA variant: a radial bar's\n// expressiveness is geometry (angles/radii, plain props) and the data mapping,\n// not a visual \"mode\". The angular sweep is exposed as startAngle/endAngle props\n// so a caller can build a gauge or a full ring.\n\n/** Row-per-arc datum: the `nameKey` label plus each metric's numeric value. */\ntype RadialBarChartDatum = Record<string, string | number>;\n\n/** What an arc's data label reads. */\nexport type RadialBarChartLabelFormat = 'value' | 'name-value';\n\nexport interface RadialBarChartCenterLabel {\n // Rendered as SVG <text>, which only lays out text — hence string | number,\n // not ReactNode.\n /** Headline metric rendered large in the hole (e.g. the gauge's value). */\n value?: string | number;\n /** Caption rendered under the value. */\n label?: string | number;\n}\n\n/**\n * The readout in the hole at the centre of the arcs — a headline value over a\n * caption. Rendered as a recharts `<Label>`, which is what supplies the polar\n * viewBox the text centres itself on.\n *\n * There is one readout for the whole chart, so it hangs off the first series\n * drawn — every series shares the same viewBox.\n */\nfunction RadialBarChartCenterLabelContent({\n centerLabel,\n}: {\n centerLabel: RadialBarChartCenterLabel;\n}) {\n return (\n <Label\n content={({ viewBox }) => {\n if (!viewBox || !('cx' in viewBox)) return null;\n const { cx: centerX = 0, cy: centerY = 0 } = viewBox as {\n cx?: number;\n cy?: number;\n };\n const hasValue = centerLabel.value != null;\n const hasLabel = centerLabel.label != null;\n // Straddle the centre when both lines show, so the value + label block\n // is centered as a whole (not just the value).\n const both = hasValue && hasLabel;\n return (\n <g>\n {hasValue && (\n <text\n x={centerX}\n y={both ? centerY - 10 : centerY}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n className=\"fill-foreground text-2xl font-semibold\"\n >\n {centerLabel.value}\n </text>\n )}\n {hasLabel && (\n <text\n x={centerX}\n y={both ? centerY + 13 : centerY}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n className=\"fill-muted-foreground text-sm\"\n >\n {centerLabel.label}\n </text>\n )}\n </g>\n );\n }}\n />\n );\n}\n\n/**\n * Compose one arc's data-label text. Exported for unit tests; not part of the\n * package's public API.\n *\n * `labelFormatter` only ever formats the numeric part, so a chart's labels and\n * its tooltip stay in the same units under either format. A nullish value yields\n * an empty label, which recharts renders as no `<text>` at all.\n */\nexport function radialBarChartLabelText(options: {\n format: RadialBarChartLabelFormat;\n name: string | number | undefined;\n value: string | number | undefined;\n formatter?: TickFormatter;\n}): string {\n const { format, name, value, formatter } = options;\n if (value == null) return '';\n const valueText = formatter ? formatter(value) : String(value);\n return format === 'name-value' && name != null\n ? `${name}: ${valueText}`\n : valueText;\n}\n\n/** One piece of a segmented gauge's ring: a length in degrees and what it is. */\nexport interface RadialBarChartSegment {\n /** Synthetic series key — stable for a given (index, kind). */\n key: string;\n /** Angular length of the piece, in degrees. */\n degrees: number;\n /** `value` is the metric, `track` the unreached remainder, `gap` the notch. */\n kind: 'value' | 'track' | 'gap';\n}\n\n/** Fallback gap between a segmented gauge's segments, in degrees. */\nconst SEGMENT_GAP = 3;\n\n/**\n * Cut a gauge's sweep into equal segments separated by gaps, and split the\n * segment the value ends inside into its reached and unreached parts. Exported\n * for unit tests; not part of the package's public API.\n *\n * Lengths come back in **degrees**, which is what lets the ring be built as one\n * stack of synthetic series over a `[0, sweep]` angular scale: recharts lays\n * stacked radial bars out sequentially along the angle, so a transparent series\n * between two colored ones reads as a real notch in the ring. A `gap` that\n * would leave no room for the segments themselves is clamped.\n */\nexport function radialBarChartSegments(options: {\n value: number;\n domain: [number, number];\n segments: number;\n gap: number;\n /** Absolute sweep of the chart, in degrees. */\n sweep: number;\n /** A full-circle sweep also needs a gap between the last segment and the first. */\n closed: boolean;\n}): RadialBarChartSegment[] {\n const { value, domain, segments, sweep, closed } = options;\n const gapCount = closed ? segments : segments - 1;\n // Leave at least half the sweep for the segments, however wide a gap is asked\n // for — an all-gap ring would render as nothing at all. A negative gap would\n // stretch the pieces past the sweep and overlap them, so it floors at zero.\n const gap =\n gapCount > 0\n ? Math.min(Math.max(options.gap, 0), sweep / (2 * gapCount))\n : 0;\n const segmentDegrees = (sweep - gap * gapCount) / segments;\n const [min, max] = domain;\n const span = max - min;\n // A domain with no span (`[n, n]`) or an inverted one (`[max, min]`) cannot\n // place a value on the ring at all, so there is no fraction to draw and the\n // ring stays empty. It deliberately does not fall back to comparing the value\n // against zero: that reported a *full* ring for `{ value: 5, domain: [100,\n // 100] }`, i.e. claimed completion the data never supported. For a gauge,\n // under-reading a domain that says nothing is the safe direction.\n const fraction =\n span > 0 ? Math.min(Math.max((value - min) / span, 0), 1) : 0;\n // The value maps onto the *drawn* ring, so the gaps never eat into it.\n let remainingValue = fraction * segmentDegrees * segments;\n\n const pieces: RadialBarChartSegment[] = [];\n for (let index = 0; index < segments; index++) {\n const reached = Math.min(Math.max(remainingValue, 0), segmentDegrees);\n remainingValue -= reached;\n // Both halves are always emitted, including at zero length: a stable key set\n // keeps recharts' series identities steady as the value changes.\n pieces.push({ key: `seg-${index}-value`, degrees: reached, kind: 'value' });\n pieces.push({\n key: `seg-${index}-track`,\n degrees: segmentDegrees - reached,\n kind: 'track',\n });\n if (gap > 0 && (closed || index < segments - 1)) {\n pieces.push({ key: `seg-${index}-gap`, degrees: gap, kind: 'gap' });\n }\n }\n return pieces;\n}\n\n/**\n * Fill for one piece of a segmented gauge's ring. Exported for unit tests and so\n * the forced-open tooltip story can build a ring from the real implementation\n * rather than a copy of it; not part of the package's public API.\n */\nexport function radialBarChartSegmentFill(\n kind: RadialBarChartSegment['kind'],\n colorName: string | number\n): string {\n if (kind === 'gap') return 'transparent';\n // The unreached remainder plays the part `showBackground`'s track plays on a\n // continuous arc, so it takes the same muted surface.\n return kind === 'track'\n ? 'var(--ui-border-on-status-neutral)'\n : `var(--color-${colorName})`;\n}\n\n/**\n * What a segmented gauge's tooltip reads. Exported for unit tests; not part of\n * the package's public API.\n *\n * A segmented ring's series are pieces of geometry, so recharts would offer the\n * hovered piece's own name and length (\"seg-3-value\", 41.2°). Hovering anywhere\n * on the ring should read the metric instead, so the reading is rebuilt from the\n * data row.\n */\nexport function radialBarChartSegmentedReading(options: {\n config: ChartConfig;\n row: RadialBarChartDatum;\n nameKey: string;\n dataKey: string;\n /** The `valueDomain` maximum, when the gauge has one. */\n domainMax?: number;\n}): { colorName: string; label: React.ReactNode; valueText: string } {\n const { config, row, nameKey, dataKey, domainMax } = options;\n const colorName = String(row[nameKey]);\n const value = row[dataKey];\n const valueText =\n typeof value === 'number' ? value.toLocaleString() : String(value ?? '');\n return {\n colorName,\n label: config[colorName]?.label ?? colorName,\n // The gauge's scale is the other half of the reading, so a known maximum\n // comes along: \"29 / 38\", not a bare \"29\".\n valueText:\n domainMax == null\n ? valueText\n : `${valueText} / ${domainMax.toLocaleString()}`,\n };\n}\n\n/**\n * The tooltip a segmented gauge shows — the same swatch/name/value layout the\n * default `ChartTooltipContent` row uses, dot included, over the reading from\n * `radialBarChartSegmentedReading`. Exported for the forced-open\n * visual-regression story; not part of the package's public API.\n *\n * `payload` is trimmed to one row: a radial tooltip is axis-shared and collects a\n * row from every series — two dozen identical rows for one metric.\n * (`tooltipType=\"none\"` only tags them, and scoping the tooltip to the hovered\n * item instead would drop it in the corner — unlike Pie/Bar sectors, a RadialBar\n * sector carries no tooltip coordinate.)\n *\n * A real component rather than a closure so it can be handed to `ChartTooltip`\n * as an *element*: recharts `cloneElement`s an element but `createElement`s a\n * function, and a closure rebuilt each render is a new element *type* — which\n * remounts the tooltip on every parent render instead of updating it.\n */\nexport function RadialBarChartSegmentedTooltipContent({\n active,\n payload,\n ...reading\n}: {\n active?: boolean;\n // Loosely typed on purpose: recharts' own payload generics are wider than the\n // shared `ChartTooltipContentProps` accepts, and only the row count matters.\n payload?: readonly unknown[];\n config: ChartConfig;\n row: RadialBarChartDatum;\n nameKey: string;\n dataKey: string;\n domainMax?: number;\n}) {\n const { colorName, label, valueText } =\n radialBarChartSegmentedReading(reading);\n\n return (\n <ChartTooltipContent\n active={active}\n payload={payload?.slice(0, 1) as ChartTooltipContentProps['payload']}\n hideLabel\n formatter={() => (\n <>\n <div\n className=\"h-2.5 w-2.5 shrink-0 rounded-full\"\n style={{ backgroundColor: `var(--color-${colorName})` }}\n />\n <div className=\"flex flex-1 items-center justify-between gap-2 leading-none\">\n <span className=\"text-muted-foreground\">{label}</span>\n <span className=\"font-medium tabular-nums text-foreground\">\n {valueText}\n </span>\n </div>\n </>\n )}\n />\n );\n}\n\n/**\n * The band a multi-metric tooltip's header names. Exported for unit tests; not\n * part of the package's public API.\n *\n * Each tooltip row is one metric, so the header names the band the hovered arc\n * belongs to. recharts' own label is the radius-axis index, which reads as a\n * bare number.\n */\nexport function radialBarChartBandName(\n row: RadialBarChartDatum | undefined,\n nameKey: string\n): string {\n const name = row?.[nameKey];\n return name == null ? '' : String(name);\n}\n\n/**\n * What an arc's data label calls the arc: the row's own `nameKey` value, or — in\n * multi-metric mode, where one arc *is* one metric — that metric's `config` label.\n */\nfunction radialBarChartArcName(options: {\n key: string;\n row: RadialBarChartDatum | undefined;\n isMultiMetric: boolean;\n nameKey: string;\n config: ChartConfig;\n}): string | number | undefined {\n const { key, row, isMultiMetric, nameKey, config } = options;\n if (!isMultiMetric) return row?.[nameKey];\n // ChartConfig labels are ReactNode; only a plain string/number can go into an\n // SVG <text>.\n const label = config[key]?.label;\n return typeof label === 'string' || typeof label === 'number' ? label : key;\n}\n\n/**\n * The default mapping's arcs: one `RadialBar` per series — one for the single\n * `dataKey`, or one per `dataKeys` entry in multi-metric mode — drawn\n * concentrically.\n *\n * recharts collects its graphical items from the store (each `RadialBar`\n * registers itself on render) rather than by scanning the chart's children for\n * their types, so grouping them inside a component of our own is invisible to it.\n * The `Cell`s stay direct children of their `RadialBar`, which *does* read its own\n * children by type.\n */\nfunction RadialBarChartSeries({\n seriesKeys,\n seriesData,\n isMultiMetric,\n config,\n nameKey,\n showBackground,\n cornerRadius,\n minPointSize,\n animation,\n centerLabel,\n showLabels,\n labelPosition,\n labelFormat,\n labelFormatter,\n}: {\n seriesKeys: string[];\n seriesData: RadialBarChartDatum[];\n isMultiMetric: boolean;\n config: ChartConfig;\n nameKey: string;\n showBackground: boolean;\n cornerRadius: number;\n minPointSize: number | undefined;\n animation: ResolvedAnimation;\n centerLabel: RadialBarChartCenterLabel | undefined;\n showLabels: boolean;\n labelPosition: PolarLabelPosition;\n labelFormat: RadialBarChartLabelFormat;\n labelFormatter?: TickFormatter;\n}) {\n return seriesKeys.map((key, seriesIndex) => (\n <RadialBar\n key={key}\n dataKey={key}\n fill={isMultiMetric ? `var(--color-${key})` : undefined}\n background={showBackground ? { fill: 'var(--ui-border-on-status-neutral)' } : false}\n cornerRadius={cornerRadius}\n minPointSize={minPointSize}\n {...animation}\n >\n {!isMultiMetric &&\n seriesData.map((entry, index) => (\n // Keyed by index, not the name: two arcs could share a nameKey\n // value, which would collide as a React key. Same-named arcs\n // intentionally share a color/config entry via `--color-<name>`.\n <Cell key={index} fill={`var(--color-${entry[nameKey]})`} />\n ))}\n {seriesIndex === 0 && centerLabel && (\n <RadialBarChartCenterLabelContent centerLabel={centerLabel} />\n )}\n {showLabels && (\n <LabelList\n // `valueAccessor` rather than `dataKey`: the label text can\n // carry the arc's name, which only the whole row (single\n // metric) or the metric's config entry can supply. recharts\n // ignores the accessor when a dataKey is set, so the two\n // can't be combined.\n valueAccessor={(entry) =>\n radialBarChartLabelText({\n format: labelFormat,\n name: radialBarChartArcName({\n key,\n row: entry.payload as RadialBarChartDatum | undefined,\n isMultiMetric,\n nameKey,\n config,\n }),\n value: entry.value as string | number | undefined,\n formatter: labelFormatter,\n })\n }\n position={labelPosition}\n className={resolveLabelFillClass(labelPosition)}\n fontSize={CHART_LABEL_FONT_SIZE}\n />\n )}\n </RadialBar>\n ));\n}\n\n/**\n * A segmented gauge's ring: the pieces from `radialBarChartSegments` as one stack\n * of synthetic series, so they lay out sequentially around the ring instead of\n * concentrically and the `gap` pieces read as notches.\n */\nfunction RadialBarChartSegmentedSeries({\n ringSegments,\n row,\n nameKey,\n cornerRadius,\n animation,\n centerLabel,\n}: {\n ringSegments: RadialBarChartSegment[];\n row: RadialBarChartDatum;\n nameKey: string;\n cornerRadius: number;\n animation: ResolvedAnimation;\n centerLabel: RadialBarChartCenterLabel | undefined;\n}) {\n return ringSegments.map((segment, index) => (\n <RadialBar\n key={segment.key}\n dataKey={segment.key}\n stackId=\"segments\"\n // The metric's name, so the hover has a row to key off at all\n // (`ChartTooltipContent` keys its row off `name`).\n name={String(row[nameKey])}\n fill={radialBarChartSegmentFill(segment.kind, row[nameKey])}\n cornerRadius={cornerRadius}\n {...animation}\n >\n {index === 0 && centerLabel && (\n <RadialBarChartCenterLabelContent centerLabel={centerLabel} />\n )}\n </RadialBar>\n ));\n}\n\nexport interface RadialBarChartProps\n extends\n Omit<React.ComponentProps<'div'>, 'children'>,\n ChartAnimationProps,\n ChartDataLabelProps {\n /**\n * The dataviz palette this chart's series are painted from. Series that\n * state no `color` of their own take a stop of it. See `ChartPalette`.\n */\n palette?: ChartPalette;\n /** Row-per-arc data. Each object holds the arc's `nameKey` label + its `dataKey` numeric value. */\n data: ReadonlyArray<RadialBarChartDatum>;\n /**\n * Per-arc map of `label` / `icon` / `tone`, keyed by the arc's `nameKey` value\n * — or, in multi-metric mode, by each `dataKeys` entry (imported from the\n * shared `Chart` primitives). Turned into `--color-<name>` custom properties.\n * Series take their colour from the container's `palette`; each entry maps a\n * key to a `label` and an optional `tone`.\n */\n config: ChartConfig;\n /** Numeric field that sizes each arc. Ignored when `dataKeys` is set. */\n dataKey: string;\n /**\n * Plot several metrics instead of one arc per row: one arc per key, colored and\n * named from `config` keyed by the **key** (not by `nameKey`) — the same\n * convention as the cartesian charts. Every metric shares one angular scale, so\n * pair it with `valueDomain` when the metrics are measured against a known\n * maximum. `nameKey` still names the band each metric's arc sits in.\n */\n dataKeys?: string[];\n /**\n * Label field that names each arc (drives the legend, tooltip, and\n * `--color-<name>` lookup). Values should be unique per chart (arcs sharing a\n * name share one `config`/color entry) and CSS-safe — they become part of a\n * custom-property name. In multi-metric mode it names the band rather than the\n * arc, so the legend and colors come from `dataKeys` instead.\n */\n nameKey: string;\n /** Inner radius of the innermost arc. */\n innerRadius?: number;\n /** Outer radius of the outermost arc. */\n outerRadius?: number;\n /** Angle (degrees) the arcs sweep from. */\n startAngle?: number;\n /** Angle (degrees) the arcs sweep to (default is a full clockwise circle). */\n endAngle?: number;\n /**\n * The value range the sweep represents, as `[min, max]`. Without it every arc\n * is drawn relative to the largest value in the data — so a **single** value\n * always fills the whole sweep, which is never what a gauge means. Set it to\n * the metric's own scale (e.g. `[0, 100]` for a percentage) and each arc\n * becomes that fraction of the sweep, over the `showBackground` track.\n */\n valueDomain?: [number, number];\n /** Corner radius on each arc's ends. */\n cornerRadius?: number;\n /**\n * Horizontal center of the arcs, in px or a percentage of the width.\n * Defaults to the middle (`50%`).\n */\n cx?: number | string;\n /**\n * Vertical center of the arcs, in px or a percentage of the height. Defaults to\n * the middle (`50%`) — worth moving for a half-circle gauge, whose drawn half\n * otherwise sits in the upper half of the surface.\n */\n cy?: number | string;\n /** Thickness of each arc, in px. Omit to let the radii and the gaps size it. */\n barSize?: number;\n /** Gap between the arcs of different metrics in one band, in px. */\n barGap?: number | string;\n /** Gap between bands, in px or a percentage string. */\n barCategoryGap?: number | string;\n /**\n * Smallest angle a non-zero arc may occupy, in degrees, so a tiny value stays\n * visible (and hoverable). recharts applies the floor to a `0` as well, which\n * reads as a small positive value — leave this unset when a metric can\n * legitimately be zero.\n */\n minAngle?: number;\n /** Plot-area margin, in px. Omit to use recharts' default (5 on every side). */\n margin?: { top?: number; right?: number; bottom?: number; left?: number };\n /**\n * Draw the gauge's ring as this many equal segments, notched apart — the\n * segmented-gauge look. Applies to a **single-value gauge** only and needs\n * `valueDomain` to know what a full ring means. Anything that isn't one — more\n * than one row, `dataKeys` set, fewer than two segments, or a `dataKey` value\n * that isn't a number (a stringified `\"29\"` off an API) — falls back to the\n * normal concentric arcs, legend included, rather than erroring.\n *\n * The ring is then synthetic geometry rather than data rows, so the arc labels\n * and the legend are suppressed: put the readout in `centerLabel`. The tooltip\n * stays, and reads the metric (with the `valueDomain` maximum when there is\n * one) wherever on the ring it is hovered. `showBackground` is redundant too —\n * the unreached segments *are* the track.\n */\n segments?: number;\n /** Gap between a segmented gauge's segments, in degrees. Defaults to `3`. */\n segmentGap?: number;\n /** Render a muted background track behind each arc. */\n showBackground?: boolean;\n /** Draw the concentric polar grid behind the arcs. */\n showPolarGrid?: boolean;\n /**\n * Custom content for the hole at the center — a headline `value` and/or a\n * `label` caption, stacked and centered. Needs an `innerRadius` big enough to\n * hold the text; it is not clipped to the hole.\n */\n centerLabel?: RadialBarChartCenterLabel;\n showTooltip?: boolean;\n showLegend?: boolean;\n /**\n * Format each arc's value in the list legend. In single-metric mode each arc\n * row gets its formatted value next to its label; in multi-metric mode values\n * are per-row (not per-series) so this is ignored.\n */\n legendValueFormatter?: (value: string | number) => string;\n /**\n * Replace the default tooltip. Pass a configured `ChartTooltipContent`\n * (imported from this library) — e.g. with a `formatter` / `labelFormatter` —\n * to customize formatting, per-arc rows, or extra fields without composing\n * recharts yourself. Ignored when `showTooltip` is false.\n *\n * On a segmented gauge it takes over from the built-in reading, and the payload\n * it receives is the ring's synthetic pieces (`seg-2-track`, a length in\n * degrees) rather than data rows — read the metric off `payload[0].payload`.\n */\n tooltipContent?: React.ComponentProps<typeof ChartTooltip>['content'];\n /**\n * Position of the value labels when `showLabels` is on. Defaults to\n * `insideStart` — the labels sit inside each arc, and therefore render in the\n * on-fill label token so they stay legible over the arc colour.\n */\n labelPosition?: PolarLabelPosition;\n /**\n * What each data label reads when `showLabels` is on — the value alone (the\n * default), or the arc's name and its value. The name is the row's `nameKey`\n * value, or the metric's `config` label in multi-metric mode.\n */\n labelFormat?: RadialBarChartLabelFormat;\n}\n\nconst RadialBarChart = React.forwardRef<HTMLDivElement, RadialBarChartProps>(\n (\n {\n className,\n config,\n palette,\n data,\n dataKey,\n dataKeys,\n nameKey,\n innerRadius = 20,\n outerRadius = 60,\n startAngle = 90,\n endAngle = -270,\n valueDomain,\n cornerRadius = 4,\n cx,\n cy,\n barSize,\n barGap,\n barCategoryGap,\n minAngle,\n margin,\n segments,\n segmentGap = SEGMENT_GAP,\n showBackground = true,\n showPolarGrid = false,\n centerLabel,\n showTooltip = true,\n showLegend = true,\n legendValueFormatter,\n tooltipContent,\n animate,\n animationDuration,\n animationBegin,\n animationEasing,\n showLabels = false,\n labelPosition,\n labelFormat = 'value',\n labelFormatter,\n ...props\n },\n ref\n ) => {\n const animation = resolveAnimation({\n animate,\n animationDuration,\n animationBegin,\n animationEasing,\n });\n const arcLabelPosition = labelPosition ?? 'insideStart';\n const isMultiMetric = !!dataKeys?.length;\n // A segmented ring is one metric cut into pieces, so it only means anything\n // for a single-row, single-metric chart.\n const isSegmented =\n segments != null &&\n segments > 1 &&\n !isMultiMetric &&\n data.length === 1 &&\n typeof data[0][dataKey] === 'number';\n const seriesKeys = isMultiMetric ? dataKeys! : [dataKey];\n // Stable across renders so the memoized legend content below keeps its\n // identity; `seriesKeys` itself is a fresh array every render.\n const legendKeys = React.useMemo(\n () => (dataKeys?.length ? dataKeys : [dataKey]),\n [dataKeys, dataKey]\n );\n const sweep = Math.abs(endAngle - startAngle);\n const ringSegments = isSegmented\n ? radialBarChartSegments({\n value: data[0][dataKey] as number,\n // Without a domain a lone value is its own maximum, so the ring fills.\n domain: valueDomain ?? [0, data[0][dataKey] as number],\n segments: segments!,\n gap: segmentGap,\n sweep,\n closed: sweep >= 360,\n })\n : [];\n\n // Stamp each row with its `fill` (the shadcn data-driven pattern) so a real\n // hover resolves the arc color in the tooltip — recharts' RadialBar, like\n // Funnel, carries no per-arc color on the tooltip payload item. Only in\n // single-metric mode: with one color per *metric*, a row-level fill would\n // paint every tooltip swatch the same.\n const seriesData: RadialBarChartDatum[] = isMultiMetric\n ? (data as RadialBarChartDatum[])\n : data.map((row) => ({\n ...row,\n fill: `var(--color-${row[nameKey]})`,\n }));\n\n // Each piece of the ring becomes a synthetic series on the one row, measured\n // in degrees — see `radialBarChartSegments`. Built from the raw row, *not*\n // from `seriesData`: a row-level `fill` wins over a series' own `fill` in\n // recharts, which would paint the track and the notches the arc's color.\n const plotData: RadialBarChartDatum[] = isSegmented\n ? [\n {\n ...data[0],\n ...Object.fromEntries(ringSegments.map((s) => [s.key, s.degrees])),\n },\n ]\n : seriesData;\n\n // recharts measures the radial floor in degrees, then extends the arc by\n // `mathSign(deltaAngle || minPointSize)`, where `deltaAngle` is the *arc's*\n // own angular length (RadialBar.js). So for a non-zero arc the floor already\n // grows along the arc's direction whatever sign it carries; the sign only\n // decides which way an arc of exactly zero degrees grows. Carry the sweep's\n // sign so that one grows forwards on a counter-clockwise chart too.\n const minPointSize =\n minAngle === undefined\n ? undefined\n : endAngle < startAngle\n ? -minAngle\n : minAngle;\n\n // Resolve colors so the external list legend has the same values as the chart\n // plot without needing to be inside ChartContainer's context.\n const resolvedConfigForLegend = React.useMemo(\n () => (showLegend ? resolveChartColors(config, palette ?? CHART_DEFAULT_PALETTE) : null),\n [showLegend, config, palette]\n );\n const rightLegendPayload: LegendPayload[] = React.useMemo(() => {\n if (!resolvedConfigForLegend) return [];\n if (isMultiMetric) {\n // Multi-metric: one entry per dataKey. No per-series row value is\n // meaningful (each metric spans multiple rows), so values are omitted.\n return legendKeys.map((key) => ({\n value: key,\n dataKey: key,\n color: resolvedConfigForLegend[key]?.color ?? `var(--color-${key})`,\n type: 'rect' as const,\n payload: {} as Record<string, unknown>,\n }));\n }\n // Single-metric: one entry per data row.\n return data.map((row) => ({\n value: String(row[nameKey]),\n dataKey: nameKey,\n color:\n resolvedConfigForLegend[String(row[nameKey])]?.color ??\n `var(--color-${String(row[nameKey])})`,\n type: 'rect' as const,\n payload: row as Record<string, unknown>,\n }));\n }, [resolvedConfigForLegend, isMultiMetric, legendKeys, data, nameKey]);\n\n const hasLegend = showLegend && !isSegmented && !!resolvedConfigForLegend;\n\n // The built-in tooltip reading, which each mapping composes differently: a\n // segmented ring rebuilds it from the data row, multi-metric renames the\n // header after the band, and the default mapping reads the hovered arc.\n const getDefaultTooltipContent = () => {\n if (isSegmented) {\n return (\n <RadialBarChartSegmentedTooltipContent\n config={config}\n row={data[0]}\n nameKey={nameKey}\n dataKey={dataKey}\n domainMax={valueDomain?.[1]}\n />\n );\n }\n\n if (isMultiMetric) {\n return (\n <ChartTooltipContent\n labelFormatter={(_, payload) =>\n radialBarChartBandName(\n payload?.[0]?.payload as RadialBarChartDatum | undefined,\n nameKey\n )\n }\n />\n );\n }\n\n return <ChartTooltipContent nameKey={nameKey} hideLabel />;\n };\n\n // Shared recharts chart composition (used in both layout modes).\n const radialChartContent = (\n <RechartsRadialBarChart\n data={plotData}\n // Only meaningful for the single-metric mapping; in multi-metric and\n // segmented mode each <RadialBar> carries its own key and the scale\n // spans them all.\n dataKey={isMultiMetric || isSegmented ? undefined : dataKey}\n cx={cx}\n cy={cy}\n innerRadius={innerRadius}\n outerRadius={outerRadius}\n startAngle={startAngle}\n endAngle={endAngle}\n barSize={barSize}\n barGap={barGap}\n barCategoryGap={barCategoryGap}\n margin={margin ?? { top: 0, right: 0, bottom: 0, left: 0 }}\n >\n {showPolarGrid && (\n <PolarGrid gridType=\"circle\" radialLines={false} />\n )}\n {(valueDomain || isSegmented) && (\n // The angular scale itself, not chrome: it maps a value onto a\n // fraction of the sweep. Ticks/axis line stay off — the arcs and\n // the optional center readout are the readout. A segmented ring is\n // already measured in degrees, so its scale *is* the sweep.\n <PolarAngleAxis\n type=\"number\"\n domain={isSegmented ? [0, sweep] : valueDomain}\n tick={false}\n axisLine={false}\n />\n )}\n {showTooltip && (\n <ChartTooltip\n // The hover cursor marks which band of the angular axis is\n // active, which on a segmented ring is one metric either way —\n // it just draws a hairline across the gauge.\n cursor={isSegmented ? false : undefined}\n content={tooltipContent ?? getDefaultTooltipContent()}\n />\n )}\n {isSegmented ? (\n <RadialBarChartSegmentedSeries\n ringSegments={ringSegments}\n row={data[0]}\n nameKey={nameKey}\n cornerRadius={cornerRadius}\n animation={animation}\n centerLabel={centerLabel}\n />\n ) : (\n <RadialBarChartSeries\n seriesKeys={seriesKeys}\n seriesData={seriesData}\n isMultiMetric={isMultiMetric}\n config={config}\n nameKey={nameKey}\n showBackground={showBackground}\n cornerRadius={cornerRadius}\n minPointSize={minPointSize}\n animation={animation}\n centerLabel={centerLabel}\n showLabels={showLabels}\n labelPosition={arcLabelPosition}\n labelFormat={labelFormat}\n labelFormatter={labelFormatter}\n />\n )}\n </RechartsRadialBarChart>\n );\n\n const chartDivSize =\n showLabels && (arcLabelPosition === 'outside' || arcLabelPosition === 'end')\n ? 'size-[200px]'\n : 'size-[120px]';\n\n return (\n <div\n ref={ref}\n className={cn('flex flex-row items-center gap-4', !hasLegend && 'justify-center', className)}\n {...props}\n >\n <div className={cn(chartDivSize, 'shrink-0')}>\n <ChartContainer config={config} palette={palette} className=\"size-full\">\n {radialChartContent}\n </ChartContainer>\n </div>\n {showLegend && !isSegmented && resolvedConfigForLegend && (\n <ChartLegendContent\n variant=\"list\"\n payload={rightLegendPayload}\n config={resolvedConfigForLegend}\n nameKey={isMultiMetric ? undefined : nameKey}\n valueKey={isMultiMetric ? undefined : dataKey}\n valueFormatter={isMultiMetric ? undefined : legendValueFormatter}\n className=\"min-w-0 flex-1\"\n />\n )}\n </div>\n );\n }\n);\nRadialBarChart.displayName = 'RadialBarChart';\n\nexport { RadialBarChart };\n"],"mappings":";;;;;;;;;AAmEA,SAAS,EAAiC,EACxC,kBAGC;CACD,OACE,kBAAC,GAAD,EACE,UAAU,EAAE,iBAAc;EACxB,IAAI,CAAC,KAAW,EAAE,QAAQ,IAAU,OAAO;EAC3C,IAAM,EAAE,IAAI,IAAU,GAAG,IAAI,IAAU,MAAM,GAIvC,IAAW,EAAY,SAAS,MAChC,IAAW,EAAY,SAAS,MAGhC,IAAO,KAAY;EACzB,OACE,kBAAC,KAAD,EAAA,UAAA,CACG,KACC,kBAAC,QAAD;GACE,GAAG;GACH,GAAG,IAAO,IAAU,KAAK;GACzB,YAAW;GACX,kBAAiB;GACjB,WAAU;GAET,UAAA,EAAY;EACT,CAAA,GAEP,KACC,kBAAC,QAAD;GACE,GAAG;GACH,GAAG,IAAO,IAAU,KAAK;GACzB,YAAW;GACX,kBAAiB;GACjB,WAAU;GAET,UAAA,EAAY;EACT,CAAA,CAEP,EAAA,CAAA;CAEP,EACD,CAAA;AAEL;AAUA,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A,CAKE,kBAAC,OAAD;GAAK,WAAW,EAAG,IAAc,UAAU;GACzC,UAAA,kBAAC,GAAD;IAAwB;IAAiB;IAAS,WAAU;IACzD,UAAA;GACa,CAAA;EACb,CAAA,GACJ,KAAc,CAAC,KAAe,KAC7B,kBAAC,GAAD;GACE,SAAQ;GACR,SAAS;GACT,QAAQ;GACR,SAAS,IAAgB,KAAA,IAAY;GACrC,UAAU,IAAgB,KAAA,IAAY;GACtC,gBAAgB,IAAgB,KAAA,IAAY;GAC5C,WAAU;EACX,CAAA,CAEA;;AAET,CACF;AACA,EAAe,cAAc"}
1
+ {"version":3,"file":"radial-bar-chart.js","names":[],"sources":["../../../../src/components/ui/radial-bar-chart/radial-bar-chart.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport {\n Cell,\n Label,\n LabelList,\n PolarAngleAxis,\n PolarGrid,\n RadialBar,\n RadialBarChart as RechartsRadialBarChart,\n} from 'recharts';\n\nimport type { LegendPayload } from 'recharts/types/component/DefaultLegendContent';\n\nimport { cn } from '@/lib/utils';\nimport {\n ChartContainer,\n ChartLegendContent,\n ChartTooltip,\n ChartTooltipContent,\n resolveAnimation,\n resolveChartColors,\n resolveLabelFillClass,\n CHART_DEFAULT_PALETTE,\n CHART_LABEL_FONT_SIZE,\n type ChartConfig,\n type ChartPalette,\n type ChartAnimationProps,\n type ChartDataLabelProps,\n type ChartTooltipContentProps,\n type PolarLabelPosition,\n toCssKey,\n type ResolvedAnimation,\n type TickFormatter,\n} from '../chart';\n\n// A typed recharts composition over the shared `Chart` primitives (a polar/radial\n// type). Rows become concentric arcs sized by `dataKey`, each colored from its\n// `--color-<name>` var; `dataKeys` switches to one arc per metric instead. Like\n// ScatterChart/ComposedChart there's no CVA variant: a radial bar's\n// expressiveness is geometry (angles/radii, plain props) and the data mapping,\n// not a visual \"mode\". The angular sweep is exposed as startAngle/endAngle props\n// so a caller can build a gauge or a full ring.\n\n/** Row-per-arc datum: the `nameKey` label plus each metric's numeric value. */\ntype RadialBarChartDatum = Record<string, string | number>;\n\n/** What an arc's data label reads. */\nexport type RadialBarChartLabelFormat = 'value' | 'name-value';\n\nexport interface RadialBarChartCenterLabel {\n // Rendered as SVG <text>, which only lays out text — hence string | number,\n // not ReactNode.\n /** Headline metric rendered large in the hole (e.g. the gauge's value). */\n value?: string | number;\n /** Caption rendered under the value. */\n label?: string | number;\n}\n\n/**\n * The readout in the hole at the centre of the arcs — a headline value over a\n * caption. Rendered as a recharts `<Label>`, which is what supplies the polar\n * viewBox the text centres itself on.\n *\n * There is one readout for the whole chart, so it hangs off the first series\n * drawn — every series shares the same viewBox.\n */\nfunction RadialBarChartCenterLabelContent({\n centerLabel,\n}: {\n centerLabel: RadialBarChartCenterLabel;\n}) {\n return (\n <Label\n content={({ viewBox }) => {\n if (!viewBox || !('cx' in viewBox)) return null;\n const { cx: centerX = 0, cy: centerY = 0 } = viewBox as {\n cx?: number;\n cy?: number;\n };\n const hasValue = centerLabel.value != null;\n const hasLabel = centerLabel.label != null;\n // Straddle the centre when both lines show, so the value + label block\n // is centered as a whole (not just the value).\n const both = hasValue && hasLabel;\n return (\n <g>\n {hasValue && (\n <text\n x={centerX}\n y={both ? centerY - 10 : centerY}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n className=\"fill-foreground text-2xl font-semibold\"\n >\n {centerLabel.value}\n </text>\n )}\n {hasLabel && (\n <text\n x={centerX}\n y={both ? centerY + 13 : centerY}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n className=\"fill-muted-foreground text-sm\"\n >\n {centerLabel.label}\n </text>\n )}\n </g>\n );\n }}\n />\n );\n}\n\n/**\n * Compose one arc's data-label text. Exported for unit tests; not part of the\n * package's public API.\n *\n * `labelFormatter` only ever formats the numeric part, so a chart's labels and\n * its tooltip stay in the same units under either format. A nullish value yields\n * an empty label, which recharts renders as no `<text>` at all.\n */\nexport function radialBarChartLabelText(options: {\n format: RadialBarChartLabelFormat;\n name: string | number | undefined;\n value: string | number | undefined;\n formatter?: TickFormatter;\n}): string {\n const { format, name, value, formatter } = options;\n if (value == null) return '';\n const valueText = formatter ? formatter(value) : String(value);\n return format === 'name-value' && name != null\n ? `${name}: ${valueText}`\n : valueText;\n}\n\n/** One piece of a segmented gauge's ring: a length in degrees and what it is. */\nexport interface RadialBarChartSegment {\n /** Synthetic series key — stable for a given (index, kind). */\n key: string;\n /** Angular length of the piece, in degrees. */\n degrees: number;\n /** `value` is the metric, `track` the unreached remainder, `gap` the notch. */\n kind: 'value' | 'track' | 'gap';\n}\n\n/** Fallback gap between a segmented gauge's segments, in degrees. */\nconst SEGMENT_GAP = 3;\n\n/**\n * Cut a gauge's sweep into equal segments separated by gaps, and split the\n * segment the value ends inside into its reached and unreached parts. Exported\n * for unit tests; not part of the package's public API.\n *\n * Lengths come back in **degrees**, which is what lets the ring be built as one\n * stack of synthetic series over a `[0, sweep]` angular scale: recharts lays\n * stacked radial bars out sequentially along the angle, so a transparent series\n * between two colored ones reads as a real notch in the ring. A `gap` that\n * would leave no room for the segments themselves is clamped.\n */\nexport function radialBarChartSegments(options: {\n value: number;\n domain: [number, number];\n segments: number;\n gap: number;\n /** Absolute sweep of the chart, in degrees. */\n sweep: number;\n /** A full-circle sweep also needs a gap between the last segment and the first. */\n closed: boolean;\n}): RadialBarChartSegment[] {\n const { value, domain, segments, sweep, closed } = options;\n const gapCount = closed ? segments : segments - 1;\n // Leave at least half the sweep for the segments, however wide a gap is asked\n // for — an all-gap ring would render as nothing at all. A negative gap would\n // stretch the pieces past the sweep and overlap them, so it floors at zero.\n const gap =\n gapCount > 0\n ? Math.min(Math.max(options.gap, 0), sweep / (2 * gapCount))\n : 0;\n const segmentDegrees = (sweep - gap * gapCount) / segments;\n const [min, max] = domain;\n const span = max - min;\n // A domain with no span (`[n, n]`) or an inverted one (`[max, min]`) cannot\n // place a value on the ring at all, so there is no fraction to draw and the\n // ring stays empty. It deliberately does not fall back to comparing the value\n // against zero: that reported a *full* ring for `{ value: 5, domain: [100,\n // 100] }`, i.e. claimed completion the data never supported. For a gauge,\n // under-reading a domain that says nothing is the safe direction.\n const fraction =\n span > 0 ? Math.min(Math.max((value - min) / span, 0), 1) : 0;\n // The value maps onto the *drawn* ring, so the gaps never eat into it.\n let remainingValue = fraction * segmentDegrees * segments;\n\n const pieces: RadialBarChartSegment[] = [];\n for (let index = 0; index < segments; index++) {\n const reached = Math.min(Math.max(remainingValue, 0), segmentDegrees);\n remainingValue -= reached;\n // Both halves are always emitted, including at zero length: a stable key set\n // keeps recharts' series identities steady as the value changes.\n pieces.push({ key: `seg-${index}-value`, degrees: reached, kind: 'value' });\n pieces.push({\n key: `seg-${index}-track`,\n degrees: segmentDegrees - reached,\n kind: 'track',\n });\n if (gap > 0 && (closed || index < segments - 1)) {\n pieces.push({ key: `seg-${index}-gap`, degrees: gap, kind: 'gap' });\n }\n }\n return pieces;\n}\n\n/**\n * Fill for one piece of a segmented gauge's ring. Exported for unit tests and so\n * the forced-open tooltip story can build a ring from the real implementation\n * rather than a copy of it; not part of the package's public API.\n */\nexport function radialBarChartSegmentFill(\n kind: RadialBarChartSegment['kind'],\n colorName: string | number\n): string {\n if (kind === 'gap') return 'transparent';\n // The unreached remainder plays the part `showBackground`'s track plays on a\n // continuous arc, so it takes the same muted surface.\n return kind === 'track'\n ? 'var(--ui-border-on-status-neutral)'\n : `var(--color-${toCssKey(String(colorName))})`;\n}\n\n/**\n * What a segmented gauge's tooltip reads. Exported for unit tests; not part of\n * the package's public API.\n *\n * A segmented ring's series are pieces of geometry, so recharts would offer the\n * hovered piece's own name and length (\"seg-3-value\", 41.2°). Hovering anywhere\n * on the ring should read the metric instead, so the reading is rebuilt from the\n * data row.\n */\nexport function radialBarChartSegmentedReading(options: {\n config: ChartConfig;\n row: RadialBarChartDatum;\n nameKey: string;\n dataKey: string;\n /** The `valueDomain` maximum, when the gauge has one. */\n domainMax?: number;\n}): { colorName: string; label: React.ReactNode; valueText: string } {\n const { config, row, nameKey, dataKey, domainMax } = options;\n const colorName = String(row[nameKey]);\n const value = row[dataKey];\n const valueText =\n typeof value === 'number' ? value.toLocaleString() : String(value ?? '');\n return {\n colorName,\n label: config[colorName]?.label ?? colorName,\n // The gauge's scale is the other half of the reading, so a known maximum\n // comes along: \"29 / 38\", not a bare \"29\".\n valueText:\n domainMax == null\n ? valueText\n : `${valueText} / ${domainMax.toLocaleString()}`,\n };\n}\n\n/**\n * The tooltip a segmented gauge shows — the same swatch/name/value layout the\n * default `ChartTooltipContent` row uses, dot included, over the reading from\n * `radialBarChartSegmentedReading`. Exported for the forced-open\n * visual-regression story; not part of the package's public API.\n *\n * `payload` is trimmed to one row: a radial tooltip is axis-shared and collects a\n * row from every series — two dozen identical rows for one metric.\n * (`tooltipType=\"none\"` only tags them, and scoping the tooltip to the hovered\n * item instead would drop it in the corner — unlike Pie/Bar sectors, a RadialBar\n * sector carries no tooltip coordinate.)\n *\n * A real component rather than a closure so it can be handed to `ChartTooltip`\n * as an *element*: recharts `cloneElement`s an element but `createElement`s a\n * function, and a closure rebuilt each render is a new element *type* — which\n * remounts the tooltip on every parent render instead of updating it.\n */\nexport function RadialBarChartSegmentedTooltipContent({\n active,\n payload,\n ...reading\n}: {\n active?: boolean;\n // Loosely typed on purpose: recharts' own payload generics are wider than the\n // shared `ChartTooltipContentProps` accepts, and only the row count matters.\n payload?: readonly unknown[];\n config: ChartConfig;\n row: RadialBarChartDatum;\n nameKey: string;\n dataKey: string;\n domainMax?: number;\n}) {\n const { colorName, label, valueText } =\n radialBarChartSegmentedReading(reading);\n\n return (\n <ChartTooltipContent\n active={active}\n payload={payload?.slice(0, 1) as ChartTooltipContentProps['payload']}\n hideLabel\n formatter={() => (\n <>\n <div\n className=\"h-2.5 w-2.5 shrink-0 rounded-full\"\n style={{ backgroundColor: `var(--color-${toCssKey(colorName)})` }}\n />\n <div className=\"flex flex-1 items-center justify-between gap-2 leading-none\">\n <span className=\"text-muted-foreground\">{label}</span>\n <span className=\"font-medium tabular-nums text-foreground\">\n {valueText}\n </span>\n </div>\n </>\n )}\n />\n );\n}\n\n/**\n * The band a multi-metric tooltip's header names. Exported for unit tests; not\n * part of the package's public API.\n *\n * Each tooltip row is one metric, so the header names the band the hovered arc\n * belongs to. recharts' own label is the radius-axis index, which reads as a\n * bare number.\n */\nexport function radialBarChartBandName(\n row: RadialBarChartDatum | undefined,\n nameKey: string\n): string {\n const name = row?.[nameKey];\n return name == null ? '' : String(name);\n}\n\n/**\n * What an arc's data label calls the arc: the row's own `nameKey` value, or — in\n * multi-metric mode, where one arc *is* one metric — that metric's `config` label.\n */\nfunction radialBarChartArcName(options: {\n key: string;\n row: RadialBarChartDatum | undefined;\n isMultiMetric: boolean;\n nameKey: string;\n config: ChartConfig;\n}): string | number | undefined {\n const { key, row, isMultiMetric, nameKey, config } = options;\n if (!isMultiMetric) return row?.[nameKey];\n // ChartConfig labels are ReactNode; only a plain string/number can go into an\n // SVG <text>.\n const label = config[key]?.label;\n return typeof label === 'string' || typeof label === 'number' ? label : key;\n}\n\n/**\n * The default mapping's arcs: one `RadialBar` per series — one for the single\n * `dataKey`, or one per `dataKeys` entry in multi-metric mode — drawn\n * concentrically.\n *\n * recharts collects its graphical items from the store (each `RadialBar`\n * registers itself on render) rather than by scanning the chart's children for\n * their types, so grouping them inside a component of our own is invisible to it.\n * The `Cell`s stay direct children of their `RadialBar`, which *does* read its own\n * children by type.\n */\nfunction RadialBarChartSeries({\n seriesKeys,\n seriesData,\n isMultiMetric,\n config,\n nameKey,\n showBackground,\n cornerRadius,\n minPointSize,\n animation,\n centerLabel,\n showLabels,\n labelPosition,\n labelFormat,\n labelFormatter,\n}: {\n seriesKeys: string[];\n seriesData: RadialBarChartDatum[];\n isMultiMetric: boolean;\n config: ChartConfig;\n nameKey: string;\n showBackground: boolean;\n cornerRadius: number;\n minPointSize: number | undefined;\n animation: ResolvedAnimation;\n centerLabel: RadialBarChartCenterLabel | undefined;\n showLabels: boolean;\n labelPosition: PolarLabelPosition;\n labelFormat: RadialBarChartLabelFormat;\n labelFormatter?: TickFormatter;\n}) {\n return seriesKeys.map((key, seriesIndex) => (\n <RadialBar\n key={key}\n dataKey={key}\n fill={isMultiMetric ? `var(--color-${toCssKey(key)})` : undefined}\n background={showBackground ? { fill: 'var(--ui-border-on-status-neutral)' } : false}\n cornerRadius={cornerRadius}\n minPointSize={minPointSize}\n {...animation}\n >\n {!isMultiMetric &&\n seriesData.map((entry, index) => (\n // Keyed by index, not the name: two arcs could share a nameKey\n // value, which would collide as a React key. Same-named arcs\n // intentionally share a color/config entry via `--color-<name>`.\n <Cell key={index} fill={`var(--color-${toCssKey(String(entry[nameKey]))})`} />\n ))}\n {seriesIndex === 0 && centerLabel && (\n <RadialBarChartCenterLabelContent centerLabel={centerLabel} />\n )}\n {showLabels && (\n <LabelList\n // `valueAccessor` rather than `dataKey`: the label text can\n // carry the arc's name, which only the whole row (single\n // metric) or the metric's config entry can supply. recharts\n // ignores the accessor when a dataKey is set, so the two\n // can't be combined.\n valueAccessor={(entry) =>\n radialBarChartLabelText({\n format: labelFormat,\n name: radialBarChartArcName({\n key,\n row: entry.payload as RadialBarChartDatum | undefined,\n isMultiMetric,\n nameKey,\n config,\n }),\n value: entry.value as string | number | undefined,\n formatter: labelFormatter,\n })\n }\n position={labelPosition}\n className={resolveLabelFillClass(labelPosition)}\n fontSize={CHART_LABEL_FONT_SIZE}\n />\n )}\n </RadialBar>\n ));\n}\n\n/**\n * A segmented gauge's ring: the pieces from `radialBarChartSegments` as one stack\n * of synthetic series, so they lay out sequentially around the ring instead of\n * concentrically and the `gap` pieces read as notches.\n */\nfunction RadialBarChartSegmentedSeries({\n ringSegments,\n row,\n nameKey,\n cornerRadius,\n animation,\n centerLabel,\n}: {\n ringSegments: RadialBarChartSegment[];\n row: RadialBarChartDatum;\n nameKey: string;\n cornerRadius: number;\n animation: ResolvedAnimation;\n centerLabel: RadialBarChartCenterLabel | undefined;\n}) {\n return ringSegments.map((segment, index) => (\n <RadialBar\n key={segment.key}\n dataKey={segment.key}\n stackId=\"segments\"\n // The metric's name, so the hover has a row to key off at all\n // (`ChartTooltipContent` keys its row off `name`).\n name={String(row[nameKey])}\n fill={radialBarChartSegmentFill(segment.kind, row[nameKey])}\n cornerRadius={cornerRadius}\n {...animation}\n >\n {index === 0 && centerLabel && (\n <RadialBarChartCenterLabelContent centerLabel={centerLabel} />\n )}\n </RadialBar>\n ));\n}\n\nexport interface RadialBarChartProps\n extends\n Omit<React.ComponentProps<'div'>, 'children'>,\n ChartAnimationProps,\n ChartDataLabelProps {\n /**\n * The dataviz palette this chart's series are painted from. Series that\n * state no `color` of their own take a stop of it. See `ChartPalette`.\n */\n palette?: ChartPalette;\n /** Row-per-arc data. Each object holds the arc's `nameKey` label + its `dataKey` numeric value. */\n data: ReadonlyArray<RadialBarChartDatum>;\n /**\n * Per-arc map of `label` / `icon` / `tone`, keyed by the arc's `nameKey` value\n * — or, in multi-metric mode, by each `dataKeys` entry (imported from the\n * shared `Chart` primitives). Turned into `--color-<name>` custom properties.\n * Series take their colour from the container's `palette`; each entry maps a\n * key to a `label` and an optional `tone`.\n */\n config: ChartConfig;\n /** Numeric field that sizes each arc. Ignored when `dataKeys` is set. */\n dataKey: string;\n /**\n * Plot several metrics instead of one arc per row: one arc per key, colored and\n * named from `config` keyed by the **key** (not by `nameKey`) — the same\n * convention as the cartesian charts. Every metric shares one angular scale, so\n * pair it with `valueDomain` when the metrics are measured against a known\n * maximum. `nameKey` still names the band each metric's arc sits in.\n */\n dataKeys?: string[];\n /**\n * Label field that names each arc (drives the legend, tooltip, and\n * `--color-<name>` lookup). Values should be unique per chart (arcs sharing a\n * name share one `config`/color entry); they are sanitized automatically to a\n * valid CSS custom-property fragment (CSS-safe values are preferred to avoid\n * dev-mode warnings). In multi-metric mode it names the band rather than the\n * arc, so the legend and colors come from `dataKeys` instead.\n */\n nameKey: string;\n /** Inner radius of the innermost arc. */\n innerRadius?: number;\n /** Outer radius of the outermost arc. */\n outerRadius?: number;\n /** Angle (degrees) the arcs sweep from. */\n startAngle?: number;\n /** Angle (degrees) the arcs sweep to (default is a full clockwise circle). */\n endAngle?: number;\n /**\n * The value range the sweep represents, as `[min, max]`. Without it every arc\n * is drawn relative to the largest value in the data — so a **single** value\n * always fills the whole sweep, which is never what a gauge means. Set it to\n * the metric's own scale (e.g. `[0, 100]` for a percentage) and each arc\n * becomes that fraction of the sweep, over the `showBackground` track.\n */\n valueDomain?: [number, number];\n /** Corner radius on each arc's ends. */\n cornerRadius?: number;\n /**\n * Horizontal center of the arcs, in px or a percentage of the width.\n * Defaults to the middle (`50%`).\n */\n cx?: number | string;\n /**\n * Vertical center of the arcs, in px or a percentage of the height. Defaults to\n * the middle (`50%`) — worth moving for a half-circle gauge, whose drawn half\n * otherwise sits in the upper half of the surface.\n */\n cy?: number | string;\n /** Thickness of each arc, in px. Omit to let the radii and the gaps size it. */\n barSize?: number;\n /** Gap between the arcs of different metrics in one band, in px. */\n barGap?: number | string;\n /** Gap between bands, in px or a percentage string. */\n barCategoryGap?: number | string;\n /**\n * Smallest angle a non-zero arc may occupy, in degrees, so a tiny value stays\n * visible (and hoverable). recharts applies the floor to a `0` as well, which\n * reads as a small positive value — leave this unset when a metric can\n * legitimately be zero.\n */\n minAngle?: number;\n /** Plot-area margin, in px. Omit to use recharts' default (5 on every side). */\n margin?: { top?: number; right?: number; bottom?: number; left?: number };\n /**\n * Draw the gauge's ring as this many equal segments, notched apart — the\n * segmented-gauge look. Applies to a **single-value gauge** only and needs\n * `valueDomain` to know what a full ring means. Anything that isn't one — more\n * than one row, `dataKeys` set, fewer than two segments, or a `dataKey` value\n * that isn't a number (a stringified `\"29\"` off an API) — falls back to the\n * normal concentric arcs, legend included, rather than erroring.\n *\n * The ring is then synthetic geometry rather than data rows, so the arc labels\n * and the legend are suppressed: put the readout in `centerLabel`. The tooltip\n * stays, and reads the metric (with the `valueDomain` maximum when there is\n * one) wherever on the ring it is hovered. `showBackground` is redundant too —\n * the unreached segments *are* the track.\n */\n segments?: number;\n /** Gap between a segmented gauge's segments, in degrees. Defaults to `3`. */\n segmentGap?: number;\n /** Render a muted background track behind each arc. */\n showBackground?: boolean;\n /** Draw the concentric polar grid behind the arcs. */\n showPolarGrid?: boolean;\n /**\n * Custom content for the hole at the center — a headline `value` and/or a\n * `label` caption, stacked and centered. Needs an `innerRadius` big enough to\n * hold the text; it is not clipped to the hole.\n */\n centerLabel?: RadialBarChartCenterLabel;\n showTooltip?: boolean;\n showLegend?: boolean;\n /**\n * Format each arc's value in the list legend. In single-metric mode each arc\n * row gets its formatted value next to its label; in multi-metric mode values\n * are per-row (not per-series) so this is ignored.\n */\n legendValueFormatter?: (value: string | number) => string;\n /**\n * Replace the default tooltip. Pass a configured `ChartTooltipContent`\n * (imported from this library) — e.g. with a `formatter` / `labelFormatter` —\n * to customize formatting, per-arc rows, or extra fields without composing\n * recharts yourself. Ignored when `showTooltip` is false.\n *\n * On a segmented gauge it takes over from the built-in reading, and the payload\n * it receives is the ring's synthetic pieces (`seg-2-track`, a length in\n * degrees) rather than data rows — read the metric off `payload[0].payload`.\n */\n tooltipContent?: React.ComponentProps<typeof ChartTooltip>['content'];\n /**\n * Position of the value labels when `showLabels` is on. Defaults to\n * `insideStart` — the labels sit inside each arc, and therefore render in the\n * on-fill label token so they stay legible over the arc colour.\n */\n labelPosition?: PolarLabelPosition;\n /**\n * What each data label reads when `showLabels` is on — the value alone (the\n * default), or the arc's name and its value. The name is the row's `nameKey`\n * value, or the metric's `config` label in multi-metric mode.\n */\n labelFormat?: RadialBarChartLabelFormat;\n}\n\nconst RadialBarChart = React.forwardRef<HTMLDivElement, RadialBarChartProps>(\n (\n {\n className,\n config,\n palette,\n data,\n dataKey,\n dataKeys,\n nameKey,\n innerRadius = 20,\n outerRadius = 60,\n startAngle = 90,\n endAngle = -270,\n valueDomain,\n cornerRadius = 4,\n cx,\n cy,\n barSize,\n barGap,\n barCategoryGap,\n minAngle,\n margin,\n segments,\n segmentGap = SEGMENT_GAP,\n showBackground = true,\n showPolarGrid = false,\n centerLabel,\n showTooltip = true,\n showLegend = true,\n legendValueFormatter,\n tooltipContent,\n animate,\n animationDuration,\n animationBegin,\n animationEasing,\n showLabels = false,\n labelPosition,\n labelFormat = 'value',\n labelFormatter,\n ...props\n },\n ref\n ) => {\n const animation = resolveAnimation({\n animate,\n animationDuration,\n animationBegin,\n animationEasing,\n });\n const arcLabelPosition = labelPosition ?? 'insideStart';\n const isMultiMetric = !!dataKeys?.length;\n // A segmented ring is one metric cut into pieces, so it only means anything\n // for a single-row, single-metric chart.\n const isSegmented =\n segments != null &&\n segments > 1 &&\n !isMultiMetric &&\n data.length === 1 &&\n typeof data[0][dataKey] === 'number';\n const seriesKeys = isMultiMetric ? dataKeys! : [dataKey];\n // Stable across renders so the memoized legend content below keeps its\n // identity; `seriesKeys` itself is a fresh array every render.\n const legendKeys = React.useMemo(\n () => (dataKeys?.length ? dataKeys : [dataKey]),\n [dataKeys, dataKey]\n );\n const sweep = Math.abs(endAngle - startAngle);\n const ringSegments = isSegmented\n ? radialBarChartSegments({\n value: data[0][dataKey] as number,\n // Without a domain a lone value is its own maximum, so the ring fills.\n domain: valueDomain ?? [0, data[0][dataKey] as number],\n segments: segments!,\n gap: segmentGap,\n sweep,\n closed: sweep >= 360,\n })\n : [];\n\n // Stamp each row with its `fill` (the shadcn data-driven pattern) so a real\n // hover resolves the arc color in the tooltip — recharts' RadialBar, like\n // Funnel, carries no per-arc color on the tooltip payload item. Only in\n // single-metric mode: with one color per *metric*, a row-level fill would\n // paint every tooltip swatch the same.\n const seriesData: RadialBarChartDatum[] = isMultiMetric\n ? (data as RadialBarChartDatum[])\n : data.map((row) => ({\n ...row,\n fill: `var(--color-${toCssKey(String(row[nameKey]))})`,\n }));\n\n // Each piece of the ring becomes a synthetic series on the one row, measured\n // in degrees — see `radialBarChartSegments`. Built from the raw row, *not*\n // from `seriesData`: a row-level `fill` wins over a series' own `fill` in\n // recharts, which would paint the track and the notches the arc's color.\n const plotData: RadialBarChartDatum[] = isSegmented\n ? [\n {\n ...data[0],\n ...Object.fromEntries(ringSegments.map((s) => [s.key, s.degrees])),\n },\n ]\n : seriesData;\n\n // recharts measures the radial floor in degrees, then extends the arc by\n // `mathSign(deltaAngle || minPointSize)`, where `deltaAngle` is the *arc's*\n // own angular length (RadialBar.js). So for a non-zero arc the floor already\n // grows along the arc's direction whatever sign it carries; the sign only\n // decides which way an arc of exactly zero degrees grows. Carry the sweep's\n // sign so that one grows forwards on a counter-clockwise chart too.\n const minPointSize =\n minAngle === undefined\n ? undefined\n : endAngle < startAngle\n ? -minAngle\n : minAngle;\n\n // Resolve colors so the external list legend has the same values as the chart\n // plot without needing to be inside ChartContainer's context.\n const resolvedConfigForLegend = React.useMemo(\n () => (showLegend ? resolveChartColors(config, palette ?? CHART_DEFAULT_PALETTE) : null),\n [showLegend, config, palette]\n );\n const rightLegendPayload: LegendPayload[] = React.useMemo(() => {\n if (!resolvedConfigForLegend) return [];\n if (isMultiMetric) {\n // Multi-metric: one entry per dataKey. No per-series row value is\n // meaningful (each metric spans multiple rows), so values are omitted.\n return legendKeys.map((key) => ({\n value: key,\n dataKey: key,\n color: resolvedConfigForLegend[key]?.color ?? `var(--color-${toCssKey(key)})`,\n type: 'rect' as const,\n payload: {} as Record<string, unknown>,\n }));\n }\n // Single-metric: one entry per data row.\n return data.map((row) => ({\n value: String(row[nameKey]),\n dataKey: nameKey,\n color:\n resolvedConfigForLegend[String(row[nameKey])]?.color ??\n `var(--color-${toCssKey(String(row[nameKey]))})`,\n type: 'rect' as const,\n payload: row as Record<string, unknown>,\n }));\n }, [resolvedConfigForLegend, isMultiMetric, legendKeys, data, nameKey]);\n\n const hasLegend = showLegend && !isSegmented && !!resolvedConfigForLegend;\n\n // The built-in tooltip reading, which each mapping composes differently: a\n // segmented ring rebuilds it from the data row, multi-metric renames the\n // header after the band, and the default mapping reads the hovered arc.\n const getDefaultTooltipContent = () => {\n if (isSegmented) {\n return (\n <RadialBarChartSegmentedTooltipContent\n config={config}\n row={data[0]}\n nameKey={nameKey}\n dataKey={dataKey}\n domainMax={valueDomain?.[1]}\n />\n );\n }\n\n if (isMultiMetric) {\n return (\n <ChartTooltipContent\n labelFormatter={(_, payload) =>\n radialBarChartBandName(\n payload?.[0]?.payload as RadialBarChartDatum | undefined,\n nameKey\n )\n }\n />\n );\n }\n\n return <ChartTooltipContent nameKey={nameKey} hideLabel />;\n };\n\n // Shared recharts chart composition (used in both layout modes).\n const radialChartContent = (\n <RechartsRadialBarChart\n data={plotData}\n // Only meaningful for the single-metric mapping; in multi-metric and\n // segmented mode each <RadialBar> carries its own key and the scale\n // spans them all.\n dataKey={isMultiMetric || isSegmented ? undefined : dataKey}\n cx={cx}\n cy={cy}\n innerRadius={innerRadius}\n outerRadius={outerRadius}\n startAngle={startAngle}\n endAngle={endAngle}\n barSize={barSize}\n barGap={barGap}\n barCategoryGap={barCategoryGap}\n margin={margin ?? { top: 0, right: 0, bottom: 0, left: 0 }}\n >\n {showPolarGrid && (\n <PolarGrid gridType=\"circle\" radialLines={false} />\n )}\n {(valueDomain || isSegmented) && (\n // The angular scale itself, not chrome: it maps a value onto a\n // fraction of the sweep. Ticks/axis line stay off — the arcs and\n // the optional center readout are the readout. A segmented ring is\n // already measured in degrees, so its scale *is* the sweep.\n <PolarAngleAxis\n type=\"number\"\n domain={isSegmented ? [0, sweep] : valueDomain}\n tick={false}\n axisLine={false}\n />\n )}\n {showTooltip && (\n <ChartTooltip\n // The hover cursor marks which band of the angular axis is\n // active, which on a segmented ring is one metric either way —\n // it just draws a hairline across the gauge.\n cursor={isSegmented ? false : undefined}\n content={tooltipContent ?? getDefaultTooltipContent()}\n />\n )}\n {isSegmented ? (\n <RadialBarChartSegmentedSeries\n ringSegments={ringSegments}\n row={data[0]}\n nameKey={nameKey}\n cornerRadius={cornerRadius}\n animation={animation}\n centerLabel={centerLabel}\n />\n ) : (\n <RadialBarChartSeries\n seriesKeys={seriesKeys}\n seriesData={seriesData}\n isMultiMetric={isMultiMetric}\n config={config}\n nameKey={nameKey}\n showBackground={showBackground}\n cornerRadius={cornerRadius}\n minPointSize={minPointSize}\n animation={animation}\n centerLabel={centerLabel}\n showLabels={showLabels}\n labelPosition={arcLabelPosition}\n labelFormat={labelFormat}\n labelFormatter={labelFormatter}\n />\n )}\n </RechartsRadialBarChart>\n );\n\n const chartDivSize =\n showLabels && (arcLabelPosition === 'outside' || arcLabelPosition === 'end')\n ? 'size-[200px]'\n : 'size-[120px]';\n\n return (\n <div\n ref={ref}\n className={cn('flex flex-row items-center gap-4', !hasLegend && 'justify-center', className)}\n {...props}\n >\n <div className={cn(chartDivSize, 'shrink-0')}>\n <ChartContainer config={config} palette={palette} className=\"size-full\">\n {radialChartContent}\n </ChartContainer>\n </div>\n {showLegend && !isSegmented && resolvedConfigForLegend && (\n <ChartLegendContent\n variant=\"list\"\n payload={rightLegendPayload}\n config={resolvedConfigForLegend}\n nameKey={isMultiMetric ? undefined : nameKey}\n valueKey={isMultiMetric ? undefined : dataKey}\n valueFormatter={isMultiMetric ? undefined : legendValueFormatter}\n className=\"min-w-0 flex-1\"\n />\n )}\n </div>\n );\n }\n);\nRadialBarChart.displayName = 'RadialBarChart';\n\nexport { RadialBarChart };\n"],"mappings":";;;;;;;;;AAoEA,SAAS,EAAiC,EACxC,kBAGC;CACD,OACE,kBAAC,GAAD,EACE,UAAU,EAAE,iBAAc;EACxB,IAAI,CAAC,KAAW,EAAE,QAAQ,IAAU,OAAO;EAC3C,IAAM,EAAE,IAAI,IAAU,GAAG,IAAI,IAAU,MAAM,GAIvC,IAAW,EAAY,SAAS,MAChC,IAAW,EAAY,SAAS,MAGhC,IAAO,KAAY;EACzB,OACE,kBAAC,KAAD,EAAA,UAAA,CACG,KACC,kBAAC,QAAD;GACE,GAAG;GACH,GAAG,IAAO,IAAU,KAAK;GACzB,YAAW;GACX,kBAAiB;GACjB,WAAU;GAET,UAAA,EAAY;EACT,CAAA,GAEP,KACC,kBAAC,QAAD;GACE,GAAG;GACH,GAAG,IAAO,IAAU,KAAK;GACzB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ACC;IACO;IACF;IACA;IACH;IACE;IACD;IACZ,eAAe;IACF;IACG;GACjB,CAAA;EAEmB;KAGpB,KACJ,MAAe,MAAqB,aAAa,MAAqB,SAClE,iBACA;CAEN,OACE,kBAAC,OAAD;EACO;EACL,WAAW,EAAG,oCAAoC,CAAC,MAAa,kBAAkB,CAAS;EAC3F,GAAI;EAHN,UAAA,CAKE,kBAAC,OAAD;GAAK,WAAW,EAAG,IAAc,UAAU;GACzC,UAAA,kBAAC,GAAD;IAAwB;IAAiB;IAAS,WAAU;IACzD,UAAA;GACa,CAAA;EACb,CAAA,GACJ,KAAc,CAAC,KAAe,KAC7B,kBAAC,GAAD;GACE,SAAQ;GACR,SAAS;GACT,QAAQ;GACR,SAAS,IAAgB,KAAA,IAAY;GACrC,UAAU,IAAgB,KAAA,IAAY;GACtC,gBAAgB,IAAgB,KAAA,IAAY;GAC5C,WAAU;EACX,CAAA,CAEA;;AAET,CACF;AACA,EAAe,cAAc"}
@@ -1,119 +1,119 @@
1
1
  "use client";
2
2
  import { cn as e } from "../../../lib/utils.js";
3
3
  import { CHART_DEFAULT_PALETTE as t } from "../chart/chart-palette.js";
4
- import { ChartContainer as n, ChartStyle as r, ChartTooltip as i, resolveChartColors as a } from "../chart/chart.js";
5
- import * as o from "react";
6
- import { jsx as s, jsxs as c } from "react/jsx-runtime";
7
- import { Rectangle as l, Sankey as u } from "recharts";
4
+ import { ChartContainer as n, ChartStyle as r, ChartTooltip as i, resolveChartColors as a, toCssKey as o } from "../chart/chart.js";
5
+ import * as s from "react";
6
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
7
+ import { Rectangle as u, Sankey as d } from "recharts";
8
8
  //#region src/components/ui/sankey-chart/sankey-chart.tsx
9
- function d(e, t, n) {
10
- return function({ x: r, y: i, width: a, height: o, index: u, payload: d }) {
11
- let f = String(d.name), p = e[f]?.label ?? f, m = t.has(u);
12
- return /* @__PURE__ */ c("g", { children: [/* @__PURE__ */ s(l, {
9
+ function f(e, t, n) {
10
+ return function({ x: r, y: i, width: a, height: s, index: d, payload: f }) {
11
+ let p = String(f.name), m = e[p]?.label ?? p, h = t.has(d);
12
+ return /* @__PURE__ */ l("g", { children: [/* @__PURE__ */ c(u, {
13
13
  x: r,
14
14
  y: i,
15
15
  width: a,
16
- height: o,
17
- fill: `var(--color-${f})`,
16
+ height: s,
17
+ fill: `var(--color-${o(p)})`,
18
18
  radius: 2
19
- }), n && /* @__PURE__ */ s("text", {
20
- x: m ? r + a + 6 : r - 6,
21
- y: i + o / 2,
22
- textAnchor: m ? "start" : "end",
19
+ }), n && /* @__PURE__ */ c("text", {
20
+ x: h ? r + a + 6 : r - 6,
21
+ y: i + s / 2,
22
+ textAnchor: h ? "start" : "end",
23
23
  dominantBaseline: "middle",
24
24
  className: "fill-foreground text-xs",
25
- children: p
25
+ children: m
26
26
  })] });
27
27
  };
28
28
  }
29
- function f({ sourceX: e, targetX: t, sourceY: n, targetY: r, sourceControlX: i, targetControlX: a, linkWidth: o, payload: c }) {
30
- let l = String(c.target.name), u = c.color ?? `var(--color-${l})`;
31
- return /* @__PURE__ */ s("path", {
29
+ function p({ sourceX: e, targetX: t, sourceY: n, targetY: r, sourceControlX: i, targetControlX: a, linkWidth: s, payload: l }) {
30
+ let u = String(l.target.name), d = l.color ?? `var(--color-${o(u)})`;
31
+ return /* @__PURE__ */ c("path", {
32
32
  d: `M${e},${n}C${i},${n} ${a},${r} ${t},${r}`,
33
33
  fill: "none",
34
- stroke: u,
35
- strokeWidth: Math.max(1, o),
36
- strokeOpacity: c.color ? 1 : .35
34
+ stroke: d,
35
+ strokeWidth: Math.max(1, s),
36
+ strokeOpacity: l.color ? 1 : .35
37
37
  });
38
38
  }
39
- function p(e, t, n) {
39
+ function m(e, t, n) {
40
40
  let r = (t) => e[t]?.label ?? t, i = /* @__PURE__ */ new Map();
41
41
  for (let e of t) {
42
42
  let t = n[e.source]?.name ?? "", r = n[e.target]?.name ?? "";
43
43
  i.set(t + " - " + r, {
44
- color: e.color ?? `var(--color-${r})`,
44
+ color: e.color ?? `var(--color-${o(r)})`,
45
45
  opacity: e.color ? 1 : .35
46
46
  });
47
47
  }
48
48
  return function({ active: e, payload: t }) {
49
49
  if (!e || !t?.length) return null;
50
- let n = t[0], a = String(n?.name ?? "").split(" - "), l = a[a.length - 1], u = i.get(String(n?.name ?? "")), d = u?.color ?? `var(--color-${l})`, f = u?.opacity ?? 1, p = n?.value;
51
- return /* @__PURE__ */ c("div", {
50
+ let n = t[0], a = String(n?.name ?? "").split(" - "), u = a[a.length - 1], d = i.get(String(n?.name ?? "")), f = d?.color ?? `var(--color-${o(u)})`, p = d?.opacity ?? 1, m = n?.value;
51
+ return /* @__PURE__ */ l("div", {
52
52
  className: "flex items-center gap-2 rounded-[var(--ui-tooltip-container-border-radius)] border border-border bg-background px-[var(--ui-tooltip-container-padding-x)] py-[var(--ui-tooltip-container-padding-y)] text-xs text-foreground shadow-md",
53
53
  children: [
54
- /* @__PURE__ */ s("span", {
54
+ /* @__PURE__ */ c("span", {
55
55
  className: "h-2.5 w-2.5 shrink-0 rounded-[2px]",
56
56
  style: {
57
- backgroundColor: d,
58
- opacity: f
57
+ backgroundColor: f,
58
+ opacity: p
59
59
  }
60
60
  }),
61
- /* @__PURE__ */ s("span", {
61
+ /* @__PURE__ */ c("span", {
62
62
  className: "text-muted-foreground",
63
- children: a.map((e, t) => /* @__PURE__ */ c(o.Fragment, { children: [t > 0 && " → ", r(e)] }, `${e}-${t}`))
63
+ children: a.map((e, t) => /* @__PURE__ */ l(s.Fragment, { children: [t > 0 && " → ", r(e)] }, `${e}-${t}`))
64
64
  }),
65
- p != null && /* @__PURE__ */ s("span", {
65
+ m != null && /* @__PURE__ */ c("span", {
66
66
  className: "ms-2 font-medium tabular-nums",
67
- children: m(p)
67
+ children: h(m)
68
68
  })
69
69
  ]
70
70
  });
71
71
  };
72
72
  }
73
- function m(e) {
74
- return Array.isArray(e) ? e.map((e) => m(e)).join(" – ") : typeof e == "number" ? e.toLocaleString() : String(e);
73
+ function h(e) {
74
+ return Array.isArray(e) ? e.map((e) => h(e)).join(" – ") : typeof e == "number" ? e.toLocaleString() : String(e);
75
75
  }
76
- var h = o.forwardRef(({ className: l, config: m, palette: h, data: g, nodePadding: _ = 24, nodeWidth: v = 12, linkCurvature: y = .5, sort: b = !1, showLabels: x = !0, showLegend: S = !1, showTooltip: C = !0, tooltipContent: w, ...T }, E) => {
77
- let D = `chart-${o.useId().replace(/:/g, "")}`, O = o.useMemo(() => new Set(g.links.map((e) => e.source)), [g.links]), k = o.useMemo(() => d(m, O, x), [
78
- m,
79
- O,
80
- x
81
- ]), A = o.useMemo(() => p(m, g.links, g.nodes), [
82
- m,
83
- g.links,
84
- g.nodes
85
- ]), j = o.useMemo(() => {
76
+ var g = s.forwardRef(({ className: u, config: h, palette: g, data: _, nodePadding: v = 24, nodeWidth: y = 12, linkCurvature: b = .5, sort: x = !1, showLabels: S = !0, showLegend: C = !1, showTooltip: w = !0, tooltipContent: T, ...E }, D) => {
77
+ let O = `chart-${s.useId().replace(/:/g, "")}`, k = s.useMemo(() => new Set(_.links.map((e) => e.source)), [_.links]), A = s.useMemo(() => f(h, k, S), [
78
+ h,
79
+ k,
80
+ S
81
+ ]), j = s.useMemo(() => m(h, _.links, _.nodes), [
82
+ h,
83
+ _.links,
84
+ _.nodes
85
+ ]), M = s.useMemo(() => {
86
86
  let e = /* @__PURE__ */ new Map(), t = /* @__PURE__ */ new Map();
87
- for (let n of g.links) t.set(n.source, (t.get(n.source) ?? 0) + n.value), e.set(n.target, (e.get(n.target) ?? 0) + n.value);
88
- let n = g.nodes.map((n, r) => e.get(r) ?? t.get(r) ?? 0), r = n.length ? Math.max(...n) : 0;
89
- return g.nodes.map((e, t) => ({
87
+ for (let n of _.links) t.set(n.source, (t.get(n.source) ?? 0) + n.value), e.set(n.target, (e.get(n.target) ?? 0) + n.value);
88
+ let n = _.nodes.map((n, r) => e.get(r) ?? t.get(r) ?? 0), r = n.length ? Math.max(...n) : 0;
89
+ return _.nodes.map((e, t) => ({
90
90
  name: e.name,
91
91
  value: n[t],
92
92
  pct: r > 0 ? Math.round(n[t] / r * 100) : 0
93
93
  }));
94
- }, [g]);
95
- return /* @__PURE__ */ c("div", {
96
- ref: E,
97
- "data-chart": D,
98
- className: e("flex flex-col", l),
99
- ...T,
94
+ }, [_]);
95
+ return /* @__PURE__ */ l("div", {
96
+ ref: D,
97
+ "data-chart": O,
98
+ className: e("flex flex-col", u),
99
+ ...E,
100
100
  children: [
101
- /* @__PURE__ */ s(r, {
102
- id: D,
103
- config: a(m, h ?? t)
101
+ /* @__PURE__ */ c(r, {
102
+ id: O,
103
+ config: a(h, g ?? t)
104
104
  }),
105
- /* @__PURE__ */ s(n, {
106
- config: m,
107
- palette: h,
105
+ /* @__PURE__ */ c(n, {
106
+ config: h,
107
+ palette: g,
108
108
  className: "min-h-0 flex-1",
109
- children: /* @__PURE__ */ s(u, {
110
- data: g,
111
- node: k,
112
- link: f,
113
- nodePadding: _,
114
- nodeWidth: v,
115
- linkCurvature: y,
116
- sort: b,
109
+ children: /* @__PURE__ */ c(d, {
110
+ data: _,
111
+ node: A,
112
+ link: p,
113
+ nodePadding: v,
114
+ nodeWidth: y,
115
+ linkCurvature: b,
116
+ sort: x,
117
117
  align: "left",
118
118
  margin: {
119
119
  top: 8,
@@ -121,28 +121,28 @@ var h = o.forwardRef(({ className: l, config: m, palette: h, data: g, nodePaddin
121
121
  bottom: 8,
122
122
  left: 24
123
123
  },
124
- children: C && /* @__PURE__ */ s(i, { content: w ?? A })
124
+ children: w && /* @__PURE__ */ c(i, { content: T ?? j })
125
125
  })
126
126
  }),
127
- S && /* @__PURE__ */ s("div", {
127
+ C && /* @__PURE__ */ c("div", {
128
128
  "data-slot": "sankey-chart-legend",
129
129
  className: "mt-3 grid grid-cols-2 gap-x-6 gap-y-1.5 text-xs",
130
- children: j.map(({ name: e, value: t, pct: n }) => /* @__PURE__ */ c("div", {
130
+ children: M.map(({ name: e, value: t, pct: n }) => /* @__PURE__ */ l("div", {
131
131
  className: "flex items-center gap-2",
132
132
  children: [
133
- /* @__PURE__ */ s("span", {
133
+ /* @__PURE__ */ c("span", {
134
134
  className: "size-2.5 shrink-0 rounded-sm",
135
- style: { backgroundColor: `var(--color-${e})` }
135
+ style: { backgroundColor: `var(--color-${o(e)})` }
136
136
  }),
137
- /* @__PURE__ */ s("span", {
137
+ /* @__PURE__ */ c("span", {
138
138
  className: "truncate text-muted-foreground",
139
- children: m[e]?.label ?? e
139
+ children: h[e]?.label ?? e
140
140
  }),
141
- /* @__PURE__ */ s("span", {
141
+ /* @__PURE__ */ c("span", {
142
142
  className: "ms-auto font-semibold tabular-nums",
143
143
  children: t.toLocaleString()
144
144
  }),
145
- /* @__PURE__ */ c("span", {
145
+ /* @__PURE__ */ l("span", {
146
146
  className: "w-9 shrink-0 text-end tabular-nums text-muted-foreground",
147
147
  children: [n, "%"]
148
148
  })
@@ -152,8 +152,8 @@ var h = o.forwardRef(({ className: l, config: m, palette: h, data: g, nodePaddin
152
152
  ]
153
153
  });
154
154
  });
155
- h.displayName = "SankeyChart";
155
+ g.displayName = "SankeyChart";
156
156
  //#endregion
157
- export { h as SankeyChart, p as makeSankeyTooltip };
157
+ export { g as SankeyChart, m as makeSankeyTooltip };
158
158
 
159
159
  //# sourceMappingURL=sankey-chart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sankey-chart.js","names":[],"sources":["../../../../src/components/ui/sankey-chart/sankey-chart.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Sankey as RechartsSankey, Rectangle } from 'recharts';\n\nimport { cn } from '@/lib/utils';\nimport {\n ChartContainer,\n ChartStyle,\n resolveChartColors,\n CHART_DEFAULT_PALETTE,\n ChartTooltip,\n type ChartConfig,\n type ChartPalette,\n} from '../chart';\n\n// A typed recharts composition over the shared `Chart` primitives — a flow\n// diagram where link width is proportional to the value flowing between nodes.\n// Like Treemap/Funnel it's a single recharts element (`<Sankey>`) themed through\n// custom `node` / `link` renderers (recharts' defaults paint one flat grey and\n// carry no token hooks). No CVA variant: a Sankey's expressiveness is the\n// nodes/links graph + geometry (plain props), not a visual \"mode\".\n//\n// Node `name`s are the color keys: each must match a `config` entry, so they\n// must be CSS-safe (they become part of a `--color-<name>` custom property).\n// The human-readable text comes from `config[name].label`.\n\n/** A node in the flow — `name` is its color/config key (CSS-safe, unique). */\nexport interface SankeyChartNode {\n name: string;\n}\n\n/** A directed flow between two nodes, referenced by their index in `nodes`. */\nexport interface SankeyChartLink {\n /** Index of the source node in `data.nodes`. */\n source: number;\n /** Index of the target node in `data.nodes`. */\n target: number;\n /** Flow magnitude — drives the link's width. */\n value: number;\n /**\n * Ribbon color (any CSS color, e.g. a `var(--ui-*)` token), rendered at **full\n * opacity** so it matches its node bar. Omit to use the target node's color at\n * 35% (the default tinted ribbon).\n */\n color?: string;\n}\n\nexport interface SankeyChartProps extends Omit<\n React.ComponentProps<'div'>,\n 'children'\n> {\n /**\n * The dataviz palette this chart's series are painted from. Series that\n * state no `color` of their own take a stop of it. See `ChartPalette`.\n */\n palette?: ChartPalette;\n /** The graph: `nodes` (color keys) + `links` (source/target indices + value). */\n data: {\n nodes: ReadonlyArray<SankeyChartNode>;\n links: ReadonlyArray<SankeyChartLink>;\n };\n /**\n * Per-node map of `label` / `icon` / `tone`, keyed by the node's `name`\n * (imported from the shared `Chart` primitives). Turned into `--color-<name>`\n * custom properties. Series take their colour from the container's `palette`;\n * each entry maps a key to a `label` and an optional `tone`.\n */\n config: ChartConfig;\n /** Vertical gap between nodes in the same column. */\n nodePadding?: number;\n /** Thickness of each node bar. */\n nodeWidth?: number;\n /** Curviness of the links (0 = straight, 1 = fully curved). */\n linkCurvature?: number;\n /**\n * Sort nodes vertically to minimize link crossings (recharts' relaxation).\n * Defaults to `false` — nodes render in the order given by `data.nodes` within\n * each column, which keeps curated flows tidy; set `true` to auto-order.\n */\n sort?: boolean;\n /** Render each node's label (from `config[name].label`) beside its bar. */\n showLabels?: boolean;\n /** Render a legend (color dot + label + value + % per node) below the chart. */\n showLegend?: boolean;\n /** Show a hover tooltip on nodes and links (dot + `source → target` + value). */\n showTooltip?: boolean;\n /**\n * Replace the default tooltip. Pass a configured `ChartTooltipContent`\n * (imported from this library) — e.g. with a `formatter` / `labelFormatter` —\n * to customize formatting without composing recharts yourself. Ignored when\n * `showTooltip` is false.\n */\n tooltipContent?: React.ComponentProps<typeof ChartTooltip>['content'];\n}\n\n// recharts injects these into the `node` / `link` render functions but doesn't\n// export their prop types from the package root, so we type the fields we use\n// (structurally compatible with recharts' internal NodeProps / LinkProps).\ninterface SankeyNodeShapeProps {\n x: number;\n y: number;\n width: number;\n height: number;\n index: number;\n payload: { name: string; value: number };\n}\n\ninterface SankeyLinkShapeProps {\n sourceX: number;\n targetX: number;\n sourceY: number;\n targetY: number;\n sourceControlX: number;\n targetControlX: number;\n linkWidth: number;\n // recharts spreads the original link onto `payload` (then overrides\n // source/target with node objects), so a custom `color` survives here.\n payload: {\n source: { name: string };\n target: { name: string };\n value: number;\n color?: string;\n };\n}\n\n// Node bar: a rect filled from `--color-<name>`, with the config label placed on\n// whichever side keeps it inside the plot — to the right for nodes that have\n// outgoing links (sources), to the left for terminal nodes (sinks).\nfunction makeNodeRenderer(\n config: ChartConfig,\n sourceIndices: ReadonlySet<number>,\n showLabels: boolean\n) {\n return function SankeyNodeShape({\n x,\n y,\n width,\n height,\n index,\n payload,\n }: SankeyNodeShapeProps) {\n const name = String(payload.name);\n const label = config[name]?.label ?? name;\n const isSource = sourceIndices.has(index);\n return (\n <g>\n <Rectangle\n x={x}\n y={y}\n width={width}\n height={height}\n fill={`var(--color-${name})`}\n radius={2}\n />\n {showLabels && (\n <text\n x={isSource ? x + width + 6 : x - 6}\n y={y + height / 2}\n textAnchor={isSource ? 'start' : 'end'}\n dominantBaseline=\"middle\"\n className=\"fill-foreground text-xs\"\n >\n {label}\n </text>\n )}\n </g>\n );\n };\n}\n\n// Link ribbon: a bezier stroked at 35% opacity in the link's own `color` if\n// given (recharts preserves custom link fields on the render `payload`), else\n// the **target** node's color (so a flow reads as \"where it goes\"). Drawn as a\n// stroke, not a fill, so the ribbon width comes from `linkWidth`.\nfunction SankeyLinkShape({\n sourceX,\n targetX,\n sourceY,\n targetY,\n sourceControlX,\n targetControlX,\n linkWidth,\n payload,\n}: SankeyLinkShapeProps) {\n const targetName = String(payload.target.name);\n const stroke = payload.color ?? `var(--color-${targetName})`;\n return (\n <path\n d={`M${sourceX},${sourceY}C${sourceControlX},${sourceY} ${targetControlX},${targetY} ${targetX},${targetY}`}\n fill=\"none\"\n stroke={stroke}\n strokeWidth={Math.max(1, linkWidth)}\n // An explicit per-link color is the caller's exact choice — render it at\n // full opacity (so it matches its node bar); the default target-tint is\n // dimmed to 35% so ribbons don't overwhelm the nodes.\n strokeOpacity={payload.color ? 1 : 0.35}\n />\n );\n}\n\n// Default tooltip: recharts' Sankey payload carries no config color, and labels\n// a hovered link \"source - target\" using the node keys (a node is a single key).\n// Parse that name to a color dot (the target node's color) + the mapped config\n// labels joined with an arrow + the value — driven by `config`, so it's reliable\n// where the shared ChartTooltipContent can't resolve the Sankey payload.\n//\n// Exported (module-only, not from the package barrel) so its branches can be\n// unit-tested directly: recharts can't lay out a Sankey in happy-dom, and its\n// hover tooltip has no statically-open form the component exposes, so rendering\n// `<SankeyChart>` never reaches this code.\nexport function makeSankeyTooltip(\n config: ChartConfig,\n links: ReadonlyArray<SankeyChartLink>,\n nodes: ReadonlyArray<SankeyChartNode>\n) {\n const labelFor = (key: string): React.ReactNode => config[key]?.label ?? key;\n // Resolve each link's dot color by its \"source - target\" name (which is the\n // tooltip item's name): the link's own color if set, else the target's, via\n // the `--color-<name>` bridge.\n const styleByName = new Map<string, { color: string; opacity: number }>();\n for (const link of links) {\n const source = nodes[link.source]?.name ?? '';\n const target = nodes[link.target]?.name ?? '';\n // Mirror the ribbon: an explicit color renders full-opacity; the default\n // target tint renders at 35%.\n styleByName.set(source + ' - ' + target, {\n color: link.color ?? `var(--color-${target})`,\n opacity: link.color ? 1 : 0.35,\n });\n }\n\n return function SankeyTooltipContent({\n active,\n payload,\n }: {\n active?: boolean;\n payload?: ReadonlyArray<{\n name?: string | number;\n value?: number | string | ReadonlyArray<number | string>;\n }>;\n }) {\n if (!active || !payload?.length) return null;\n const item = payload[0];\n const parts = String(item?.name ?? '').split(' - ');\n const targetKey = parts[parts.length - 1];\n const linkStyle = styleByName.get(String(item?.name ?? ''));\n const dotColor = linkStyle?.color ?? `var(--color-${targetKey})`;\n const dotOpacity = linkStyle?.opacity ?? 1;\n const value = item?.value;\n return (\n <div className=\"flex items-center gap-2 rounded-[var(--ui-tooltip-container-border-radius)] border border-border bg-background px-[var(--ui-tooltip-container-padding-x)] py-[var(--ui-tooltip-container-padding-y)] text-xs text-foreground shadow-md\">\n <span\n className=\"h-2.5 w-2.5 shrink-0 rounded-[2px]\"\n style={{ backgroundColor: dotColor, opacity: dotOpacity }}\n />\n <span className=\"text-muted-foreground\">\n {/* A config label can be any ReactNode, so the arrow-joined label is\n built as nodes rather than stringified. */}\n {parts.map((key, index) => (\n <React.Fragment key={`${key}-${index}`}>\n {index > 0 && ' → '}\n {labelFor(key)}\n </React.Fragment>\n ))}\n </span>\n {value != null && (\n <span className=\"ms-2 font-medium tabular-nums\">\n {formatTooltipValue(value)}\n </span>\n )}\n </div>\n );\n };\n}\n\n// recharts types a tooltip item's value as a scalar *or* a range tuple; a plain\n// `String()` would print \"1,2\" for the tuple, so format each part and join.\nfunction formatTooltipValue(\n value: number | string | ReadonlyArray<number | string>\n): string {\n if (Array.isArray(value)) {\n return value.map((part) => formatTooltipValue(part)).join(' – ');\n }\n return typeof value === 'number'\n ? value.toLocaleString()\n : String(value as string);\n}\n\nconst SankeyChart = React.forwardRef<HTMLDivElement, SankeyChartProps>(\n (\n {\n className,\n config,\n palette,\n data,\n nodePadding = 24,\n nodeWidth = 12,\n linkCurvature = 0.5,\n sort = false,\n showLabels = true,\n showLegend = false,\n showTooltip = true,\n tooltipContent,\n ...props\n },\n ref\n ) => {\n const uniqueId = React.useId();\n const chartId = `chart-${uniqueId.replace(/:/g, '')}`;\n\n // Node indices that appear as a link `source` have outgoing flow — used by\n // the node renderer to place the label on the readable side.\n const sourceIndices = React.useMemo(\n () => new Set(data.links.map((link) => link.source)),\n [data.links]\n );\n\n const nodeRenderer = React.useMemo(\n () => makeNodeRenderer(config, sourceIndices, showLabels),\n [config, sourceIndices, showLabels]\n );\n\n const defaultTooltip = React.useMemo(\n () => makeSankeyTooltip(config, data.links, data.nodes),\n [config, data.links, data.nodes]\n );\n\n // Per-node value (incoming flow, or outgoing for a source with no incoming)\n // and its share of the largest node — drives the legend's count + %.\n const nodeStats = React.useMemo(() => {\n const incoming = new Map<number, number>();\n const outgoing = new Map<number, number>();\n for (const link of data.links) {\n outgoing.set(\n link.source,\n (outgoing.get(link.source) ?? 0) + link.value\n );\n incoming.set(\n link.target,\n (incoming.get(link.target) ?? 0) + link.value\n );\n }\n const values = data.nodes.map(\n (_, i) => incoming.get(i) ?? outgoing.get(i) ?? 0\n );\n const total = values.length ? Math.max(...values) : 0;\n return data.nodes.map((node, i) => ({\n name: node.name,\n value: values[i],\n pct: total > 0 ? Math.round((values[i] / total) * 100) : 0,\n }));\n }, [data]);\n\n return (\n <div\n ref={ref}\n // The legend sits outside `ChartContainer`, so the root carries its own\n // `--color-<name>` scope for it (the plot and the recharts-portaled\n // tooltip resolve theirs from ChartContainer's).\n data-chart={chartId}\n className={cn('flex flex-col', className)}\n {...props}\n >\n <ChartStyle\n id={chartId}\n config={resolveChartColors(config, palette ?? CHART_DEFAULT_PALETTE)}\n />\n <ChartContainer\n config={config}\n palette={palette}\n className=\"min-h-0 flex-1\"\n >\n <RechartsSankey\n data={\n data as { nodes: SankeyChartNode[]; links: SankeyChartLink[] }\n }\n node={nodeRenderer}\n link={SankeyLinkShape}\n nodePadding={nodePadding}\n nodeWidth={nodeWidth}\n linkCurvature={linkCurvature}\n sort={sort}\n // recharts defaults to `justify`, which right-aligns sink nodes to\n // the last column — so a terminal node like \"No certification\" would\n // jump to the far right instead of staying at its real depth. `left`\n // positions every node by its distance from the source, keeping the\n // flow's columns intact.\n align=\"left\"\n // Node labels never extend past the plot's right edge: a node in the\n // last column has no outgoing links, so its label is drawn to the\n // LEFT of its bar (see the node renderer). Only a small gutter is\n // needed here — a wide reserve would just shrink the diagram.\n margin={{ top: 8, right: 24, bottom: 8, left: 24 }}\n >\n {showTooltip && (\n <ChartTooltip content={tooltipContent ?? defaultTooltip} />\n )}\n </RechartsSankey>\n </ChartContainer>\n {showLegend && (\n <div\n data-slot=\"sankey-chart-legend\"\n className=\"mt-3 grid grid-cols-2 gap-x-6 gap-y-1.5 text-xs\"\n >\n {nodeStats.map(({ name, value, pct }) => (\n <div key={name} className=\"flex items-center gap-2\">\n <span\n className=\"size-2.5 shrink-0 rounded-sm\"\n style={{ backgroundColor: `var(--color-${name})` }}\n />\n <span className=\"truncate text-muted-foreground\">\n {config[name]?.label ?? name}\n </span>\n <span className=\"ms-auto font-semibold tabular-nums\">\n {value.toLocaleString()}\n </span>\n <span className=\"w-9 shrink-0 text-end tabular-nums text-muted-foreground\">\n {pct}%\n </span>\n </div>\n ))}\n </div>\n )}\n </div>\n );\n }\n);\nSankeyChart.displayName = 'SankeyChart';\n\nexport { SankeyChart };\n"],"mappings":";;;;;;;;AAiIA,SAAS,EACP,GACA,GACA,GACA;CACA,OAAO,SAAyB,EAC9B,MACA,MACA,UACA,WACA,UACA,cACuB;EACvB,IAAM,IAAO,OAAO,EAAQ,IAAI,GAC1B,IAAQ,EAAO,EAAK,EAAE,SAAS,GAC/B,IAAW,EAAc,IAAI,CAAK;EACxC,OACE,kBAAC,KAAD,EAAA,UAAA,CACE,kBAAC,GAAD;GACK;GACA;GACI;GACC;GACR,MAAM,eAAe,EAAK;GAC1B,QAAQ;EACT,CAAA,GACA,KACC,kBAAC,QAAD;GACE,GAAG,IAAW,IAAI,IAAQ,IAAI,IAAI;GAClC,GAAG,IAAI,IA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kBAAC,QAAD;OAAM,WAAU;OACb,UAAA,EAAM,eAAe;MAClB,CAAA;MACN,kBAAC,QAAD;OAAM,WAAU;OAAhB,UAAA,CACG,GAAI,GACD;;KACH;IAdK,GAAA,CAcL,CACN;GACE,CAAA;EAEJ;;AAET,CACF;AACA,EAAY,cAAc"}
1
+ {"version":3,"file":"sankey-chart.js","names":[],"sources":["../../../../src/components/ui/sankey-chart/sankey-chart.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport { Sankey as RechartsSankey, Rectangle } from 'recharts';\n\nimport { cn } from '@/lib/utils';\nimport {\n ChartContainer,\n ChartStyle,\n resolveChartColors,\n CHART_DEFAULT_PALETTE,\n ChartTooltip,\n toCssKey,\n type ChartConfig,\n type ChartPalette,\n} from '../chart';\n\n// A typed recharts composition over the shared `Chart` primitives — a flow\n// diagram where link width is proportional to the value flowing between nodes.\n// Like Treemap/Funnel it's a single recharts element (`<Sankey>`) themed through\n// custom `node` / `link` renderers (recharts' defaults paint one flat grey and\n// carry no token hooks). No CVA variant: a Sankey's expressiveness is the\n// nodes/links graph + geometry (plain props), not a visual \"mode\".\n//\n// Node `name`s are the color keys: each must match a `config` entry. They are\n// sanitized automatically to a valid CSS custom-property fragment; CSS-safe\n// names are preferred to avoid dev-mode warnings.\n// The human-readable text comes from `config[name].label`.\n\n/** A node in the flow — `name` is its color/config key (unique; sanitized automatically to a CSS-safe fragment). */\nexport interface SankeyChartNode {\n name: string;\n}\n\n/** A directed flow between two nodes, referenced by their index in `nodes`. */\nexport interface SankeyChartLink {\n /** Index of the source node in `data.nodes`. */\n source: number;\n /** Index of the target node in `data.nodes`. */\n target: number;\n /** Flow magnitude — drives the link's width. */\n value: number;\n /**\n * Ribbon color (any CSS color, e.g. a `var(--ui-*)` token), rendered at **full\n * opacity** so it matches its node bar. Omit to use the target node's color at\n * 35% (the default tinted ribbon).\n */\n color?: string;\n}\n\nexport interface SankeyChartProps extends Omit<\n React.ComponentProps<'div'>,\n 'children'\n> {\n /**\n * The dataviz palette this chart's series are painted from. Series that\n * state no `color` of their own take a stop of it. See `ChartPalette`.\n */\n palette?: ChartPalette;\n /** The graph: `nodes` (color keys) + `links` (source/target indices + value). */\n data: {\n nodes: ReadonlyArray<SankeyChartNode>;\n links: ReadonlyArray<SankeyChartLink>;\n };\n /**\n * Per-node map of `label` / `icon` / `tone`, keyed by the node's `name`\n * (imported from the shared `Chart` primitives). Turned into `--color-<name>`\n * custom properties. Series take their colour from the container's `palette`;\n * each entry maps a key to a `label` and an optional `tone`.\n */\n config: ChartConfig;\n /** Vertical gap between nodes in the same column. */\n nodePadding?: number;\n /** Thickness of each node bar. */\n nodeWidth?: number;\n /** Curviness of the links (0 = straight, 1 = fully curved). */\n linkCurvature?: number;\n /**\n * Sort nodes vertically to minimize link crossings (recharts' relaxation).\n * Defaults to `false` — nodes render in the order given by `data.nodes` within\n * each column, which keeps curated flows tidy; set `true` to auto-order.\n */\n sort?: boolean;\n /** Render each node's label (from `config[name].label`) beside its bar. */\n showLabels?: boolean;\n /** Render a legend (color dot + label + value + % per node) below the chart. */\n showLegend?: boolean;\n /** Show a hover tooltip on nodes and links (dot + `source → target` + value). */\n showTooltip?: boolean;\n /**\n * Replace the default tooltip. Pass a configured `ChartTooltipContent`\n * (imported from this library) — e.g. with a `formatter` / `labelFormatter` —\n * to customize formatting without composing recharts yourself. Ignored when\n * `showTooltip` is false.\n */\n tooltipContent?: React.ComponentProps<typeof ChartTooltip>['content'];\n}\n\n// recharts injects these into the `node` / `link` render functions but doesn't\n// export their prop types from the package root, so we type the fields we use\n// (structurally compatible with recharts' internal NodeProps / LinkProps).\ninterface SankeyNodeShapeProps {\n x: number;\n y: number;\n width: number;\n height: number;\n index: number;\n payload: { name: string; value: number };\n}\n\ninterface SankeyLinkShapeProps {\n sourceX: number;\n targetX: number;\n sourceY: number;\n targetY: number;\n sourceControlX: number;\n targetControlX: number;\n linkWidth: number;\n // recharts spreads the original link onto `payload` (then overrides\n // source/target with node objects), so a custom `color` survives here.\n payload: {\n source: { name: string };\n target: { name: string };\n value: number;\n color?: string;\n };\n}\n\n// Node bar: a rect filled from `--color-<name>`, with the config label placed on\n// whichever side keeps it inside the plot — to the right for nodes that have\n// outgoing links (sources), to the left for terminal nodes (sinks).\nfunction makeNodeRenderer(\n config: ChartConfig,\n sourceIndices: ReadonlySet<number>,\n showLabels: boolean\n) {\n return function SankeyNodeShape({\n x,\n y,\n width,\n height,\n index,\n payload,\n }: SankeyNodeShapeProps) {\n const name = String(payload.name);\n const label = config[name]?.label ?? name;\n const isSource = sourceIndices.has(index);\n return (\n <g>\n <Rectangle\n x={x}\n y={y}\n width={width}\n height={height}\n fill={`var(--color-${toCssKey(name)})`}\n radius={2}\n />\n {showLabels && (\n <text\n x={isSource ? x + width + 6 : x - 6}\n y={y + height / 2}\n textAnchor={isSource ? 'start' : 'end'}\n dominantBaseline=\"middle\"\n className=\"fill-foreground text-xs\"\n >\n {label}\n </text>\n )}\n </g>\n );\n };\n}\n\n// Link ribbon: a bezier stroked at 35% opacity in the link's own `color` if\n// given (recharts preserves custom link fields on the render `payload`), else\n// the **target** node's color (so a flow reads as \"where it goes\"). Drawn as a\n// stroke, not a fill, so the ribbon width comes from `linkWidth`.\nfunction SankeyLinkShape({\n sourceX,\n targetX,\n sourceY,\n targetY,\n sourceControlX,\n targetControlX,\n linkWidth,\n payload,\n}: SankeyLinkShapeProps) {\n const targetName = String(payload.target.name);\n const stroke = payload.color ?? `var(--color-${toCssKey(targetName)})`;\n return (\n <path\n d={`M${sourceX},${sourceY}C${sourceControlX},${sourceY} ${targetControlX},${targetY} ${targetX},${targetY}`}\n fill=\"none\"\n stroke={stroke}\n strokeWidth={Math.max(1, linkWidth)}\n // An explicit per-link color is the caller's exact choice — render it at\n // full opacity (so it matches its node bar); the default target-tint is\n // dimmed to 35% so ribbons don't overwhelm the nodes.\n strokeOpacity={payload.color ? 1 : 0.35}\n />\n );\n}\n\n// Default tooltip: recharts' Sankey payload carries no config color, and labels\n// a hovered link \"source - target\" using the node keys (a node is a single key).\n// Parse that name to a color dot (the target node's color) + the mapped config\n// labels joined with an arrow + the value — driven by `config`, so it's reliable\n// where the shared ChartTooltipContent can't resolve the Sankey payload.\n//\n// Exported (module-only, not from the package barrel) so its branches can be\n// unit-tested directly: recharts can't lay out a Sankey in happy-dom, and its\n// hover tooltip has no statically-open form the component exposes, so rendering\n// `<SankeyChart>` never reaches this code.\nexport function makeSankeyTooltip(\n config: ChartConfig,\n links: ReadonlyArray<SankeyChartLink>,\n nodes: ReadonlyArray<SankeyChartNode>\n) {\n const labelFor = (key: string): React.ReactNode => config[key]?.label ?? key;\n // Resolve each link's dot color by its \"source - target\" name (which is the\n // tooltip item's name): the link's own color if set, else the target's, via\n // the `--color-<name>` bridge.\n const styleByName = new Map<string, { color: string; opacity: number }>();\n for (const link of links) {\n const source = nodes[link.source]?.name ?? '';\n const target = nodes[link.target]?.name ?? '';\n // Mirror the ribbon: an explicit color renders full-opacity; the default\n // target tint renders at 35%.\n styleByName.set(source + ' - ' + target, {\n color: link.color ?? `var(--color-${toCssKey(target)})`,\n opacity: link.color ? 1 : 0.35,\n });\n }\n\n return function SankeyTooltipContent({\n active,\n payload,\n }: {\n active?: boolean;\n payload?: ReadonlyArray<{\n name?: string | number;\n value?: number | string | ReadonlyArray<number | string>;\n }>;\n }) {\n if (!active || !payload?.length) return null;\n const item = payload[0];\n const parts = String(item?.name ?? '').split(' - ');\n const targetKey = parts[parts.length - 1];\n const linkStyle = styleByName.get(String(item?.name ?? ''));\n const dotColor = linkStyle?.color ?? `var(--color-${toCssKey(targetKey)})`;\n const dotOpacity = linkStyle?.opacity ?? 1;\n const value = item?.value;\n return (\n <div className=\"flex items-center gap-2 rounded-[var(--ui-tooltip-container-border-radius)] border border-border bg-background px-[var(--ui-tooltip-container-padding-x)] py-[var(--ui-tooltip-container-padding-y)] text-xs text-foreground shadow-md\">\n <span\n className=\"h-2.5 w-2.5 shrink-0 rounded-[2px]\"\n style={{ backgroundColor: dotColor, opacity: dotOpacity }}\n />\n <span className=\"text-muted-foreground\">\n {/* A config label can be any ReactNode, so the arrow-joined label is\n built as nodes rather than stringified. */}\n {parts.map((key, index) => (\n <React.Fragment key={`${key}-${index}`}>\n {index > 0 && ' → '}\n {labelFor(key)}\n </React.Fragment>\n ))}\n </span>\n {value != null && (\n <span className=\"ms-2 font-medium tabular-nums\">\n {formatTooltipValue(value)}\n </span>\n )}\n </div>\n );\n };\n}\n\n// recharts types a tooltip item's value as a scalar *or* a range tuple; a plain\n// `String()` would print \"1,2\" for the tuple, so format each part and join.\nfunction formatTooltipValue(\n value: number | string | ReadonlyArray<number | string>\n): string {\n if (Array.isArray(value)) {\n return value.map((part) => formatTooltipValue(part)).join(' – ');\n }\n return typeof value === 'number'\n ? value.toLocaleString()\n : String(value as string);\n}\n\nconst SankeyChart = React.forwardRef<HTMLDivElement, SankeyChartProps>(\n (\n {\n className,\n config,\n palette,\n data,\n nodePadding = 24,\n nodeWidth = 12,\n linkCurvature = 0.5,\n sort = false,\n showLabels = true,\n showLegend = false,\n showTooltip = true,\n tooltipContent,\n ...props\n },\n ref\n ) => {\n const uniqueId = React.useId();\n const chartId = `chart-${uniqueId.replace(/:/g, '')}`;\n\n // Node indices that appear as a link `source` have outgoing flow — used by\n // the node renderer to place the label on the readable side.\n const sourceIndices = React.useMemo(\n () => new Set(data.links.map((link) => link.source)),\n [data.links]\n );\n\n const nodeRenderer = React.useMemo(\n () => makeNodeRenderer(config, sourceIndices, showLabels),\n [config, sourceIndices, showLabels]\n );\n\n const defaultTooltip = React.useMemo(\n () => makeSankeyTooltip(config, data.links, data.nodes),\n [config, data.links, data.nodes]\n );\n\n // Per-node value (incoming flow, or outgoing for a source with no incoming)\n // and its share of the largest node — drives the legend's count + %.\n const nodeStats = React.useMemo(() => {\n const incoming = new Map<number, number>();\n const outgoing = new Map<number, number>();\n for (const link of data.links) {\n outgoing.set(\n link.source,\n (outgoing.get(link.source) ?? 0) + link.value\n );\n incoming.set(\n link.target,\n (incoming.get(link.target) ?? 0) + link.value\n );\n }\n const values = data.nodes.map(\n (_, i) => incoming.get(i) ?? outgoing.get(i) ?? 0\n );\n const total = values.length ? Math.max(...values) : 0;\n return data.nodes.map((node, i) => ({\n name: node.name,\n value: values[i],\n pct: total > 0 ? Math.round((values[i] / total) * 100) : 0,\n }));\n }, [data]);\n\n return (\n <div\n ref={ref}\n // The legend sits outside `ChartContainer`, so the root carries its own\n // `--color-<name>` scope for it (the plot and the recharts-portaled\n // tooltip resolve theirs from ChartContainer's).\n data-chart={chartId}\n className={cn('flex flex-col', className)}\n {...props}\n >\n <ChartStyle\n id={chartId}\n config={resolveChartColors(config, palette ?? CHART_DEFAULT_PALETTE)}\n />\n <ChartContainer\n config={config}\n palette={palette}\n className=\"min-h-0 flex-1\"\n >\n <RechartsSankey\n data={\n data as { nodes: SankeyChartNode[]; links: SankeyChartLink[] }\n }\n node={nodeRenderer}\n link={SankeyLinkShape}\n nodePadding={nodePadding}\n nodeWidth={nodeWidth}\n linkCurvature={linkCurvature}\n sort={sort}\n // recharts defaults to `justify`, which right-aligns sink nodes to\n // the last column — so a terminal node like \"No certification\" would\n // jump to the far right instead of staying at its real depth. `left`\n // positions every node by its distance from the source, keeping the\n // flow's columns intact.\n align=\"left\"\n // Node labels never extend past the plot's right edge: a node in the\n // last column has no outgoing links, so its label is drawn to the\n // LEFT of its bar (see the node renderer). Only a small gutter is\n // needed here — a wide reserve would just shrink the diagram.\n margin={{ top: 8, right: 24, bottom: 8, left: 24 }}\n >\n {showTooltip && (\n <ChartTooltip content={tooltipContent ?? defaultTooltip} />\n )}\n </RechartsSankey>\n </ChartContainer>\n {showLegend && (\n <div\n data-slot=\"sankey-chart-legend\"\n className=\"mt-3 grid grid-cols-2 gap-x-6 gap-y-1.5 text-xs\"\n >\n {nodeStats.map(({ name, value, pct }) => (\n <div key={name} className=\"flex items-center gap-2\">\n <span\n className=\"size-2.5 shrink-0 rounded-sm\"\n style={{ backgroundColor: `var(--color-${toCssKey(name)})` }}\n />\n <span className=\"truncate text-muted-foreground\">\n {config[name]?.label ?? name}\n </span>\n <span className=\"ms-auto font-semibold tabular-nums\">\n {value.toLocaleString()}\n </span>\n <span className=\"w-9 shrink-0 text-end tabular-nums text-muted-foreground\">\n {pct}%\n </span>\n </div>\n ))}\n </div>\n )}\n </div>\n );\n }\n);\nSankeyChart.displayName = 'SankeyChart';\n\nexport { SankeyChart };\n"],"mappings":";;;;;;;;AAmIA,SAAS,EACP,GACA,GACA,GACA;CACA,OAAO,SAAyB,EAC9B,MACA,MACA,UACA,WACA,UACA,cACuB;EACvB,IAAM,IAAO,OAAO,EAAQ,IAAI,GAC1B,IAAQ,EAAO,EAAK,EAAE,SAAS,GAC/B,IAAW,EAAc,IAAI,CAAK;EACxC,OACE,kBAAC,KAAD,EAAA,UAAA,CACE,kBAAC,GAAD;GACK;GACA;GACI;GACC;GACR,MAAM,eAAe,EAAS,CAAI,EAAE;GACpC,QAAQ;EACT,CAAA,GACA,KACC,kBAAC,QAAD;GACE,GAAG,IAAW,IAAI,IAAQ,IAAI,IAAI;GAClC,GAAG,IAAI,IAAS;GAChB,YAAY,IAAW,UAAU;GACjC,kBAAiB;GACjB,WAAU;GAET,UAAA;EACG,CAAA,CAEP,EAAA,CAAA;CAEP;AACF;AAMA,SAAS,EAAgB,EACvB,YACA,YACA,YACA,YACA,mBACA,mBACA,cACA,cACuB;CACvB,IAAM,IAAa,OAAO,EAAQ,OAAO,IAAI,GACvC,IAAS,EAAQ,SAAS,eAAe,EAAS,CAAU,EAAE;CACpE,OACE,kBAAC,QAAD;EACE,GAAG,IAAI,EAAQ,GAAG,EAAQ,GAAG,EAAe,GAAG,EAAQ,GAAG,EAAe,GAAG,EAAQ,GAAG,EAAQ,GAAG;EAClG,MAAK;EACG;EACR,aAAa,KAAK,IAAI,GAAG,CAAS;EAIlC,eAAe,EAAQ,QAAQ,IAAI;CACpC,CAAA;AAEL;AAYA,SAAgB,EACd,GACA,GACA,GACA;CACA,I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