@sybilion/uilib 1.7.1 → 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.
- package/dist/agent-glossary/content-prompt.generated.ts +2 -0
- package/dist/agent-glossary/content.generated.ts +2 -0
- package/dist/agent-glossary/content.md +2 -0
- package/dist/agent-glossary/content.prompt.md +2 -0
- package/dist/agent-glossary/workspace.generated.ts +1 -0
- package/dist/agent-glossary/workspace.index.md +1 -0
- package/dist/agent-glossary/workspace.md +1 -0
- package/dist/esm/src/components/ui/AnalysesSelector/AnalysesSelector.js +37 -20
- package/dist/esm/src/components/ui/Chart/Chart.styl.js +2 -2
- package/dist/esm/src/components/ui/Chart/components/BaseChartWrapper.js +46 -51
- package/dist/esm/src/components/ui/Chart/components/ChartContainer.js +2 -2
- package/dist/esm/src/components/ui/Chart/components/ChartGrid.js +2 -2
- package/dist/esm/src/components/ui/Chart/components/ChartLegendContent.js +2 -2
- package/dist/esm/src/components/ui/Chart/components/ChartLegendItem.js +2 -2
- package/dist/esm/src/components/ui/Chart/components/ChartTooltipContent.js +2 -2
- package/dist/esm/src/components/ui/Chart/components/ChartTooltipItem.js +3 -3
- package/dist/esm/src/components/ui/Chart/components/CustomChartLegend/CustomChartLegend.js +8 -3
- package/dist/esm/src/components/ui/Chart/components/LegendSvg/LegendSvg.js +1 -1
- package/dist/esm/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.js +17 -6
- package/dist/esm/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.js +40 -10
- package/dist/esm/src/components/ui/ChartAreaInteractive/ChartLines.js +43 -13
- package/dist/esm/src/components/ui/ChartAreaInteractive/chartHistories.js +44 -0
- package/dist/esm/src/components/ui/ChartAreaInteractive/overlays/useChartYRange.js +32 -7
- package/dist/esm/src/components/ui/Page/PageTabs/PageTabs.styl.js +2 -2
- package/dist/esm/src/components/ui/Page/PageXScroll/PageXScroll.js +50 -15
- package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.js +212 -0
- package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.js +123 -0
- package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.styl.js +7 -0
- package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.js +29 -0
- package/dist/esm/src/index.js +3 -1
- package/dist/esm/src/utils/chartConnectionPoint.js +31 -16
- package/dist/esm/types/src/components/ui/AnalysesSelector/AnalysesSelector.d.ts +1 -1
- package/dist/esm/types/src/components/ui/AnalysesSelector/AnalysesSelector.types.d.ts +12 -0
- package/dist/esm/types/src/components/ui/AnalysesSelector/index.d.ts +1 -1
- package/dist/esm/types/src/components/ui/Chart/components/BaseChartWrapper.d.ts +8 -0
- package/dist/esm/types/src/components/ui/Chart/components/CustomChartLegend/CustomChartLegend.d.ts +8 -1
- package/dist/esm/types/src/components/ui/Chart/components/LegendSvg/LegendSvg.d.ts +2 -0
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.d.ts +1 -1
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.d.ts +5 -0
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartLines.d.ts +19 -1
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/chartHistories.d.ts +40 -0
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/index.d.ts +1 -0
- package/dist/esm/types/src/components/ui/ChartAreaInteractive/overlays/useChartYRange.d.ts +6 -1
- package/dist/esm/types/src/components/ui/Page/PageXScroll/PageXScroll.d.ts +1 -1
- package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.d.ts +3 -0
- package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.d.ts +65 -0
- package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.d.ts +20 -0
- package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.types.d.ts +85 -0
- package/dist/esm/types/src/components/ui/StackedAreaChart/index.d.ts +2 -0
- package/dist/esm/types/src/docs/pages/StackedAreaChartPage.d.ts +1 -0
- package/dist/esm/types/src/index.d.ts +1 -0
- package/dist/esm/types/src/utils/chartConnectionPoint.d.ts +11 -3
- package/dist/esm/types/tests/chartHistories.test.d.ts +1 -0
- package/dist/esm/types/tests/pageXScroll.test.d.ts +1 -0
- package/dist/esm/types/tests/stackedAreaChart.test.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/ui/AnalysesSelector/AnalysesSelector.tsx +50 -22
- package/src/components/ui/AnalysesSelector/AnalysesSelector.types.ts +13 -0
- package/src/components/ui/AnalysesSelector/index.ts +1 -0
- package/src/components/ui/Chart/components/BaseChartWrapper.tsx +71 -52
- package/src/components/ui/Chart/components/CustomChartLegend/CustomChartLegend.tsx +21 -1
- package/src/components/ui/Chart/components/LegendSvg/LegendSvg.tsx +3 -1
- package/src/components/ui/ChartAreaInteractive/AGENT.md +2 -0
- package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.helpers.ts +27 -5
- package/src/components/ui/ChartAreaInteractive/ChartAreaInteractive.tsx +64 -10
- package/src/components/ui/ChartAreaInteractive/ChartLines.tsx +86 -30
- package/src/components/ui/ChartAreaInteractive/chartHistories.ts +63 -0
- package/src/components/ui/ChartAreaInteractive/index.ts +1 -0
- package/src/components/ui/ChartAreaInteractive/overlays/useChartYRange.ts +52 -6
- package/src/components/ui/Page/AGENT.md +2 -0
- package/src/components/ui/Page/PageTabs/PageTabs.styl +8 -0
- package/src/components/ui/Page/PageXScroll/PageXScroll.tsx +57 -13
- package/src/components/ui/StackedAreaChart/AGENT.md +26 -0
- package/src/components/ui/StackedAreaChart/StackedAreaChart.helpers.ts +268 -0
- package/src/components/ui/StackedAreaChart/StackedAreaChart.styl +32 -0
- package/src/components/ui/StackedAreaChart/StackedAreaChart.styl.d.ts +13 -0
- package/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.tsx +82 -0
- package/src/components/ui/StackedAreaChart/StackedAreaChart.tsx +416 -0
- package/src/components/ui/StackedAreaChart/StackedAreaChart.types.ts +97 -0
- package/src/components/ui/StackedAreaChart/index.ts +2 -0
- package/src/docs/pages/ChartAreaInteractivePage.tsx +67 -0
- package/src/docs/pages/StackedAreaChartPage.tsx +141 -0
- package/src/docs/registry.ts +6 -0
- package/src/index.ts +1 -0
- package/src/utils/chartConnectionPoint.ts +41 -18
- package/src/components/ui/Chart/chart-types.csv +0 -33
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { HTMLAttributes, ReactNode } from 'react';
|
|
2
|
+
export type StackedAreaChartDatum = Record<string, string | number | null | undefined>;
|
|
3
|
+
export interface StackedAreaChartLayer {
|
|
4
|
+
/** Data key of the layer in each datum. A value that is not a number stacks as 0. */
|
|
5
|
+
key: string;
|
|
6
|
+
/** Legend and tooltip label; falls back to the key. */
|
|
7
|
+
label?: ReactNode;
|
|
8
|
+
/** CSS colour; falls back to the built-in series palette. */
|
|
9
|
+
color?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface StackedAreaChartOverlay {
|
|
12
|
+
/** Data key of the line in each datum. Gaps are bridged. */
|
|
13
|
+
key: string;
|
|
14
|
+
/** Legend and tooltip label; falls back to the key. */
|
|
15
|
+
label?: ReactNode;
|
|
16
|
+
/** CSS colour; falls back to the foreground colour. */
|
|
17
|
+
color?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Shade the x ranges where this line is above or below the stacked total
|
|
20
|
+
* (the visible layers plus the margin), changing at rows. Hidden with the
|
|
21
|
+
* line. At most one overlay should set it; the first one that does is used.
|
|
22
|
+
*/
|
|
23
|
+
compare?: boolean;
|
|
24
|
+
}
|
|
25
|
+
export interface StackedAreaChartMargin {
|
|
26
|
+
/**
|
|
27
|
+
* Margin on top of the layers, in percent of the layers' total at each x.
|
|
28
|
+
* null or 0 hides the margin layer; it stays mounted, so changing it as the
|
|
29
|
+
* user types does not redraw the chart from scratch.
|
|
30
|
+
*/
|
|
31
|
+
pct: number | null;
|
|
32
|
+
/** Legend and tooltip label; defaults to `margin <pct>%`. */
|
|
33
|
+
label?: ReactNode;
|
|
34
|
+
/** CSS colour of the margin layer. */
|
|
35
|
+
color?: string;
|
|
36
|
+
}
|
|
37
|
+
export interface StackedAreaChartZoneLabels {
|
|
38
|
+
above: ReactNode;
|
|
39
|
+
below: ReactNode;
|
|
40
|
+
}
|
|
41
|
+
export interface StackedAreaChartProps extends Omit<HTMLAttributes<HTMLDivElement>, 'children'> {
|
|
42
|
+
/** Rows in x order. */
|
|
43
|
+
data: StackedAreaChartDatum[];
|
|
44
|
+
/** Data key holding the x value (a date string such as `2026-01-01`, or a label). */
|
|
45
|
+
xKey: string;
|
|
46
|
+
/** Stacked layers, bottom first. */
|
|
47
|
+
layers: StackedAreaChartLayer[];
|
|
48
|
+
/** Lines drawn over the stack (e.g. prices paid). */
|
|
49
|
+
overlays?: StackedAreaChartOverlay[];
|
|
50
|
+
/** An extra layer on top of the stack, a percentage of the layers' total. */
|
|
51
|
+
margin?: StackedAreaChartMargin;
|
|
52
|
+
/**
|
|
53
|
+
* Show each visible layer's share of the total in the legend, from the last
|
|
54
|
+
* row where every visible layer has a value (or, when none has, the last
|
|
55
|
+
* row with a total).
|
|
56
|
+
*/
|
|
57
|
+
showWeights?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Label the x axis by year, one tick at the first row of each year, when
|
|
60
|
+
* the x values are dates (`YYYY…`) spanning at least three years.
|
|
61
|
+
*/
|
|
62
|
+
yearTicks?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* With fewer rows than this, the stack draws as bars (an area needs a
|
|
65
|
+
* few points to show anything). Default 3.
|
|
66
|
+
*/
|
|
67
|
+
barsBelow?: number;
|
|
68
|
+
/** Legend labels of the compare zones. */
|
|
69
|
+
zoneLabels?: StackedAreaChartZoneLabels;
|
|
70
|
+
/** Keys of hidden layers and overlays. With it, the host owns visibility. */
|
|
71
|
+
hiddenKeys?: ReadonlySet<string>;
|
|
72
|
+
/** Called with a layer or overlay key when its legend entry is clicked. */
|
|
73
|
+
onToggleKey?: (key: string) => void;
|
|
74
|
+
showLegend?: boolean;
|
|
75
|
+
showTooltip?: boolean;
|
|
76
|
+
showGrid?: boolean;
|
|
77
|
+
/** Formats numeric y-axis ticks and tooltip values. */
|
|
78
|
+
valueFormatter?: (value: number) => string;
|
|
79
|
+
/** Formats x-axis ticks (ignored for year ticks, which show the year). */
|
|
80
|
+
xTickFormatter?: (value: string | number) => string;
|
|
81
|
+
/** Formats the tooltip's x label. */
|
|
82
|
+
tooltipLabelFormatter?: (value: string | number) => string;
|
|
83
|
+
/** Fixed chart height in px; defaults to a 16:9 responsive box. */
|
|
84
|
+
height?: number;
|
|
85
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function StackedAreaChartPage(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -22,6 +22,7 @@ export * from './components/ui/Chart';
|
|
|
22
22
|
export * from './components/ui/ChartAreaInteractive';
|
|
23
23
|
export * from './components/ui/DonutChart';
|
|
24
24
|
export * from './components/ui/BarChart';
|
|
25
|
+
export * from './components/ui/StackedAreaChart';
|
|
25
26
|
export * from './components/ui/Checkbox';
|
|
26
27
|
export * from './components/ui/Confirm';
|
|
27
28
|
export * from './components/ui/DatePicker';
|
|
@@ -8,11 +8,18 @@ export type EnsureChartForecastBridgeOptions = {
|
|
|
8
8
|
forecastSeriesIds?: number[];
|
|
9
9
|
/** When true, returns `chartData` unchanged */
|
|
10
10
|
disabled?: boolean;
|
|
11
|
+
/**
|
|
12
|
+
* The history line each forecast joins, by forecast id: a data key such as
|
|
13
|
+
* `historical` or `historical_<id>`, or null to leave that forecast unjoined.
|
|
14
|
+
* Defaults to the single `historical` line for every forecast.
|
|
15
|
+
*/
|
|
16
|
+
historyKeyFor?: (forecastId: number) => string | null;
|
|
11
17
|
};
|
|
12
18
|
/**
|
|
13
19
|
* Injects `forecast_{id}` on the row before each series’ first forecast month (historical value)
|
|
14
20
|
* so dashed forecast lines meet the historical line. Matches sybilion-client bridge behavior.
|
|
15
|
-
* Never overwrites an existing forecast value on that row.
|
|
21
|
+
* Never overwrites an existing forecast value on that row. With several history lines,
|
|
22
|
+
* `historyKeyFor` says which one each forecast joins (null: none).
|
|
16
23
|
*/
|
|
17
24
|
export declare function ensureChartForecastBridge(chartData: ChartDataPoint[], options?: EnsureChartForecastBridgeOptions): ChartDataPoint[];
|
|
18
25
|
/**
|
|
@@ -20,9 +27,10 @@ export declare function ensureChartForecastBridge(chartData: ChartDataPoint[], o
|
|
|
20
27
|
*/
|
|
21
28
|
export declare function findLastValidHistoricalPoint(historical: TimeSeriesPoint[]): TimeSeriesPoint | null;
|
|
22
29
|
/**
|
|
23
|
-
* Find the last valid historical data point from ChartDataPoint array
|
|
30
|
+
* Find the last valid historical data point from ChartDataPoint array, on the
|
|
31
|
+
* single `historical` line or on the history line under `key`.
|
|
24
32
|
*/
|
|
25
|
-
export declare function findLastValidHistoricalChartPoint(historical: ChartDataPoint[]): ChartDataPoint | null;
|
|
33
|
+
export declare function findLastValidHistoricalChartPoint(historical: ChartDataPoint[], key?: string): ChartDataPoint | null;
|
|
26
34
|
/**
|
|
27
35
|
* Check if two dates are in the same month (ignoring day)
|
|
28
36
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@testing-library/jest-dom';
|
package/package.json
CHANGED
|
@@ -32,7 +32,20 @@ import { SelectInlineRenamer } from './SelectInlineRenamer';
|
|
|
32
32
|
const isFailed = (item: AnalysesSelectorItem) =>
|
|
33
33
|
item.status?.toLowerCase() === 'fail';
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
/**
|
|
36
|
+
* An entry listed in the selector. History entries (the single "Historical",
|
|
37
|
+
* id -1, or one per `historicalItems` line, which carries its `seriesKey`) are
|
|
38
|
+
* shown only: like "Historical", they do not toggle or select.
|
|
39
|
+
*/
|
|
40
|
+
type ListedItem = AnalysesSelectorItem & {
|
|
41
|
+
dimmed?: boolean;
|
|
42
|
+
seriesKey?: string;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const isHistoryItem = (item: ListedItem) =>
|
|
46
|
+
item.id === -1 || item.seriesKey !== undefined;
|
|
47
|
+
|
|
48
|
+
const isDashedIcon = (item: AnalysesSelectorItem) => !isHistoryItem(item);
|
|
36
49
|
|
|
37
50
|
const defaultIsAnalysisInProgress = (status?: string) =>
|
|
38
51
|
['pending', 'running', 'cancelling'].includes(status?.toLowerCase() ?? '');
|
|
@@ -106,6 +119,7 @@ export function AnalysesSelector({
|
|
|
106
119
|
triggerProps,
|
|
107
120
|
onFailedItemClick,
|
|
108
121
|
showHistorical = true,
|
|
122
|
+
historicalItems,
|
|
109
123
|
enableToggleHidden = false,
|
|
110
124
|
maxVisibleItems = 1,
|
|
111
125
|
preventDeselection = false,
|
|
@@ -138,17 +152,35 @@ export function AnalysesSelector({
|
|
|
138
152
|
);
|
|
139
153
|
}, [selectedIds]);
|
|
140
154
|
|
|
155
|
+
// The history entries: one per `historicalItems` line, or the single "Historical".
|
|
156
|
+
const historyEntries = useMemo(() => {
|
|
157
|
+
if (!showHistorical) return [];
|
|
158
|
+
if (historicalItems?.length) {
|
|
159
|
+
return historicalItems.map(
|
|
160
|
+
(h, index): ListedItem => ({
|
|
161
|
+
// Negative ids keep them apart from analyses in keys; the history
|
|
162
|
+
// is recognised by its seriesKey.
|
|
163
|
+
id: -(index + 1),
|
|
164
|
+
label: h.label,
|
|
165
|
+
color: h.color,
|
|
166
|
+
seriesKey: h.seriesKey,
|
|
167
|
+
dimmed: hiddenSeries.has(h.seriesKey),
|
|
168
|
+
}),
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return [
|
|
172
|
+
{
|
|
173
|
+
id: -1,
|
|
174
|
+
label: 'Historical',
|
|
175
|
+
dimmed: hiddenSeries.has('historical'),
|
|
176
|
+
},
|
|
177
|
+
];
|
|
178
|
+
}, [showHistorical, historicalItems, hiddenSeries]);
|
|
179
|
+
|
|
141
180
|
// In inlineMode, show Historical + selected analyses (limited by maxVisibleItems)
|
|
142
181
|
const selectedItems = useMemo(() => {
|
|
143
182
|
if (inlineMode) {
|
|
144
|
-
const list = [];
|
|
145
|
-
if (showHistorical) {
|
|
146
|
-
list.push({
|
|
147
|
-
id: -1,
|
|
148
|
-
label: 'Historical',
|
|
149
|
-
dimmed: hiddenSeries.has('historical'),
|
|
150
|
-
});
|
|
151
|
-
}
|
|
183
|
+
const list: ListedItem[] = [...historyEntries];
|
|
152
184
|
// Filter by selectedIds, exclude failed items and user series
|
|
153
185
|
const analysesOnly = items.filter(
|
|
154
186
|
item =>
|
|
@@ -167,18 +199,12 @@ export function AnalysesSelector({
|
|
|
167
199
|
return list.concat(limitedItems);
|
|
168
200
|
}
|
|
169
201
|
// Non-inlineMode: keep original behavior
|
|
170
|
-
const list = [];
|
|
171
|
-
if (showHistorical) {
|
|
172
|
-
list.push({
|
|
173
|
-
id: -1,
|
|
174
|
-
label: 'Historical',
|
|
175
|
-
});
|
|
176
|
-
}
|
|
202
|
+
const list: ListedItem[] = [...historyEntries];
|
|
177
203
|
return list.concat(items.filter(item => selectedSet.has(item.id)));
|
|
178
204
|
}, [
|
|
179
205
|
items,
|
|
180
206
|
selectedSet,
|
|
181
|
-
|
|
207
|
+
historyEntries,
|
|
182
208
|
inlineMode,
|
|
183
209
|
hiddenSeries,
|
|
184
210
|
maxVisibleItems,
|
|
@@ -262,7 +288,8 @@ export function AnalysesSelector({
|
|
|
262
288
|
handleItemClick(item);
|
|
263
289
|
};
|
|
264
290
|
|
|
265
|
-
const handleItemClick = (item:
|
|
291
|
+
const handleItemClick = (item: ListedItem) => {
|
|
292
|
+
if (item.seriesKey !== undefined) return;
|
|
266
293
|
if (isFailed(item) && onFailedItemClick) {
|
|
267
294
|
onFailedItemClick(item.id);
|
|
268
295
|
} else if (preventDeselection || (inlineMode && enableToggleHidden)) {
|
|
@@ -288,9 +315,10 @@ export function AnalysesSelector({
|
|
|
288
315
|
);
|
|
289
316
|
};
|
|
290
317
|
|
|
291
|
-
const renderItemLabel = (item:
|
|
318
|
+
const renderItemLabel = (item: ListedItem) => (
|
|
292
319
|
<LabelWithId
|
|
293
|
-
id
|
|
320
|
+
// -1 shows no id badge: history lines have no analysis id.
|
|
321
|
+
id={isHistoryItem(item) ? -1 : item.id}
|
|
294
322
|
label={
|
|
295
323
|
isAnalysisInProgressProp(item.status) ? (
|
|
296
324
|
<TextShimmer as="span">{item.label}</TextShimmer>
|
|
@@ -323,11 +351,11 @@ export function AnalysesSelector({
|
|
|
323
351
|
>
|
|
324
352
|
{selectedItems.map(item => (
|
|
325
353
|
<div
|
|
326
|
-
key={item.id}
|
|
354
|
+
key={item.seriesKey ?? item.id}
|
|
327
355
|
className={cn(
|
|
328
356
|
S.item,
|
|
329
357
|
disabled && S.disabled,
|
|
330
|
-
item
|
|
358
|
+
isHistoryItem(item) && S.historical,
|
|
331
359
|
item.dimmed && S.dimmed,
|
|
332
360
|
)}
|
|
333
361
|
onClick={() => !disabled && handleItemClick(item)}
|
|
@@ -10,6 +10,12 @@ export interface AnalysesSelectorItem {
|
|
|
10
10
|
updated_at?: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
export interface AnalysesSelectorHistoricalItem {
|
|
14
|
+
seriesKey: string;
|
|
15
|
+
label: string;
|
|
16
|
+
color?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
13
19
|
export interface AnalysesSelectorProps {
|
|
14
20
|
items: AnalysesSelectorItem[];
|
|
15
21
|
/** Single id, set, or array. Omit or `undefined` = nothing selected (Select falls back to first item for display). */
|
|
@@ -27,6 +33,13 @@ export interface AnalysesSelectorProps {
|
|
|
27
33
|
onFailedItemClick?: (id: number) => void;
|
|
28
34
|
/** Show historical item as first in the list */
|
|
29
35
|
showHistorical?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Several history lines (one per product), shown in place of the single
|
|
38
|
+
* "Historical" item, each with its own colour. Like "Historical" they are
|
|
39
|
+
* shown only, not toggled. `seriesKey` is the line's data key (e.g.
|
|
40
|
+
* `historical_<id>`); the entry dims while `hiddenSeries` has it.
|
|
41
|
+
*/
|
|
42
|
+
historicalItems?: AnalysesSelectorHistoricalItem[];
|
|
30
43
|
enableToggleHidden?: boolean;
|
|
31
44
|
maxVisibleItems?: number;
|
|
32
45
|
/** When true, prevents deselection and shows maxVisibleItems inline + rest in dropdown */
|
|
@@ -15,7 +15,13 @@ import {
|
|
|
15
15
|
ChartLines,
|
|
16
16
|
ForecastItemData,
|
|
17
17
|
getForecastColor,
|
|
18
|
+
resolveHistoryLines,
|
|
18
19
|
} from '#uilib/components/ui/ChartAreaInteractive/ChartLines';
|
|
20
|
+
import {
|
|
21
|
+
HistoryItemData,
|
|
22
|
+
historySeriesKeys,
|
|
23
|
+
isHistorySeriesKey,
|
|
24
|
+
} from '#uilib/components/ui/ChartAreaInteractive/chartHistories';
|
|
19
25
|
import { Skeleton } from '#uilib/components/ui/Skeleton';
|
|
20
26
|
import { chartRenderQueue } from '#uilib/utils/chartRenderQueue';
|
|
21
27
|
import { Tooltip as ChartTooltip, ComposedChart, LineChart } from 'recharts';
|
|
@@ -84,6 +90,13 @@ export interface BaseChartWrapperProps {
|
|
|
84
90
|
chartData: ChartDataPoint[];
|
|
85
91
|
historicalLineColor?: string;
|
|
86
92
|
forecastData?: ForecastItemData[];
|
|
93
|
+
/**
|
|
94
|
+
* Several history lines (one per product), each under `historical_<id>` in
|
|
95
|
+
* `chartData`, with its own colour and legend entry. Omit for the single
|
|
96
|
+
* `historical` line. With it, `historicalLineColor` does not apply: give
|
|
97
|
+
* each history its `color`.
|
|
98
|
+
*/
|
|
99
|
+
historyData?: HistoryItemData[];
|
|
87
100
|
loading: boolean;
|
|
88
101
|
hasCombinedData?: boolean; // Indicates if combinedData is available (for cache hits)
|
|
89
102
|
isDarkTheme: boolean;
|
|
@@ -202,6 +215,7 @@ const BaseChartWrapperContent = forwardRef<
|
|
|
202
215
|
chartData,
|
|
203
216
|
historicalLineColor,
|
|
204
217
|
forecastData = [],
|
|
218
|
+
historyData,
|
|
205
219
|
loading,
|
|
206
220
|
hasCombinedData,
|
|
207
221
|
renderId,
|
|
@@ -445,43 +459,39 @@ const BaseChartWrapperContent = forwardRef<
|
|
|
445
459
|
);
|
|
446
460
|
};
|
|
447
461
|
|
|
448
|
-
//
|
|
449
|
-
//
|
|
450
|
-
//
|
|
451
|
-
const
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
return linePoint;
|
|
482
|
-
});
|
|
483
|
-
return lineData;
|
|
484
|
-
}, [lineDataKey]);
|
|
462
|
+
// Only the line data (history and forecast_* keys) triggers the draw
|
|
463
|
+
// animation, so a change to quantile band data alone does not re-animate.
|
|
464
|
+
// The string key keeps the array's reference stable while the values are.
|
|
465
|
+
const lineData = useMemo(
|
|
466
|
+
() =>
|
|
467
|
+
chartData.map(point => {
|
|
468
|
+
const linePoint: Record<string, unknown> = { date: point.date };
|
|
469
|
+
Object.keys(point).forEach(key => {
|
|
470
|
+
if (
|
|
471
|
+
(isHistorySeriesKey(key) && point[key] !== undefined) ||
|
|
472
|
+
key.startsWith('forecast_')
|
|
473
|
+
) {
|
|
474
|
+
linePoint[key] = point[key];
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
return linePoint;
|
|
478
|
+
}),
|
|
479
|
+
[chartData],
|
|
480
|
+
);
|
|
481
|
+
const lineDataKey = useMemo(() => JSON.stringify(lineData), [lineData]);
|
|
482
|
+
const lineDataForAnimation = useMemo(() => lineData, [lineDataKey]);
|
|
483
|
+
|
|
484
|
+
const historyLegend = useMemo(
|
|
485
|
+
() =>
|
|
486
|
+
showLegend && historyData?.length
|
|
487
|
+
? resolveHistoryLines(historyData).map(h => ({
|
|
488
|
+
value: h.name,
|
|
489
|
+
color: h.color,
|
|
490
|
+
dataKey: h.dataKey,
|
|
491
|
+
}))
|
|
492
|
+
: undefined,
|
|
493
|
+
[historyData, showLegend],
|
|
494
|
+
);
|
|
485
495
|
|
|
486
496
|
const legendPayload = useMemo(() => {
|
|
487
497
|
if (!showLegend) return [];
|
|
@@ -614,12 +624,12 @@ const BaseChartWrapperContent = forwardRef<
|
|
|
614
624
|
let effectiveAutoScale = autoScaleYAxis;
|
|
615
625
|
if (autoScaleYAxis !== false && yMin !== undefined && yMax !== undefined) {
|
|
616
626
|
const dataKeys = chartData.length > 0 ? Object.keys(chartData[0]) : [];
|
|
617
|
-
const
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
627
|
+
const visibleHistoryKeys = historySeriesKeys(historyData).filter(
|
|
628
|
+
k => includeHiddenInYScale || !hiddenSeries?.has(k),
|
|
629
|
+
);
|
|
630
|
+
const historicalValues = chartData
|
|
631
|
+
.flatMap(p => visibleHistoryKeys.map(k => p[k]))
|
|
632
|
+
.filter(v => v !== null && v !== undefined);
|
|
623
633
|
const forecastKeys = dataKeys.filter(k => k.startsWith('forecast_'));
|
|
624
634
|
const visibleForecastKeys =
|
|
625
635
|
!includeHiddenInYScale && hiddenSeries
|
|
@@ -631,10 +641,14 @@ const BaseChartWrapperContent = forwardRef<
|
|
|
631
641
|
const allLineValues = [...historicalValues, ...forecastValues];
|
|
632
642
|
|
|
633
643
|
if (allLineValues.length > 0) {
|
|
634
|
-
//
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
644
|
+
// A loop, not Math.min(...values): one value per row and line can
|
|
645
|
+
// exceed the engine's argument limit.
|
|
646
|
+
let dataMin = Infinity;
|
|
647
|
+
let dataMax = -Infinity;
|
|
648
|
+
for (const v of allLineValues as number[]) {
|
|
649
|
+
if (v < dataMin) dataMin = v;
|
|
650
|
+
if (v > dataMax) dataMax = v;
|
|
651
|
+
}
|
|
638
652
|
const explicitRange = yMax - yMin;
|
|
639
653
|
const dataRange = dataMax - dataMin;
|
|
640
654
|
const wastedSpaceRatio = (explicitRange - dataRange) / dataRange;
|
|
@@ -737,6 +751,7 @@ const BaseChartWrapperContent = forwardRef<
|
|
|
737
751
|
historicalLineColor={historicalLineColor}
|
|
738
752
|
chartData={chartData}
|
|
739
753
|
forecastData={forecastData}
|
|
754
|
+
historyData={historyData}
|
|
740
755
|
hiddenSeries={hiddenSeries}
|
|
741
756
|
isDarkTheme={isDarkTheme}
|
|
742
757
|
shouldAnimate={shouldAnimate}
|
|
@@ -765,11 +780,14 @@ const BaseChartWrapperContent = forwardRef<
|
|
|
765
780
|
{showLegend &&
|
|
766
781
|
(legendVariant === 'svg' ? (
|
|
767
782
|
<LegendSvg
|
|
768
|
-
payload={
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
783
|
+
payload={[
|
|
784
|
+
...(historyLegend ?? []).map(p => ({ ...p, solid: true })),
|
|
785
|
+
...legendPayload.map(p => ({
|
|
786
|
+
value: p.value,
|
|
787
|
+
color: p.color,
|
|
788
|
+
dataKey: p.dataKey,
|
|
789
|
+
})),
|
|
790
|
+
]}
|
|
773
791
|
width={legendWidth}
|
|
774
792
|
marginLeft={legendMarginLeft}
|
|
775
793
|
/>
|
|
@@ -777,6 +795,7 @@ const BaseChartWrapperContent = forwardRef<
|
|
|
777
795
|
<CustomChartLegend
|
|
778
796
|
className={legendClassName}
|
|
779
797
|
payload={legendPayload}
|
|
798
|
+
histories={historyLegend}
|
|
780
799
|
onClick={onLegendClick}
|
|
781
800
|
hiddenSeries={hiddenSeries}
|
|
782
801
|
onAnalysisSelect={onAnalysisSelect}
|
|
@@ -17,8 +17,16 @@ interface CustomChartLegendPayloadItem {
|
|
|
17
17
|
updated_at?: string;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
interface CustomChartLegendHistoryItem {
|
|
21
|
+
value: string;
|
|
22
|
+
color: string;
|
|
23
|
+
dataKey: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
20
26
|
interface CustomChartLegendProps {
|
|
21
27
|
payload?: CustomChartLegendPayloadItem[];
|
|
28
|
+
/** Several history lines, shown in place of the single "Historical" entry. */
|
|
29
|
+
histories?: CustomChartLegendHistoryItem[];
|
|
22
30
|
onClick?: (data: any, index: number, event: any) => void;
|
|
23
31
|
className?: string;
|
|
24
32
|
wrapperStyle?: React.CSSProperties;
|
|
@@ -48,6 +56,7 @@ function extractIdFromDataKey(dataKey?: string): number {
|
|
|
48
56
|
*/
|
|
49
57
|
export function CustomChartLegend({
|
|
50
58
|
payload,
|
|
59
|
+
histories,
|
|
51
60
|
onClick,
|
|
52
61
|
hiddenSeries,
|
|
53
62
|
className,
|
|
@@ -69,6 +78,16 @@ export function CustomChartLegend({
|
|
|
69
78
|
[payload],
|
|
70
79
|
);
|
|
71
80
|
|
|
81
|
+
const historicalItems = useMemo(
|
|
82
|
+
() =>
|
|
83
|
+
histories?.map(h => ({
|
|
84
|
+
seriesKey: h.dataKey,
|
|
85
|
+
label: h.value,
|
|
86
|
+
color: h.color,
|
|
87
|
+
})),
|
|
88
|
+
[histories],
|
|
89
|
+
);
|
|
90
|
+
|
|
72
91
|
const selectedIds = useMemo(() => {
|
|
73
92
|
if (preventDeselection) {
|
|
74
93
|
// Always keep all items selected when preventDeselection is true
|
|
@@ -128,7 +147,7 @@ export function CustomChartLegend({
|
|
|
128
147
|
[onClick, payload, hiddenSeries, onAnalysisSelect],
|
|
129
148
|
);
|
|
130
149
|
|
|
131
|
-
if (!items.length) return null;
|
|
150
|
+
if (!items.length && !histories?.length) return null;
|
|
132
151
|
|
|
133
152
|
return (
|
|
134
153
|
<div className={cn(S.legendContainer, className)}>
|
|
@@ -144,6 +163,7 @@ export function CustomChartLegend({
|
|
|
144
163
|
maxVisibleItems={maxVisibleItems}
|
|
145
164
|
preventDeselection={preventDeselection}
|
|
146
165
|
hiddenSeries={hiddenSeries ?? new Set()}
|
|
166
|
+
historicalItems={historicalItems}
|
|
147
167
|
onToggleSeries={handleToggleSeriesVisibility}
|
|
148
168
|
/>
|
|
149
169
|
</div>
|
|
@@ -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
|
|
|
7
9
|
interface LegendSvgProps {
|
|
@@ -42,7 +44,7 @@ export function LegendSvg({ payload, width, marginLeft = 0 }: LegendSvgProps) {
|
|
|
42
44
|
y2={ROW_HEIGHT / 2}
|
|
43
45
|
stroke={item.color}
|
|
44
46
|
strokeWidth={2}
|
|
45
|
-
strokeDasharray=
|
|
47
|
+
strokeDasharray={item.solid ? undefined : '3 3'}
|
|
46
48
|
/>
|
|
47
49
|
<circle cx={20} cy={ROW_HEIGHT / 2} r={3} fill={item.color} />
|
|
48
50
|
<text
|
|
@@ -14,10 +14,12 @@ ChartAreaInteractive is the full chart shell for time series data, combining an
|
|
|
14
14
|
## Do
|
|
15
15
|
|
|
16
16
|
- Pass loading while data is being fetched so the chart shows its skeleton state.
|
|
17
|
+
- For several products, pass `historyData` (one history line each, data key `historical_<id>` in `chartData`) and set each forecast's `continues` to the history it extends. A forecast joins a history only when `continues` names it or there is exactly one history; otherwise it starts on its own first point. Without `historyData`, the single `historical` line works as before.
|
|
17
18
|
|
|
18
19
|
## Host provides
|
|
19
20
|
|
|
20
21
|
- `chartData`, `forecastData` built from API
|
|
22
|
+
- Optional `historyData` for several history lines, with `continues` on each forecast
|
|
21
23
|
- `timeRange` / `onTimeRangeChange` or brush-only range
|
|
22
24
|
- Optional `mode`: pin | intervals | thresholds + overlay state
|
|
23
25
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Analysis, ChartDataPoint } from './ChartAreaInteractive.types';
|
|
2
|
+
import { isHistorySeriesKey } from './chartHistories';
|
|
2
3
|
|
|
3
4
|
// Helper function to format large numbers with k/m abbreviations
|
|
4
5
|
export const formatNumber = (value: number): string => {
|
|
@@ -112,14 +113,24 @@ function hasPlottableChartSeriesValue(item: ChartDataPoint): boolean {
|
|
|
112
113
|
|
|
113
114
|
/**
|
|
114
115
|
* Row counts toward the "end" of the window when anchoring the time range to a
|
|
115
|
-
* selected forecast (
|
|
116
|
+
* selected forecast (the history it joins + that analysis line / quantiles).
|
|
117
|
+
* `historyKey`: that history's data key, null for none, undefined for any.
|
|
116
118
|
*/
|
|
117
119
|
function rowContributesToAnchoredTimeRange(
|
|
118
120
|
item: ChartDataPoint,
|
|
119
121
|
analysisId: number,
|
|
122
|
+
historyKey: string | null | undefined,
|
|
120
123
|
): boolean {
|
|
121
|
-
if (
|
|
122
|
-
|
|
124
|
+
if (historyKey !== undefined) {
|
|
125
|
+
if (historyKey !== null && isPlottableNumber(item[historyKey])) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
} else {
|
|
129
|
+
for (const key of Object.keys(item)) {
|
|
130
|
+
if (isHistorySeriesKey(key) && isPlottableNumber(item[key])) {
|
|
131
|
+
return true;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
123
134
|
}
|
|
124
135
|
const forecastKey = `forecast_${analysisId}`;
|
|
125
136
|
if (isPlottableNumber(item[forecastKey])) {
|
|
@@ -137,14 +148,20 @@ function rowContributesToAnchoredTimeRange(
|
|
|
137
148
|
|
|
138
149
|
function computeLatestPlottableDate(
|
|
139
150
|
data: ChartDataPoint[],
|
|
140
|
-
options?:
|
|
151
|
+
options?: FilterDataForTimeRangeOptions,
|
|
141
152
|
): Date | null {
|
|
142
153
|
const anchorId = options?.endDateAnchorAnalysisId;
|
|
143
154
|
|
|
144
155
|
const pick = (item: ChartDataPoint, useAnchor: boolean): Date | null => {
|
|
145
156
|
if (!item.date) return null;
|
|
146
157
|
if (useAnchor && anchorId != null) {
|
|
147
|
-
if (
|
|
158
|
+
if (
|
|
159
|
+
!rowContributesToAnchoredTimeRange(
|
|
160
|
+
item,
|
|
161
|
+
anchorId,
|
|
162
|
+
options?.anchorHistoryKey,
|
|
163
|
+
)
|
|
164
|
+
) {
|
|
148
165
|
return null;
|
|
149
166
|
}
|
|
150
167
|
} else if (!hasPlottableChartSeriesValue(item)) {
|
|
@@ -177,6 +194,11 @@ export type FilterDataForTimeRangeOptions = {
|
|
|
177
194
|
/** When set (e.g. selected forecast on Forecast tab), the window ends at the
|
|
178
195
|
* latest point that has shared historical or that analysis — not at another run. */
|
|
179
196
|
endDateAnchorAnalysisId?: number | null;
|
|
197
|
+
/**
|
|
198
|
+
* The history line that anchored forecast joins (`historical`,
|
|
199
|
+
* `historical_<id>`), or null for none. Omitted: any history line counts.
|
|
200
|
+
*/
|
|
201
|
+
anchorHistoryKey?: string | null;
|
|
180
202
|
};
|
|
181
203
|
|
|
182
204
|
export const filterDataForTimeRange = (
|