@sybilion/uilib 1.7.2 → 1.8.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 (85) hide show
  1. package/dist/agent-glossary/content-prompt.generated.ts +2 -0
  2. package/dist/agent-glossary/content.generated.ts +2 -0
  3. package/dist/agent-glossary/content.md +2 -0
  4. package/dist/agent-glossary/content.prompt.md +2 -0
  5. package/dist/agent-glossary/workspace.generated.ts +1 -0
  6. package/dist/agent-glossary/workspace.index.md +1 -0
  7. package/dist/agent-glossary/workspace.md +1 -0
  8. package/dist/esm/src/components/ui/AnalysesSelector/AnalysesSelector.js +37 -20
  9. package/dist/esm/src/components/ui/Chart/Chart.styl.js +2 -2
  10. package/dist/esm/src/components/ui/Chart/components/BaseChartWrapper.js +46 -51
  11. package/dist/esm/src/components/ui/Chart/components/ChartContainer.js +2 -2
  12. package/dist/esm/src/components/ui/Chart/components/ChartGrid.js +2 -2
  13. package/dist/esm/src/components/ui/Chart/components/ChartLegendContent.js +2 -2
  14. package/dist/esm/src/components/ui/Chart/components/ChartLegendItem.js +2 -2
  15. package/dist/esm/src/components/ui/Chart/components/ChartTooltipContent.js +2 -2
  16. package/dist/esm/src/components/ui/Chart/components/ChartTooltipItem.js +3 -3
  17. package/dist/esm/src/components/ui/Chart/components/CustomChartLegend/CustomChartLegend.js +8 -3
  18. package/dist/esm/src/components/ui/Chart/components/LegendSvg/LegendSvg.js +1 -1
  19. package/dist/esm/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.js +17 -6
  20. package/dist/esm/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.js +40 -10
  21. package/dist/esm/src/components/ui/ChartAreaInteractive/ChartLines.js +43 -13
  22. package/dist/esm/src/components/ui/ChartAreaInteractive/chartHistories.js +44 -0
  23. package/dist/esm/src/components/ui/ChartAreaInteractive/overlays/useChartYRange.js +32 -7
  24. package/dist/esm/src/components/ui/Page/PageTabs/PageTabs.styl.js +2 -2
  25. package/dist/esm/src/components/ui/Page/PageXScroll/PageXScroll.js +50 -15
  26. package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.js +212 -0
  27. package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.js +123 -0
  28. package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.styl.js +7 -0
  29. package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.js +29 -0
  30. package/dist/esm/src/index.js +3 -1
  31. package/dist/esm/src/utils/chartConnectionPoint.js +31 -16
  32. package/dist/esm/types/src/components/ui/AnalysesSelector/AnalysesSelector.d.ts +1 -1
  33. package/dist/esm/types/src/components/ui/AnalysesSelector/AnalysesSelector.types.d.ts +12 -0
  34. package/dist/esm/types/src/components/ui/AnalysesSelector/index.d.ts +1 -1
  35. package/dist/esm/types/src/components/ui/Chart/components/BaseChartWrapper.d.ts +8 -0
  36. package/dist/esm/types/src/components/ui/Chart/components/CustomChartLegend/CustomChartLegend.d.ts +8 -1
  37. package/dist/esm/types/src/components/ui/Chart/components/LegendSvg/LegendSvg.d.ts +2 -0
  38. package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.d.ts +1 -1
  39. package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.d.ts +5 -0
  40. package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartLines.d.ts +19 -1
  41. package/dist/esm/types/src/components/ui/ChartAreaInteractive/chartHistories.d.ts +40 -0
  42. package/dist/esm/types/src/components/ui/ChartAreaInteractive/index.d.ts +1 -0
  43. package/dist/esm/types/src/components/ui/ChartAreaInteractive/overlays/useChartYRange.d.ts +6 -1
  44. package/dist/esm/types/src/components/ui/Page/PageXScroll/PageXScroll.d.ts +1 -1
  45. package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.d.ts +3 -0
  46. package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.d.ts +65 -0
  47. package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.d.ts +20 -0
  48. package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.types.d.ts +85 -0
  49. package/dist/esm/types/src/components/ui/StackedAreaChart/index.d.ts +2 -0
  50. package/dist/esm/types/src/docs/pages/StackedAreaChartPage.d.ts +1 -0
  51. package/dist/esm/types/src/index.d.ts +1 -0
  52. package/dist/esm/types/src/utils/chartConnectionPoint.d.ts +11 -3
  53. package/dist/esm/types/tests/chartHistories.test.d.ts +1 -0
  54. package/dist/esm/types/tests/pageXScroll.test.d.ts +1 -0
  55. package/dist/esm/types/tests/stackedAreaChart.test.d.ts +1 -0
  56. package/package.json +1 -1
  57. package/src/components/ui/AnalysesSelector/AnalysesSelector.tsx +50 -22
  58. package/src/components/ui/AnalysesSelector/AnalysesSelector.types.ts +13 -0
  59. package/src/components/ui/AnalysesSelector/index.ts +1 -0
  60. package/src/components/ui/Chart/components/BaseChartWrapper.tsx +71 -52
  61. package/src/components/ui/Chart/components/CustomChartLegend/CustomChartLegend.tsx +21 -1
  62. package/src/components/ui/Chart/components/LegendSvg/LegendSvg.tsx +3 -1
  63. package/src/components/ui/ChartAreaInteractive/AGENT.md +2 -0
  64. package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.ts +27 -5
  65. package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.tsx +64 -10
  66. package/src/components/ui/ChartAreaInteractive/ChartLines.tsx +86 -30
  67. package/src/components/ui/ChartAreaInteractive/chartHistories.ts +63 -0
  68. package/src/components/ui/ChartAreaInteractive/index.ts +1 -0
  69. package/src/components/ui/ChartAreaInteractive/overlays/useChartYRange.ts +52 -6
  70. package/src/components/ui/Page/AGENT.md +2 -0
  71. package/src/components/ui/Page/PageTabs/PageTabs.styl +8 -0
  72. package/src/components/ui/Page/PageXScroll/PageXScroll.tsx +57 -13
  73. package/src/components/ui/StackedAreaChart/AGENT.md +26 -0
  74. package/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.ts +268 -0
  75. package/src/components/ui/StackedAreaChart/StackedAreaChart.styl +32 -0
  76. package/src/components/ui/StackedAreaChart/StackedAreaChart.styl.d.ts +13 -0
  77. package/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.tsx +82 -0
  78. package/src/components/ui/StackedAreaChart/StackedAreaChart.tsx +416 -0
  79. package/src/components/ui/StackedAreaChart/StackedAreaChart.types.ts +97 -0
  80. package/src/components/ui/StackedAreaChart/index.ts +2 -0
  81. package/src/docs/pages/ChartAreaInteractivePage.tsx +67 -0
  82. package/src/docs/pages/StackedAreaChartPage.tsx +141 -0
  83. package/src/docs/registry.ts +6 -0
  84. package/src/index.ts +1 -0
  85. package/src/utils/chartConnectionPoint.ts +41 -18
