@sybilion/uilib 1.7.2 → 1.8.1

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 (115) 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.js +4 -1
  10. package/dist/esm/src/components/ui/Chart/Chart.styl.js +2 -2
  11. package/dist/esm/src/components/ui/Chart/components/BaseChartWrapper.js +74 -57
  12. package/dist/esm/src/components/ui/Chart/components/ChartAxes.js +8 -7
  13. package/dist/esm/src/components/ui/Chart/components/ChartContainer.js +2 -2
  14. package/dist/esm/src/components/ui/Chart/components/ChartGrid.js +2 -2
  15. package/dist/esm/src/components/ui/Chart/components/ChartLegendContent.js +2 -2
  16. package/dist/esm/src/components/ui/Chart/components/ChartLegendItem.js +2 -2
  17. package/dist/esm/src/components/ui/Chart/components/ChartPlacedTooltip.js +65 -0
  18. package/dist/esm/src/components/ui/Chart/components/ChartTooltipContent.js +4 -4
  19. package/dist/esm/src/components/ui/Chart/components/ChartTooltipItem.js +24 -8
  20. package/dist/esm/src/components/ui/Chart/components/CustomChartLegend/CustomChartLegend.js +8 -3
  21. package/dist/esm/src/components/ui/Chart/components/LegendSvg/LegendSvg.js +1 -1
  22. package/dist/esm/src/components/ui/Chart/components/QuantileBands.js +1 -1
  23. package/dist/esm/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.js +17 -6
  24. package/dist/esm/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.js +40 -10
  25. package/dist/esm/src/components/ui/ChartAreaInteractive/ChartLines.js +55 -19
  26. package/dist/esm/src/components/ui/ChartAreaInteractive/chartHistories.js +44 -0
  27. package/dist/esm/src/components/ui/ChartAreaInteractive/overlays/useChartYRange.js +32 -7
  28. package/dist/esm/src/components/ui/Page/PageTabs/PageTabs.styl.js +2 -2
  29. package/dist/esm/src/components/ui/Page/PageXScroll/PageXScroll.js +50 -15
  30. package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.js +212 -0
  31. package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.js +123 -0
  32. package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.styl.js +7 -0
  33. package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.js +28 -0
  34. package/dist/esm/src/components/widgets/DriverCard/DriverPerformanceChart.js +5 -25
  35. package/dist/esm/src/index.js +4 -1
  36. package/dist/esm/src/utils/chartConnectionPoint.js +31 -16
  37. package/dist/esm/types/src/components/ui/AnalysesSelector/AnalysesSelector.d.ts +1 -1
  38. package/dist/esm/types/src/components/ui/AnalysesSelector/AnalysesSelector.types.d.ts +12 -0
  39. package/dist/esm/types/src/components/ui/AnalysesSelector/index.d.ts +1 -1
  40. package/dist/esm/types/src/components/ui/Chart/Chart.d.ts +4 -2
  41. package/dist/esm/types/src/components/ui/Chart/Chart.types.d.ts +5 -0
  42. package/dist/esm/types/src/components/ui/Chart/chartForecastVisualization.types.d.ts +7 -0
  43. package/dist/esm/types/src/components/ui/Chart/components/BaseChartWrapper.d.ts +25 -0
  44. package/dist/esm/types/src/components/ui/Chart/components/BaseChartWrapper.test.d.ts +1 -0
  45. package/dist/esm/types/src/components/ui/Chart/components/ChartAxes.d.ts +8 -1
  46. package/dist/esm/types/src/components/ui/Chart/components/ChartAxes.test.d.ts +1 -0
  47. package/dist/esm/types/src/components/ui/Chart/components/ChartPlacedTooltip.d.ts +31 -0
  48. package/dist/esm/types/src/components/ui/Chart/components/ChartPlacedTooltip.test.d.ts +1 -0
  49. package/dist/esm/types/src/components/ui/Chart/components/ChartTooltipContent.d.ts +1 -1
  50. package/dist/esm/types/src/components/ui/Chart/components/ChartTooltipContent.test.d.ts +1 -0
  51. package/dist/esm/types/src/components/ui/Chart/components/ChartTooltipItem.d.ts +2 -1
  52. package/dist/esm/types/src/components/ui/Chart/components/CustomChartLegend/CustomChartLegend.d.ts +8 -1
  53. package/dist/esm/types/src/components/ui/Chart/components/LegendSvg/LegendSvg.d.ts +2 -0
  54. package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.d.ts +1 -1
  55. package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.d.ts +5 -0
  56. package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartLines.d.ts +30 -1
  57. package/dist/esm/types/src/components/ui/ChartAreaInteractive/chartHistories.d.ts +40 -0
  58. package/dist/esm/types/src/components/ui/ChartAreaInteractive/index.d.ts +1 -0
  59. package/dist/esm/types/src/components/ui/ChartAreaInteractive/overlays/useChartYRange.d.ts +6 -1
  60. package/dist/esm/types/src/components/ui/Page/PageXScroll/PageXScroll.d.ts +1 -1
  61. package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.d.ts +3 -0
  62. package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.d.ts +65 -0
  63. package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.d.ts +19 -0
  64. package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.types.d.ts +85 -0
  65. package/dist/esm/types/src/components/ui/StackedAreaChart/index.d.ts +2 -0
  66. package/dist/esm/types/src/docs/pages/StackedAreaChartPage.d.ts +1 -0
  67. package/dist/esm/types/src/index.d.ts +1 -0
  68. package/dist/esm/types/src/utils/chartConnectionPoint.d.ts +11 -3
  69. package/dist/esm/types/tests/chartHistories.test.d.ts +1 -0
  70. package/dist/esm/types/tests/pageXScroll.test.d.ts +1 -0
  71. package/dist/esm/types/tests/stackedAreaChart.test.d.ts +1 -0
  72. package/package.json +2 -2
  73. package/src/components/ui/AnalysesSelector/AnalysesSelector.tsx +50 -22
  74. package/src/components/ui/AnalysesSelector/AnalysesSelector.types.ts +13 -0
  75. package/src/components/ui/AnalysesSelector/index.ts +1 -0
  76. package/src/components/ui/Chart/AGENT.md +5 -0
  77. package/src/components/ui/Chart/Chart.tsx +7 -1
  78. package/src/components/ui/Chart/Chart.types.ts +5 -0
  79. package/src/components/ui/Chart/chartForecastVisualization.types.ts +7 -0
  80. package/src/components/ui/Chart/components/BaseChartWrapper.test.tsx +344 -0
  81. package/src/components/ui/Chart/components/BaseChartWrapper.tsx +149 -88
  82. package/src/components/ui/Chart/components/ChartAxes.test.tsx +49 -0
  83. package/src/components/ui/Chart/components/ChartAxes.tsx +36 -20
  84. package/src/components/ui/Chart/components/ChartPlacedTooltip.test.tsx +160 -0
  85. package/src/components/ui/Chart/components/ChartPlacedTooltip.tsx +93 -0
  86. package/src/components/ui/Chart/components/ChartTooltipContent.test.tsx +85 -0
  87. package/src/components/ui/Chart/components/ChartTooltipContent.tsx +2 -0
  88. package/src/components/ui/Chart/components/ChartTooltipItem.tsx +41 -10
  89. package/src/components/ui/Chart/components/CustomChartLegend/CustomChartLegend.tsx +21 -1
  90. package/src/components/ui/Chart/components/LegendSvg/LegendSvg.tsx +3 -1
  91. package/src/components/ui/Chart/components/QuantileBands.tsx +1 -1
  92. package/src/components/ui/ChartAreaInteractive/AGENT.md +4 -0
  93. package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.ts +27 -5
  94. package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.tsx +64 -10
  95. package/src/components/ui/ChartAreaInteractive/ChartLines.tsx +151 -65
  96. package/src/components/ui/ChartAreaInteractive/chartHistories.ts +63 -0
  97. package/src/components/ui/ChartAreaInteractive/index.ts +1 -0
  98. package/src/components/ui/ChartAreaInteractive/overlays/useChartYRange.ts +52 -6
  99. package/src/components/ui/Page/AGENT.md +2 -0
  100. package/src/components/ui/Page/PageTabs/PageTabs.styl +8 -0
  101. package/src/components/ui/Page/PageXScroll/PageXScroll.tsx +57 -13
  102. package/src/components/ui/StackedAreaChart/AGENT.md +26 -0
  103. package/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.ts +268 -0
  104. package/src/components/ui/StackedAreaChart/StackedAreaChart.styl +32 -0
  105. package/src/components/ui/StackedAreaChart/StackedAreaChart.styl.d.ts +13 -0
  106. package/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.tsx +81 -0
  107. package/src/components/ui/StackedAreaChart/StackedAreaChart.tsx +416 -0
  108. package/src/components/ui/StackedAreaChart/StackedAreaChart.types.ts +97 -0
  109. package/src/components/ui/StackedAreaChart/index.ts +2 -0
  110. package/src/components/widgets/DriverCard/DriverPerformanceChart.tsx +2 -2
  111. package/src/docs/pages/ChartAreaInteractivePage.tsx +67 -0
  112. package/src/docs/pages/StackedAreaChartPage.tsx +141 -0
  113. package/src/docs/registry.ts +6 -0
  114. package/src/index.ts +1 -0
  115. package/src/utils/chartConnectionPoint.ts +41 -18
