@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":"confidence-cone.js","names":[],"sources":["../../../../src/components/ui/confidence-cone/confidence-cone.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport {\n Area,\n CartesianGrid,\n ComposedChart,\n Line,\n ReferenceArea,\n ReferenceLine,\n Text,\n XAxis,\n YAxis,\n} from 'recharts';\n\nimport { cn } from '@/lib/utils';\nimport {\n ChartContainer,\n ChartLegend,\n ChartLegendContent,\n ChartTooltip,\n ChartTooltipContent,\n resolveAxisDomain,\n resolveAnimation,\n resolveRotatedTickAnchor,\n resolveXAxisHeight,\n resolveXAxisTitle,\n resolveYAxisTitle,\n CHART_LABEL_FONT_SIZE,\n type ChartConfig,\n type ChartPalette,\n type ChartLegendContentProps,\n type ChartTooltipContentProps,\n type CartesianChartProps,\n type ChartAnimationProps,\n} from '../chart';\n\n// A forecast confidence-cone: a solid line over the known/actual period, a\n// dashed line over the forecast period, and a shaded band (the \"cone\") between\n// a lower and upper bound that typically widens with the horizon — visualizing\n// growing uncertainty. Built on the shared Chart primitives; no new tokens\n// (series colors are caller-supplied via `config`). The whole metric renders in\n// one hue — actual and forecast differ by line style, not color — so the cone\n// band and the forecast line both reuse the actual series' color.\n\n// Each series' band is a synthetic `[lower, upper]` range field per row that a\n// recharts <Area> shades; kept out of the tooltip/legend (see the filters\n// below). One band per series, so the key carries the series' actual key — the\n// whole `__cone` prefix is reserved.\nconst BAND_PREFIX = '__cone';\nconst bandKeyFor = (actualKey: string) => `${BAND_PREFIX}:${actualKey}`;\n\n/**\n * Drop every synthetic cone-band range series from a recharts tooltip/legend\n * payload, keeping the real actual/forecast series (and their order). Applied to\n * both the default tooltip and any caller-supplied `tooltipContent`, so no band\n * surfaces regardless of which path renders or how many series are plotted.\n */\nexport function dropConeBand<T extends { dataKey?: unknown }>(\n payload: readonly T[] | undefined\n): T[] | undefined {\n return payload?.filter(\n (item) =>\n !(\n typeof item.dataKey === 'string' && item.dataKey.startsWith(BAND_PREFIX)\n )\n );\n}\n\n/**\n * Reduce a legend payload to the metrics the chart plots — one entry per series.\n * A series' actual, forecast and cone are three recharts series painting a\n * single metric in a single hue, so the legend names each metric once, with its\n * actual series' swatch, instead of listing line styles as separate series.\n */\nexport function keepMetricSeries<T extends { dataKey?: unknown }>(\n payload: readonly T[] | undefined,\n actualKeys: readonly string[]\n): T[] | undefined {\n return payload?.filter(\n (item) =>\n typeof item.dataKey === 'string' && actualKeys.includes(item.dataKey)\n );\n}\n\n/**\n * Wrap a caller-supplied `tooltipContent` so the synthetic cone band is stripped\n * from the payload before it renders, while preserving recharts' own mount\n * semantics — a function is mounted via `createElement` (its own component\n * identity + hook state), an element via `cloneElement`. This mirrors what the\n * pass-through charts get by handing `content` straight to recharts, so a\n * function-form tooltip keeps its state across re-renders here too. The returned\n * component is a stable content type (memoize it on `tooltipContent`).\n */\ntype TooltipContentType = NonNullable<\n React.ComponentProps<typeof ChartTooltip>['content']\n>;\ntype TooltipContentFn = Extract<\n TooltipContentType,\n (...args: never[]) => unknown\n>;\ntype TooltipRenderProps = Parameters<TooltipContentFn>[0];\n\nexport function createConeTooltip(tooltipContent: TooltipContentType) {\n return function ConeTooltip(props: TooltipRenderProps) {\n const merged = {\n ...props,\n payload: dropConeBand(props.payload),\n } as TooltipRenderProps;\n return typeof tooltipContent === 'function'\n ? React.createElement(\n tooltipContent as React.FunctionComponent<TooltipRenderProps>,\n merged\n )\n : React.cloneElement(tooltipContent, merged);\n };\n}\n\n/**\n * One plotted metric: its actual / forecast columns and, optionally, the two\n * bound columns that shade its cone. Omit `lowerKey`/`upperKey` for a band-less\n * metric — a solid line handing off to a bare dashed projection.\n */\nexport interface ConfidenceConeSeries {\n /** Field for the known/actual values — drawn as a solid line with a filled area. */\n actualKey: string;\n /** Field for the projected values — drawn as a dashed line. */\n forecastKey: string;\n /** Field for the cone's lower bound. Omit (with `upperKey`) for no cone. */\n lowerKey?: string;\n /** Field for the cone's upper bound. Omit (with `lowerKey`) for no cone. */\n upperKey?: string;\n}\n\n/**\n * The x values of the projected period — every row carrying a forecast value for\n * at least one series, in data order. The first is the hand-off point (where the\n * shaded region and divider start); the whole set drives the forecast tick\n * styling, matched by value so tick `interval` can't skew it the way a tick\n * index would. Exported for unit tests; not part of the package's public API.\n */\nexport function forecastPeriodX(\n data: ReadonlyArray<Record<string, string | number | null | undefined>>,\n series: readonly ConfidenceConeSeries[],\n xKey: string\n): Array<string | number | null | undefined> {\n return data\n .filter((row) =>\n series.some(({ forecastKey }) => typeof row[forecastKey] === 'number')\n )\n .map((row) => row[xKey]);\n}\n\n/**\n * Build the X-axis tick renderer that sets the projected columns apart: italic,\n * in the metric's hue. Styled inline rather than through the `fill` attribute\n * recharts hands every tick, so the accent survives the class-based tick color\n * a chart theme may apply. A custom tick owns its own text, so the caller's\n * `xTickFormatter` is applied here — recharts only applies it to default ticks.\n * Exported for unit tests; not part of the package's public API.\n */\nexport function createForecastTick(\n forecastX: ReadonlySet<string | number | null | undefined>,\n color: string,\n tickFormatter?: CartesianChartProps['xTickFormatter']\n) {\n return function ForecastTick({\n payload,\n index,\n ...tickProps\n }: {\n payload?: { value?: string | number };\n index?: number;\n }) {\n const value = payload?.value;\n return (\n <Text\n {...tickProps}\n style={\n value != null && forecastX.has(value)\n ? { fontStyle: 'italic', fill: color }\n : undefined\n }\n >\n {tickFormatter && value != null ? tickFormatter(value, index) : value}\n </Text>\n );\n };\n}\n\n/** A dashed horizontal threshold on the value axis. */\nexport interface ConfidenceConeReferenceLine {\n /** Position on the value (Y) axis. */\n value: number;\n /** Optional caption rendered at the line's right end. */\n label?: string;\n}\n\n/**\n * Every prop except the one-form-or-the-other requirement `ConfidenceConeProps`\n * layers on below. Exported so the stories can type their `Meta` on a single\n * object shape — Storybook can't split a union's required args between `meta.args`\n * and a story's. Not re-exported from `index.ts`; not part of the public API.\n */\nexport interface ConfidenceConeBaseProps\n extends\n Omit<React.ComponentProps<'div'>, 'children'>,\n CartesianChartProps,\n ChartAnimationProps {\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 /**\n * Row-per-point data — the shared x dimension plus each series' actual /\n * forecast / bound fields. Rows are naturally sparse (a point has either an\n * actual or a forecast + bounds), so missing fields are allowed. Avoid fields\n * starting with `__cone` — that prefix is reserved for the internal\n * prediction-band series.\n */\n data: ReadonlyArray<Record<string, string | number | null | undefined>>;\n /**\n * Per-series map of `label` / `icon` / `tone` for the actual + forecast lines\n * (imported from the shared `Chart` primitives). Series take their colour from\n * the container's `palette`; each entry maps a key to a `label` and an optional\n * `tone`. Each metric renders in one hue: its cone band and forecast line both\n * reuse its actual series' color — actual and forecast differ by line style,\n * not hue.\n */\n config: ChartConfig;\n /** Category / time axis key (the shared dimension across rows). */\n xKey: string;\n /**\n * Plot several metrics against one shared axis — each with its own actual /\n * forecast / bound fields and its own hue (from `config[actualKey]`). Takes\n * precedence over the single-series `actualKey`/`forecastKey`/`lowerKey`/\n * `upperKey` shorthand below; pass one form or the other, not both. One of the\n * two forms is required.\n */\n series?: readonly ConfidenceConeSeries[];\n /**\n * Single-series shorthand — field for the known/actual values, drawn as a\n * solid line with a filled area. Required (with `forecastKey`) unless `series`\n * is set, which supersedes it.\n */\n actualKey?: string;\n /**\n * Single-series shorthand — field for the projected values, drawn as a dashed\n * line. Required (with `actualKey`) unless `series` is set, which supersedes\n * it.\n */\n forecastKey?: string;\n /** Field for the cone's lower bound. Omit (with `upperKey`) for no cone. */\n lowerKey?: string;\n /** Field for the cone's upper bound. Omit (with `lowerKey`) for no cone. */\n upperKey?: string;\n /**\n * How the known/actual period is drawn: a filled `area` under the line (the\n * default), or a bare `line` — for a chart where the cone is the only shaded\n * region, or where several metrics' fills would muddy each other.\n */\n actualType?: 'area' | 'line';\n /** Stroke width of the actual + forecast lines. */\n strokeWidth?: number;\n /**\n * Mark each data point: a filled dot on the observed values, a hollow one on\n * the projection — so a point reads as measured or predicted at a glance.\n */\n showDots?: boolean;\n /**\n * Italicize the X-axis ticks over the forecast period and paint them in the\n * first series' hue, so the projected columns read as projected even when the\n * shaded region is off.\n */\n styleForecastTicks?: boolean;\n /**\n * One or more dashed horizontal thresholds on the value axis — e.g. a target\n * or a capacity limit. Pass a single object or an array to draw several.\n */\n referenceLine?: ConfidenceConeReferenceLine | ConfidenceConeReferenceLine[];\n /**\n * Set off the forecast period from the actuals with a dashed divider at the\n * hand-off point (the first row with a forecast value) and a subtle shaded\n * band over the forecast region.\n */\n showForecastRegion?: boolean;\n showLegend?: boolean;\n}\n\n/**\n * Which columns to plot has to be spelled out one way or the other: the `series`\n * array, or the flat `actualKey` + `forecastKey` shorthand. Expressed as a union\n * so a chart with neither is a compile error rather than a silent plot of axes\n * and nothing else. Both forms together stay legal — `series` wins (see\n * `plotted`), which is what the multi-series stories rely on to clear the args\n * table.\n */\nexport type ConfidenceConeProps = ConfidenceConeBaseProps &\n (\n | { series: readonly ConfidenceConeSeries[] }\n | { actualKey: string; forecastKey: string }\n );\n\nconst ConfidenceCone = React.forwardRef<HTMLDivElement, ConfidenceConeProps>(\n (\n {\n className,\n config,\n palette,\n data,\n xKey,\n series,\n actualKey,\n forecastKey,\n lowerKey,\n upperKey,\n xAxisLabel,\n yAxisLabel,\n yUnit,\n actualType = 'area',\n strokeWidth = 2,\n showDots = false,\n styleForecastTicks = false,\n referenceLine,\n showForecastRegion = true,\n showGrid = true,\n showTooltip = true,\n showLegend = true,\n showXAxis = true,\n showYAxis = true,\n xTickFormatter,\n yTickFormatter,\n xAxisAngle,\n xAxisInterval,\n yAxisTickCount,\n yAxisDomain,\n gridDashed,\n gridHorizontal,\n gridVertical,\n tooltipContent,\n animate,\n animationDuration,\n animationBegin,\n animationEasing,\n ...props\n },\n ref\n ) => {\n // The flat *Key props are the single-series shorthand for `series`.\n const plotted = React.useMemo<readonly ConfidenceConeSeries[]>(() => {\n if (series?.length) return series;\n if (!actualKey || !forecastKey) return [];\n return [{ actualKey, forecastKey, lowerKey, upperKey }];\n }, [series, actualKey, forecastKey, lowerKey, upperKey]);\n\n const animation = resolveAnimation({\n animate,\n animationDuration,\n animationBegin,\n animationEasing,\n });\n // Memoized so recharts sees a stable content type across renders — a fresh\n // wrapper each render would remount the caller's tooltip and reset its state.\n const customTooltip = React.useMemo(\n () => (tooltipContent ? createConeTooltip(tooltipContent) : undefined),\n [tooltipContent]\n );\n\n const xAxisTitle = resolveXAxisTitle(xAxisLabel);\n const yAxisTitle = resolveYAxisTitle(yAxisLabel);\n\n const yDomain = resolveAxisDomain(yAxisDomain);\n\n // One hue per metric. Each cone and forecast line already paints with its own\n // series' actual color; re-pointing that series' forecast key's `--color-*`\n // at it too means nothing downstream — a custom tooltip, a caller's\n // `var(--color-<forecastKey>)` — can reintroduce a second color.\n const seriesConfig = React.useMemo(() => {\n let next: ChartConfig | undefined;\n for (const { actualKey: aKey, forecastKey: fKey } of plotted) {\n const actual = config[aKey];\n const forecast = config[fKey];\n if (!actual || !forecast) continue;\n next ??= { ...config };\n next[fKey] = {\n label: forecast.label,\n icon: forecast.icon,\n tone: { sameAs: aKey },\n };\n }\n return next ?? config;\n }, [config, plotted]);\n\n const xAxisHeight = resolveXAxisHeight(xAxisLabel, xAxisAngle);\n\n // Augment each row with one `[lower, upper]` band tuple per coned series for\n // its Area to shade. Rows missing a numeric bound are left un-coned (the\n // band breaks there); a series without bounds gets no band at all.\n const chartData = data.map((row) => {\n const next: Record<string, unknown> = { ...row };\n for (const {\n actualKey: aKey,\n lowerKey: lKey,\n upperKey: uKey,\n } of plotted) {\n if (!lKey || !uKey) continue;\n const lower = row[lKey];\n const upper = row[uKey];\n next[bandKeyFor(aKey)] =\n typeof lower === 'number' && typeof upper === 'number'\n ? [lower, upper]\n : undefined;\n }\n return next;\n });\n\n const forecastX = forecastPeriodX(data, plotted, xKey);\n // Set the projected period off from the actuals with a shaded band + a\n // divider at the hand-off.\n const forecastStart = showForecastRegion ? forecastX[0] : undefined;\n const lastX = data[data.length - 1]?.[xKey];\n\n const renderForecastTick = createForecastTick(\n new Set(forecastX),\n `var(--color-${plotted[0]?.actualKey})`,\n xTickFormatter\n );\n\n const referenceLines = referenceLine\n ? Array.isArray(referenceLine)\n ? referenceLine\n : [referenceLine]\n : [];\n\n // Everything from here to the `return` is lifted out of the returned tree\n // only to keep it readable as a flat list of chart children. Nothing in\n // recharts forces the `render*` helpers to be plain functions: axes and\n // series register themselves with the chart's store, and `<Cell>` is the\n // only child still looked up by element type — a component wrapper renders\n // fine (see AreaChart's `AreaFillGradients`). They stay functions because\n // they are declared inside the render body, where a component would get a\n // fresh element type on every render and remount its subtree.\n\n const renderAxes = () => (\n <>\n <XAxis\n dataKey={xKey}\n type=\"category\"\n hide={!showXAxis}\n tickLine={false}\n axisLine={false}\n tickMargin={8}\n tickFormatter={xTickFormatter}\n tick={styleForecastTicks ? renderForecastTick : undefined}\n angle={xAxisAngle}\n interval={xAxisInterval}\n textAnchor={resolveRotatedTickAnchor(xAxisAngle)}\n height={xAxisHeight}\n label={xAxisTitle}\n />\n <YAxis\n type=\"number\"\n hide={!showYAxis}\n tickLine={false}\n axisLine={false}\n unit={yUnit}\n tickFormatter={yTickFormatter}\n tickCount={yAxisTickCount}\n domain={yDomain}\n width={yAxisLabel ? 72 : undefined}\n label={yAxisTitle}\n />\n </>\n );\n\n // Set the forecast region off from the actuals (behind everything).\n const renderForecastRegion = () => (\n <>\n {forecastStart != null && lastX != null && (\n <ReferenceArea\n x1={forecastStart}\n x2={lastX}\n fill=\"var(--ui-background-surface-secondary)\"\n fillOpacity={0.5}\n ifOverflow=\"extendDomain\"\n />\n )}\n {forecastStart != null && (\n <ReferenceLine\n x={forecastStart}\n stroke=\"var(--ui-border-on-surface-border)\"\n strokeDasharray=\"4 4\"\n />\n )}\n </>\n );\n\n const renderThreshold = (\n threshold: ConfidenceConeReferenceLine,\n index: number\n ) => (\n <ReferenceLine\n key={`${threshold.label ?? 'threshold'}-${index}`}\n y={threshold.value}\n stroke=\"var(--ui-text-on-surface-secondary)\"\n strokeDasharray=\"4 4\"\n // extendDomain so a threshold beyond the data max stays visible.\n ifOverflow=\"extendDomain\"\n label={\n threshold.label\n ? {\n value: threshold.label,\n position: 'insideTopRight',\n fill: 'var(--ui-text-on-surface-secondary)',\n fontSize: CHART_LABEL_FONT_SIZE,\n }\n : undefined\n }\n />\n );\n\n const renderTooltip = () =>\n customTooltip ? (\n // Strips the synthetic band before the caller's tooltip sees it — the\n // `__cone` series feeds the Area, not the tooltip.\n <ChartTooltip content={customTooltip} />\n ) : (\n <ChartTooltip\n content={(tp) => (\n <ChartTooltipContent\n active={tp.active}\n label={tp.label}\n // The synthetic band feeds the Area, not the tooltip.\n payload={\n dropConeBand(tp.payload) as ChartTooltipContentProps['payload']\n }\n />\n )}\n />\n );\n\n const renderLegend = () => (\n <ChartLegend\n content={(lp) => (\n <ChartLegendContent\n verticalAlign={lp.verticalAlign}\n payload={\n keepMetricSeries(\n lp.payload,\n plotted.map((s) => s.actualKey)\n ) as ChartLegendContentProps['payload']\n }\n />\n )}\n />\n );\n\n // One color per metric — actual and forecast differ by line style, not hue\n // — so a cone reuses its series' actual color.\n const renderConeBand = ({\n actualKey: aKey,\n lowerKey: lKey,\n upperKey: uKey,\n }: ConfidenceConeSeries) =>\n lKey && uKey ? (\n <Area\n key={bandKeyFor(aKey)}\n // The band paints in the same hue, at the same opacity, as the\n // actual series' own area, so nothing on the rendered path tells\n // the two apart. recharts forwards `data-*` onto the path it\n // draws; the tests select the band through this.\n data-slot=\"confidence-cone-band\"\n dataKey={bandKeyFor(aKey)}\n type=\"monotone\"\n stroke=\"none\"\n fill={`var(--color-${aKey})`}\n fillOpacity={0.15}\n connectNulls={false}\n dot={false}\n activeDot={false}\n {...animation}\n legendType=\"none\"\n tooltipType=\"none\"\n />\n ) : null;\n\n const renderActualMark = ({ actualKey: aKey }: ConfidenceConeSeries) => {\n // An area and a line take the same props here; only the region under the\n // curve (and the mark recharts draws) differ. A `Line` gets no fill at\n // all — `fillOpacity: 0` would also erase its dots.\n const ActualMark = actualType === 'line' ? Line : Area;\n const areaFill =\n actualType === 'line'\n ? undefined\n : { fill: `var(--color-${aKey})`, fillOpacity: 0.15 };\n // Observed points read as measured: LineChart's dot geometry (r 3, 2px\n // ring) filled with the metric hue. The ring is that same hue, so the\n // mark is solid — and wide enough against the 2px line not to read as a\n // mere thickening of it. `fillOpacity: 1` is load-bearing: recharts\n // merges the parent mark's own presentation props into every dot it\n // draws, so an `<Area>`'s 0.15 would otherwise wash the dot out to a halo.\n const dot = showDots\n ? {\n r: 3,\n fill: `var(--color-${aKey})`,\n fillOpacity: 1,\n stroke: `var(--color-${aKey})`,\n strokeWidth: 2,\n }\n : false;\n return (\n <ActualMark\n key={aKey}\n dataKey={aKey}\n type=\"monotone\"\n stroke={`var(--color-${aKey})`}\n strokeWidth={strokeWidth}\n {...areaFill}\n dot={dot}\n activeDot={showDots ? { r: 5 } : false}\n connectNulls\n {...animation}\n // The legend names the metric once, so it carries the swatch that\n // stands for the whole series rather than the actual line's style.\n legendType=\"rect\"\n />\n );\n };\n\n const renderForecastLine = ({\n actualKey: aKey,\n forecastKey: fKey,\n }: ConfidenceConeSeries) => {\n // Projected points read as predicted: the same LineChart dot, inverted —\n // the metric's hue as the ring, the surface color as the fill, so the\n // dashed line doesn't show through the middle. (LineChart leaves the fill\n // to recharts, whose `Line` defaults it to `#fff`; the token is that same\n // white in the light theme and also holds up in the dark one.)\n // `strokeDasharray: 'none'` is load-bearing: recharts merges the parent\n // mark's presentation props into every dot, so this line's `5 5` would\n // otherwise break each dot's ring into two arcs.\n const dot = showDots\n ? {\n r: 3,\n fill: 'var(--ui-background-surface-primary)',\n stroke: `var(--color-${aKey})`,\n strokeWidth: 2,\n strokeDasharray: 'none',\n }\n : false;\n return (\n <Line\n key={fKey}\n dataKey={fKey}\n type=\"monotone\"\n stroke={`var(--color-${aKey})`}\n strokeWidth={strokeWidth}\n strokeDasharray=\"5 5\"\n dot={dot}\n // Paired with `dot` the way every other chart does it — left unset,\n // the projection would keep recharts' default active dot while the\n // actuals had none (and a different radius when on).\n activeDot={showDots ? { r: 5 } : false}\n connectNulls\n {...animation}\n />\n );\n };\n\n return (\n <div ref={ref} className={cn(className)} {...props}>\n <ChartContainer\n config={seriesConfig}\n palette={palette}\n className=\"size-full [&_.recharts-label]:fill-foreground\"\n >\n <ComposedChart data={chartData as readonly unknown[]}>\n {showGrid && (\n <CartesianGrid\n horizontal={gridHorizontal ?? true}\n vertical={gridVertical ?? false}\n strokeDasharray={gridDashed ? '3 3' : undefined}\n />\n )}\n {renderAxes()}\n {renderForecastRegion()}\n {referenceLines.map(renderThreshold)}\n {showTooltip && renderTooltip()}\n {showLegend && renderLegend()}\n {/* Every cone renders before any line, so the lines draw on top of\n all of them. */}\n {plotted.map(renderConeBand)}\n {plotted.map(renderActualMark)}\n {plotted.map(renderForecastLine)}\n </ComposedChart>\n </ChartContainer>\n </div>\n );\n }\n);\nConfidenceCone.displayName = 'ConfidenceCone';\n\nexport { ConfidenceCone };\n"],"mappings":";;;;;;;;AAiDA,IAAM,IAAc,UACd,KAAc,MAAsB,GAAG,EAAY,GAAG;AAQ5D,SAAgB,EACd,GACiB;CACjB,OAAO,GAAS,QACb,MACC,EACE,OAAO,EAAK,WAAY,YAAY,EAAK,QAAQ,WAAW,CAAW,EAE7E;AACF;AAQA,SAAgB,EACd,GACA,GACiB;CACjB,OAAO,GAAS,QACb,MACC,OAAO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MAAM;IAArB,UAAA;KACG,KACC,kBAAC,IAAD;MACE,YAAY,MAAkB;MAC9B,UAAU,MAAgB;MAC1B,iBAAiB,KAAa,QAAQ,KAAA;KACvC,CAAA;KAEF,EAAW;KACX,GAAqB;KACrB,GAAe,IAAI,EAAe;KAClC,KAAe,GAAc;KAC7B,KAAc,GAAa;KAG3B,EAAQ,IAAI,EAAc;KAC1B,EAAQ,IAAI,EAAgB;KAC5B,EAAQ,IAAI,EAAkB;IAClB;;EACD,CAAA;CACb,CAAA;AAET,CACF;AACA,EAAe,cAAc"}
1
+ {"version":3,"file":"confidence-cone.js","names":[],"sources":["../../../../src/components/ui/confidence-cone/confidence-cone.tsx"],"sourcesContent":["'use client';\n\nimport * as React from 'react';\nimport {\n Area,\n CartesianGrid,\n ComposedChart,\n Line,\n ReferenceArea,\n ReferenceLine,\n Text,\n XAxis,\n YAxis,\n} from 'recharts';\n\nimport { cn } from '@/lib/utils';\nimport {\n ChartContainer,\n ChartLegend,\n ChartLegendContent,\n ChartTooltip,\n ChartTooltipContent,\n resolveAxisDomain,\n resolveAnimation,\n resolveRotatedTickAnchor,\n resolveXAxisHeight,\n resolveXAxisTitle,\n resolveYAxisTitle,\n CHART_LABEL_FONT_SIZE,\n type ChartConfig,\n type ChartPalette,\n type ChartLegendContentProps,\n type ChartTooltipContentProps,\n toCssKey,\n type CartesianChartProps,\n type ChartAnimationProps,\n} from '../chart';\n\n// A forecast confidence-cone: a solid line over the known/actual period, a\n// dashed line over the forecast period, and a shaded band (the \"cone\") between\n// a lower and upper bound that typically widens with the horizon — visualizing\n// growing uncertainty. Built on the shared Chart primitives; no new tokens\n// (series colors are caller-supplied via `config`). The whole metric renders in\n// one hue — actual and forecast differ by line style, not color — so the cone\n// band and the forecast line both reuse the actual series' color.\n\n// Each series' band is a synthetic `[lower, upper]` range field per row that a\n// recharts <Area> shades; kept out of the tooltip/legend (see the filters\n// below). One band per series, so the key carries the series' actual key — the\n// whole `__cone` prefix is reserved.\nconst BAND_PREFIX = '__cone';\nconst bandKeyFor = (actualKey: string) => `${BAND_PREFIX}:${actualKey}`;\n\n/**\n * Drop every synthetic cone-band range series from a recharts tooltip/legend\n * payload, keeping the real actual/forecast series (and their order). Applied to\n * both the default tooltip and any caller-supplied `tooltipContent`, so no band\n * surfaces regardless of which path renders or how many series are plotted.\n */\nexport function dropConeBand<T extends { dataKey?: unknown }>(\n payload: readonly T[] | undefined\n): T[] | undefined {\n return payload?.filter(\n (item) =>\n !(\n typeof item.dataKey === 'string' && item.dataKey.startsWith(BAND_PREFIX)\n )\n );\n}\n\n/**\n * Reduce a legend payload to the metrics the chart plots — one entry per series.\n * A series' actual, forecast and cone are three recharts series painting a\n * single metric in a single hue, so the legend names each metric once, with its\n * actual series' swatch, instead of listing line styles as separate series.\n */\nexport function keepMetricSeries<T extends { dataKey?: unknown }>(\n payload: readonly T[] | undefined,\n actualKeys: readonly string[]\n): T[] | undefined {\n return payload?.filter(\n (item) =>\n typeof item.dataKey === 'string' && actualKeys.includes(item.dataKey)\n );\n}\n\n/**\n * Wrap a caller-supplied `tooltipContent` so the synthetic cone band is stripped\n * from the payload before it renders, while preserving recharts' own mount\n * semantics — a function is mounted via `createElement` (its own component\n * identity + hook state), an element via `cloneElement`. This mirrors what the\n * pass-through charts get by handing `content` straight to recharts, so a\n * function-form tooltip keeps its state across re-renders here too. The returned\n * component is a stable content type (memoize it on `tooltipContent`).\n */\ntype TooltipContentType = NonNullable<\n React.ComponentProps<typeof ChartTooltip>['content']\n>;\ntype TooltipContentFn = Extract<\n TooltipContentType,\n (...args: never[]) => unknown\n>;\ntype TooltipRenderProps = Parameters<TooltipContentFn>[0];\n\nexport function createConeTooltip(tooltipContent: TooltipContentType) {\n return function ConeTooltip(props: TooltipRenderProps) {\n const merged = {\n ...props,\n payload: dropConeBand(props.payload),\n } as TooltipRenderProps;\n return typeof tooltipContent === 'function'\n ? React.createElement(\n tooltipContent as React.FunctionComponent<TooltipRenderProps>,\n merged\n )\n : React.cloneElement(tooltipContent, merged);\n };\n}\n\n/**\n * One plotted metric: its actual / forecast columns and, optionally, the two\n * bound columns that shade its cone. Omit `lowerKey`/`upperKey` for a band-less\n * metric — a solid line handing off to a bare dashed projection.\n */\nexport interface ConfidenceConeSeries {\n /** Field for the known/actual values — drawn as a solid line with a filled area. */\n actualKey: string;\n /** Field for the projected values — drawn as a dashed line. */\n forecastKey: string;\n /** Field for the cone's lower bound. Omit (with `upperKey`) for no cone. */\n lowerKey?: string;\n /** Field for the cone's upper bound. Omit (with `lowerKey`) for no cone. */\n upperKey?: string;\n}\n\n/**\n * The x values of the projected period — every row carrying a forecast value for\n * at least one series, in data order. The first is the hand-off point (where the\n * shaded region and divider start); the whole set drives the forecast tick\n * styling, matched by value so tick `interval` can't skew it the way a tick\n * index would. Exported for unit tests; not part of the package's public API.\n */\nexport function forecastPeriodX(\n data: ReadonlyArray<Record<string, string | number | null | undefined>>,\n series: readonly ConfidenceConeSeries[],\n xKey: string\n): Array<string | number | null | undefined> {\n return data\n .filter((row) =>\n series.some(({ forecastKey }) => typeof row[forecastKey] === 'number')\n )\n .map((row) => row[xKey]);\n}\n\n/**\n * Build the X-axis tick renderer that sets the projected columns apart: italic,\n * in the metric's hue. Styled inline rather than through the `fill` attribute\n * recharts hands every tick, so the accent survives the class-based tick color\n * a chart theme may apply. A custom tick owns its own text, so the caller's\n * `xTickFormatter` is applied here — recharts only applies it to default ticks.\n * Exported for unit tests; not part of the package's public API.\n */\nexport function createForecastTick(\n forecastX: ReadonlySet<string | number | null | undefined>,\n color: string,\n tickFormatter?: CartesianChartProps['xTickFormatter']\n) {\n return function ForecastTick({\n payload,\n index,\n ...tickProps\n }: {\n payload?: { value?: string | number };\n index?: number;\n }) {\n const value = payload?.value;\n return (\n <Text\n {...tickProps}\n style={\n value != null && forecastX.has(value)\n ? { fontStyle: 'italic', fill: color }\n : undefined\n }\n >\n {tickFormatter && value != null ? tickFormatter(value, index) : value}\n </Text>\n );\n };\n}\n\n/** A dashed horizontal threshold on the value axis. */\nexport interface ConfidenceConeReferenceLine {\n /** Position on the value (Y) axis. */\n value: number;\n /** Optional caption rendered at the line's right end. */\n label?: string;\n}\n\n/**\n * Every prop except the one-form-or-the-other requirement `ConfidenceConeProps`\n * layers on below. Exported so the stories can type their `Meta` on a single\n * object shape — Storybook can't split a union's required args between `meta.args`\n * and a story's. Not re-exported from `index.ts`; not part of the public API.\n */\nexport interface ConfidenceConeBaseProps\n extends\n Omit<React.ComponentProps<'div'>, 'children'>,\n CartesianChartProps,\n ChartAnimationProps {\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 /**\n * Row-per-point data — the shared x dimension plus each series' actual /\n * forecast / bound fields. Rows are naturally sparse (a point has either an\n * actual or a forecast + bounds), so missing fields are allowed. Avoid fields\n * starting with `__cone` — that prefix is reserved for the internal\n * prediction-band series.\n */\n data: ReadonlyArray<Record<string, string | number | null | undefined>>;\n /**\n * Per-series map of `label` / `icon` / `tone` for the actual + forecast lines\n * (imported from the shared `Chart` primitives). Series take their colour from\n * the container's `palette`; each entry maps a key to a `label` and an optional\n * `tone`. Each metric renders in one hue: its cone band and forecast line both\n * reuse its actual series' color — actual and forecast differ by line style,\n * not hue.\n */\n config: ChartConfig;\n /** Category / time axis key (the shared dimension across rows). */\n xKey: string;\n /**\n * Plot several metrics against one shared axis — each with its own actual /\n * forecast / bound fields and its own hue (from `config[actualKey]`). Takes\n * precedence over the single-series `actualKey`/`forecastKey`/`lowerKey`/\n * `upperKey` shorthand below; pass one form or the other, not both. One of the\n * two forms is required.\n */\n series?: readonly ConfidenceConeSeries[];\n /**\n * Single-series shorthand — field for the known/actual values, drawn as a\n * solid line with a filled area. Required (with `forecastKey`) unless `series`\n * is set, which supersedes it.\n */\n actualKey?: string;\n /**\n * Single-series shorthand — field for the projected values, drawn as a dashed\n * line. Required (with `actualKey`) unless `series` is set, which supersedes\n * it.\n */\n forecastKey?: string;\n /** Field for the cone's lower bound. Omit (with `upperKey`) for no cone. */\n lowerKey?: string;\n /** Field for the cone's upper bound. Omit (with `lowerKey`) for no cone. */\n upperKey?: string;\n /**\n * How the known/actual period is drawn: a filled `area` under the line (the\n * default), or a bare `line` — for a chart where the cone is the only shaded\n * region, or where several metrics' fills would muddy each other.\n */\n actualType?: 'area' | 'line';\n /** Stroke width of the actual + forecast lines. */\n strokeWidth?: number;\n /**\n * Mark each data point: a filled dot on the observed values, a hollow one on\n * the projection — so a point reads as measured or predicted at a glance.\n */\n showDots?: boolean;\n /**\n * Italicize the X-axis ticks over the forecast period and paint them in the\n * first series' hue, so the projected columns read as projected even when the\n * shaded region is off.\n */\n styleForecastTicks?: boolean;\n /**\n * One or more dashed horizontal thresholds on the value axis — e.g. a target\n * or a capacity limit. Pass a single object or an array to draw several.\n */\n referenceLine?: ConfidenceConeReferenceLine | ConfidenceConeReferenceLine[];\n /**\n * Set off the forecast period from the actuals with a dashed divider at the\n * hand-off point (the first row with a forecast value) and a subtle shaded\n * band over the forecast region.\n */\n showForecastRegion?: boolean;\n showLegend?: boolean;\n}\n\n/**\n * Which columns to plot has to be spelled out one way or the other: the `series`\n * array, or the flat `actualKey` + `forecastKey` shorthand. Expressed as a union\n * so a chart with neither is a compile error rather than a silent plot of axes\n * and nothing else. Both forms together stay legal — `series` wins (see\n * `plotted`), which is what the multi-series stories rely on to clear the args\n * table.\n */\nexport type ConfidenceConeProps = ConfidenceConeBaseProps &\n (\n | { series: readonly ConfidenceConeSeries[] }\n | { actualKey: string; forecastKey: string }\n );\n\nconst ConfidenceCone = React.forwardRef<HTMLDivElement, ConfidenceConeProps>(\n (\n {\n className,\n config,\n palette,\n data,\n xKey,\n series,\n actualKey,\n forecastKey,\n lowerKey,\n upperKey,\n xAxisLabel,\n yAxisLabel,\n yUnit,\n actualType = 'area',\n strokeWidth = 2,\n showDots = false,\n styleForecastTicks = false,\n referenceLine,\n showForecastRegion = true,\n showGrid = true,\n showTooltip = true,\n showLegend = true,\n showXAxis = true,\n showYAxis = true,\n xTickFormatter,\n yTickFormatter,\n xAxisAngle,\n xAxisInterval,\n yAxisTickCount,\n yAxisDomain,\n gridDashed,\n gridHorizontal,\n gridVertical,\n tooltipContent,\n animate,\n animationDuration,\n animationBegin,\n animationEasing,\n ...props\n },\n ref\n ) => {\n // The flat *Key props are the single-series shorthand for `series`.\n const plotted = React.useMemo<readonly ConfidenceConeSeries[]>(() => {\n if (series?.length) return series;\n if (!actualKey || !forecastKey) return [];\n return [{ actualKey, forecastKey, lowerKey, upperKey }];\n }, [series, actualKey, forecastKey, lowerKey, upperKey]);\n\n const animation = resolveAnimation({\n animate,\n animationDuration,\n animationBegin,\n animationEasing,\n });\n // Memoized so recharts sees a stable content type across renders — a fresh\n // wrapper each render would remount the caller's tooltip and reset its state.\n const customTooltip = React.useMemo(\n () => (tooltipContent ? createConeTooltip(tooltipContent) : undefined),\n [tooltipContent]\n );\n\n const xAxisTitle = resolveXAxisTitle(xAxisLabel);\n const yAxisTitle = resolveYAxisTitle(yAxisLabel);\n\n const yDomain = resolveAxisDomain(yAxisDomain);\n\n // One hue per metric. Each cone and forecast line already paints with its own\n // series' actual color; re-pointing that series' forecast key's `--color-*`\n // at it too means nothing downstream — a custom tooltip, a caller's\n // `var(--color-<forecastKey>)` — can reintroduce a second color.\n const seriesConfig = React.useMemo(() => {\n let next: ChartConfig | undefined;\n for (const { actualKey: aKey, forecastKey: fKey } of plotted) {\n const actual = config[aKey];\n const forecast = config[fKey];\n if (!actual || !forecast) continue;\n next ??= { ...config };\n next[fKey] = {\n label: forecast.label,\n icon: forecast.icon,\n tone: { sameAs: aKey },\n };\n }\n return next ?? config;\n }, [config, plotted]);\n\n const xAxisHeight = resolveXAxisHeight(xAxisLabel, xAxisAngle);\n\n // Augment each row with one `[lower, upper]` band tuple per coned series for\n // its Area to shade. Rows missing a numeric bound are left un-coned (the\n // band breaks there); a series without bounds gets no band at all.\n const chartData = data.map((row) => {\n const next: Record<string, unknown> = { ...row };\n for (const {\n actualKey: aKey,\n lowerKey: lKey,\n upperKey: uKey,\n } of plotted) {\n if (!lKey || !uKey) continue;\n const lower = row[lKey];\n const upper = row[uKey];\n next[bandKeyFor(aKey)] =\n typeof lower === 'number' && typeof upper === 'number'\n ? [lower, upper]\n : undefined;\n }\n return next;\n });\n\n const forecastX = forecastPeriodX(data, plotted, xKey);\n // Set the projected period off from the actuals with a shaded band + a\n // divider at the hand-off.\n const forecastStart = showForecastRegion ? forecastX[0] : undefined;\n const lastX = data[data.length - 1]?.[xKey];\n\n const renderForecastTick = createForecastTick(\n new Set(forecastX),\n `var(--color-${toCssKey(plotted[0]?.actualKey ?? '')})`,\n xTickFormatter\n );\n\n const referenceLines = referenceLine\n ? Array.isArray(referenceLine)\n ? referenceLine\n : [referenceLine]\n : [];\n\n // Everything from here to the `return` is lifted out of the returned tree\n // only to keep it readable as a flat list of chart children. Nothing in\n // recharts forces the `render*` helpers to be plain functions: axes and\n // series register themselves with the chart's store, and `<Cell>` is the\n // only child still looked up by element type — a component wrapper renders\n // fine (see AreaChart's `AreaFillGradients`). They stay functions because\n // they are declared inside the render body, where a component would get a\n // fresh element type on every render and remount its subtree.\n\n const renderAxes = () => (\n <>\n <XAxis\n dataKey={xKey}\n type=\"category\"\n hide={!showXAxis}\n tickLine={false}\n axisLine={false}\n tickMargin={8}\n tickFormatter={xTickFormatter}\n tick={styleForecastTicks ? renderForecastTick : undefined}\n angle={xAxisAngle}\n interval={xAxisInterval}\n textAnchor={resolveRotatedTickAnchor(xAxisAngle)}\n height={xAxisHeight}\n label={xAxisTitle}\n />\n <YAxis\n type=\"number\"\n hide={!showYAxis}\n tickLine={false}\n axisLine={false}\n unit={yUnit}\n tickFormatter={yTickFormatter}\n tickCount={yAxisTickCount}\n domain={yDomain}\n width={yAxisLabel ? 72 : undefined}\n label={yAxisTitle}\n />\n </>\n );\n\n // Set the forecast region off from the actuals (behind everything).\n const renderForecastRegion = () => (\n <>\n {forecastStart != null && lastX != null && (\n <ReferenceArea\n x1={forecastStart}\n x2={lastX}\n fill=\"var(--ui-background-surface-secondary)\"\n fillOpacity={0.5}\n ifOverflow=\"extendDomain\"\n />\n )}\n {forecastStart != null && (\n <ReferenceLine\n x={forecastStart}\n stroke=\"var(--ui-border-on-surface-border)\"\n strokeDasharray=\"4 4\"\n />\n )}\n </>\n );\n\n const renderThreshold = (\n threshold: ConfidenceConeReferenceLine,\n index: number\n ) => (\n <ReferenceLine\n key={`${threshold.label ?? 'threshold'}-${index}`}\n y={threshold.value}\n stroke=\"var(--ui-text-on-surface-secondary)\"\n strokeDasharray=\"4 4\"\n // extendDomain so a threshold beyond the data max stays visible.\n ifOverflow=\"extendDomain\"\n label={\n threshold.label\n ? {\n value: threshold.label,\n position: 'insideTopRight',\n fill: 'var(--ui-text-on-surface-secondary)',\n fontSize: CHART_LABEL_FONT_SIZE,\n }\n : undefined\n }\n />\n );\n\n const renderTooltip = () =>\n customTooltip ? (\n // Strips the synthetic band before the caller's tooltip sees it — the\n // `__cone` series feeds the Area, not the tooltip.\n <ChartTooltip content={customTooltip} />\n ) : (\n <ChartTooltip\n content={(tp) => (\n <ChartTooltipContent\n active={tp.active}\n label={tp.label}\n // The synthetic band feeds the Area, not the tooltip.\n payload={\n dropConeBand(tp.payload) as ChartTooltipContentProps['payload']\n }\n />\n )}\n />\n );\n\n const renderLegend = () => (\n <ChartLegend\n content={(lp) => (\n <ChartLegendContent\n verticalAlign={lp.verticalAlign}\n payload={\n keepMetricSeries(\n lp.payload,\n plotted.map((s) => s.actualKey)\n ) as ChartLegendContentProps['payload']\n }\n />\n )}\n />\n );\n\n // One color per metric — actual and forecast differ by line style, not hue\n // — so a cone reuses its series' actual color.\n const renderConeBand = ({\n actualKey: aKey,\n lowerKey: lKey,\n upperKey: uKey,\n }: ConfidenceConeSeries) =>\n lKey && uKey ? (\n <Area\n key={bandKeyFor(aKey)}\n // The band paints in the same hue, at the same opacity, as the\n // actual series' own area, so nothing on the rendered path tells\n // the two apart. recharts forwards `data-*` onto the path it\n // draws; the tests select the band through this.\n data-slot=\"confidence-cone-band\"\n dataKey={bandKeyFor(aKey)}\n type=\"monotone\"\n stroke=\"none\"\n fill={`var(--color-${toCssKey(aKey)})`}\n fillOpacity={0.15}\n connectNulls={false}\n dot={false}\n activeDot={false}\n {...animation}\n legendType=\"none\"\n tooltipType=\"none\"\n />\n ) : null;\n\n const renderActualMark = ({ actualKey: aKey }: ConfidenceConeSeries) => {\n // An area and a line take the same props here; only the region under the\n // curve (and the mark recharts draws) differ. A `Line` gets no fill at\n // all — `fillOpacity: 0` would also erase its dots.\n const ActualMark = actualType === 'line' ? Line : Area;\n const areaFill =\n actualType === 'line'\n ? undefined\n : { fill: `var(--color-${toCssKey(aKey)})`, fillOpacity: 0.15 };\n // Observed points read as measured: LineChart's dot geometry (r 3, 2px\n // ring) filled with the metric hue. The ring is that same hue, so the\n // mark is solid — and wide enough against the 2px line not to read as a\n // mere thickening of it. `fillOpacity: 1` is load-bearing: recharts\n // merges the parent mark's own presentation props into every dot it\n // draws, so an `<Area>`'s 0.15 would otherwise wash the dot out to a halo.\n const dot = showDots\n ? {\n r: 3,\n fill: `var(--color-${toCssKey(aKey)})`,\n fillOpacity: 1,\n stroke: `var(--color-${toCssKey(aKey)})`,\n strokeWidth: 2,\n }\n : false;\n return (\n <ActualMark\n key={aKey}\n dataKey={aKey}\n type=\"monotone\"\n stroke={`var(--color-${toCssKey(aKey)})`}\n strokeWidth={strokeWidth}\n {...areaFill}\n dot={dot}\n activeDot={showDots ? { r: 5 } : false}\n connectNulls\n {...animation}\n // The legend names the metric once, so it carries the swatch that\n // stands for the whole series rather than the actual line's style.\n legendType=\"rect\"\n />\n );\n };\n\n const renderForecastLine = ({\n actualKey: aKey,\n forecastKey: fKey,\n }: ConfidenceConeSeries) => {\n // Projected points read as predicted: the same LineChart dot, inverted —\n // the metric's hue as the ring, the surface color as the fill, so the\n // dashed line doesn't show through the middle. (LineChart leaves the fill\n // to recharts, whose `Line` defaults it to `#fff`; the token is that same\n // white in the light theme and also holds up in the dark one.)\n // `strokeDasharray: 'none'` is load-bearing: recharts merges the parent\n // mark's presentation props into every dot, so this line's `5 5` would\n // otherwise break each dot's ring into two arcs.\n const dot = showDots\n ? {\n r: 3,\n fill: 'var(--ui-background-surface-primary)',\n stroke: `var(--color-${toCssKey(aKey)})`,\n strokeWidth: 2,\n strokeDasharray: 'none',\n }\n : false;\n return (\n <Line\n key={fKey}\n dataKey={fKey}\n type=\"monotone\"\n stroke={`var(--color-${toCssKey(aKey)})`}\n strokeWidth={strokeWidth}\n strokeDasharray=\"5 5\"\n dot={dot}\n // Paired with `dot` the way every other chart does it — left unset,\n // the projection would keep recharts' default active dot while the\n // actuals had none (and a different radius when on).\n activeDot={showDots ? { r: 5 } : false}\n connectNulls\n {...animation}\n />\n );\n };\n\n return (\n <div ref={ref} className={cn(className)} {...props}>\n <ChartContainer\n config={seriesConfig}\n palette={palette}\n className=\"size-full [&_.recharts-label]:fill-foreground\"\n >\n <ComposedChart data={chartData as readonly unknown[]}>\n {showGrid && (\n <CartesianGrid\n horizontal={gridHorizontal ?? true}\n vertical={gridVertical ?? false}\n strokeDasharray={gridDashed ? '3 3' : undefined}\n />\n )}\n {renderAxes()}\n {renderForecastRegion()}\n {referenceLines.map(renderThreshold)}\n {showTooltip && renderTooltip()}\n {showLegend && renderLegend()}\n {/* Every cone renders before any line, so the lines draw on top of\n all of them. */}\n {plotted.map(renderConeBand)}\n {plotted.map(renderActualMark)}\n {plotted.map(renderForecastLine)}\n </ComposedChart>\n </ChartContainer>\n </div>\n );\n }\n);\nConfidenceCone.displayName = 'ConfidenceCone';\n\nexport { ConfidenceCone };\n"],"mappings":";;;;;;;;AAkDA,IAAM,IAAc,UACd,KAAc,MAAsB,GAAG,EAAY,GAAG;AAQ5D,SAAgB,EACd,GACiB;CACjB,OAAO,GAAS,QACb,MACC,EACE,OAAO,EAAK,WAAY,YAAY,EAAK,QAAQ,WAAW,CAAW,EAE7E;AACF;AAQA,S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L;CAEA,OACE,kBAAC,OAAD;EAAU;EAAK,WAAW,EAAG,CAAS;EAAG,GAAI;EAC3C,UAAA,kBAAC,GAAD;GACE,QAAQ;GACC;GACT,WAAU;GAEV,UAAA,kBAAC,IAAD;IAAe,MAAM;IAArB,UAAA;KACG,KACC,kBAAC,IAAD;MACE,YAAY,MAAkB;MAC9B,UAAU,MAAgB;MAC1B,iBAAiB,KAAa,QAAQ,KAAA;KACvC,CAAA;KAEF,GAAW;KACX,GAAqB;KACrB,GAAe,IAAI,CAAe;KAClC,KAAe,GAAc;KAC7B,KAAc,GAAa;KAG3B,EAAQ,IAAI,EAAc;KAC1B,EAAQ,IAAI,EAAgB;KAC5B,EAAQ,IAAI,EAAkB;IAClB;;EACD,CAAA;CACb,CAAA;AAET,CACF;AACA,EAAe,cAAc"}
@@ -1,61 +1,61 @@
1
1
  "use client";