@@ -0,0 +1,123 @@
1
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
2
+ import cn from 'classnames';
3
+ import { forwardRef, useMemo } from 'react';
4
+ import { ChartTooltip } from '../Chart/Chart.js';
5
+ import ChartS from '../Chart/Chart.styl.js';
6
+ import { getChartSeriesColor } from '../Chart/chartSeriesPalette.js';
7
+ import { useLegendState } from '../Chart/hooks/useLegendState.js';
8
+ import { ComposedChart, CartesianGrid, XAxis, YAxis, ReferenceArea, Bar, Area, Line } from 'recharts';
9
+ import { stackRows, stackWeights, valueAxis, chartTop, yearTicks, MARGIN_KEY, yearLabel, compareRowZones, compareZones } from './StackedAreaChart.helpers.js';
10
+ import S from './StackedAreaChart.styl.js';
11
+ import { StackedTooltip } from './StackedAreaChart.tooltip.js';
12
+ import { ChartContainer } from '../Chart/components/ChartContainer.js';
13
+
14
+ const STACK_ID = 'stack';
15
+ const DEFAULT_BARS_BELOW = 3;
16
+ const DEFAULT_MARGIN_COLOR = 'var(--sb-slate-300)';
17
+ const DEFAULT_OVERLAY_COLOR = 'var(--foreground)';
18
+ const ZONE_FILL = {
19
+ above: 'var(--sb-green-100)',
20
+ below: 'var(--sb-red-100)',
21
+ };
22
+ const DEFAULT_ZONE_LABELS = { above: 'above', below: 'below' };
23
+ const NO_OVERLAYS = [];
24
+ /** Joins keys into one memo dependency; a key cannot hold this character. */
25
+ const KEY_SEP = '\u0000';
26
+ /** Each key is prefixed with the separator, so an empty key survives the trip. */
27
+ const joinKeys = (keys) => keys.map(key => KEY_SEP + key).join('');
28
+ const splitKeys = (joined) => joined.split(KEY_SEP).slice(1);
29
+ /**
30
+ * Recharts 3 draws by layer: grid -100, area 100, bar 300, line 400. Zones go
31
+ * over the grid and under the stack.
32
+ */
33
+ const ZONE_Z_INDEX = 50;
34
+ const AXIS_LINE = { stroke: 'var(--border)', strokeWidth: 1 };
35
+ const layerColor = (layer, index) => layer.color ?? getChartSeriesColor(index);
36
+ const overlayColor = (overlay) => overlay.color ?? DEFAULT_OVERLAY_COLOR;
37
+ function LegendEntry({ swatch, label, extra, dimmed, onClick, }) {
38
+ const content = (jsxs(Fragment, { children: [swatch, label, extra != null && jsx("span", { className: S.legendExtra, children: extra })] }));
39
+ return onClick ? (jsx("button", { type: "button", className: cn(ChartS.legendItem, S.legendButton, dimmed && S.dimmed), "aria-pressed": !dimmed, onClick: onClick, children: content })) : (jsx("span", { className: ChartS.legendItem, children: content }));
40
+ }
41
+ const StackedAreaChart = forwardRef(({ className, data, xKey, layers, overlays = NO_OVERLAYS, margin, showWeights = true, yearTicks: yearTicks$1 = false, barsBelow = DEFAULT_BARS_BELOW, zoneLabels = DEFAULT_ZONE_LABELS, hiddenKeys, onToggleKey, showLegend = true, showTooltip = true, showGrid = true, valueFormatter, xTickFormatter, tooltipLabelFormatter, height, ...props }, ref) => {
42
+ const legend = useLegendState();
43
+ const hidden = hiddenKeys ?? legend.hiddenSeries;
44
+ // With hiddenKeys and no onToggleKey nothing can change visibility, so
45
+ // the legend entries are not buttons.
46
+ const toggle = hiddenKeys && !onToggleKey
47
+ ? undefined
48
+ : (key) => {
49
+ onToggleKey?.(key);
50
+ if (!hiddenKeys)
51
+ legend.toggleSeries(key);
52
+ };
53
+ // Keyed on the joined keys, so layers passed inline do not redo the maths.
54
+ const layerKeysJoined = joinKeys(layers.map(l => l.key));
55
+ const visibleKeysJoined = joinKeys(layers.filter(l => !hidden.has(l.key)).map(l => l.key));
56
+ const layerKeys = useMemo(() => splitKeys(layerKeysJoined), [layerKeysJoined]);
57
+ // Recharts leaves hidden layers out of the stack, so the margin and the
58
+ // zones follow the stack that is drawn.
59
+ const visibleKeys = useMemo(() => splitKeys(visibleKeysJoined), [visibleKeysJoined]);
60
+ const marginPct = margin?.pct ?? null;
61
+ const marginOn = marginPct != null && marginPct > 0;
62
+ const marginLabel = margin?.label ?? `margin ${marginPct ?? 0}%`;
63
+ const marginColor = margin?.color ?? DEFAULT_MARGIN_COLOR;
64
+ const rows = useMemo(() => stackRows(data, layerKeys, marginPct, visibleKeys), [data, layerKeys, marginPct, visibleKeys]);
65
+ // Shares of the layers that are drawn, from the data: typing a margin
66
+ // does not change them.
67
+ const weights = useMemo(() => (showWeights ? stackWeights(data, visibleKeys) : undefined), [showWeights, data, visibleKeys]);
68
+ const asBars = rows.length < barsBelow;
69
+ const compareKey = overlays.find(o => o.compare)?.key;
70
+ const zonesOn = compareKey != null && !hidden.has(compareKey);
71
+ const zones = useMemo(() => {
72
+ if (!zonesOn || compareKey == null)
73
+ return [];
74
+ const find = asBars ? compareRowZones : compareZones;
75
+ return find(rows, xKey, visibleKeys, compareKey);
76
+ }, [zonesOn, compareKey, asBars, rows, xKey, visibleKeys]);
77
+ const zoneKinds = ['above', 'below'].filter(kind => zones.some(zone => zone.kind === kind));
78
+ const visibleLinesJoined = joinKeys(overlays.filter(o => !hidden.has(o.key)).map(o => o.key));
79
+ const yAxis = useMemo(() => valueAxis(chartTop(rows, visibleKeys, splitKeys(visibleLinesJoined))), [rows, visibleKeys, visibleLinesJoined]);
80
+ const ticks = useMemo(() => (yearTicks$1 ? yearTicks(data, xKey) : undefined), [yearTicks$1, data, xKey]);
81
+ const config = useMemo(() => {
82
+ const out = {};
83
+ layers.forEach((layer, index) => {
84
+ out[layer.key] = {
85
+ label: layer.label ?? layer.key,
86
+ color: layerColor(layer, index),
87
+ };
88
+ });
89
+ out[MARGIN_KEY] = { label: marginLabel, color: marginColor };
90
+ overlays.forEach(overlay => {
91
+ out[overlay.key] = {
92
+ label: overlay.label ?? overlay.key,
93
+ color: overlayColor(overlay),
94
+ };
95
+ });
96
+ return out;
97
+ }, [layers, overlays, marginLabel, marginColor]);
98
+ const stackProps = {
99
+ stackId: STACK_ID,
100
+ stroke: 'var(--background)',
101
+ strokeWidth: 1,
102
+ isAnimationActive: false,
103
+ };
104
+ return (jsxs("div", { ref: ref, className: cn(S.root, className), ...props, children: [jsx(ChartContainer, { config: config, style: height ? { height: `${height}px` } : undefined, children: jsxs(ComposedChart, { data: rows, accessibilityLayer: true, children: [showGrid && (jsx(CartesianGrid, { stroke: "var(--border)", strokeWidth: 0.6, vertical: false })), jsx(XAxis, { dataKey: xKey,
105
+ // A point scale runs the areas edge to edge and starts and ends
106
+ // each zone on its rows; bars keep a band each.
107
+ scale: asBars ? 'auto' : 'point', ticks: ticks, tickFormatter: ticks ? yearLabel : xTickFormatter, minTickGap: ticks ? 8 : 24, tickLine: false, axisLine: AXIS_LINE }), jsx(YAxis
108
+ // Our own steps: automatic rounding can double the axis when the
109
+ // margin nudges the top past a round number.
110
+ , {
111
+ // Our own steps: automatic rounding can double the axis when the
112
+ // margin nudges the top past a round number.
113
+ domain: [0, yAxis.max], ticks: yAxis.ticks, allowDataOverflow: true, tickFormatter: valueFormatter, width: 56, tickLine: false, axisLine: AXIS_LINE }), showTooltip && (jsx(ChartTooltip, { content: tooltip => (jsx(StackedTooltip, { active: tooltip.active, payload: tooltip.payload, label: tooltip.label, config: config, valueFormatter: valueFormatter, labelFormatter: tooltipLabelFormatter })) })), zones.map(zone => (jsx(ReferenceArea, { x1: zone.x1, x2: zone.x2, fill: ZONE_FILL[zone.kind], fillOpacity: 1, stroke: "none", ifOverflow: "hidden", zIndex: ZONE_Z_INDEX }, `${zone.kind}-${String(zone.x1)}`))), layers.map((layer, index) => asBars ? (jsx(Bar, { dataKey: layer.key, name: layer.key, fill: layerColor(layer, index), maxBarSize: 96, hide: hidden.has(layer.key), ...stackProps }, layer.key)) : (jsx(Area, { type: "monotone", dataKey: layer.key, name: layer.key, fill: layerColor(layer, index), fillOpacity: 1, hide: hidden.has(layer.key), ...stackProps }, layer.key))), margin &&
114
+ (asBars ? (jsx(Bar, { dataKey: MARGIN_KEY, name: MARGIN_KEY, fill: marginColor, maxBarSize: 96, hide: !marginOn, ...stackProps }, MARGIN_KEY)) : (jsx(Area, { type: "monotone", dataKey: MARGIN_KEY, name: MARGIN_KEY, fill: marginColor, fillOpacity: 1, hide: !marginOn, ...stackProps }, MARGIN_KEY))), overlays.map(overlay => {
115
+ const color = overlayColor(overlay);
116
+ return (jsx(Line, { type: "linear", dataKey: overlay.key, name: overlay.key, stroke: color, strokeWidth: 1.75, dot: asBars ? { r: 4, fill: color, stroke: color } : false, activeDot: false, connectNulls: true, isAnimationActive: false, hide: hidden.has(overlay.key) }, overlay.key));
117
+ })] }) }), showLegend && (jsxs("div", { className: cn(ChartS.legendContainer, S.legend), children: [layers.map((layer, index) => (jsx(LegendEntry, { swatch: jsx("span", { className: ChartS.legendIndicator, style: { backgroundColor: layerColor(layer, index) } }), label: layer.label ?? layer.key, extra: weights && !hidden.has(layer.key)
118
+ ? `${weights[layer.key] ?? 0}%`
119
+ : undefined, dimmed: hidden.has(layer.key), onClick: toggle && (() => toggle(layer.key)) }, layer.key))), marginOn && (jsx(LegendEntry, { swatch: jsx("span", { className: ChartS.legendIndicator, style: { backgroundColor: marginColor } }), label: marginLabel })), overlays.map(overlay => (jsx(LegendEntry, { swatch: jsx("span", { className: S.legendLine, style: { backgroundColor: overlayColor(overlay) } }), label: overlay.label ?? overlay.key, dimmed: hidden.has(overlay.key), onClick: toggle && (() => toggle(overlay.key)) }, overlay.key))), zoneKinds.map(kind => (jsx(LegendEntry, { swatch: jsx("span", { className: cn(ChartS.legendIndicator, S.legendZone), style: { backgroundColor: ZONE_FILL[kind] } }), label: zoneLabels[kind] }, kind)))] }))] }));
120
+ });
121
+ StackedAreaChart.displayName = 'StackedAreaChart';
122
+
123
+ export { StackedAreaChart };
@@ -0,0 +1,7 @@
1
+ import styleInject from 'style-inject';
2
+
3
+ var css_248z = ".StackedAreaChart_root__BkxHH{width:100%}.StackedAreaChart_legend__JVlx8{flex-wrap:wrap;margin-top:.75rem;row-gap:.5rem}.StackedAreaChart_legendButton__-nJsf{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:none;border:0;color:inherit;cursor:pointer;font:inherit;padding:0}.StackedAreaChart_dimmed__L-fX7{opacity:.4}.StackedAreaChart_legendExtra__xGgeV{color:var(--muted-foreground);font-feature-settings:\"tnum\";font-variant-numeric:tabular-nums}.StackedAreaChart_legendLine__UDtNb{border-radius:1px;flex-shrink:0;height:2px;width:14px}.StackedAreaChart_legendZone__-47oB{border:1px solid var(--border)}";
4
+ var S = {"root":"StackedAreaChart_root__BkxHH","legend":"StackedAreaChart_legend__JVlx8","legendButton":"StackedAreaChart_legendButton__-nJsf","dimmed":"StackedAreaChart_dimmed__L-fX7","legendExtra":"StackedAreaChart_legendExtra__xGgeV","legendLine":"StackedAreaChart_legendLine__UDtNb","legendZone":"StackedAreaChart_legendZone__-47oB"};
5
+ styleInject(css_248z);
6
+
7
+ export { S as default };
@@ -0,0 +1,29 @@
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
+ import cn from 'classnames';
3
+ import ChartS from '../Chart/Chart.styl.js';
4
+
5
+ /**
6
+ * Tooltip rows in series order, showing real zeros (ChartTooltipContent hides
7
+ * them) and colouring each row from the chart config (an area's own colour
8
+ * is its white stack stroke).
9
+ */
10
+ function StackedTooltip({ active, payload, label, config, valueFormatter, labelFormatter, }) {
11
+ const rows = (payload ?? []).filter(row => typeof row.value === 'number' && Number.isFinite(row.value));
12
+ if (!active || rows.length === 0)
13
+ return null;
14
+ const x = typeof label === 'number' || typeof label === 'string' ? label : '';
15
+ return (jsxs("div", { className: ChartS.tooltipContainer, children: [jsx("div", { className: "font-medium", children: labelFormatter ? labelFormatter(x) : String(x) }), jsx("div", { className: ChartS.tooltipContentGrid, children: rows.map(row => {
16
+ const key = String(row.dataKey ?? row.name);
17
+ const value = row.value;
18
+ return (jsxs("div", { className: cn(ChartS.tooltipItem, 'items-center'), children: [jsx("div", { className: cn(ChartS.tooltipIndicator, ChartS['indicator-dot']), style: {
19
+ '--color-bg': config[key]?.color ?? row.color,
20
+ '--color-border': config[key]?.color ?? row.color,
21
+ } }), jsxs("div", { className: cn(ChartS.tooltipContent, 'items-center'), children: [jsx("span", { className: cn('text-muted-foreground', ChartS.tooltipLabelText), children: config[key]?.label ?? String(row.name ?? key) }), jsx("span", { className: ChartS.tooltipValue, children: valueFormatter
22
+ ? valueFormatter(value)
23
+ : value.toLocaleString(undefined, {
24
+ maximumFractionDigits: 2,
25
+ }) })] })] }, key));
26
+ }) })] }));
27
+ }
28
+
29
+ export { StackedTooltip };
@@ -24,9 +24,11 @@ export { ChartLegend, ChartTooltip } from './components/ui/Chart/Chart.js';
24
24
  export { THEMES } from './components/ui/Chart/Chart.types.js';