@@ -19,8 +19,25 @@ import {
19
19
  import S from './ChartAreaInteractive.styl';
20
20
  import { ChartAreaInteractiveProps } from './ChartAreaInteractive.types';
21
21
  import { TimeRangeBrushHost } from './TimeRangeBrushLayer';
22
+ import { forecastHistoryKey } from './chartHistories';
22
23
  import { IntervalsOverlay, PinOverlay, ThresholdsOverlay } from './overlays';
23
24
 
25
+ type ForecastHistoryKeys = {
26
+ /** [forecastId, history key or null] for each `forecastData` item. */
27
+ byId: [number, string | null][];
28
+ /** For a forecast that is only in `chartData`: no `continues` to go on. */
29
+ other: string | null;
30
+ };
31
+
32
+ /** The bridge's `historyKeyFor`, from serialised {@link ForecastHistoryKeys}. */
33
+ function historyKeyLookup(
34
+ serialised: string,
35
+ ): (forecastId: number) => string | null {
36
+ const { byId, other }: ForecastHistoryKeys = JSON.parse(serialised);
37
+ const map = new Map(byId);
38
+ return id => (map.has(id) ? map.get(id)! : other);
39
+ }
40
+
24
41
  export const chartConfig = {
25
42
  // Chart now supports light/dark themes with dynamic colors
26
43
  } satisfies ChartConfig;
@@ -38,6 +55,7 @@ export function ChartAreaInteractive({
38
55
  onPreviewMonthChange,
39
56
  chartData,
40
57
  forecastData,
58
+ historyData,
41
59
  error,
42
60
  loading = false,
43
61
  isDarkTheme = false,
@@ -99,23 +117,52 @@ export function ChartAreaInteractive({
99
117
  }
100
118
  }, [selectedAnalysisId, ensureAnalysisSeriesVisible]);
101
119
 
102
- const timeFilteredChartData = useMemo(() => {
120
+ const anchorAnalysisId = useMemo(() => {
103
121
  const raw = selectedAnalysisId ?? selectedForecast?.id ?? null;
104
- const anchorId =
105
- raw == null ? null : typeof raw === 'number' ? raw : Number(raw);
122
+ const id = raw == null ? null : typeof raw === 'number' ? raw : Number(raw);
123
+ return id != null && Number.isFinite(id) ? id : null;
124
+ }, [selectedAnalysisId, selectedForecast?.id]);
125
+
126
+ // The history the anchored forecast joins, as a string, so the time filter
127
+ // does not rerun when the host passes new but equal arrays.
128
+ const anchorHistoryKey = useMemo(
129
+ () =>
130
+ anchorAnalysisId == null
131
+ ? undefined
132
+ : forecastHistoryKey(
133
+ forecastData?.find(f => f.id === anchorAnalysisId),
134
+ historyData,
135
+ ),
136
+ [anchorAnalysisId, forecastData, historyData],
137
+ );
138
+
139
+ const timeFilteredChartData = useMemo(() => {
106
140
  const anchorForecastLoaded =
107
- anchorId != null &&
108
- Number.isFinite(anchorId) &&
141
+ anchorAnalysisId != null &&
109
142
  chartData.some(row => {
110
- const value = row[`forecast_${anchorId}`];
143
+ const value = row[`forecast_${anchorAnalysisId}`];
111
144
  return typeof value === 'number' && Number.isFinite(value);
112
145
  });
113
146
  const opts =
114
- anchorId != null && Number.isFinite(anchorId) && anchorForecastLoaded
115
- ? { endDateAnchorAnalysisId: anchorId }
147
+ anchorAnalysisId != null && anchorForecastLoaded
148
+ ? { endDateAnchorAnalysisId: anchorAnalysisId, anchorHistoryKey }
116
149
  : undefined;
117
150
  return filterDataForTimeRange(chartData, timeRange, opts);
118
- }, [chartData, timeRange, selectedAnalysisId, selectedForecast?.id]);
151
+ }, [chartData, timeRange, anchorAnalysisId, anchorHistoryKey]);
152
+
153
+ // Which history each forecast joins, as a string, so the bridge does not
154
+ // rerun when the host passes a new but equal historyData array.
155
+ const forecastHistoryKeys = useMemo(
156
+ () =>
157
+ JSON.stringify({
158
+ byId: (forecastData ?? []).map(f => [
159
+ f.id,
160
+ forecastHistoryKey(f, historyData),
161
+ ]),
162
+ other: forecastHistoryKey(undefined, historyData),
163
+ } satisfies ForecastHistoryKeys),
164
+ [forecastData, historyData],
165
+ );
119
166
 
120
167
  const bridgedChartData = useMemo(
121
168
  () =>
@@ -123,8 +170,14 @@ export function ChartAreaInteractive({
123
170
  ? timeFilteredChartData
124
171
  : ensureChartForecastBridge(timeFilteredChartData, {
125
172
  forecastSeriesIds: forecastData?.map(f => f.id),
173
+ historyKeyFor: historyKeyLookup(forecastHistoryKeys),
126
174
  }),
127
- [timeFilteredChartData, disableForecastHistoricalBridge, forecastData],
175
+ [
176
+ timeFilteredChartData,
177
+ disableForecastHistoricalBridge,
178
+ forecastData,
179
+ forecastHistoryKeys,
180
+ ],
128
181
  );
129
182
 
130
183
  // Extract quantileBands from restProps
@@ -151,6 +204,7 @@ export function ChartAreaInteractive({
151
204
  xAxisClassName,
152
205
  yAxisClassName,
153
206
  chartData: bridgedChartData,
207
+ historyData,
154
208
  chartClassName: S.chartContainer,
155
209
  // chartClassName: cn(S.chartContainer, chartContainerClassName),
156
210
  legendClassName,
@@ -1,8 +1,13 @@
1
1
  import { memo, useMemo } from 'react';
2
2
 
3
- import { Line } from 'recharts';
3
+ import { DefaultZIndexes, Line } from 'recharts';
4
4
 
5
5
  import { ChartDataPoint } from './ChartAreaInteractive.types';
6
+ import {
7
+ HISTORY_SERIES_KEY,
8
+ HistoryItemData,
9
+ historySeriesKey,
10
+ } from './chartHistories';
6
11
 
7
12
  export interface LineConfig {
8
13
  dataKey: string;
@@ -20,6 +25,11 @@ export type ForecastItemData = {
20
25
  tooltip?: string;
21
26
  dimmed?: boolean;
22
27
  updated_at?: string;
28
+ /**
29
+ * Id of the history (`historyData`) this forecast continues. With several
30
+ * histories, a forecast joins one only when this names it.
31
+ */
32
+ continues?: string | number;
23
33
  };
24
34
 
25
35
  export type Dot = {
@@ -52,6 +62,26 @@ export const getForecastQuantileBandColor = (index: number) =>
52
62
  FORECAST_LINE_COLORS[index % FORECAST_LINE_COLORS.length]
53
63
  ];
54
64
 
65
+ /** A history line as drawn: data key, label and colour with defaults applied. */
66
+ export type HistoryLine = { dataKey: string; name: string; color: string };
67
+
68
+ /** Default colour of the history at `index`: the forecast palette from its far end. */
69
+ export function getHistoryColor(index: number): string {
70
+ const n = FORECAST_LINE_COLORS.length;
71
+ return FORECAST_LINE_COLORS[n - 1 - (index % n)];
72
+ }
73
+
74
+ /** `historyData` with the defaults applied, in order (empty without it). */
75
+ export function resolveHistoryLines(
76
+ histories?: HistoryItemData[],
77
+ ): HistoryLine[] {
78
+ return (histories ?? []).map((h, index) => ({
79
+ dataKey: historySeriesKey(h.id),
80
+ name: h.name || String(h.id),
81
+ color: h.color ?? getHistoryColor(index),
82
+ }));
83
+ }
84
+
55
85
  /** Same tint logic as intervals/threshold overlays: band fill follows forecast line hex when known. */
56
86
  export function resolveQuantileBandFillForForecastLine(
57
87
  lineColor: string,
@@ -67,6 +97,7 @@ export const ChartLines = memo(
67
97
  ({
68
98
  chartData,
69
99
  forecastData,
100
+ historyData,
70
101
  hiddenSeries,
71
102
  isDarkTheme,
72
103
  shouldAnimate,
@@ -75,9 +106,15 @@ export const ChartLines = memo(
75
106
  forecastLineStyle = 'dashed',
76
107
  disableAnimation = false,
77
108
  disableHistoricalAnimation = false,
109
+ connectHistoryNulls = false,
110
+ connectForecastNulls = false,
111
+ historyOnTop = false,
112
+ showEndDots = true,
78
113
  }: {
79
114
  chartData: ChartDataPoint[];
80
115
  forecastData?: ForecastItemData[];
116
+ /** Several history lines (one per product). Omit for the single `historical` line. */
117
+ historyData?: HistoryItemData[];
81
118
  hiddenSeries?: Set<string>;
82
119
  isDarkTheme: boolean;
83
120
  shouldAnimate?: boolean;
@@ -86,6 +123,17 @@ export const ChartLines = memo(
86
123
  forecastLineStyle?: 'dashed' | 'solid';
87
124
  disableAnimation?: boolean;
88
125
  disableHistoricalAnimation?: boolean;
126
+ /** Draw each history line across months it has no value for. */
127
+ connectHistoryNulls?: boolean;
128
+ /** Draw each forecast line across months it has no value for. */
129
+ connectForecastNulls?: boolean;
130
+ /**
131
+ * Draw the history lines after the forecast lines, over them (for many
132
+ * faint forecasts that would otherwise cover the history).
133
+ */
134
+ historyOnTop?: boolean;
135
+ /** Mark each line's last point with a dot (default: on). */
136
+ showEndDots?: boolean;
89
137
  }) => {
90
138
  const dotStroke = isDarkTheme ? '#000000' : '#FFFFFF';
91
139
 
@@ -103,16 +151,37 @@ export const ChartLines = memo(
103
151
  fill: color,
104
152
  });
105
153
 
106
- // Memoize last historical index to avoid recalculating on every render call
107
- const lastHistoricalIndex = useMemo(() => {
108
- for (let i = chartData.length - 1; i >= 0; i--) {
109
- const value = chartData[i].historical;
110
- if (value !== undefined && value !== null) {
111
- return i;
154
+ // One entry per history line: the single `historical` line, or one per
155
+ // `historyData` item under `historical_<id>`.
156
+ const historyLines = useMemo(
157
+ () =>
158
+ historyData?.length
159
+ ? resolveHistoryLines(historyData)
160
+ : [
161
+ {
162
+ dataKey: HISTORY_SERIES_KEY,
163
+ name: 'Historical Data',
164
+ color: historicalLineColor,
165
+ },
166
+ ],
167
+ [historyData, historicalLineColor],
168
+ );
169
+
170
+ // Memoize last index per history line to avoid recalculating on every render call
171
+ const lastHistoryIndices = useMemo(() => {
172
+ const indices: Record<string, number> = {};
173
+ historyLines.forEach(({ dataKey }) => {
174
+ indices[dataKey] = -1;
175
+ for (let i = chartData.length - 1; i >= 0; i--) {
176
+ const value = chartData[i][dataKey];
177
+ if (value !== undefined && value !== null) {
178
+ indices[dataKey] = i;
179
+ break;
180
+ }
112
181
  }
113
- }
114
- return -1;
115
- }, [chartData]);
182
+ });
183
+ return indices;
184
+ }, [chartData, historyLines]);
116
185
 
117
186
  // Memoize last forecast indices per forecast ID
118
187
  const lastForecastIndices = useMemo(() => {
@@ -149,8 +218,8 @@ export const ChartLines = memo(
149
218
  return null;
150
219
  };
151
220
 
152
- const renderHistoricalDot = (props: any) =>
153
- renderDot(props, lastHistoricalIndex, 'historical', historicalLineColor);
221
+ const renderHistoryDot = (props: any, dataKey: string, color: string) =>
222
+ renderDot(props, lastHistoryIndices[dataKey] ?? -1, dataKey, color);
154
223
 
155
224
  const renderForecastDot = (props: any, id: number, color: string) =>
156
225
  renderDot(props, lastForecastIndices[id] ?? -1, `forecast_${id}`, color);
@@ -162,61 +231,78 @@ export const ChartLines = memo(
162
231
  const animationDuration = disableAnimation ? 0 : ANIMATION_DURATION;
163
232
  const valueAnimationEnabled = !disableAnimation;
164
233
 
234
+ // recharts draws each line into its z-index layer in mount order, not in
235
+ // JSX order: a layer above the forecasts keeps history on top through
236
+ // hiding, showing and added forecasts, and leaves the tooltip's order.
237
+ const historyZIndex = historyOnTop ? DefaultZIndexes.line + 1 : undefined;
238
+
239
+ const historyElements = historyLines.map(({ dataKey, name, color }) => (
240
+ <Line
241
+ key={dataKey}
242
+ zIndex={historyZIndex}
243
+ type="monotone"
244
+ dataKey={dataKey}
245
+ stroke={color}
246
+ strokeWidth={1}
247
+ dot={
248
+ showEndDots ? props => renderHistoryDot(props, dataKey, color) : false
249
+ }
250
+ activeDot={{ ...activeDotHistorical, fill: color }}
251
+ name={name}
252
+ legendType={showLegend === false ? 'none' : undefined}
253
+ strokeDasharray="0"
254
+ connectNulls={connectHistoryNulls}
255
+ hide={hiddenSeries?.has(dataKey)}
256
+ isAnimationActive={historicalAnimationActive}
257
+ animationDuration={animationDuration}
258
+ animateNewValues={valueAnimationEnabled}
259
+ animationBegin={0}
260
+ animationEasing="ease-out"
261
+ />
262
+ ));
263
+
264
+ const forecastElements = forecastData?.map(
265
+ (data: ForecastItemData, index: number) => {
266
+ const {
267
+ id,
268
+ name,
269
+ color = FORECAST_LINE_COLORS[index % FORECAST_LINE_COLORS.length],
270
+ } = data;
271
+ const dataKey = `forecast_${id}`;
272
+
273
+ return (
274
+ <Line
275
+ key={`forecast-${id}`}
276
+ type="monotone"
277
+ dataKey={dataKey}
278
+ stroke={color}
279
+ strokeWidth={1}
280
+ strokeDasharray={forecastLineStyle === 'dashed' ? '4 2' : '0'}
281
+ dot={
282
+ showEndDots ? props => renderForecastDot(props, id, color) : false
283
+ }
284
+ activeDot={activeDotForecast(color)}
285
+ name={`${name || `${id}`}`}
286
+ legendType={showLegend === false ? 'none' : undefined}
287
+ connectNulls={connectForecastNulls}
288
+ hide={hiddenSeries?.has(dataKey)}
289
+ isAnimationActive={forecastAnimationActive}
290
+ animationDuration={animationDuration}
291
+ animateNewValues={valueAnimationEnabled}
292
+ animationBegin={0}
293
+ animationEasing="ease-out"
294
+ className={
295
+ data.status === 'pending' ? 'chart-line-blinking' : undefined
296
+ }
297
+ />
298
+ );
299
+ },
300
+ );
301
+
165
302
  return (
166
303
  <>
167
- {/* Historical Data Line */}
168
- <Line
169
- key="historical"
170
- type="monotone"
171
- dataKey="historical"
172
- stroke={historicalLineColor}
173
- strokeWidth={1}
174
- dot={props => renderHistoricalDot(props)}
175
- activeDot={activeDotHistorical}
176
- name="Historical Data"
177
- legendType={showLegend === false ? 'none' : undefined}
178
- strokeDasharray="0"
179
- hide={hiddenSeries?.has('historical')}
180
- isAnimationActive={historicalAnimationActive}
181
- animationDuration={animationDuration}
182
- animateNewValues={valueAnimationEnabled}
183
- animationBegin={0}
184
- animationEasing="ease-out"
185
- />
186
-
187
- {/* Forecast Lines */}
188
- {forecastData?.map((data: ForecastItemData, index: number) => {
189
- const {
190
- id,
191
- name,
192
- color = FORECAST_LINE_COLORS[index % FORECAST_LINE_COLORS.length],
193
- } = data;
194
- const dataKey = `forecast_${id}`;
195
-
196
- return (
197
- <Line
198
- key={`forecast-${id}`}
199
- type="monotone"
200
- dataKey={dataKey}
201
- stroke={color}
202
- strokeWidth={1}
203
- strokeDasharray={forecastLineStyle === 'dashed' ? '4 2' : '0'}
204
- dot={props => renderForecastDot(props, id, color)}
205
- activeDot={activeDotForecast(color)}
206
- name={`${name || `${id}`}`}
207
- legendType={showLegend === false ? 'none' : undefined}
208
- hide={hiddenSeries?.has(dataKey)}
209
- isAnimationActive={forecastAnimationActive}
210
- animationDuration={animationDuration}
211
- animateNewValues={valueAnimationEnabled}
212
- animationBegin={0}
213
- animationEasing="ease-out"
214
- className={
215
- data.status === 'pending' ? 'chart-line-blinking' : undefined
216
- }
217
- />
218
- );
219
- })}
304
+ {historyElements}
305
+ {forecastElements}
220
306
  </>
221
307
  );
222
308
  },
@@ -0,0 +1,63 @@
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
+
11
+ /** The single history line's key, when the chart has no `historyData`. */
12
+ export const HISTORY_SERIES_KEY = 'historical';
13
+
14
+ export type HistoryItemData = {
15
+ /** Unique within the chart. The line's data key is `historical_<id>`. */
16
+ id: string | number;
17
+ /** Legend and tooltip label. Defaults to the id (also when empty). */
18
+ name?: string;
19
+ /**
20
+ * Line colour. Defaults to the forecast palette taken from its far end, so
21
+ * histories and forecasts differ while there are 8 lines or fewer (the
22
+ * palette's size). To pair a product's history and forecast, pass the same
23
+ * colour to both.
24
+ */
25
+ color?: string;
26
+ };
27
+
28
+ /** Data key of one history line in `chartData` rows. */
29
+ export function historySeriesKey(id: string | number): string {
30
+ return `${HISTORY_SERIES_KEY}_${id}`;
31
+ }
32
+
33
+ /** True for `historical` and for every `historical_<id>` key. */
34
+ export function isHistorySeriesKey(key: string): boolean {
35
+ return key === HISTORY_SERIES_KEY || key.startsWith(`${HISTORY_SERIES_KEY}_`);
36
+ }
37
+
38
+ /** The data keys of the chart's history lines, in order. */
39
+ export function historySeriesKeys(histories?: HistoryItemData[]): string[] {
40
+ return histories?.length
41
+ ? histories.map(h => historySeriesKey(h.id))
42
+ : [HISTORY_SERIES_KEY];
43
+ }
44
+
45
+ /**
46
+ * The history line a forecast joins, or null when it joins none.
47
+ *
48
+ * - No `historyData`: the single `historical` line, as before.
49
+ * - `continues` set: that history, or none when no history has that id.
50
+ * - Otherwise: the only history when there is exactly one, else none.
51
+ */
52
+ export function forecastHistoryKey(
53
+ forecast: { continues?: string | number } | undefined,
54
+ histories?: HistoryItemData[],
55
+ ): string | null {
56
+ if (!histories?.length) return HISTORY_SERIES_KEY;
57
+ const continues = forecast?.continues;
58
+ if (continues != null) {
59
+ const match = histories.find(h => String(h.id) === String(continues));
60
+ return match ? historySeriesKey(match.id) : null;
61
+ }
62
+ return histories.length === 1 ? historySeriesKey(histories[0].id) : null;
63
+ }
@@ -16,4 +16,5 @@ export {
16
16
  } from './ChartAreaInteractive.helpers';
17
17
  export * from './ChartAreaInteractive.types';
18
18
  export * from './ChartLines';
19
+ export * from './chartHistories';
19
20
  export type { OverlayMode } from './ChartAreaInteractive.types';
@@ -2,6 +2,10 @@ import { useMemo, useRef } from 'react';
2
2
 
3
3
  import { BaseChartWrapperProps } from '#uilib/components/ui/Chart/components/BaseChartWrapper';
4
4
  import { ChartDataPoint } from '#uilib/components/ui/ChartAreaInteractive/ChartAreaInteractive.types';
5
+ import {
6
+ forecastHistoryKey as historyKeyOfForecast,
7
+ isHistorySeriesKey,
8
+ } from '#uilib/components/ui/ChartAreaInteractive/chartHistories';
5
9
 
6
10
  interface UseChartYRangeOptions {
7
11
  baseChartProps: BaseChartWrapperProps;
@@ -14,6 +18,11 @@ interface UseChartYRangeOptions {
14
18
  export interface CalculateChartYRangeOptions {
15
19
  excludeQuantileBands: boolean;
16
20
  forecastId?: number;
21
+ /**
22
+ * With `forecastId`: the history line that forecast joins (null: none).
23
+ * Other history lines are left out. Omitted: every history line counts.
24
+ */
25
+ forecastHistoryKey?: string | null;
17
26
  hiddenSeries?: Set<string>;
18
27
  includeHiddenInYScale?: boolean;
19
28
  }
@@ -33,8 +42,8 @@ export function isKeyExcludedFromYScale(
33
42
  ): boolean {
34
43
  if (!hiddenSeries || hiddenSeries.size === 0) return false;
35
44
 
36
- if (key === 'historical') {
37
- return hiddenSeries.has('historical');
45
+ if (isHistorySeriesKey(key)) {
46
+ return hiddenSeries.has(key);
38
47
  }
39
48
 
40
49
  if (key.startsWith('forecast_')) {
@@ -60,6 +69,7 @@ export function calculateChartYRange(
60
69
  {
61
70
  excludeQuantileBands,
62
71
  forecastId,
72
+ forecastHistoryKey,
63
73
  hiddenSeries,
64
74
  includeHiddenInYScale = false,
65
75
  }: CalculateChartYRangeOptions,
@@ -82,6 +92,12 @@ export function calculateChartYRange(
82
92
  if (forecastId !== undefined) {
83
93
  if (key.startsWith('forecast_') && key !== `forecast_${forecastId}`)
84
94
  return;
95
+ if (
96
+ forecastHistoryKey !== undefined &&
97
+ isHistorySeriesKey(key) &&
98
+ key !== forecastHistoryKey
99
+ )
100
+ return;
85
101
  // Exclude q{quantile}_{otherAnalysisId} - only include selected forecast's quantiles
86
102
  if (key.startsWith('q') && !key.endsWith(`_${forecastId}`)) return;
87
103
  }
@@ -132,8 +148,14 @@ export function calculateChartYRange(
132
148
  return { yMin: 0, yMax: 100 };
133
149
  }
134
150
 
135
- const min = Math.min(...allValues);
136
- const max = Math.max(...allValues);
151
+ // A loop, not Math.min(...values): one value per row and line can exceed
152
+ // the engine's argument limit.
153
+ let min = Infinity;
154
+ let max = -Infinity;
155
+ for (const v of allValues) {
156
+ if (v < min) min = v;
157
+ if (v > max) max = v;
158
+ }
137
159
  const diff = max - min;
138
160
 
139
161
  return {
@@ -161,10 +183,24 @@ export function useChartYRange({
161
183
  yMin: number;
162
184
  yMax: number;
163
185
  forecastId?: number;
186
+ historyKey?: string | null;
164
187
  } | null>(null);
165
188
  const prevBaseChartDataRef = useRef(baseChartProps.chartData);
166
189
  const prevHiddenSeriesKeyRef = useRef(serializeHiddenSeries(hiddenSeries));
167
190
 
191
+ // With several histories, the selected forecast scales with its own only.
192
+ const { forecastData, historyData } = baseChartProps;
193
+ const selectedHistoryKey = useMemo(
194
+ () =>
195
+ selectedForecastId !== undefined && historyData?.length
196
+ ? historyKeyOfForecast(
197
+ forecastData?.find(f => f.id === selectedForecastId),
198
+ historyData,
199
+ )
200
+ : undefined,
201
+ [selectedForecastId, forecastData, historyData],
202
+ );
203
+
168
204
  const calculateYRange = (
169
205
  dataToUse: ChartDataPoint[],
170
206
  excludeBands: boolean,
@@ -173,6 +209,8 @@ export function useChartYRange({
173
209
  calculateChartYRange(dataToUse, {
174
210
  excludeQuantileBands: excludeBands,
175
211
  forecastId,
212
+ forecastHistoryKey:
213
+ forecastId === selectedForecastId ? selectedHistoryKey : undefined,
176
214
  hiddenSeries,
177
215
  includeHiddenInYScale,
178
216
  });
@@ -200,7 +238,10 @@ export function useChartYRange({
200
238
  prevBaseChartDataRef.current = baseChartProps.chartData;
201
239
  stableYRangeRef.current = null;
202
240
  }
203
- if (stableYRangeRef.current?.forecastId !== selectedForecastId) {
241
+ if (
242
+ stableYRangeRef.current?.forecastId !== selectedForecastId ||
243
+ stableYRangeRef.current?.historyKey !== selectedHistoryKey
244
+ ) {
204
245
  stableYRangeRef.current = null;
205
246
  }
206
247
  const hiddenSeriesKey = serializeHiddenSeries(hiddenSeries);
@@ -227,6 +268,7 @@ export function useChartYRange({
227
268
  stableYRangeRef.current = {
228
269
  ...result,
229
270
  forecastId: selectedForecastId,
271
+ historyKey: selectedHistoryKey,
230
272
  };
231
273
  }
232
274
 
@@ -241,6 +283,7 @@ export function useChartYRange({
241
283
  selectedForecastId,
242
284
  hiddenSeries,
243
285
  includeHiddenInYScale,
286
+ selectedHistoryKey,
244
287
  ]);
245
288
 
246
289
  // When disableRescaleWhenQuantileChanges is false, calculate from transformed data
@@ -271,13 +314,16 @@ export function useChartYRange({
271
314
  selectedForecastId,
272
315
  hiddenSeries,
273
316
  includeHiddenInYScale,
317
+ selectedHistoryKey,
274
318
  ]);
275
319
 
276
320
  // Return appropriate range
277
321
  if (disableRescaleWhenQuantileChanges) {
278
322
  const cached = stableYRangeRef.current;
279
323
  const cachedMatchesForecast =
280
- cached && cached.forecastId === selectedForecastId;
324
+ cached &&
325
+ cached.forecastId === selectedForecastId &&
326
+ cached.historyKey === selectedHistoryKey;
281
327
  return cachedMatchesForecast
282
328
  ? { yMin: cached!.yMin, yMax: cached!.yMax }
283
329
  : (stableRange ?? { yMin: 0, yMax: 100 });
@@ -114,6 +114,8 @@ Pass `columns={[node1, node2, …]}`. For 3–4 equal columns, omit `fill`; do n
114
114
 
115
115
  Horizontal scroll strip; used inside `PageTabs` and anywhere a overflowing row needs page-aligned padding. Props: `size`, `fullWidth`, `innerClassName`, `scrollbarClassName`.
116
116
 
117
+ The inset before and after the row is `--page-x-padding`, as the cascade resolves it for the row: an app that needs another inset sets that variable on `:root` or on any ancestor of the row (for example `0` when a layout around the row already has its own gutter), and the spacers, the scrollbar and the fade all follow. The scrollbar and the fade read it when the row mounts and when the window is resized, so a value that changes in a media query follows too; one changed another way after mount (a class toggled on an ancestor) shows in the spacers at once and in the scrollbar and fade at the next resize. The row's tabs draw their keyboard focus ring inside themselves, since the scrolling row would clip a ring drawn outside.
118
+
117
119
  ### SectionHeader
118
120
 
119
121
  In-section title block (`title`, `description`, `actions`). Use **inside** `PageContentSection`, not as a replacement for `PageHeader`.
@@ -14,6 +14,14 @@
14
14
  padding-left var(--page-x-padding)
15
15
  padding-right var(--page-x-padding)
16
16
 
17
+ // The row scrolls, so it clips whatever is drawn outside the tabs, and the
18
+ // shared focus ring (2px wide, 2px outside) would lose its top and bottom.
19
+ // Draw it inside the tab instead, its outer edge 2px in so that it clears the
20
+ // link variant's 2px underline. A value set on a tab itself still wins; one set
21
+ // higher up does not, because the ring has to stay inside.
22
+ .listInner
23
+ --focus-outline-offset calc(-1 * var(--focus-outline-width, 2px) - 2px)
24
+
17
25
  .variant-button
18
26
  .variant-outline
19
27
  .listInner