2
2
  import { cn as e } from "../../../lib/utils.js";
3
3
  import { cva as t } from "../../../node_modules/.pnpm/class-variance-authority@0.7.1/node_modules/class-variance-authority/dist/index.js";
4
- import { ChartContainer as n, ChartLegendContent as r, ChartTooltip as i, ChartTooltipContent as a, resolveChartColors as o } from "../chart/chart.js";
5
- import { resolveAnimation as s, resolveLabelFillClass as c } from "../chart/chart-format.js";
6
- import * as l from "react";
7
- import { jsx as u, jsxs as d } from "react/jsx-runtime";
8
- import { Cell as f, Funnel as p, FunnelChart as m, LabelList as h } from "recharts";
4
+ import { ChartContainer as n, ChartLegendContent as r, ChartTooltip as i, ChartTooltipContent as a, resolveChartColors as o, toCssKey as s } from "../chart/chart.js";
5
+ import { resolveAnimation as c, resolveLabelFillClass as l } from "../chart/chart-format.js";
6
+ import * as u from "react";
7
+ import { jsx as d, jsxs as f } from "react/jsx-runtime";
8
+ import { Cell as p, Funnel as m, FunnelChart as h, LabelList as g } from "recharts";
9
9
  //#region src/components/ui/funnel-chart/funnel-chart.tsx
