@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.
- 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.js +4 -1
- package/dist/esm/src/components/ui/Chart/Chart.styl.js +2 -2
- package/dist/esm/src/components/ui/Chart/components/BaseChartWrapper.js +74 -57
- package/dist/esm/src/components/ui/Chart/components/ChartAxes.js +8 -7
- 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/ChartPlacedTooltip.js +65 -0
- package/dist/esm/src/components/ui/Chart/components/ChartTooltipContent.js +4 -4
- package/dist/esm/src/components/ui/Chart/components/ChartTooltipItem.js +24 -8
- 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/Chart/components/QuantileBands.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 +55 -19
- 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 +28 -0
- package/dist/esm/src/components/widgets/DriverCard/DriverPerformanceChart.js +5 -25
- package/dist/esm/src/index.js +4 -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/Chart.d.ts +4 -2
- package/dist/esm/types/src/components/ui/Chart/Chart.types.d.ts +5 -0
- package/dist/esm/types/src/components/ui/Chart/chartForecastVisualization.types.d.ts +7 -0
- package/dist/esm/types/src/components/ui/Chart/components/BaseChartWrapper.d.ts +25 -0
- package/dist/esm/types/src/components/ui/Chart/components/BaseChartWrapper.test.d.ts +1 -0
- package/dist/esm/types/src/components/ui/Chart/components/ChartAxes.d.ts +8 -1
- package/dist/esm/types/src/components/ui/Chart/components/ChartAxes.test.d.ts +1 -0
- package/dist/esm/types/src/components/ui/Chart/components/ChartPlacedTooltip.d.ts +31 -0
- package/dist/esm/types/src/components/ui/Chart/components/ChartPlacedTooltip.test.d.ts +1 -0
- package/dist/esm/types/src/components/ui/Chart/components/ChartTooltipContent.d.ts +1 -1
- package/dist/esm/types/src/components/ui/Chart/components/ChartTooltipContent.test.d.ts +1 -0
- package/dist/esm/types/src/components/ui/Chart/components/ChartTooltipItem.d.ts +2 -1
- 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 +30 -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 +19 -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 +2 -2
- 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/AGENT.md +5 -0
- package/src/components/ui/Chart/Chart.tsx +7 -1
- package/src/components/ui/Chart/Chart.types.ts +5 -0
- package/src/components/ui/Chart/chartForecastVisualization.types.ts +7 -0
- package/src/components/ui/Chart/components/BaseChartWrapper.test.tsx +344 -0
- package/src/components/ui/Chart/components/BaseChartWrapper.tsx +149 -88
- package/src/components/ui/Chart/components/ChartAxes.test.tsx +49 -0
- package/src/components/ui/Chart/components/ChartAxes.tsx +36 -20
- package/src/components/ui/Chart/components/ChartPlacedTooltip.test.tsx +160 -0
- package/src/components/ui/Chart/components/ChartPlacedTooltip.tsx +93 -0
- package/src/components/ui/Chart/components/ChartTooltipContent.test.tsx +85 -0
- package/src/components/ui/Chart/components/ChartTooltipContent.tsx +2 -0
- package/src/components/ui/Chart/components/ChartTooltipItem.tsx +41 -10
- 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/Chart/components/QuantileBands.tsx +1 -1
- package/src/components/ui/ChartAreaInteractive/AGENT.md +4 -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 +151 -65
- 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 +81 -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/components/widgets/DriverCard/DriverPerformanceChart.tsx +2 -2
- 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
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useMemo } from 'react';
|
|
3
|
+
import { useChartWidth, useChartHeight, useIsTooltipActive, useMargin, Tooltip } from 'recharts';
|
|
4
|
+
|
|
5
|
+
/** Charts narrower than this open their tooltip under the chart, not over it. */
|
|
6
|
+
const NARROW_CHART_PX = 500;
|
|
7
|
+
/** Gap between a narrow chart's x-axis labels and its tooltip. */
|
|
8
|
+
const NARROW_TOOLTIP_GAP_PX = 4;
|
|
9
|
+
/**
|
|
10
|
+
* Set to 1 on the tooltip wrapper's style while it sits under the chart, so
|
|
11
|
+
* code that moves the wrapper itself (BaseChartWrapper) leaves it alone
|
|
12
|
+
* instead of deciding again.
|
|
13
|
+
*/
|
|
14
|
+
const TOOLTIP_UNDER_VAR = '--chart-tooltip-under';
|
|
15
|
+
/** Whether a chart this wide opens its tooltip under itself. */
|
|
16
|
+
function opensTooltipUnder(chartWidth) {
|
|
17
|
+
return chartWidth != null && chartWidth > 0 && chartWidth < NARROW_CHART_PX;
|
|
18
|
+
}
|
|
19
|
+
/** Whether ChartPlacedTooltip put this tooltip wrapper under its chart. */
|
|
20
|
+
function isTooltipUnder(wrapper) {
|
|
21
|
+
return wrapper.style.getPropertyValue(TOOLTIP_UNDER_VAR).trim() === '1';
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A recharts Tooltip that, on a chart narrower than {@link NARROW_CHART_PX},
|
|
25
|
+
* sits under the chart instead of over the lines, starting right under the
|
|
26
|
+
* x-axis labels (the chart's bottom margin is left out), so a small chart stays
|
|
27
|
+
* readable while it is hovered. It may then cover what follows the chart, be
|
|
28
|
+
* clipped by a parent that hides overflow, or run past the page edge; that is
|
|
29
|
+
* accepted. Under a chart it does not slide (no transition, whatever
|
|
30
|
+
* `wrapperStyle` says), and while no point is hovered it takes no room
|
|
31
|
+
* (`display: none`), so it never grows a scrolling parent. A caller's
|
|
32
|
+
* `position.x` and `position.y` each win, as does `isAnimationActive`. With
|
|
33
|
+
* `portal`, recharts places nothing, so neither does this.
|
|
34
|
+
*/
|
|
35
|
+
function ChartPlacedTooltip(props) {
|
|
36
|
+
const width = useChartWidth();
|
|
37
|
+
const height = useChartHeight();
|
|
38
|
+
const hovered = useIsTooltipActive();
|
|
39
|
+
const bottomMargin = useMargin()?.bottom ?? 0;
|
|
40
|
+
const open = props.active ?? hovered;
|
|
41
|
+
const under = props.portal == null &&
|
|
42
|
+
opensTooltipUnder(width) &&
|
|
43
|
+
height != null &&
|
|
44
|
+
height > 0;
|
|
45
|
+
const callerPosition = props.position;
|
|
46
|
+
const y = under
|
|
47
|
+
? (callerPosition?.y ??
|
|
48
|
+
height - Math.max(0, bottomMargin) + NARROW_TOOLTIP_GAP_PX)
|
|
49
|
+
: undefined;
|
|
50
|
+
const position = useMemo(() => (y == null ? undefined : { ...callerPosition, y }), [callerPosition, y]);
|
|
51
|
+
const callerWrapperStyle = props.wrapperStyle;
|
|
52
|
+
const wrapperStyle = useMemo(() => under
|
|
53
|
+
? {
|
|
54
|
+
...callerWrapperStyle,
|
|
55
|
+
[TOOLTIP_UNDER_VAR]: '1',
|
|
56
|
+
transition: 'none',
|
|
57
|
+
...(open ? {} : { display: 'none' }),
|
|
58
|
+
}
|
|
59
|
+
: undefined, [under, open, callerWrapperStyle]);
|
|
60
|
+
if (!under)
|
|
61
|
+
return jsx(Tooltip, { ...props });
|
|
62
|
+
return (jsx(Tooltip, { ...props, position: position, isAnimationActive: props.isAnimationActive ?? false, wrapperStyle: wrapperStyle }));
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export { ChartPlacedTooltip, NARROW_CHART_PX, NARROW_TOOLTIP_GAP_PX, TOOLTIP_UNDER_VAR, isTooltipUnder, opensTooltipUnder };
|
|
@@ -3,10 +3,10 @@ import cn from 'classnames';
|
|
|
3
3
|
import { useState, useMemo, useEffect } from 'react';
|
|
4
4
|
import { useChart } from '../Chart.context.js';
|
|
5
5
|
import { normalizeTooltipPayload, getPayloadConfigFromPayload } from '../Chart.helpers.js';
|
|
6
|
-
import
|
|
6
|
+
import ChartS from '../Chart.styl.js';
|
|
7
7
|
import { ChartTooltipItem } from './ChartTooltipItem.js';
|
|
8
8
|
|
|
9
|
-
function ChartTooltipContent({ active, className, indicator = 'dot', hideLabel = false, hideIndicator = false, label, labelFormatter, labelClassName, payload, formatter, color, nameKey, labelKey, }) {
|
|
9
|
+
function ChartTooltipContent({ active, className, indicator = 'dot', hideLabel = false, hideIndicator = false, label, labelFormatter, labelClassName, payload, formatter, valueFormatter, color, nameKey, labelKey, }) {
|
|
10
10
|
const { config } = useChart();
|
|
11
11
|
// Keep last tooltip data in state to maintain position when inactive
|
|
12
12
|
const [lastTooltipData, setLastTooltipData] = useState(null);
|
|
@@ -69,9 +69,9 @@ function ChartTooltipContent({ active, className, indicator = 'dot', hideLabel =
|
|
|
69
69
|
return null;
|
|
70
70
|
}
|
|
71
71
|
const nestLabel = displayPayload.length === 1 && indicator !== 'dot';
|
|
72
|
-
return (jsxs("div", { className: cn(
|
|
72
|
+
return (jsxs("div", { className: cn(ChartS.tooltipContainer, className), children: [!nestLabel ? tooltipLabel : null, jsx("div", { className: ChartS.tooltipContentGrid, children: displayPayload
|
|
73
73
|
.filter(item => item.type !== 'none')
|
|
74
|
-
.map((item, index) => (jsx(ChartTooltipItem, { item: item, index: index, config: config, indicator: indicator, hideIndicator: hideIndicator, nestLabel: nestLabel, tooltipLabel: tooltipLabel, color: color, nameKey: nameKey, formatter: formatter }, item.dataKey || index))) })] }));
|
|
74
|
+
.map((item, index) => (jsx(ChartTooltipItem, { item: item, index: index, config: config, indicator: indicator, hideIndicator: hideIndicator, nestLabel: nestLabel, tooltipLabel: tooltipLabel, color: color, nameKey: nameKey, formatter: formatter, valueFormatter: valueFormatter }, item.dataKey || index))) })] }));
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
export { ChartTooltipContent };
|
|
@@ -1,9 +1,29 @@
|
|
|
1
1
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import cn from 'classnames';
|
|
3
3
|
import { getPayloadConfigFromPayload } from '../Chart.helpers.js';
|
|
4
|
-
import
|
|
4
|
+
import ChartS from '../Chart.styl.js';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
const rawValue = (value) => value.toLocaleString(undefined, { maximumFractionDigits: 20 });
|
|
7
|
+
const isMissing = (value) => value == null || (typeof value === 'number' && Number.isNaN(value));
|
|
8
|
+
/**
|
|
9
|
+
* A row's value as text: numbers through `format`, anything else as is, and
|
|
10
|
+
* a missing one (null, NaN) as null. A range shows a missing end as a dash,
|
|
11
|
+
* and is missing itself when both ends are.
|
|
12
|
+
*/
|
|
13
|
+
function valueText(value, format) {
|
|
14
|
+
const one = (v) => isMissing(v) ? null : typeof v === 'number' ? format(v) : String(v);
|
|
15
|
+
if (!Array.isArray(value))
|
|
16
|
+
return one(value);
|
|
17
|
+
const [low, high] = [one(value[0]), one(value[1])];
|
|
18
|
+
if (low == null && high == null)
|
|
19
|
+
return null;
|
|
20
|
+
return `${low ?? '—'} – ${high ?? '—'}`;
|
|
21
|
+
}
|
|
22
|
+
function TooltipValue({ value, format, }) {
|
|
23
|
+
const text = valueText(value, format);
|
|
24
|
+
return text == null ? null : jsx("span", { className: ChartS.tooltipValue, children: text });
|
|
25
|
+
}
|
|
26
|
+
function ChartTooltipItem({ item, index, config, indicator, hideIndicator, nestLabel, tooltipLabel, color, nameKey, formatter, valueFormatter = rawValue, }) {
|
|
7
27
|
const key = `${nameKey || item.name || item.dataKey || 'value'}`;
|
|
8
28
|
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
9
29
|
const payloadFill = item.payload &&
|
|
@@ -13,14 +33,10 @@ function ChartTooltipItem({ item, index, config, indicator, hideIndicator, nestL
|
|
|
13
33
|
? item.payload.fill
|
|
14
34
|
: undefined;
|
|
15
35
|
const indicatorColor = color || payloadFill || item.color;
|
|
16
|
-
return (jsx("div", { className: cn(
|
|
36
|
+
return (jsx("div", { className: cn(ChartS.tooltipItem, indicator === 'dot' && 'items-center'), children: formatter && item?.value !== undefined && item.name ? (formatter(item.value, item.name, item, index, item.payload)) : (jsxs(Fragment, { children: [itemConfig?.icon ? (jsx(itemConfig.icon, {})) : (!hideIndicator && (jsx("div", { className: cn(ChartS.tooltipIndicator, ChartS[`indicator-${indicator}`], nestLabel && ChartS.nested), style: {
|
|
17
37
|
'--color-bg': indicatorColor,
|
|
18
38
|
'--color-border': indicatorColor,
|
|
19
|
-
} }))), jsxs("div", { className: cn(
|
|
20
|
-
? `${item.value[0].toLocaleString(undefined, { maximumFractionDigits: 20 })} – ${item.value[1].toLocaleString(undefined, { maximumFractionDigits: 20 })}`
|
|
21
|
-
: item.value.toLocaleString(undefined, {
|
|
22
|
-
maximumFractionDigits: 20,
|
|
23
|
-
}) }))] })] })) }, item.dataKey));
|
|
39
|
+
} }))), jsxs("div", { className: cn(ChartS.tooltipContent, nestLabel ? 'items-end' : 'items-center'), children: [jsxs("div", { className: ChartS.tooltipLabel, children: [nestLabel ? tooltipLabel : null, jsx("span", { className: cn('text-muted-foreground', ChartS.tooltipLabelText), children: itemConfig?.label || item.name })] }), jsx(TooltipValue, { value: item.value, format: valueFormatter })] })] })) }, item.dataKey));
|
|
24
40
|
}
|
|
25
41
|
|
|
26
42
|
export { ChartTooltipItem };
|
|
@@ -16,7 +16,7 @@ function extractIdFromDataKey(dataKey) {
|
|
|
16
16
|
* Custom chart legend using AnalysesSelector (inline mode)
|
|
17
17
|
* Supports forecast icon indicator, failed badge, toggle visibility
|
|
18
18
|
*/
|
|
19
|
-
function CustomChartLegend({ payload, onClick, hiddenSeries, className, onAnalysisSelect, onFailedAnalysisClick, maxVisibleItems, preventDeselection = true, }) {
|
|
19
|
+
function CustomChartLegend({ payload, histories, onClick, hiddenSeries, className, onAnalysisSelect, onFailedAnalysisClick, maxVisibleItems, preventDeselection = true, }) {
|
|
20
20
|
const items = useMemo(() => (payload ?? []).map(p => ({
|
|
21
21
|
id: extractIdFromDataKey(p.dataKey),
|
|
22
22
|
label: p.value,
|
|
@@ -25,6 +25,11 @@ function CustomChartLegend({ payload, onClick, hiddenSeries, className, onAnalys
|
|
|
25
25
|
icon: p.icon,
|
|
26
26
|
updated_at: p.updated_at,
|
|
27
27
|
})), [payload]);
|
|
28
|
+
const historicalItems = useMemo(() => histories?.map(h => ({
|
|
29
|
+
seriesKey: h.dataKey,
|
|
30
|
+
label: h.value,
|
|
31
|
+
color: h.color,
|
|
32
|
+
})), [histories]);
|
|
28
33
|
const selectedIds = useMemo(() => {
|
|
29
34
|
if (preventDeselection) {
|
|
30
35
|
// Always keep all items selected when preventDeselection is true
|
|
@@ -56,9 +61,9 @@ function CustomChartLegend({ payload, onClick, hiddenSeries, className, onAnalys
|
|
|
56
61
|
onAnalysisSelect(id);
|
|
57
62
|
}
|
|
58
63
|
}, [onClick, payload, hiddenSeries, onAnalysisSelect]);
|
|
59
|
-
if (!items.length)
|
|
64
|
+
if (!items.length && !histories?.length)
|
|
60
65
|
return null;
|
|
61
|
-
return (jsx("div", { className: cn(S.legendContainer, className), children: jsx(AnalysesSelector, { items: items, selectedIds: selectedIds, onItemToggle: handleItemToggle, inlineMode: true, size: "xs", variant: "clear", onFailedItemClick: onFailedAnalysisClick, enableToggleHidden: true, maxVisibleItems: maxVisibleItems, preventDeselection: preventDeselection, hiddenSeries: hiddenSeries ?? new Set(), onToggleSeries: handleToggleSeriesVisibility }) }));
|
|
66
|
+
return (jsx("div", { className: cn(S.legendContainer, className), children: jsx(AnalysesSelector, { items: items, selectedIds: selectedIds, onItemToggle: handleItemToggle, inlineMode: true, size: "xs", variant: "clear", onFailedItemClick: onFailedAnalysisClick, enableToggleHidden: true, maxVisibleItems: maxVisibleItems, preventDeselection: preventDeselection, hiddenSeries: hiddenSeries ?? new Set(), historicalItems: historicalItems, onToggleSeries: handleToggleSeriesVisibility }) }));
|
|
62
67
|
}
|
|
63
68
|
|
|
64
69
|
export { CustomChartLegend };
|
|
@@ -13,7 +13,7 @@ function LegendSvg({ payload, width, marginLeft = 0 }) {
|
|
|
13
13
|
items.push({ x, item });
|
|
14
14
|
x += ICON_WIDTH + ITEM_GAP + item.value.length * FONT_SIZE * 0.6 + ITEM_GAP;
|
|
15
15
|
});
|
|
16
|
-
return (jsx("svg", { width: width, height: ROW_HEIGHT, viewBox: `0 0 ${Math.max(width, x)} ${ROW_HEIGHT}`, style: { display: 'block' }, children: items.map(({ x: itemX, item }) => (jsxs("g", { transform: `translate(${itemX}, 0)`, children: [jsx("line", { x1: 0, y1: ROW_HEIGHT / 2, x2: ICON_WIDTH, y2: ROW_HEIGHT / 2, stroke: item.color, strokeWidth: 2, strokeDasharray:
|
|
16
|
+
return (jsx("svg", { width: width, height: ROW_HEIGHT, viewBox: `0 0 ${Math.max(width, x)} ${ROW_HEIGHT}`, style: { display: 'block' }, children: items.map(({ x: itemX, item }) => (jsxs("g", { transform: `translate(${itemX}, 0)`, children: [jsx("line", { x1: 0, y1: ROW_HEIGHT / 2, x2: ICON_WIDTH, y2: ROW_HEIGHT / 2, stroke: item.color, strokeWidth: 2, strokeDasharray: item.solid ? undefined : '3 3' }), jsx("circle", { cx: 20, cy: ROW_HEIGHT / 2, r: 3, fill: item.color }), jsx("text", { x: ICON_WIDTH + ITEM_GAP, y: ROW_HEIGHT / 2, dy: "0.35em", fontSize: FONT_SIZE, fill: "#333333", children: item.value })] }, item.dataKey))) }));
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
export { LegendSvg };
|
|
@@ -14,7 +14,7 @@ function QuantileBands({ color, hiddenBands = new Set(), quantileBandKey, animat
|
|
|
14
14
|
const fillColor = color || band.color || getForecastQuantileBandColor(index);
|
|
15
15
|
return (jsx(Area, { type: band.type || 'monotone', dataKey: band.key, name: band.name, stroke: band.strokeWidth ? fillColor : 'none', strokeWidth: band.strokeWidth || 0, strokeDasharray: band.strokeDasharray, strokeOpacity: band.strokeOpacity, fill: fillColor,
|
|
16
16
|
// fillOpacity={band.opacity}
|
|
17
|
-
legendType: showLegend === false ? 'none' : undefined, connectNulls: true, dot: false, activeDot: false, isAnimationActive: animate, animationDuration: animationDuration, animationBegin: animationBegin, animationEasing: "ease-out" }, quantileBandKey
|
|
17
|
+
legendType: showLegend === false ? 'none' : undefined, connectNulls: band.connectNulls ?? true, dot: false, activeDot: false, isAnimationActive: animate, animationDuration: animationDuration, animationBegin: animationBegin, animationEasing: "ease-out" }, quantileBandKey
|
|
18
18
|
? `${quantileBandKey}-${index}`
|
|
19
19
|
: `quantile-band-${index}`));
|
|
20
20
|
}) }));
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
import { isHistorySeriesKey } from './chartHistories.js';
|
|
2
|
+
|
|
2
3
|
// Find pin position for a specific date in the current filtered data
|
|
3
4
|
const findPinPositionForDate = (targetDate, filteredData) => {
|
|
4
5
|
if (!filteredData.length)
|
|
@@ -83,11 +84,21 @@ function hasPlottableChartSeriesValue(item) {
|
|
|
83
84
|
}
|
|
84
85
|
/**
|
|
85
86
|
* Row counts toward the "end" of the window when anchoring the time range to a
|
|
86
|
-
* selected forecast (
|
|
87
|
+
* selected forecast (the history it joins + that analysis line / quantiles).
|
|
88
|
+
* `historyKey`: that history's data key, null for none, undefined for any.
|
|
87
89
|
*/
|
|
88
|
-
function rowContributesToAnchoredTimeRange(item, analysisId) {
|
|
89
|
-
if (
|
|
90
|
-
|
|
90
|
+
function rowContributesToAnchoredTimeRange(item, analysisId, historyKey) {
|
|
91
|
+
if (historyKey !== undefined) {
|
|
92
|
+
if (historyKey !== null && isPlottableNumber(item[historyKey])) {
|
|
93
|
+
return true;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
for (const key of Object.keys(item)) {
|
|
98
|
+
if (isHistorySeriesKey(key) && isPlottableNumber(item[key])) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
91
102
|
}
|
|
92
103
|
const forecastKey = `forecast_${analysisId}`;
|
|
93
104
|
if (isPlottableNumber(item[forecastKey])) {
|
|
@@ -108,7 +119,7 @@ function computeLatestPlottableDate(data, options) {
|
|
|
108
119
|
if (!item.date)
|
|
109
120
|
return null;
|
|
110
121
|
if (useAnchor && anchorId != null) {
|
|
111
|
-
if (!rowContributesToAnchoredTimeRange(item, anchorId)) {
|
|
122
|
+
if (!rowContributesToAnchoredTimeRange(item, anchorId, options?.anchorHistoryKey)) {
|
|
112
123
|
return null;
|
|
113
124
|
}
|
|
114
125
|
}
|
|
@@ -9,14 +9,21 @@ import { CHART_MARGINS } from './ChartAreaInteractive.constants.js';
|
|
|
9
9
|
import { filterDataForTimeRange, shortDateFormatter, longDateFormatter } from './ChartAreaInteractive.helpers.js';
|
|
10
10
|
import S from './ChartAreaInteractive.styl.js';
|
|
11
11
|
import { TimeRangeBrushHost } from './TimeRangeBrushLayer.js';
|
|
12
|
+
import { forecastHistoryKey } from './chartHistories.js';
|
|
12
13
|
import { PinOverlay } from './overlays/PinOverlay/PinOverlay.js';
|
|
13
14
|
import { IntervalsOverlay } from './overlays/IntervalsOverlay/IntervalsOverlay.js';
|
|
14
15
|
import { ThresholdsOverlay } from './overlays/ThresholdsOverlay/ThresholdsOverlay.js';
|
|
15
16
|
|
|
17
|
+
/** The bridge's `historyKeyFor`, from serialised {@link ForecastHistoryKeys}. */
|
|
18
|
+
function historyKeyLookup(serialised) {
|
|
19
|
+
const { byId, other } = JSON.parse(serialised);
|
|
20
|
+
const map = new Map(byId);
|
|
21
|
+
return id => (map.has(id) ? map.get(id) : other);
|
|
22
|
+
}
|
|
16
23
|
const chartConfig = {
|
|
17
24
|
// Chart now supports light/dark themes with dynamic colors
|
|
18
25
|
};
|
|
19
|
-
function ChartAreaInteractive({ className, chartContainerClassName, legendClassName, xAxisClassName, yAxisClassName, timeRange, onTimeRangeChange, pinMonth, onPinMonthChange, onPreviewMonthChange, chartData, forecastData, error, loading = false, isDarkTheme = false, footerActions, mode, selectedForecast, upperQuantiles, lowerQuantiles, selectedLowerQuantile, selectedUpperQuantile, onLowerQuantileChange, onUpperQuantileChange, lowerThreshold, upperThreshold, onLowerThresholdChange, onUpperThresholdChange, discreteThresholdValues, headerActions, excludeLegendIds, loadingAnalyses, onLegendClick, onAnalysisSelect, disableTimeRangeSelector, enableTimeRangeBrush = false, forecastLineStyle = 'dashed', selectedAnalysisId, chartRenderId, toggleLegendSeries, ensureAnalysisSeriesVisible, overlayForecastData = {}, hiddenSeries, disableForecastHistoricalBridge, overlayElements: overlayElementsProp, ...restProps }) {
|
|
26
|
+
function ChartAreaInteractive({ className, chartContainerClassName, legendClassName, xAxisClassName, yAxisClassName, timeRange, onTimeRangeChange, pinMonth, onPinMonthChange, onPreviewMonthChange, chartData, forecastData, historyData, error, loading = false, isDarkTheme = false, footerActions, mode, selectedForecast, upperQuantiles, lowerQuantiles, selectedLowerQuantile, selectedUpperQuantile, onLowerQuantileChange, onUpperQuantileChange, lowerThreshold, upperThreshold, onLowerThresholdChange, onUpperThresholdChange, discreteThresholdValues, headerActions, excludeLegendIds, loadingAnalyses, onLegendClick, onAnalysisSelect, disableTimeRangeSelector, enableTimeRangeBrush = false, forecastLineStyle = 'dashed', selectedAnalysisId, chartRenderId, toggleLegendSeries, ensureAnalysisSeriesVisible, overlayForecastData = {}, hiddenSeries, disableForecastHistoricalBridge, overlayElements: overlayElementsProp, ...restProps }) {
|
|
20
27
|
const seriesHidden = hiddenSeries ?? new Set();
|
|
21
28
|
const hiddenSeriesRef = useRef(seriesHidden);
|
|
22
29
|
const prevSelectedAnalysisIdRef = useRef(selectedAnalysisId);
|
|
@@ -39,25 +46,47 @@ function ChartAreaInteractive({ className, chartContainerClassName, legendClassN
|
|
|
39
46
|
ensureAnalysisSeriesVisible(selectedAnalysisId);
|
|
40
47
|
}
|
|
41
48
|
}, [selectedAnalysisId, ensureAnalysisSeriesVisible]);
|
|
42
|
-
const
|
|
49
|
+
const anchorAnalysisId = useMemo(() => {
|
|
43
50
|
const raw = selectedAnalysisId ?? selectedForecast?.id ?? null;
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
const id = raw == null ? null : typeof raw === 'number' ? raw : Number(raw);
|
|
52
|
+
return id != null && Number.isFinite(id) ? id : null;
|
|
53
|
+
}, [selectedAnalysisId, selectedForecast?.id]);
|
|
54
|
+
// The history the anchored forecast joins, as a string, so the time filter
|
|
55
|
+
// does not rerun when the host passes new but equal arrays.
|
|
56
|
+
const anchorHistoryKey = useMemo(() => anchorAnalysisId == null
|
|
57
|
+
? undefined
|
|
58
|
+
: forecastHistoryKey(forecastData?.find(f => f.id === anchorAnalysisId), historyData), [anchorAnalysisId, forecastData, historyData]);
|
|
59
|
+
const timeFilteredChartData = useMemo(() => {
|
|
60
|
+
const anchorForecastLoaded = anchorAnalysisId != null &&
|
|
47
61
|
chartData.some(row => {
|
|
48
|
-
const value = row[`forecast_${
|
|
62
|
+
const value = row[`forecast_${anchorAnalysisId}`];
|
|
49
63
|
return typeof value === 'number' && Number.isFinite(value);
|
|
50
64
|
});
|
|
51
|
-
const opts =
|
|
52
|
-
? { endDateAnchorAnalysisId:
|
|
65
|
+
const opts = anchorAnalysisId != null && anchorForecastLoaded
|
|
66
|
+
? { endDateAnchorAnalysisId: anchorAnalysisId, anchorHistoryKey }
|
|
53
67
|
: undefined;
|
|
54
68
|
return filterDataForTimeRange(chartData, timeRange, opts);
|
|
55
|
-
}, [chartData, timeRange,
|
|
69
|
+
}, [chartData, timeRange, anchorAnalysisId, anchorHistoryKey]);
|
|
70
|
+
// Which history each forecast joins, as a string, so the bridge does not
|
|
71
|
+
// rerun when the host passes a new but equal historyData array.
|
|
72
|
+
const forecastHistoryKeys = useMemo(() => JSON.stringify({
|
|
73
|
+
byId: (forecastData ?? []).map(f => [
|
|
74
|
+
f.id,
|
|
75
|
+
forecastHistoryKey(f, historyData),
|
|
76
|
+
]),
|
|
77
|
+
other: forecastHistoryKey(undefined, historyData),
|
|
78
|
+
}), [forecastData, historyData]);
|
|
56
79
|
const bridgedChartData = useMemo(() => disableForecastHistoricalBridge
|
|
57
80
|
? timeFilteredChartData
|
|
58
81
|
: ensureChartForecastBridge(timeFilteredChartData, {
|
|
59
82
|
forecastSeriesIds: forecastData?.map(f => f.id),
|
|
60
|
-
|
|
83
|
+
historyKeyFor: historyKeyLookup(forecastHistoryKeys),
|
|
84
|
+
}), [
|
|
85
|
+
timeFilteredChartData,
|
|
86
|
+
disableForecastHistoricalBridge,
|
|
87
|
+
forecastData,
|
|
88
|
+
forecastHistoryKeys,
|
|
89
|
+
]);
|
|
61
90
|
// Extract quantileBands from restProps
|
|
62
91
|
// const quantileBands = (restProps as any).quantileBands;
|
|
63
92
|
const getLoadingMessage = () => {
|
|
@@ -77,6 +106,7 @@ function ChartAreaInteractive({ className, chartContainerClassName, legendClassN
|
|
|
77
106
|
xAxisClassName,
|
|
78
107
|
yAxisClassName,
|
|
79
108
|
chartData: bridgedChartData,
|
|
109
|
+
historyData,
|
|
80
110
|
chartClassName: S.chartContainer,
|
|
81
111
|
// chartClassName: cn(S.chartContainer, chartContainerClassName),
|
|
82
112
|
legendClassName,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { jsxs, Fragment
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { memo, useMemo } from 'react';
|
|
3
|
-
import { Line } from 'recharts';
|
|
3
|
+
import { DefaultZIndexes, Line } from 'recharts';
|
|
4
|
+
import { HISTORY_SERIES_KEY, historySeriesKey } from './chartHistories.js';
|
|
4
5
|
|
|
5
6
|
const ANIMATION_DURATION = 300;
|
|
6
7
|
// Colors for different forecast series
|
|
@@ -17,13 +18,26 @@ const FORECAST_COLORS_MAP = {
|
|
|
17
18
|
const FORECAST_LINE_COLORS = Object.keys(FORECAST_COLORS_MAP);
|
|
18
19
|
const getForecastColor = (index) => FORECAST_LINE_COLORS[index % FORECAST_LINE_COLORS.length];
|
|
19
20
|
const getForecastQuantileBandColor = (index) => FORECAST_COLORS_MAP[FORECAST_LINE_COLORS[index % FORECAST_LINE_COLORS.length]];
|
|
21
|
+
/** Default colour of the history at `index`: the forecast palette from its far end. */
|
|
22
|
+
function getHistoryColor(index) {
|
|
23
|
+
const n = FORECAST_LINE_COLORS.length;
|
|
24
|
+
return FORECAST_LINE_COLORS[n - 1 - (index % n)];
|
|
25
|
+
}
|
|
26
|
+
/** `historyData` with the defaults applied, in order (empty without it). */
|
|
27
|
+
function resolveHistoryLines(histories) {
|
|
28
|
+
return (histories ?? []).map((h, index) => ({
|
|
29
|
+
dataKey: historySeriesKey(h.id),
|
|
30
|
+
name: h.name || String(h.id),
|
|
31
|
+
color: h.color ?? getHistoryColor(index),
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
20
34
|
/** Same tint logic as intervals/threshold overlays: band fill follows forecast line hex when known. */
|
|
21
35
|
function resolveQuantileBandFillForForecastLine(lineColor, forecastIndex) {
|
|
22
36
|
const mapped = FORECAST_COLORS_MAP[lineColor];
|
|
23
37
|
return mapped ?? getForecastQuantileBandColor(forecastIndex);
|
|
24
38
|
}
|
|
25
39
|
// Memoized component for chart lines - only re-renders when data/analyses/hiddenSeries change
|
|
26
|
-
const ChartLines = memo(({ chartData, forecastData, hiddenSeries, isDarkTheme, shouldAnimate, historicalLineColor = isDarkTheme ? '#ffffff' : '#000000', showLegend = true, forecastLineStyle = 'dashed', disableAnimation = false, disableHistoricalAnimation = false, }) => {
|
|
40
|
+
const ChartLines = memo(({ chartData, forecastData, historyData, hiddenSeries, isDarkTheme, shouldAnimate, historicalLineColor = isDarkTheme ? '#ffffff' : '#000000', showLegend = true, forecastLineStyle = 'dashed', disableAnimation = false, disableHistoricalAnimation = false, connectHistoryNulls = false, connectForecastNulls = false, historyOnTop = false, showEndDots = true, }) => {
|
|
27
41
|
const dotStroke = isDarkTheme ? '#000000' : '#FFFFFF';
|
|
28
42
|
const activeDotHistorical = {
|
|
29
43
|
r: 6,
|
|
@@ -37,16 +51,32 @@ const ChartLines = memo(({ chartData, forecastData, hiddenSeries, isDarkTheme, s
|
|
|
37
51
|
...activeDotHistorical,
|
|
38
52
|
fill: color,
|
|
39
53
|
});
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
54
|
+
// One entry per history line: the single `historical` line, or one per
|
|
55
|
+
// `historyData` item under `historical_<id>`.
|
|
56
|
+
const historyLines = useMemo(() => historyData?.length
|
|
57
|
+
? resolveHistoryLines(historyData)
|
|
58
|
+
: [
|
|
59
|
+
{
|
|
60
|
+
dataKey: HISTORY_SERIES_KEY,
|
|
61
|
+
name: 'Historical Data',
|
|
62
|
+
color: historicalLineColor,
|
|
63
|
+
},
|
|
64
|
+
], [historyData, historicalLineColor]);
|
|
65
|
+
// Memoize last index per history line to avoid recalculating on every render call
|
|
66
|
+
const lastHistoryIndices = useMemo(() => {
|
|
67
|
+
const indices = {};
|
|
68
|
+
historyLines.forEach(({ dataKey }) => {
|
|
69
|
+
indices[dataKey] = -1;
|
|
70
|
+
for (let i = chartData.length - 1; i >= 0; i--) {
|
|
71
|
+
const value = chartData[i][dataKey];
|
|
72
|
+
if (value !== undefined && value !== null) {
|
|
73
|
+
indices[dataKey] = i;
|
|
74
|
+
break;
|
|
75
|
+
}
|
|
46
76
|
}
|
|
47
|
-
}
|
|
48
|
-
return
|
|
49
|
-
}, [chartData]);
|
|
77
|
+
});
|
|
78
|
+
return indices;
|
|
79
|
+
}, [chartData, historyLines]);
|
|
50
80
|
// Memoize last forecast indices per forecast ID
|
|
51
81
|
const lastForecastIndices = useMemo(() => {
|
|
52
82
|
const indices = {};
|
|
@@ -73,19 +103,25 @@ const ChartLines = memo(({ chartData, forecastData, hiddenSeries, isDarkTheme, s
|
|
|
73
103
|
}
|
|
74
104
|
return null;
|
|
75
105
|
};
|
|
76
|
-
const
|
|
106
|
+
const renderHistoryDot = (props, dataKey, color) => renderDot(props, lastHistoryIndices[dataKey] ?? -1, dataKey, color);
|
|
77
107
|
const renderForecastDot = (props, id, color) => renderDot(props, lastForecastIndices[id] ?? -1, `forecast_${id}`, color);
|
|
78
108
|
const animationActive = Boolean(shouldAnimate) && !disableAnimation;
|
|
79
109
|
const historicalAnimationActive = animationActive && !disableHistoricalAnimation;
|
|
80
110
|
const forecastAnimationActive = animationActive;
|
|
81
111
|
const animationDuration = disableAnimation ? 0 : ANIMATION_DURATION;
|
|
82
112
|
const valueAnimationEnabled = !disableAnimation;
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
113
|
+
// recharts draws each line into its z-index layer in mount order, not in
|
|
114
|
+
// JSX order: a layer above the forecasts keeps history on top through
|
|
115
|
+
// hiding, showing and added forecasts, and leaves the tooltip's order.
|
|
116
|
+
const historyZIndex = historyOnTop ? DefaultZIndexes.line + 1 : undefined;
|
|
117
|
+
const historyElements = historyLines.map(({ dataKey, name, color }) => (jsx(Line, { zIndex: historyZIndex, type: "monotone", dataKey: dataKey, stroke: color, strokeWidth: 1, dot: showEndDots ? props => renderHistoryDot(props, dataKey, color) : false, activeDot: { ...activeDotHistorical, fill: color }, name: name, legendType: showLegend === false ? 'none' : undefined, strokeDasharray: "0", connectNulls: connectHistoryNulls, hide: hiddenSeries?.has(dataKey), isAnimationActive: historicalAnimationActive, animationDuration: animationDuration, animateNewValues: valueAnimationEnabled, animationBegin: 0, animationEasing: "ease-out" }, dataKey)));
|
|
118
|
+
const forecastElements = forecastData?.map((data, index) => {
|
|
119
|
+
const { id, name, color = FORECAST_LINE_COLORS[index % FORECAST_LINE_COLORS.length], } = data;
|
|
120
|
+
const dataKey = `forecast_${id}`;
|
|
121
|
+
return (jsx(Line, { type: "monotone", dataKey: dataKey, stroke: color, strokeWidth: 1, strokeDasharray: forecastLineStyle === 'dashed' ? '4 2' : '0', dot: showEndDots ? props => renderForecastDot(props, id, color) : false, activeDot: activeDotForecast(color), name: `${name || `${id}`}`, legendType: showLegend === false ? 'none' : undefined, connectNulls: connectForecastNulls, hide: hiddenSeries?.has(dataKey), isAnimationActive: forecastAnimationActive, animationDuration: animationDuration, animateNewValues: valueAnimationEnabled, animationBegin: 0, animationEasing: "ease-out", className: data.status === 'pending' ? 'chart-line-blinking' : undefined }, `forecast-${id}`));
|
|
122
|
+
});
|
|
123
|
+
return (jsxs(Fragment, { children: [historyElements, forecastElements] }));
|
|
88
124
|
});
|
|
89
125
|
ChartLines.displayName = 'ChartLines';
|
|
90
126
|
|
|
91
|
-
export { ChartLines, FORECAST_COLORS_MAP, FORECAST_LINE_COLORS, getForecastColor, getForecastQuantileBandColor, resolveQuantileBandFillForForecastLine };
|
|
127
|
+
export { ChartLines, FORECAST_COLORS_MAP, FORECAST_LINE_COLORS, getForecastColor, getForecastQuantileBandColor, getHistoryColor, resolveHistoryLines, resolveQuantileBandFillForForecastLine };
|
|
@@ -0,0 +1,44 @@
|
|
|
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
|
+
const HISTORY_SERIES_KEY = 'historical';
|
|
12
|
+
/** Data key of one history line in `chartData` rows. */
|
|
13
|
+
function historySeriesKey(id) {
|
|
14
|
+
return `${HISTORY_SERIES_KEY}_${id}`;
|
|
15
|
+
}
|
|
16
|
+
/** True for `historical` and for every `historical_<id>` key. */
|
|
17
|
+
function isHistorySeriesKey(key) {
|
|
18
|
+
return key === HISTORY_SERIES_KEY || key.startsWith(`${HISTORY_SERIES_KEY}_`);
|
|
19
|
+
}
|
|
20
|
+
/** The data keys of the chart's history lines, in order. */
|
|
21
|
+
function historySeriesKeys(histories) {
|
|
22
|
+
return histories?.length
|
|
23
|
+
? histories.map(h => historySeriesKey(h.id))
|
|
24
|
+
: [HISTORY_SERIES_KEY];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* The history line a forecast joins, or null when it joins none.
|
|
28
|
+
*
|
|
29
|
+
* - No `historyData`: the single `historical` line, as before.
|
|
30
|
+
* - `continues` set: that history, or none when no history has that id.
|
|
31
|
+
* - Otherwise: the only history when there is exactly one, else none.
|
|
32
|
+
*/
|
|
33
|
+
function forecastHistoryKey(forecast, histories) {
|
|
34
|
+
if (!histories?.length)
|
|
35
|
+
return HISTORY_SERIES_KEY;
|
|
36
|
+
const continues = forecast?.continues;
|
|
37
|
+
if (continues != null) {
|
|
38
|
+
const match = histories.find(h => String(h.id) === String(continues));
|
|
39
|
+
return match ? historySeriesKey(match.id) : null;
|
|
40
|
+
}
|
|
41
|
+
return histories.length === 1 ? historySeriesKey(histories[0].id) : null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export { HISTORY_SERIES_KEY, forecastHistoryKey, historySeriesKey, historySeriesKeys, isHistorySeriesKey };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useRef, useMemo } from 'react';
|
|
2
|
+
import { forecastHistoryKey, isHistorySeriesKey } from '../chartHistories.js';
|
|
2
3
|
|
|
3
4
|
/** Serialize hidden series keys for stable cache comparison. */
|
|
4
5
|
function serializeHiddenSeries(hiddenSeries) {
|
|
@@ -12,8 +13,8 @@ function serializeHiddenSeries(hiddenSeries) {
|
|
|
12
13
|
function isKeyExcludedFromYScale(key, hiddenSeries) {
|
|
13
14
|
if (!hiddenSeries || hiddenSeries.size === 0)
|
|
14
15
|
return false;
|
|
15
|
-
if (key
|
|
16
|
-
return hiddenSeries.has(
|
|
16
|
+
if (isHistorySeriesKey(key)) {
|
|
17
|
+
return hiddenSeries.has(key);
|
|
17
18
|
}
|
|
18
19
|
if (key.startsWith('forecast_')) {
|
|
19
20
|
return hiddenSeries.has(key);
|
|
@@ -29,7 +30,7 @@ function isKeyExcludedFromYScale(key, hiddenSeries) {
|
|
|
29
30
|
return false;
|
|
30
31
|
}
|
|
31
32
|
/** Pure Y-range calculation from chart data points. */
|
|
32
|
-
function calculateChartYRange(dataToUse, { excludeQuantileBands, forecastId, hiddenSeries, includeHiddenInYScale = false, }) {
|
|
33
|
+
function calculateChartYRange(dataToUse, { excludeQuantileBands, forecastId, forecastHistoryKey, hiddenSeries, includeHiddenInYScale = false, }) {
|
|
33
34
|
const allValues = [];
|
|
34
35
|
dataToUse.forEach(point => {
|
|
35
36
|
Object.entries(point).forEach(([key, value]) => {
|
|
@@ -44,6 +45,10 @@ function calculateChartYRange(dataToUse, { excludeQuantileBands, forecastId, hid
|
|
|
44
45
|
if (forecastId !== undefined) {
|
|
45
46
|
if (key.startsWith('forecast_') && key !== `forecast_${forecastId}`)
|
|
46
47
|
return;
|
|
48
|
+
if (forecastHistoryKey !== undefined &&
|
|
49
|
+
isHistorySeriesKey(key) &&
|
|
50
|
+
key !== forecastHistoryKey)
|
|
51
|
+
return;
|
|
47
52
|
// Exclude q{quantile}_{otherAnalysisId} - only include selected forecast's quantiles
|
|
48
53
|
if (key.startsWith('q') && !key.endsWith(`_${forecastId}`))
|
|
49
54
|
return;
|
|
@@ -86,8 +91,16 @@ function calculateChartYRange(dataToUse, { excludeQuantileBands, forecastId, hid
|
|
|
86
91
|
if (allValues.length === 0) {
|
|
87
92
|
return { yMin: 0, yMax: 100 };
|
|
88
93
|
}
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
// A loop, not Math.min(...values): one value per row and line can exceed
|
|
95
|
+
// the engine's argument limit.
|
|
96
|
+
let min = Infinity;
|
|
97
|
+
let max = -Infinity;
|
|
98
|
+
for (const v of allValues) {
|
|
99
|
+
if (v < min)
|
|
100
|
+
min = v;
|
|
101
|
+
if (v > max)
|
|
102
|
+
max = v;
|
|
103
|
+
}
|
|
91
104
|
const diff = max - min;
|
|
92
105
|
return {
|
|
93
106
|
yMin: min - diff * 0.1,
|
|
@@ -105,9 +118,15 @@ function useChartYRange({ baseChartProps, chartData, disableRescaleWhenQuantileC
|
|
|
105
118
|
const stableYRangeRef = useRef(null);
|
|
106
119
|
const prevBaseChartDataRef = useRef(baseChartProps.chartData);
|
|
107
120
|
const prevHiddenSeriesKeyRef = useRef(serializeHiddenSeries(hiddenSeries));
|
|
121
|
+
// With several histories, the selected forecast scales with its own only.
|
|
122
|
+
const { forecastData, historyData } = baseChartProps;
|
|
123
|
+
const selectedHistoryKey = useMemo(() => selectedForecastId !== undefined && historyData?.length
|
|
124
|
+
? forecastHistoryKey(forecastData?.find(f => f.id === selectedForecastId), historyData)
|
|
125
|
+
: undefined, [selectedForecastId, forecastData, historyData]);
|
|
108
126
|
const calculateYRange = (dataToUse, excludeBands, forecastId) => calculateChartYRange(dataToUse, {
|
|
109
127
|
excludeQuantileBands: excludeBands,
|
|
110
128
|
forecastId,
|
|
129
|
+
forecastHistoryKey: forecastId === selectedForecastId ? selectedHistoryKey : undefined,
|
|
111
130
|
hiddenSeries,
|
|
112
131
|
includeHiddenInYScale,
|
|
113
132
|
});
|
|
@@ -130,7 +149,8 @@ function useChartYRange({ baseChartProps, chartData, disableRescaleWhenQuantileC
|
|
|
130
149
|
prevBaseChartDataRef.current = baseChartProps.chartData;
|
|
131
150
|
stableYRangeRef.current = null;
|
|
132
151
|
}
|
|
133
|
-
if (stableYRangeRef.current?.forecastId !== selectedForecastId
|
|
152
|
+
if (stableYRangeRef.current?.forecastId !== selectedForecastId ||
|
|
153
|
+
stableYRangeRef.current?.historyKey !== selectedHistoryKey) {
|
|
134
154
|
stableYRangeRef.current = null;
|
|
135
155
|
}
|
|
136
156
|
const hiddenSeriesKey = serializeHiddenSeries(hiddenSeries);
|
|
@@ -150,6 +170,7 @@ function useChartYRange({ baseChartProps, chartData, disableRescaleWhenQuantileC
|
|
|
150
170
|
stableYRangeRef.current = {
|
|
151
171
|
...result,
|
|
152
172
|
forecastId: selectedForecastId,
|
|
173
|
+
historyKey: selectedHistoryKey,
|
|
153
174
|
};
|
|
154
175
|
}
|
|
155
176
|
return result;
|
|
@@ -163,6 +184,7 @@ function useChartYRange({ baseChartProps, chartData, disableRescaleWhenQuantileC
|
|
|
163
184
|
selectedForecastId,
|
|
164
185
|
hiddenSeries,
|
|
165
186
|
includeHiddenInYScale,
|
|
187
|
+
selectedHistoryKey,
|
|
166
188
|
]);
|
|
167
189
|
// When disableRescaleWhenQuantileChanges is false, calculate from transformed data
|
|
168
190
|
const dynamicRange = useMemo(() => {
|
|
@@ -188,11 +210,14 @@ function useChartYRange({ baseChartProps, chartData, disableRescaleWhenQuantileC
|
|
|
188
210
|
selectedForecastId,
|
|
189
211
|
hiddenSeries,
|
|
190
212
|
includeHiddenInYScale,
|
|
213
|
+
selectedHistoryKey,
|
|
191
214
|
]);
|
|
192
215
|
// Return appropriate range
|
|
193
216
|
if (disableRescaleWhenQuantileChanges) {
|
|
194
217
|
const cached = stableYRangeRef.current;
|
|
195
|
-
const cachedMatchesForecast = cached &&
|
|
218
|
+
const cachedMatchesForecast = cached &&
|
|
219
|
+
cached.forecastId === selectedForecastId &&
|
|
220
|
+
cached.historyKey === selectedHistoryKey;
|
|
196
221
|
return cachedMatchesForecast
|
|
197
222
|
? { yMin: cached.yMin, yMax: cached.yMax }
|
|
198
223
|
: (stableRange ?? { yMin: 0, yMax: 100 });
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import styleInject from 'style-inject';
|
|
2
2
|
|
|
3
|
-
var css_248z = ".PageTabs_root__0c-ao{gap:var(--p-6);margin-bottom:var(--p-10);max-width:100%;width:var(--page-width)}.PageTabs_scrollbar__-2Uze{max-height:12px}.PageTabs_list__fNzQB{max-width:100%}.PageTabs_list__fNzQB.PageTabs_withPaddings__pt93u{padding-left:var(--page-x-padding);padding-right:var(--page-x-padding)}.PageTabs_variant-button__3oueI .PageTabs_listInner__cZ4lf,.PageTabs_variant-outline__vdIR7 .PageTabs_listInner__cZ4lf{gap:var(--p-2)}.PageTabs_content__6XOr3{display:flex;flex-direction:column;position:relative}.PageTabs_content__6XOr3[hidden]{display:none!important}";
|
|
4
|
-
var S = {"root":"PageTabs_root__0c-ao","scrollbar":"PageTabs_scrollbar__-2Uze","list":"PageTabs_list__fNzQB","withPaddings":"PageTabs_withPaddings__pt93u","variant-button":"PageTabs_variant-button__3oueI","
|
|
3
|
+
var css_248z = ".PageTabs_root__0c-ao{gap:var(--p-6);margin-bottom:var(--p-10);max-width:100%;width:var(--page-width)}.PageTabs_scrollbar__-2Uze{max-height:12px}.PageTabs_list__fNzQB{max-width:100%}.PageTabs_list__fNzQB.PageTabs_withPaddings__pt93u{padding-left:var(--page-x-padding);padding-right:var(--page-x-padding)}.PageTabs_listInner__cZ4lf{--focus-outline-offset:calc(var(--focus-outline-width, 2px)*-1 - 2px)}.PageTabs_variant-button__3oueI .PageTabs_listInner__cZ4lf,.PageTabs_variant-outline__vdIR7 .PageTabs_listInner__cZ4lf{gap:var(--p-2)}.PageTabs_content__6XOr3{display:flex;flex-direction:column;position:relative}.PageTabs_content__6XOr3[hidden]{display:none!important}";
|
|
4
|
+
var S = {"root":"PageTabs_root__0c-ao","scrollbar":"PageTabs_scrollbar__-2Uze","list":"PageTabs_list__fNzQB","withPaddings":"PageTabs_withPaddings__pt93u","listInner":"PageTabs_listInner__cZ4lf","variant-button":"PageTabs_variant-button__3oueI","variant-outline":"PageTabs_variant-outline__vdIR7","content":"PageTabs_content__6XOr3"};
|
|
5
5
|
styleInject(css_248z);
|
|
6
6
|
|
|
7
7
|
export { S as default };
|