25
25
  export { ChartAreaInteractive, chartConfig } from './components/ui/ChartAreaInteractive/ChartAreaInteractive.js';
26
26
  export { DRAG_TIME_RANGE_PREFIX, encodeDragTimeRange, filterDataForTimeRange, findPinPositionForDate, isAnalysisDone, isAnalysisFailed, isAnalysisNotFailed, isTimeRangePreset, longDateFormatter, parseDragTimeRange, shortDateFormatter } from './components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.js';
27
- export { ChartLines, FORECAST_COLORS_MAP, FORECAST_LINE_COLORS, getForecastColor, getForecastQuantileBandColor, resolveQuantileBandFillForForecastLine } from './components/ui/ChartAreaInteractive/ChartLines.js';
27
+ export { ChartLines, FORECAST_COLORS_MAP, FORECAST_LINE_COLORS, getForecastColor, getForecastQuantileBandColor, getHistoryColor, resolveHistoryLines, resolveQuantileBandFillForForecastLine } from './components/ui/ChartAreaInteractive/ChartLines.js';
28
+ export { HISTORY_SERIES_KEY, forecastHistoryKey, historySeriesKey, historySeriesKeys, isHistorySeriesKey } from './components/ui/ChartAreaInteractive/chartHistories.js';
28
29
  export { DonutChart } from './components/ui/DonutChart/DonutChart.js';