10
- var g = t("", {
10
+ var _ = t("", {
11
11
  variants: { lastShape: {
12
12
  triangle: "",
13
13
  rectangle: ""
14
14
  } },
15
15
  defaultVariants: { lastShape: "triangle" }
16
- }), _ = {
16
+ }), v = {
17
17
  right: "right",
18
18
  left: "left",
19
19
  inside: "center"
20
20
  };
21
- function v(e) {
21
+ function y(e) {
22
22
  switch (e) {
23
23
  case "right": return "left";
24
24
  case "left": return "right";
25
25
  case "inside": return "right";
26
26
  }
27
27
  }
28
- var y = "__stageLabel", b = "__stageValueLabel", x = "__stageIndex", S = "var(--ui-border-on-surface-border-active)", C = 2, ee = "size-[120px]", w = 2, T = 2, E = 1, D = {
28
+ var b = "__stageLabel", x = "__stageValueLabel", S = "__stageIndex", C = "var(--ui-border-on-surface-border-active)", w = 2, ee = "size-[120px]", T = 2, E = 2, D = 1, O = {
29
29
  top: 4,
30
30
  right: 8,
31
31
  bottom: 4,
32
32
  left: 8
33
- }, O = Object.freeze({
33
+ }, k = Object.freeze({
34
34
  type: "sequential",
35
35
  ramp: "blue"
36
- }), k = (e, t) => Math.hypot(t[0] - e[0], t[1] - e[1]);
37
- function A(e, t, n) {
38
- let r = k(e, t);
36
+ }), A = (e, t) => Math.hypot(t[0] - e[0], t[1] - e[1]);
37
+ function j(e, t, n) {
38
+ let r = A(e, t);
39
39
  return r === 0 ? e : [e[0] + (t[0] - e[0]) * n / r, e[1] + (t[1] - e[1]) * n / r];
40
40
  }
41
- var j = ([e, t]) => `${Number(e.toFixed(3))},${Number(t.toFixed(3))}`;
42
- function M(e, t) {
41
+ var M = ([e, t]) => `${Number(e.toFixed(3))},${Number(t.toFixed(3))}`;
42
+ function N(e, t) {
43
43
  let n = e.length;
44
44
  if (n < 3) return "";
45
45
  let r = "";
46
46
  for (let i = 0; i < n; i++) {
47
- let a = typeof t == "number" ? t : t[i], o = e[(i - 1 + n) % n], s = e[i], c = e[(i + 1) % n], l = Math.max(0, Math.min(a, k(o, s) / 2, k(s, c) / 2)), u = A(s, o, l), d = A(s, c, l);
48
- r += `${i === 0 ? "M" : " L"} ${j(u)}`, r += ` Q ${j(s)} ${j(d)}`;
47
+ let a = typeof t == "number" ? t : t[i], o = e[(i - 1 + n) % n], s = e[i], c = e[(i + 1) % n], l = Math.max(0, Math.min(a, A(o, s) / 2, A(s, c) / 2)), u = j(s, o, l), d = j(s, c, l);
48
+ r += `${i === 0 ? "M" : " L"} ${M(u)}`, r += ` Q ${M(s)} ${M(d)}`;
49
49
  }
50
50
  return `${r} Z`;
51
51
  }
52
- function N(e) {
53
- let { x: t, y: n, upperWidth: r, lowerWidth: i, height: a } = e, o = e.radius, s = e.topRadius ?? o ?? T, c = e.bottomRadius ?? o ?? E;
52
+ function P(e) {
53
+ let { x: t, y: n, upperWidth: r, lowerWidth: i, height: a } = e, o = e.radius, s = e.topRadius ?? o ?? E, c = e.bottomRadius ?? o ?? D;
54
54
  if (a <= 0 || r <= 0 && i <= 0) return "";
55
55
  let l = t + r / 2, u = r <= 0 ? [[l, n]] : [[t, n], [t + r, n]], d = i <= 0 ? [[l, n + a]] : [[l + i / 2, n + a], [l - i / 2, n + a]], f = [...u.map(() => s), ...d.map(() => c)];
56
- return M([...u, ...d], f);
56
+ return N([...u, ...d], f);
57
57
  }
58
- function P(e) {
58
+ function F(e) {
59
59
  let { x: t, y: n, upperWidth: r, lowerWidth: i, height: a, gap: o } = e;
60
60
  if (o <= 0 || a <= o) return {
61
61
  x: t,
@@ -73,32 +73,32 @@ function P(e) {
73
73
  height: a - o
74
74
  };
75
75
  }
76
- var F = 96, I = {
76
+ var I = 96, L = {
77
77
  top: 8,
78
- right: F,
78
+ right: I,
79
79
  bottom: 8,
80
80
  left: 24
81
- }, L = "75%";
82
- function R(e) {
81
+ }, R = "75%";
82
+ function z(e) {
83
83
  return e.includes("-");
84
84
  }
85
- function z(e) {
85
+ function B(e) {
86
86
  let { showLabels: t, labelPosition: n, labelFormat: r } = e;
87
- return t && n === "right" && R(r) ? L : void 0;
87
+ return t && n === "right" && z(r) ? R : void 0;
88
88
  }
89
- function B(e) {
89
+ function V(e) {
90
90
  let { showLabels: t, labelPosition: n, showValueLabels: r, valuePosition: i } = e, a = t ? n : void 0, o = r ? i : void 0, s = a === "left" || o === "left";
91
- return !s && a !== "right" && o !== "right" ? { ...D } : {
92
- ...I,
93
- left: s ? F : I.left
91
+ return !s && a !== "right" && o !== "right" ? { ...O } : {
92
+ ...L,
93
+ left: s ? I : L.left
94
94
  };
95
95
  }
96
- var V = (e) => {
96
+ var H = (e) => {
97
97
  let t = typeof e == "number" ? e : Number(e);
98
98
  return Number.isFinite(t) ? `${(t * 100).toFixed(1)}%` : String(e);
99
99
  };
100
- function H(e) {
101
- let { name: t, value: n, base: r, format: i, formatter: a, percentFormatter: o = V } = e, s = a ? a(n) : String(n), c = typeof n == "number" ? n : Number(n), l = r > 0 && Number.isFinite(c) ? o(c / r) : "";
100
+ function U(e) {
101
+ let { name: t, value: n, base: r, format: i, formatter: a, percentFormatter: o = H } = e, s = a ? a(n) : String(n), c = typeof n == "number" ? n : Number(n), l = r > 0 && Number.isFinite(c) ? o(c / r) : "";
102
102
  switch (i) {
103
103
  case "name": return t;
104
104
  case "value": return s;
@@ -108,160 +108,160 @@ function H(e) {
108
108
  case "value-percent": return l ? `${s} (${l})` : s;
109
109
  }
110
110
  }
111
- function U({ x: t = 0, y: n = 0, upperWidth: r = 0, lowerWidth: i = 0, height: a = 0, fill: o, stroke: s, strokeWidth: c, className: l, isActive: d, payload: f, showActiveShape: p, topStageIndex: m = 0 }) {
112
- let h = N(P({
111
+ function te({ x: t = 0, y: n = 0, upperWidth: r = 0, lowerWidth: i = 0, height: a = 0, fill: o, stroke: s, strokeWidth: c, className: l, isActive: u, payload: f, showActiveShape: p, topStageIndex: m = 0 }) {
112
+ let h = P(F({
113
113
  x: t,
114
114
  y: n,
115
115
  upperWidth: r,
116
116
  lowerWidth: i,
117
117
  height: a,
118
- gap: f?.[x] === m ? 0 : w
118
+ gap: f?.[S] === m ? 0 : T
119
119
  }));
120
120
  if (!h) return null;
121
- let g = !!(d && p);
122
- return /* @__PURE__ */ u("path", {
121
+ let g = !!(u && p);
122
+ return /* @__PURE__ */ d("path", {
123
123
  className: e("recharts-funnel-stage", l),
124
124
  d: h,
125
125
  fill: o,
126
- stroke: g ? S : s,
127
- strokeWidth: g ? C : c
126
+ stroke: g ? C : s,
127
+ strokeWidth: g ? w : c
128
128
  });
129
129
  }
130
- var W = l.forwardRef(({ className: t, config: S, palette: C, data: w, dataKey: T, nameKey: E, lastShape: D = "triangle", reversed: k = !1, showLabels: A = !1, labelFormat: j = "name", labelPosition: M = "right", showValueLabels: N = !1, valuePosition: P, labelFill: F, labelFormatter: I, percentFormatter: L, showLegend: R = !0, legendValueFormatter: V, stageSettings: W, showActiveShape: G = !1, stroke: K, strokeWidth: q, funnelWidth: te, margin: ne, showTooltip: re = !0, tooltipContent: ie, animate: ae, animationDuration: oe, animationBegin: se, animationEasing: ce, ...le }, ue) => {
131
- let de = s({
132
- animate: ae,
133
- animationDuration: oe,
134
- animationBegin: se,
135
- animationEasing: ce
136
- }), J = l.useMemo(() => {
137
- let e = w.filter((e) => !W?.[String(e[E])]?.hidden), t = e.reduce((e, t) => {
138
- let n = Number(t[T]);
130
+ var W = u.forwardRef(({ className: t, config: C, palette: w, data: T, dataKey: E, nameKey: D, lastShape: O = "triangle", reversed: A = !1, showLabels: j = !1, labelFormat: M = "name", labelPosition: N = "right", showValueLabels: P = !1, valuePosition: F, labelFill: I, labelFormatter: L, percentFormatter: R, showLegend: z = !0, legendValueFormatter: H, stageSettings: W, showActiveShape: ne = !1, stroke: re, strokeWidth: G, funnelWidth: ie, margin: ae, showTooltip: K = !0, tooltipContent: q, animate: oe, animationDuration: se, animationBegin: ce, animationEasing: le, ...ue }, de) => {
131
+ let fe = c({
132
+ animate: oe,
133
+ animationDuration: se,
134
+ animationBegin: ce,
135
+ animationEasing: le
136
+ }), J = u.useMemo(() => {
137
+ let e = T.filter((e) => !W?.[String(e[D])]?.hidden), t = e.reduce((e, t) => {
138
+ let n = Number(t[E]);
139
139
  return Number.isFinite(n) && n > e ? n : e;
140
140
  }, 0);
141
141
  return e.map((e, n) => {
142
- let r = String(e[E]), i = W?.[r]?.color ?? `var(--color-${r})`, a = {
142
+ let r = String(e[D]), i = W?.[r]?.color ?? `var(--color-${s(r)})`, a = {
143
143
  name: r,
144
- value: e[T],
144
+ value: e[E],
145
145
  base: t,
146
- formatter: I,
147
- percentFormatter: L
146
+ formatter: L,
147
+ percentFormatter: R
148
148
  };
149
149
  return {
150
150
  ...e,
151
151
  fill: i,
152
- [x]: n,
153
- [y]: H({
152
+ [S]: n,
153
+ [b]: U({
154
154
  ...a,
155
- format: j
155
+ format: M
156
156
  }),
157
- [b]: H({
157
+ [x]: U({
158
158
  ...a,
159
159
  format: "value"
160
160
  })
161
161
  };
162
162
  });
163
163
  }, [
164
- w,
165
164
  T,
166
- j,
167
- I,
168
165
  E,
166
+ M,
169
167
  L,
170
- W
171
- ]), Y = l.useMemo(() => R ? o(S, C ?? O) : null, [
168
+ D,
172
169
  R,
173
- S,
174
- C
175
- ]), fe = l.useMemo(() => {
170
+ W
171
+ ]), Y = u.useMemo(() => z ? o(C, w ?? k) : null, [
172
+ z,
173
+ C,
174
+ w
175
+ ]), pe = u.useMemo(() => {
176
176
  if (!Y) return [];
177
177
  let e = /* @__PURE__ */ new Set();
178
178
  return J.flatMap((t) => {
179
- let n = String(t[E]);
179
+ let n = String(t[D]);
180
180
  return e.has(n) ? [] : (e.add(n), [{
181
181
  value: n,
182
- dataKey: E,
182
+ dataKey: D,
183
183
  type: "rect",
184
184
  color: W?.[n]?.color ?? Y[n]?.color ?? String(t.fill),
185
185
  payload: t
186
186
  }]);
187
187
  });
188
188
  }, [
189
- E,
189
+ D,
190
190
  J,
191
191
  Y,
192
192
  W
193
- ]), X = P ?? v(M), pe = A && M !== "inside" || N && X !== "inside", Z = _[M], Q = _[X], me = {
194
- ...B({
195
- showLabels: A,
196
- labelPosition: M,
197
- showValueLabels: N,
193
+ ]), X = F ?? y(N), me = j && N !== "inside" || P && X !== "inside", Z = v[N], Q = v[X], he = {
194
+ ...V({
195
+ showLabels: j,
196
+ labelPosition: N,
197
+ showValueLabels: P,
198
198
  valuePosition: X
199
199
  }),
200
- ...ne
201
- }, he = te ?? z({
202
- showLabels: A,
203
- labelPosition: M,
204
- labelFormat: j
205
- }), ge = K ?? (q == null ? "none" : "var(--ui-border-on-surface-border)"), $ = (e) => /* @__PURE__ */ u(U, {
200
+ ...ae
201
+ }, ge = ie ?? B({
202
+ showLabels: j,
203
+ labelPosition: N,
204
+ labelFormat: M
205
+ }), _e = re ?? (G == null ? "none" : "var(--ui-border-on-surface-border)"), $ = (e) => /* @__PURE__ */ d(te, {
206
206
  ...e,
207
- showActiveShape: G,
208
- topStageIndex: k ? J.length - 1 : 0
207
+ showActiveShape: ne,
208
+ topStageIndex: A ? J.length - 1 : 0
209
209
  });
210
- return /* @__PURE__ */ d("div", {
211
- ref: ue,
212
- "data-last-shape": D,
213
- className: e("flex flex-row items-center gap-4", !R && "justify-center", g({ lastShape: D }), t),
214
- ...le,
215
- children: [/* @__PURE__ */ u("div", {
216
- className: pe ? "h-[120px] flex-1" : e(ee, "shrink-0"),
217
- children: /* @__PURE__ */ u(n, {
218
- config: S,
219
- palette: C ?? O,
210
+ return /* @__PURE__ */ f("div", {
211
+ ref: de,
212
+ "data-last-shape": O,
213
+ className: e("flex flex-row items-center gap-4", !z && "justify-center", _({ lastShape: O }), t),
214
+ ...ue,
215
+ children: [/* @__PURE__ */ d("div", {
216
+ className: me ? "h-[120px] flex-1" : e(ee, "shrink-0"),
217
+ children: /* @__PURE__ */ d(n, {
218
+ config: C,
219
+ palette: w ?? k,
220
220
  className: "size-full",
221
- children: /* @__PURE__ */ d(m, {
222
- margin: me,
223
- children: [re && /* @__PURE__ */ u(i, { content: ie ?? /* @__PURE__ */ u(a, {
224
- nameKey: E,
221
+ children: /* @__PURE__ */ f(h, {
222
+ margin: he,
223
+ children: [K && /* @__PURE__ */ d(i, { content: q ?? /* @__PURE__ */ d(a, {
224
+ nameKey: D,
225
225
  hideLabel: !0
226
- }) }), /* @__PURE__ */ d(p, {
227
- dataKey: T,
228
- nameKey: E,
226
+ }) }), /* @__PURE__ */ f(m, {
227
+ dataKey: E,
228
+ nameKey: D,
229
229
  data: J,
230
- lastShapeType: D ?? "triangle",
231
- reversed: k,
232
- width: he,
233
- stroke: ge,
234
- strokeWidth: q,
230
+ lastShapeType: O ?? "triangle",
231
+ reversed: A,
232
+ width: ge,
233
+ stroke: _e,
234
+ strokeWidth: G,
235
235
  shape: $,
236
236
  activeShape: $,
237
- ...de,
237
+ ...fe,
238
238
  children: [
239
- J.map((e, t) => /* @__PURE__ */ u(f, { fill: String(e.fill) }, t)),
240
- A && /* @__PURE__ */ u(h, {
239
+ J.map((e, t) => /* @__PURE__ */ d(p, { fill: String(e.fill) }, t)),
240
+ j && /* @__PURE__ */ d(g, {
241
241
  position: Z,
242
- dataKey: y,
243
- className: F ? void 0 : c(Z),
244
- fill: F,
242
+ dataKey: b,
243
+ className: I ? void 0 : l(Z),
244
+ fill: I,
245
245
  stroke: "none"
246
246
  }),
247
- N && /* @__PURE__ */ u(h, {
247
+ P && /* @__PURE__ */ d(g, {
248
248
  position: Q,
249
- dataKey: b,
250
- className: F ? void 0 : c(Q),
251
- fill: F,
249
+ dataKey: x,
250
+ className: I ? void 0 : l(Q),
251
+ fill: I,
252
252
  stroke: "none"
253
253
  })
254
254
  ]
255
255
  })]
256
256
  })
257
257
  })
258
- }), R && Y && /* @__PURE__ */ u(r, {
258
+ }), z && Y && /* @__PURE__ */ d(r, {
259
259
  variant: "list",
260
- payload: fe,
260
+ payload: pe,
261
261
  config: Y,
262
- nameKey: E,
263
- valueKey: T,
264
- valueFormatter: V,
262
+ nameKey: D,
263
+ valueKey: E,
264
+ valueFormatter: H,
265
265
  valueClassName: "text-[var(--ui-text-on-surface-primary)]",
266
266
  className: "min-w-0 flex-1"
267
267
  })]
@@ -269,6 +269,6 @@ var W = l.forwardRef(({ className: t, config: S, palette: C, data: w, dataKey: T
269
269
  });
270
270
  W.displayName = "FunnelChart";
271
271
  //#endregion
272
- export { O as FUNNEL_CHART_DEFAULT_PALETTE, W as FunnelChart, B as funnelChartLabelMargin, z as funnelChartLabelReserve, H as funnelChartLabelText, v as funnelChartOppositeSide, V as funnelChartPercent, P as funnelChartStageInset, N as funnelChartStagePath, g as funnelChartVariants };
272
+ export { k as FUNNEL_CHART_DEFAULT_PALETTE, W as FunnelChart, V as funnelChartLabelMargin, B as funnelChartLabelReserve, U as funnelChartLabelText, y as funnelChartOppositeSide, H as funnelChartPercent, F as funnelChartStageInset, P as funnelChartStagePath, _ as funnelChartVariants };
273
273
 
274
274
  //# sourceMappingURL=funnel-chart.js.map