29
30
  export { BarChart } from './components/ui/BarChart/BarChart.js';
31
+ export { StackedAreaChart } from './components/ui/StackedAreaChart/StackedAreaChart.js';
30
32
  export { Checkbox } from './components/ui/Checkbox/Checkbox.js';
31
33
  export { Confirm } from './components/ui/Confirm/Confirm.js';
32
34
  export { Calendar } from './components/ui/DatePicker/Calendar.js';
@@ -1,3 +1,10 @@
1
+ import { HISTORY_SERIES_KEY } from '../components/ui/ChartAreaInteractive/chartHistories.js';
2
+
3
+ /** A history line's value on a row, or null when it has none. */
4
+ function historyValueAt(row, key) {
5
+ const v = row[key];
6
+ return v == null || Array.isArray(v) ? null : v;
7
+ }
1
8
  const FORECAST_KEY_RE = /^forecast_(\d+)$/;
2
9
  function collectForecastSeriesIds(chartData) {
3
10
  const ids = new Set();
@@ -21,7 +28,7 @@ function hasForecastValue(point, id) {
21
28
  * First forecast month for bridge logic — skips synthetic connection rows already
22
29
  * injected upstream (forecast equals historical on the month before the next forecast).
23
30
  */
24
- function findFirstForecastDateForBridge(rows, id) {
31
+ function findFirstForecastDateForBridge(rows, id, historyKey) {
25
32
  const dataKey = forecastSeriesKey(id);
26
33
  const withForecast = rows
27
34
  .filter(row => hasForecastValue(row, id))
@@ -34,10 +41,11 @@ function findFirstForecastDateForBridge(rows, id) {
34
41
  }
35
42
  const expectedBridgeDate = normalizeToMonthStart(getPreviousMonth(next.date));
36
43
  const forecastVal = row[dataKey];
44
+ const historyVal = historyValueAt(row, historyKey);
37
45
  const isSyntheticBridge = normalizeToMonthStart(row.date) === expectedBridgeDate &&
38
- row.historical != null &&
46
+ historyVal != null &&
39
47
  typeof forecastVal === 'number' &&
40
- forecastVal === row.historical;
48
+ forecastVal === historyVal;
41
49
  if (!isSyntheticBridge) {
42
50
  return row.date;
43
51
  }
@@ -49,7 +57,8 @@ function findFirstForecastDateForBridge(rows, id) {
49
57
  /**
50
58
  * Injects `forecast_{id}` on the row before each series’ first forecast month (historical value)
51
59
  * so dashed forecast lines meet the historical line. Matches sybilion-client bridge behavior.
52
- * Never overwrites an existing forecast value on that row.
60
+ * Never overwrites an existing forecast value on that row. With several history lines,
61
+ * `historyKeyFor` says which one each forecast joins (null: none).
53
62
  */
54
63
  function ensureChartForecastBridge(chartData, options) {
55
64
  if (options?.disabled || chartData.length === 0) {
@@ -63,9 +72,13 @@ function ensureChartForecastBridge(chartData, options) {
63
72
  return sorted;
64
73
  }
65
74
  const rows = sorted.map(p => ({ ...p }));
75
+ const historyKeyFor = options?.historyKeyFor ?? (() => HISTORY_SERIES_KEY);
66
76
  for (const id of seriesIds) {
77
+ const historyKey = historyKeyFor(id);
78
+ if (historyKey == null)
79
+ continue;
67
80
  const dataKey = forecastSeriesKey(id);
68
- const firstForecastDate = findFirstForecastDateForBridge(rows, id);
81
+ const firstForecastDate = findFirstForecastDateForBridge(rows, id, historyKey);
69
82
  if (!firstForecastDate)
70
83
  continue;
71
84
  const prevMonthRaw = getPreviousMonth(firstForecastDate);
@@ -73,17 +86,15 @@ function ensureChartForecastBridge(chartData, options) {
73
86
  const prevMonthIdx = rows.findIndex(row => normalizeToMonthStart(row.date) === prevMonthNorm);
74
87
  if (prevMonthIdx >= 0) {
75
88
  const existing = rows[prevMonthIdx][dataKey];
76
- const hPrev = rows[prevMonthIdx].historical;
77
- if ((existing === undefined || existing === null) &&
78
- hPrev !== undefined &&
79
- hPrev !== null) {
89
+ const hPrev = historyValueAt(rows[prevMonthIdx], historyKey);
90
+ if ((existing === undefined || existing === null) && hPrev !== null) {
80
91
  rows[prevMonthIdx] = {
81
92
  ...rows[prevMonthIdx],
82
93
  [dataKey]: hPrev,
83
94
  };
84
95
  }
85
96
  }
86
- const lastHist = findLastValidHistoricalChartPoint(rows);
97
+ const lastHist = findLastValidHistoricalChartPoint(rows, historyKey);
87
98
  if (!lastHist)
88
99
  continue;
89
100
  const normLast = normalizeToMonthStart(lastHist.date);
@@ -96,19 +107,23 @@ function ensureChartForecastBridge(chartData, options) {
96
107
  const existingAtLast = rows[idxLast][dataKey];
97
108
  if (existingAtLast !== undefined && existingAtLast !== null)
98
109
  continue;
99
- const hLast = rows[idxLast].historical;
100
- if (hLast !== undefined && hLast !== null) {
110
+ const hLast = historyValueAt(rows[idxLast], historyKey);
111
+ if (hLast !== null) {
101
112
  rows[idxLast] = { ...rows[idxLast], [dataKey]: hLast };
102
113
  }
103
114
  }
104
115
  return rows;
105
116
  }
106
117
  /**
107
- * Find the last valid historical data point from ChartDataPoint array
118
+ * Find the last valid historical data point from ChartDataPoint array, on the
119
+ * single `historical` line or on the history line under `key`.
108
120
  */
109
- function findLastValidHistoricalChartPoint(historical) {
110
- const validPoints = historical.filter(point => point.historical !== null && point.historical !== undefined);
111
- return validPoints.length > 0 ? validPoints[validPoints.length - 1] : null;
121
+ function findLastValidHistoricalChartPoint(historical, key = HISTORY_SERIES_KEY) {
122
+ for (let i = historical.length - 1; i >= 0; i--) {
123
+ if (historyValueAt(historical[i], key) !== null)
124
+ return historical[i];
125
+ }
126
+ return null;
112
127
  }
113
128
  function parseYearMonth(date) {
114
129
  const datePart = String(date).split(' ')[0] ?? date;
@@ -1,2 +1,2 @@
1
1
  import type { AnalysesSelectorProps } from './AnalysesSelector.types';
2
- export declare function AnalysesSelector({ items, selectedIds, onItemToggle, inlineMode, placeholder, disabled, size, variant, darker, className, triggerProps, onFailedItemClick, showHistorical, enableToggleHidden, maxVisibleItems, preventDeselection, hiddenSeries: hiddenSeriesProp, onToggleSeries, isAnalysisInProgress: isAnalysisInProgressProp, rename, }: AnalysesSelectorProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function AnalysesSelector({ items, selectedIds, onItemToggle, inlineMode, placeholder, disabled, size, variant, darker, className, triggerProps, onFailedItemClick, showHistorical, historicalItems, enableToggleHidden, maxVisibleItems, preventDeselection, hiddenSeries: hiddenSeriesProp, onToggleSeries, isAnalysisInProgress: isAnalysisInProgressProp, rename, }: AnalysesSelectorProps): import("react/jsx-runtime").JSX.Element;
@@ -8,6 +8,11 @@ export interface AnalysesSelectorItem {
8
8
  icon?: ReactNode;
9
9
  updated_at?: string;
10
10
  }
11
+ export interface AnalysesSelectorHistoricalItem {
12
+ seriesKey: string;
13
+ label: string;
14
+ color?: string;
15
+ }
11
16
  export interface AnalysesSelectorProps {
12
17
  items: AnalysesSelectorItem[];
13
18
  /** Single id, set, or array. Omit or `undefined` = nothing selected (Select falls back to first item for display). */
@@ -25,6 +30,13 @@ export interface AnalysesSelectorProps {
25
30
  onFailedItemClick?: (id: number) => void;
26
31
  /** Show historical item as first in the list */
27
32
  showHistorical?: boolean;
33
+ /**
34
+ * Several history lines (one per product), shown in place of the single
35
+ * "Historical" item, each with its own colour. Like "Historical" they are
36
+ * shown only, not toggled. `seriesKey` is the line's data key (e.g.
37
+ * `historical_<id>`); the entry dims while `hiddenSeries` has it.
38
+ */
39
+ historicalItems?: AnalysesSelectorHistoricalItem[];
28
40
  enableToggleHidden?: boolean;
29
41
  maxVisibleItems?: number;
30
42
  /** When true, prevents deselection and shows maxVisibleItems inline + rest in dropdown */
@@ -1,2 +1,2 @@
1
1
  export { AnalysesSelector } from './AnalysesSelector';
2
- export type { AnalysesSelectorItem, AnalysesSelectorProps, } from './AnalysesSelector.types';
2
+ export type { AnalysesSelectorHistoricalItem, AnalysesSelectorItem, AnalysesSelectorProps, } from './AnalysesSelector.types';
@@ -2,6 +2,7 @@ import { ComponentProps, ReactNode } from 'react';
2
2
  import type { QuantileBandConfig } from '#uilib/components/ui/Chart/chartForecastVisualization.types';
3
3
  import { ChartDataPoint } from '#uilib/components/ui/ChartAreaInteractive/ChartAreaInteractive.types';
4
4
  import { ForecastItemData } from '#uilib/components/ui/ChartAreaInteractive/ChartLines';
5
+ import { HistoryItemData } from '#uilib/components/ui/ChartAreaInteractive/chartHistories';
5
6
  import { LegendPayload } from 'recharts/types/component/DefaultLegendContent';
6
7
  import type { ChartConfig } from '../Chart.types';
7
8
  import { ChartContainer } from './ChartContainer';
@@ -12,6 +13,13 @@ export interface BaseChartWrapperProps {
12
13
  chartData: ChartDataPoint[];
13
14
  historicalLineColor?: string;
14
15
  forecastData?: ForecastItemData[];
16
+ /**
17
+ * Several history lines (one per product), each under `historical_<id>` in
18
+ * `chartData`, with its own colour and legend entry. Omit for the single
19
+ * `historical` line. With it, `historicalLineColor` does not apply: give
20
+ * each history its `color`.
21
+ */
22
+ historyData?: HistoryItemData[];
15
23
  loading: boolean;
16
24
  hasCombinedData?: boolean;
17
25
  isDarkTheme: boolean;
@@ -7,8 +7,15 @@ interface CustomChartLegendPayloadItem {
7
7
  dimmed?: boolean;
8
8
  updated_at?: string;
9
9
  }
10
+ interface CustomChartLegendHistoryItem {
11
+ value: string;
12
+ color: string;
13
+ dataKey: string;
14
+ }
10
15
  interface CustomChartLegendProps {
11
16
  payload?: CustomChartLegendPayloadItem[];
17
+ /** Several history lines, shown in place of the single "Historical" entry. */
18
+ histories?: CustomChartLegendHistoryItem[];
12
19
  onClick?: (data: any, index: number, event: any) => void;
13
20
  className?: string;
14
21
  wrapperStyle?: React.CSSProperties;
@@ -27,5 +34,5 @@ interface CustomChartLegendProps {
27
34
  * Custom chart legend using AnalysesSelector (inline mode)
28
35
  * Supports forecast icon indicator, failed badge, toggle visibility
29
36
  */
30
- export declare function CustomChartLegend({ payload, onClick, hiddenSeries, className, onAnalysisSelect, onFailedAnalysisClick, maxVisibleItems, preventDeselection, }: CustomChartLegendProps): import("react/jsx-runtime").JSX.Element;
37
+ export declare function CustomChartLegend({ payload, histories, onClick, hiddenSeries, className, onAnalysisSelect, onFailedAnalysisClick, maxVisibleItems, preventDeselection, }: CustomChartLegendProps): import("react/jsx-runtime").JSX.Element;
31
38
  export {};
@@ -2,6 +2,8 @@ export interface LegendSvgPayloadItem {
2
2
  value: string;
3
3
  color: string;
4
4
  dataKey: string;
5
+ /** A history line: drawn solid, where forecasts are dashed. */
6
+ solid?: boolean;
5
7
  }
6
8
  interface LegendSvgProps {
7
9
  payload: LegendSvgPayloadItem[];
@@ -1,3 +1,3 @@
1
1
  import { ChartAreaInteractiveProps } from './ChartAreaInteractive.types';
2
2
  export declare const chartConfig: {};
3
- export declare function ChartAreaInteractive({ className, chartContainerClassName, legendClassName, xAxisClassName, yAxisClassName, timeRange, onTimeRangeChange, pinMonth, onPinMonthChange, onPreviewMonthChange, chartData, forecastData, error, loading, isDarkTheme, footerActions, mode, selectedForecast, upperQuantiles, lowerQuantiles, selectedLowerQuantile, selectedUpperQuantile, onLowerQuantileChange, onUpperQuantileChange, lowerThreshold, upperThreshold, onLowerThresholdChange, onUpperThresholdChange, discreteThresholdValues, headerActions, excludeLegendIds, loadingAnalyses, onLegendClick, onAnalysisSelect, disableTimeRangeSelector, enableTimeRangeBrush, forecastLineStyle, selectedAnalysisId, chartRenderId, toggleLegendSeries, ensureAnalysisSeriesVisible, overlayForecastData, hiddenSeries, disableForecastHistoricalBridge, overlayElements: overlayElementsProp, ...restProps }: ChartAreaInteractiveProps): import("react/jsx-runtime").JSX.Element;
3
+ export declare function ChartAreaInteractive({ className, chartContainerClassName, legendClassName, xAxisClassName, yAxisClassName, timeRange, onTimeRangeChange, pinMonth, onPinMonthChange, onPreviewMonthChange, chartData, forecastData, historyData, error, loading, isDarkTheme, footerActions, mode, selectedForecast, upperQuantiles, lowerQuantiles, selectedLowerQuantile, selectedUpperQuantile, onLowerQuantileChange, onUpperQuantileChange, lowerThreshold, upperThreshold, onLowerThresholdChange, onUpperThresholdChange, discreteThresholdValues, headerActions, excludeLegendIds, loadingAnalyses, onLegendClick, onAnalysisSelect, disableTimeRangeSelector, enableTimeRangeBrush, forecastLineStyle, selectedAnalysisId, chartRenderId, toggleLegendSeries, ensureAnalysisSeriesVisible, overlayForecastData, hiddenSeries, disableForecastHistoricalBridge, overlayElements: overlayElementsProp, ...restProps }: ChartAreaInteractiveProps): import("react/jsx-runtime").JSX.Element;
@@ -20,6 +20,11 @@ export type FilterDataForTimeRangeOptions = {
20
20
  /** When set (e.g. selected forecast on Forecast tab), the window ends at the
21
21
  * latest point that has shared historical or that analysis — not at another run. */
22
22
  endDateAnchorAnalysisId?: number | null;
23
+ /**
24
+ * The history line that anchored forecast joins (`historical`,
25
+ * `historical_<id>`), or null for none. Omitted: any history line counts.
26
+ */
27
+ anchorHistoryKey?: string | null;
23
28
  };
24
29
  export declare const filterDataForTimeRange: (data: ChartDataPoint[], currentTimeRange: string, options?: FilterDataForTimeRangeOptions) => ChartDataPoint[];
25
30
  export declare const shortDateFormatter: (value: string) => string;
@@ -1,4 +1,5 @@
1
1
  import { ChartDataPoint } from './ChartAreaInteractive.types';
2
+ import { HistoryItemData } from './chartHistories';
2
3
  export interface LineConfig {
3
4
  dataKey: string;
4
5
  color: string;
@@ -13,6 +14,11 @@ export type ForecastItemData = {
13
14
  tooltip?: string;
14
15
  dimmed?: boolean;
15
16
  updated_at?: string;
17
+ /**
18
+ * Id of the history (`historyData`) this forecast continues. With several
19
+ * histories, a forecast joins one only when this names it.
20
+ */
21
+ continues?: string | number;
16
22
  };
17
23
  export type Dot = {
18
24
  x: number;
@@ -32,11 +38,23 @@ export declare const FORECAST_COLORS_MAP: {
32
38
  export declare const FORECAST_LINE_COLORS: string[];
33
39
  export declare const getForecastColor: (index: number) => string;
34
40
  export declare const getForecastQuantileBandColor: (index: number) => any;
41
+ /** A history line as drawn: data key, label and colour with defaults applied. */
42
+ export type HistoryLine = {
43
+ dataKey: string;
44
+ name: string;
45
+ color: string;
46
+ };
47
+ /** Default colour of the history at `index`: the forecast palette from its far end. */
48
+ export declare function getHistoryColor(index: number): string;
49
+ /** `historyData` with the defaults applied, in order (empty without it). */
50
+ export declare function resolveHistoryLines(histories?: HistoryItemData[]): HistoryLine[];
35
51
  /** Same tint logic as intervals/threshold overlays: band fill follows forecast line hex when known. */
36
52
  export declare function resolveQuantileBandFillForForecastLine(lineColor: string, forecastIndex: number): string;
37
- export declare const ChartLines: import("react").MemoExoticComponent<({ chartData, forecastData, hiddenSeries, isDarkTheme, shouldAnimate, historicalLineColor, showLegend, forecastLineStyle, disableAnimation, disableHistoricalAnimation, }: {
53
+ export declare const ChartLines: import("react").MemoExoticComponent<({ chartData, forecastData, historyData, hiddenSeries, isDarkTheme, shouldAnimate, historicalLineColor, showLegend, forecastLineStyle, disableAnimation, disableHistoricalAnimation, }: {
38
54
  chartData: ChartDataPoint[];
39
55
  forecastData?: ForecastItemData[];
56
+ /** Several history lines (one per product). Omit for the single `historical` line. */
57
+ historyData?: HistoryItemData[];
40
58
  hiddenSeries?: Set<string>;
41
59
  isDarkTheme: boolean;
42
60
  shouldAnimate?: boolean;
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Several history lines in one chart (one per product).
3
+ *
4
+ * Without `historyData` a chart has one history line under the `historical`
5
+ * key, and every forecast joins it. With `historyData`, each history has its
6
+ * own line under `historical_<id>`, and a forecast joins a history only when
7
+ * it can say which one: its `continues` names the history, or the chart has
8
+ * exactly one. Otherwise the forecast starts on its own first point.
9
+ */
10
+ /** The single history line's key, when the chart has no `historyData`. */
11
+ export declare const HISTORY_SERIES_KEY = "historical";
12
+ export type HistoryItemData = {
13
+ /** Unique within the chart. The line's data key is `historical_<id>`. */
14
+ id: string | number;
15
+ /** Legend and tooltip label. Defaults to the id (also when empty). */
16
+ name?: string;
17
+ /**
18
+ * Line colour. Defaults to the forecast palette taken from its far end, so
19
+ * histories and forecasts differ while there are 8 lines or fewer (the
20
+ * palette's size). To pair a product's history and forecast, pass the same
21
+ * colour to both.
22
+ */
23
+ color?: string;
24
+ };
25
+ /** Data key of one history line in `chartData` rows. */
26
+ export declare function historySeriesKey(id: string | number): string;
27
+ /** True for `historical` and for every `historical_<id>` key. */
28
+ export declare function isHistorySeriesKey(key: string): boolean;
29
+ /** The data keys of the chart's history lines, in order. */
30
+ export declare function historySeriesKeys(histories?: HistoryItemData[]): string[];
31
+ /**
32
+ * The history line a forecast joins, or null when it joins none.
33
+ *
34
+ * - No `historyData`: the single `historical` line, as before.
35
+ * - `continues` set: that history, or none when no history has that id.
36
+ * - Otherwise: the only history when there is exactly one, else none.
37
+ */
38
+ export declare function forecastHistoryKey(forecast: {
39
+ continues?: string | number;
40
+ } | undefined, histories?: HistoryItemData[]): string | null;
@@ -2,4 +2,5 @@ export * from './ChartAreaInteractive';
2
2
  export { DRAG_TIME_RANGE_PREFIX, encodeDragTimeRange, filterDataForTimeRange, findPinPositionForDate, isAnalysisDone, isAnalysisFailed, isAnalysisNotFailed, isTimeRangePreset, longDateFormatter, parseDragTimeRange, shortDateFormatter, type FilterDataForTimeRangeOptions, type TimeRangePreset, } from './ChartAreaInteractive.helpers';
3
3
  export * from './ChartAreaInteractive.types';
4
4
  export * from './ChartLines';
5
+ export * from './chartHistories';
5
6
  export type { OverlayMode } from './ChartAreaInteractive.types';
@@ -10,6 +10,11 @@ interface UseChartYRangeOptions {
10
10
  export interface CalculateChartYRangeOptions {
11
11
  excludeQuantileBands: boolean;
12
12
  forecastId?: number;
13
+ /**
14
+ * With `forecastId`: the history line that forecast joins (null: none).
15
+ * Other history lines are left out. Omitted: every history line counts.
16
+ */
17
+ forecastHistoryKey?: string | null;
13
18
  hiddenSeries?: Set<string>;
14
19
  includeHiddenInYScale?: boolean;
15
20
  }
@@ -18,7 +23,7 @@ export interface CalculateChartYRangeOptions {
18
23
  */
19
24
  export declare function isKeyExcludedFromYScale(key: string, hiddenSeries?: Set<string>): boolean;
20
25
  /** Pure Y-range calculation from chart data points. */
21
- export declare function calculateChartYRange(dataToUse: ChartDataPoint[], { excludeQuantileBands, forecastId, hiddenSeries, includeHiddenInYScale, }: CalculateChartYRangeOptions): {
26
+ export declare function calculateChartYRange(dataToUse: ChartDataPoint[], { excludeQuantileBands, forecastId, forecastHistoryKey, hiddenSeries, includeHiddenInYScale, }: CalculateChartYRangeOptions): {
22
27
  yMin: number;
23
28
  yMax: number;
24
29
  };
@@ -13,4 +13,4 @@ export interface PageXScrollProps extends Omit<React.ComponentProps<typeof Scrol
13
13
  };
14
14
  };
15
15
  }
16
- export declare function PageXScroll({ children, className, innerClassName, scrollbarClassName, fullWidth, size, scrollbarOffset, ...props }: PageXScrollProps): import("react/jsx-runtime").JSX.Element;
16
+ export declare function PageXScroll({ children, className, innerClassName, scrollbarClassName, fullWidth, size, scrollbarOffset, onInnerRef, ...props }: PageXScrollProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import type { StackedAreaChartProps } from './StackedAreaChart.types';
2
+ declare const StackedAreaChart: import("react").ForwardRefExoticComponent<StackedAreaChartProps & import("react").RefAttributes<HTMLDivElement>>;
3
+ export { StackedAreaChart };
@@ -0,0 +1,65 @@
1
+ import type { StackedAreaChartDatum } from './StackedAreaChart.types';
2
+ /** Data key of the margin layer. Prefixed so it cannot clash with a layer key. */
3
+ export declare const MARGIN_KEY = "__margin";
4
+ /** 1 when a row from {@link stackRows} has a value for any stacked layer, else 0. */
5
+ export declare const COST_KNOWN_KEY = "__costKnown";
6
+ /** Sum of the layers on a row; a missing value counts as 0. */
7
+ export declare function layersTotal(row: StackedAreaChartDatum, layerKeys: readonly string[]): number;
8
+ /**
9
+ * Rows ready to stack: every missing layer value becomes 0, and the margin
10
+ * layer (`MARGIN_KEY`) is `pct` percent of the total of `totalKeys` (the
11
+ * layers that are drawn; all layers by default). Without a positive `pct`
12
+ * the margin key is 0, so the layer can stay mounted. `COST_KNOWN_KEY` says
13
+ * whether any of `totalKeys` had a value, so a row with no cost at all is
14
+ * not compared as a cost of 0.
15
+ */
16
+ export declare function stackRows(rows: readonly StackedAreaChartDatum[], layerKeys: readonly string[], marginPct?: number | null, totalKeys?: readonly string[]): StackedAreaChartDatum[];
17
+ /**
18
+ * Each layer's share of the total, in whole percent, at the last row where
19
+ * every layer has a value and the total is above zero; when no row is
20
+ * complete, at the last row with a total. A negative value counts as 0.
21
+ * Rounded by largest remainder, so the shares add up to 100. All zeros when
22
+ * no row has a total.
23
+ */
24
+ export declare function stackWeights(rows: readonly StackedAreaChartDatum[], layerKeys: readonly string[]): Record<string, number>;
25
+ export type CompareZone = {
26
+ x1: string | number;
27
+ x2: string | number;
28
+ kind: 'above' | 'below';
29
+ };
30
+ /**
31
+ * The x ranges where the compare line is above or below the stacked total
32
+ * (the given layers plus the margin on rows from {@link stackRows}). Gaps in
33
+ * the compare line are bridged as the line is drawn; a row with no cost is
34
+ * on neither side. Each run of rows on one side becomes a range from its first
35
+ * row to the row after it (where the side changes), so adjacent ranges meet
36
+ * on a row; a row where the line touches the stack starts the next range.
37
+ * Ranges are whole rows: a crossing between two rows shows at the next, and a
38
+ * run of one row with no compared row after it has no width and is left out.
39
+ * Meant for a point-scale x axis, where a range starts and ends on its rows.
40
+ */
41
+ export declare function compareZones(rows: readonly StackedAreaChartDatum[], xKey: string, layerKeys: readonly string[], compareKey: string): CompareZone[];
42
+ /**
43
+ * One zone per row on the side the compare line is on (x1 === x2), for a
44
+ * chart that draws each row as its own bar.
45
+ */
46
+ export declare function compareRowZones(rows: readonly StackedAreaChartDatum[], xKey: string, layerKeys: readonly string[], compareKey: string): CompareZone[];
47
+ /**
48
+ * A value axis from 0 for a top value: at most `maxIntervals` steps of
49
+ * 1, 2, 2.5 or 5 × 10ⁿ, with a little headroom above the top. Small changes
50
+ * in the top (a margin being typed) move the axis by one step at most,
51
+ * instead of doubling it the way automatic rounding can.
52
+ */
53
+ export declare function valueAxis(top: number, maxIntervals?: number, headroom?: number): {
54
+ max: number;
55
+ ticks: number[];
56
+ };
57
+ /** The highest stacked total (layers plus margin) or line value on any row. */
58
+ export declare function chartTop(rows: readonly StackedAreaChartDatum[], layerKeys: readonly string[], lineKeys: readonly string[]): number;
59
+ /**
60
+ * The x value of the first row in each year, when x values are date strings
61
+ * (`YYYY` or `YYYY-…`) and span at least `minYears` years; otherwise undefined.
62
+ */
63
+ export declare function yearTicks(rows: readonly StackedAreaChartDatum[], xKey: string, minYears?: number): Array<string | number> | undefined;
64
+ /** The year of a year tick's x value, or the value as text. */
65
+ export declare function yearLabel(x: string | number): string;
@@ -0,0 +1,20 @@
1
+ import type { ChartConfig } from '#uilib/components/ui/Chart';
2
+ export type TooltipRow = {
3
+ dataKey?: unknown;
4
+ name?: unknown;
5
+ value?: unknown;
6
+ color?: string;
7
+ };
8
+ /**
9
+ * Tooltip rows in series order, showing real zeros (ChartTooltipContent hides
10
+ * them) and colouring each row from the chart config (an area's own colour
11
+ * is its white stack stroke).
12
+ */
13
+ export declare function StackedTooltip({ active, payload, label, config, valueFormatter, labelFormatter, }: {
14
+ active?: boolean;
15
+ payload?: ReadonlyArray<TooltipRow>;
16
+ label?: unknown;
17
+ config: ChartConfig;
18
+ valueFormatter?: (value: number) => string;
19
+ labelFormatter?: (value: string | number) => string;
20
+ }): import("react/jsx-runtime").JSX.Element;