@sybilion/uilib 1.8.0 → 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/esm/src/components/ui/Chart/Chart.js +4 -1
- package/dist/esm/src/components/ui/Chart/components/BaseChartWrapper.js +30 -8
- package/dist/esm/src/components/ui/Chart/components/ChartAxes.js +8 -7
- package/dist/esm/src/components/ui/Chart/components/ChartPlacedTooltip.js +65 -0
- package/dist/esm/src/components/ui/Chart/components/ChartTooltipContent.js +2 -2
- package/dist/esm/src/components/ui/Chart/components/ChartTooltipItem.js +22 -6
- package/dist/esm/src/components/ui/Chart/components/QuantileBands.js +1 -1
- package/dist/esm/src/components/ui/ChartAreaInteractive/ChartLines.js +14 -8
- package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.js +2 -3
- package/dist/esm/src/components/widgets/DriverCard/DriverPerformanceChart.js +5 -25
- package/dist/esm/src/index.js +1 -0
- 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 +17 -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/ChartAreaInteractive/ChartLines.d.ts +12 -1
- package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.d.ts +2 -3
- package/package.json +2 -2
- 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 +78 -36
- 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/QuantileBands.tsx +1 -1
- package/src/components/ui/ChartAreaInteractive/AGENT.md +2 -0
- package/src/components/ui/ChartAreaInteractive/ChartLines.tsx +75 -45
- package/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.tsx +2 -3
- package/src/components/widgets/DriverCard/DriverPerformanceChart.tsx +2 -2
|
@@ -5,6 +5,8 @@ import 'classnames';
|
|
|
5
5
|
import 'react';
|
|
6
6
|
import './Chart.context.js';
|
|
7
7
|
import './Chart.styl.js';
|
|
8
|
+
import { ChartPlacedTooltip } from './components/ChartPlacedTooltip.js';
|
|
9
|
+
export { NARROW_CHART_PX } from './components/ChartPlacedTooltip.js';
|
|
8
10
|
import '../AnalysisLineIcon/AnalysisLineIcon.styl.js';
|
|
9
11
|
import 'lucide-react';
|
|
10
12
|
import '../Chip/Chip.styl.js';
|
|
@@ -25,7 +27,8 @@ import './lightweight/LightweightForecastChart.styl.js';
|
|
|
25
27
|
import './components/ChartEmptyState/ChartEmptyState.styl.js';
|
|
26
28
|
export { DEFAULT_QUANTILE_BAND_COLOR, QuantileBands } from './components/QuantileBands.js';
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
/** recharts' Tooltip, opening under any chart narrower than {@link NARROW_CHART_PX}. */
|
|
31
|
+
const ChartTooltip = ChartPlacedTooltip;
|
|
29
32
|
const ChartLegend = RechartsPrimitive.Legend;
|
|
30
33
|
|
|
31
34
|
export { ChartLegend, ChartTooltip };
|
|
@@ -5,7 +5,7 @@ import { resolveHistoryLines, getForecastColor, ChartLines } from '../../ChartAr
|
|
|
5
5
|
import { isHistorySeriesKey, historySeriesKeys } from '../../ChartAreaInteractive/chartHistories.js';
|
|
6
6
|
import { Skeleton } from '../../Skeleton/Skeleton.js';
|
|
7
7
|
import { chartRenderQueue } from '../../../../utils/chartRenderQueue.js';
|
|
8
|
-
import {
|
|
8
|
+
import { LineChart, ComposedChart } from 'recharts';
|
|
9
9
|
import { normalizeTooltipPayload } from '../Chart.helpers.js';
|
|
10
10
|
import { resolveChartMargin, getPlotViewBox } from '../tools/chartPlotGeometry.js';
|
|
11
11
|
import { formatDate } from '../tools/formatters.js';
|
|
@@ -14,6 +14,7 @@ import { ChartAxes } from './ChartAxes.js';
|
|
|
14
14
|
import { ChartContainer } from './ChartContainer.js';
|
|
15
15
|
import { ChartEmptyState } from './ChartEmptyState/ChartEmptyState.js';
|
|
16
16
|
import { ChartGrid } from './ChartGrid.js';
|
|
17
|
+
import { ChartPlacedTooltip, isTooltipUnder } from './ChartPlacedTooltip.js';
|
|
17
18
|
import { ChartTooltipContent } from './ChartTooltipContent.js';
|
|
18
19
|
import { CustomChartLegend } from './CustomChartLegend/CustomChartLegend.js';
|
|
19
20
|
import { LegendSvg } from './LegendSvg/LegendSvg.js';
|
|
@@ -38,6 +39,18 @@ function clampTooltipTranslate(args) {
|
|
|
38
39
|
ty = clamp(ty, minY, maxY);
|
|
39
40
|
return { x: tx, y: ty };
|
|
40
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* The tooltip slides after the cursor, unless the user asked for less motion.
|
|
44
|
+
* ChartPlacedTooltip turns this off under a narrow chart.
|
|
45
|
+
*/
|
|
46
|
+
const TOOLTIP_WRAPPER_STYLE = {
|
|
47
|
+
transition: 'transform 0.2s ease-out, opacity 0.2s ease-out',
|
|
48
|
+
};
|
|
49
|
+
function tooltipWrapperStyle() {
|
|
50
|
+
const reduceMotion = typeof window !== 'undefined' &&
|
|
51
|
+
window.matchMedia?.('(prefers-reduced-motion: reduce)').matches;
|
|
52
|
+
return reduceMotion ? undefined : TOOLTIP_WRAPPER_STYLE;
|
|
53
|
+
}
|
|
41
54
|
/**
|
|
42
55
|
* Simple loading component without hooks for better performance
|
|
43
56
|
* Rendered when chart is waiting in render queue
|
|
@@ -51,7 +64,7 @@ BaseChartWrapperLoading.displayName = 'BaseChartWrapperLoading';
|
|
|
51
64
|
* Separated to maintain hook order consistency
|
|
52
65
|
*/
|
|
53
66
|
const BaseChartWrapperContent = forwardRef((props, ref) => {
|
|
54
|
-
const { chartConfig = {}, chartData, historicalLineColor, forecastData = [], historyData, loading, hasCombinedData, renderId, isDarkTheme, height, className, loadingComponentClassName, footerClassName, chartClassName, xAxisClassName, yAxisClassName, legendClassName, footerActions, quantileBands, quantileBandKey, xMin, xMax, yMin, yMax, autoScaleYAxis = true, formatNumber, formatDate: formatDateFn = formatDate, labelFormatter, onLegendClick, margin, chartType = 'composed', disableAnimation = false, disableLineDrawAnimation = false, showGrid = true, showAxes = true, showTooltip = true, showLegend = true, showChartAxesLegend = true, xAxisLabel, yAxisLabel, showActiveDots = true, overlayElements, hiddenSeries, includeHiddenInYScale = false, excludeLegendIds, onAnalysisSelect, onFailedAnalysisClick, containerProps, error, loadingMessage, noDataHint, noDataMessage = 'No data available', noDataStatusTone = 'muted', suppressNoDataState = false, onGridHeightChange, forecastLineStyle = 'dashed', disableHistoricalAnimation = false, onShowAll: _onShowAll, onShowOnly: _onShowOnly, maxVisibleItems, preventDeselection, legendVariant = 'default', legendWidth = 1000, legendMarginLeft = 0, } = props;
|
|
67
|
+
const { chartConfig = {}, chartData, historicalLineColor, forecastData = [], historyData, loading, hasCombinedData, renderId, isDarkTheme, height, className, loadingComponentClassName, footerClassName, chartClassName, xAxisClassName, yAxisClassName, legendClassName, footerActions, quantileBands, quantileBandKey, xMin, xMax, yMin, yMax, autoScaleYAxis = true, formatNumber, formatTooltipValue, connectHistoryNulls, connectForecastNulls, historyOnTop, showEndDots, formatDate: formatDateFn = formatDate, labelFormatter, onLegendClick, margin, chartType = 'composed', disableAnimation = false, disableLineDrawAnimation = false, showGrid = true, showAxes = true, showTooltip = true, showLegend = true, showChartAxesLegend = true, xAxisLabel, yAxisLabel, showActiveDots = true, overlayElements, hiddenSeries, includeHiddenInYScale = false, excludeLegendIds, onAnalysisSelect, onFailedAnalysisClick, containerProps, error, loadingMessage, noDataHint, noDataMessage = 'No data available', noDataStatusTone = 'muted', suppressNoDataState = false, onGridHeightChange, forecastLineStyle = 'dashed', disableHistoricalAnimation = false, onShowAll: _onShowAll, onShowOnly: _onShowOnly, maxVisibleItems, preventDeselection, legendVariant = 'default', legendWidth = 1000, legendMarginLeft = 0, } = props;
|
|
55
68
|
const [shouldAnimate, setShouldAnimate] = useState(false);
|
|
56
69
|
const lineDataInitializedRef = useRef(false);
|
|
57
70
|
const rootRef = useRef(null);
|
|
@@ -78,9 +91,16 @@ const BaseChartWrapperContent = forwardRef((props, ref) => {
|
|
|
78
91
|
const applyTooltipPosition = () => {
|
|
79
92
|
const wrapper = tooltipWrapperRef.current;
|
|
80
93
|
const coord = rawTooltipCoordinateRef.current;
|
|
81
|
-
|
|
94
|
+
// The chart the tooltip belongs to (with the grid on, the first chart in
|
|
95
|
+
// the root is the grid layer's).
|
|
96
|
+
const chartWrapper = wrapper?.closest('.recharts-wrapper') ??
|
|
97
|
+
rootRef.current?.querySelector('.recharts-wrapper');
|
|
82
98
|
if (!wrapper || !coord || !(chartWrapper instanceof HTMLElement))
|
|
83
99
|
return;
|
|
100
|
+
// A narrow chart's tooltip sits under it, where ChartPlacedTooltip has
|
|
101
|
+
// recharts put it. Leave it there: one writer, so it does not jump.
|
|
102
|
+
if (isTooltipUnder(wrapper))
|
|
103
|
+
return;
|
|
84
104
|
const measured = wrapper.getBoundingClientRect();
|
|
85
105
|
const width = tooltipSizeRef.current.width || measured.width;
|
|
86
106
|
const height = tooltipSizeRef.current.height || measured.height;
|
|
@@ -123,8 +143,6 @@ const BaseChartWrapperContent = forwardRef((props, ref) => {
|
|
|
123
143
|
resizeRo.observe(wrapperEl);
|
|
124
144
|
if (wrapperEl instanceof HTMLElement) {
|
|
125
145
|
tooltipWrapperRef.current = wrapperEl;
|
|
126
|
-
wrapperEl.style.transition =
|
|
127
|
-
'transform 0.2s ease-out, opacity 0.2s ease-out';
|
|
128
146
|
requestAnimationFrame(() => applyTooltipPositionRef.current());
|
|
129
147
|
}
|
|
130
148
|
};
|
|
@@ -172,7 +190,7 @@ const BaseChartWrapperContent = forwardRef((props, ref) => {
|
|
|
172
190
|
// If no valid payload items, render ChartTooltipContent with active=false and empty payload
|
|
173
191
|
// This allows ChartTooltipContent to clear its lastTooltipData state
|
|
174
192
|
if (!filteredPayload || filteredPayload.length === 0) {
|
|
175
|
-
return (jsx(ChartTooltipContent, { active: false, payload: [], label: props.label, labelFormatter: labelFormatter || defaultLabelFormatter, indicator: "dot" }));
|
|
193
|
+
return (jsx(ChartTooltipContent, { active: false, payload: [], label: props.label, labelFormatter: labelFormatter || defaultLabelFormatter, indicator: "dot", valueFormatter: formatTooltipValue }));
|
|
176
194
|
}
|
|
177
195
|
const isActive = props.active === true;
|
|
178
196
|
if (isActive && props.coordinate) {
|
|
@@ -185,7 +203,7 @@ const BaseChartWrapperContent = forwardRef((props, ref) => {
|
|
|
185
203
|
else {
|
|
186
204
|
rawTooltipCoordinateRef.current = null;
|
|
187
205
|
}
|
|
188
|
-
return (jsx(ChartTooltipContent, { active: props.active, payload: filteredPayload, label: props.label, labelFormatter: labelFormatter || defaultLabelFormatter, indicator: "dot" }));
|
|
206
|
+
return (jsx(ChartTooltipContent, { active: props.active, payload: filteredPayload, label: props.label, labelFormatter: labelFormatter || defaultLabelFormatter, indicator: "dot", valueFormatter: formatTooltipValue }));
|
|
189
207
|
};
|
|
190
208
|
// Only the line data (history and forecast_* keys) triggers the draw
|
|
191
209
|
// animation, so a change to quantile band data alone does not re-animate.
|
|
@@ -315,7 +333,11 @@ const BaseChartWrapperContent = forwardRef((props, ref) => {
|
|
|
315
333
|
}
|
|
316
334
|
const ChartComponent = chartType === 'line' ? LineChart : ComposedChart;
|
|
317
335
|
const defaultLabelFormatter = (v) => formatDateFn(v, true);
|
|
318
|
-
|
|
336
|
+
// The same axes in the grid layer and the chart layer, so both share one
|
|
337
|
+
// scale. Hidden when showAxes is off: the hidden x-axis still places the
|
|
338
|
+
// rows by date, so the tooltip names it.
|
|
339
|
+
const axes = (jsx(ChartAxes, { hide: !showAxes, formatDate: formatDateFn, formatNumber: formatNumber, xAxisClassName: xAxisClassName, yAxisClassName: yAxisClassName, xAxisLabel: xAxisLabel, yAxisLabel: yAxisLabel, xMin: xMin, xMax: xMax, yMin: yMin, yMax: yMax, autoScaleYAxis: effectiveAutoScale }));
|
|
340
|
+
return (jsxs("div", { className: cn(S.root, !showLegend && S.noLegend, !showChartAxesLegend && S.hideChartAxesLegend, disableLineDrawAnimation && S.noLineDrawAnimation, isLoaded && S.loaded, className), ref: setRefs, children: [loading && (jsx("div", { className: S.loadingOverlay, children: jsx(Skeleton, {}) })), showGrid && (jsx(ChartContainer, { config: chartConfig, className: cn(S.gridLayer, chartClassName), style: height ? { height: `${height}px` } : undefined, children: jsxs(ChartComponent, { data: chartData, margin: margin, children: [jsx(ChartGrid, {}), axes] }) })), jsx(ChartContainer, { config: chartConfig, className: cn(S.chartLayer, chartClassName), style: height ? { height: `${height}px` } : undefined, ...containerProps, children: jsxs(ChartComponent, { data: chartData, margin: margin, children: [axes, quantileBands?.[0] && (jsx(QuantileBands, { hiddenBands: hiddenSeries, quantileBandKey: quantileBandKey, animate: true, animationDuration: 150, animationBegin: 0, customBands: quantileBands, showLegend: showLegend })), jsx(ChartLines, { historicalLineColor: historicalLineColor, chartData: chartData, forecastData: forecastData, historyData: historyData, hiddenSeries: hiddenSeries, isDarkTheme: isDarkTheme, shouldAnimate: shouldAnimate, disableAnimation: disableAnimation, disableHistoricalAnimation: disableHistoricalAnimation, showLegend: showLegend, forecastLineStyle: forecastLineStyle, connectHistoryNulls: connectHistoryNulls, connectForecastNulls: connectForecastNulls, historyOnTop: historyOnTop, showEndDots: showEndDots }), showTooltip && (jsx("div", { children: jsx(ChartPlacedTooltip, { cursor: false, offset: TOOLTIP_OFFSET, allowEscapeViewBox: { x: false, y: false }, wrapperStyle: tooltipWrapperStyle(), content: renderTooltipContent }) }))] }) }), overlayElements, jsxs("div", { className: cn(S.footer, footerClassName), children: [showLegend &&
|
|
319
341
|
(legendVariant === 'svg' ? (jsx(LegendSvg, { payload: [
|
|
320
342
|
...(historyLegend ?? []).map(p => ({ ...p, solid: true })),
|
|
321
343
|
...legendPayload.map(p => ({
|
|
@@ -4,14 +4,15 @@ import { XAxis, Label, YAxis } from 'recharts';
|
|
|
4
4
|
import { generateRoundedYTicks, formatNumber, formatYAxisNumber } from '../tools/formatters.js';
|
|
5
5
|
|
|
6
6
|
function ChartAxes({ xAxisClassName, yAxisClassName, xAxisLabel, yAxisLabel, formatDate,
|
|
7
|
-
//
|
|
8
|
-
|
|
7
|
+
// The host's number format for the y-axis ticks; uilib's compact one
|
|
8
|
+
// (K/M/B, whole numbers below 1000) without it.
|
|
9
|
+
formatNumber: formatNumber$1 = formatNumber, xMin, xMax, yMin, yMax, autoScaleYAxis = false, hide = false, }) {
|
|
9
10
|
const tickColor = 'var(--muted-foreground)';
|
|
10
11
|
// Generate rounded ticks to avoid duplicates when we have explicit domain
|
|
11
12
|
const yTicks = useMemo(() => {
|
|
12
|
-
if (yMin !== undefined && yMax !== undefined && !autoScaleYAxis) {
|
|
13
|
+
if (!hide && yMin !== undefined && yMax !== undefined && !autoScaleYAxis) {
|
|
13
14
|
const ticks = generateRoundedYTicks(yMin, yMax);
|
|
14
|
-
const formatter = formatNumber || formatYAxisNumber;
|
|
15
|
+
const formatter = formatNumber$1 || formatYAxisNumber;
|
|
15
16
|
// Group ticks by formatted value and keep the one closest to its rounded value
|
|
16
17
|
const ticksByFormatted = new Map();
|
|
17
18
|
ticks.forEach(tick => {
|
|
@@ -33,7 +34,7 @@ xMin, xMax, yMin, yMax, autoScaleYAxis = false, }) {
|
|
|
33
34
|
return Array.from(ticksByFormatted.values()).sort((a, b) => a - b);
|
|
34
35
|
}
|
|
35
36
|
return undefined;
|
|
36
|
-
}, [yMin, yMax, autoScaleYAxis, formatNumber]);
|
|
37
|
+
}, [hide, yMin, yMax, autoScaleYAxis, formatNumber$1]);
|
|
37
38
|
// Determine Y-axis domain
|
|
38
39
|
let yDomain;
|
|
39
40
|
if (autoScaleYAxis) {
|
|
@@ -45,8 +46,8 @@ xMin, xMax, yMin, yMax, autoScaleYAxis = false, }) {
|
|
|
45
46
|
else if (yMin !== undefined && yMax !== undefined) {
|
|
46
47
|
yDomain = [yMin, yMax];
|
|
47
48
|
}
|
|
48
|
-
return (jsxs(Fragment, { children: [jsx(XAxis, { className: xAxisClassName, dataKey: "date", tickLine: false, axisLine: false, tickMargin: 8, minTickGap: 32, tick: { fill: tickColor }, tickFormatter: value => formatDate(value), ...(xMin !== undefined &&
|
|
49
|
-
xMax !== undefined && { domain: [xMin, xMax] }), children: xAxisLabel && (jsx(Label, { value: xAxisLabel, position: "insideBottom", offset: -5 })) }), jsx(YAxis, { className: yAxisClassName, tickLine: false, axisLine: false, tickMargin: 8, minTickGap: 32, tick: { fill: tickColor }, tickFormatter: formatNumber, ...(yDomain && { domain: yDomain }), ...(yTicks && { ticks: yTicks }), allowDataOverflow: !autoScaleYAxis, children: yAxisLabel && (jsx(Label, { value: yAxisLabel, angle: -90, position: "insideLeft" })) })] }));
|
|
49
|
+
return (jsxs(Fragment, { children: [jsx(XAxis, { className: xAxisClassName, dataKey: "date", hide: hide, tickLine: false, axisLine: false, tickMargin: 8, minTickGap: 32, tick: { fill: tickColor }, tickFormatter: value => formatDate(value), ...(xMin !== undefined &&
|
|
50
|
+
xMax !== undefined && { domain: [xMin, xMax] }), children: xAxisLabel && (jsx(Label, { value: xAxisLabel, position: "insideBottom", offset: -5 })) }), hide && !autoScaleYAxis && yMin !== undefined && yMax !== undefined && (jsx(YAxis, { hide: true, domain: [yMin, yMax] })), !hide && (jsx(YAxis, { className: yAxisClassName, tickLine: false, axisLine: false, tickMargin: 8, minTickGap: 32, tick: { fill: tickColor }, tickFormatter: formatNumber$1, ...(yDomain && { domain: yDomain }), ...(yTicks && { ticks: yTicks }), allowDataOverflow: !autoScaleYAxis, children: yAxisLabel && (jsx(Label, { value: yAxisLabel, angle: -90, position: "insideLeft" })) }))] }));
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
export { ChartAxes };
|
|
@@ -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 };
|
|
@@ -6,7 +6,7 @@ import { normalizeTooltipPayload, getPayloadConfigFromPayload } from '../Chart.h
|
|
|
6
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);
|
|
@@ -71,7 +71,7 @@ function ChartTooltipContent({ active, className, indicator = 'dot', hideLabel =
|
|
|
71
71
|
const nestLabel = displayPayload.length === 1 && indicator !== 'dot';
|
|
72
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 };
|
|
@@ -3,7 +3,27 @@ import cn from 'classnames';
|
|
|
3
3
|
import { getPayloadConfigFromPayload } from '../Chart.helpers.js';
|
|
4
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 &&
|
|
@@ -16,11 +36,7 @@ function ChartTooltipItem({ item, index, config, indicator, hideIndicator, nestL
|
|
|
16
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(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 })] }),
|
|
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 };
|
|
@@ -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,6 +1,6 @@
|
|
|
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
4
|
import { HISTORY_SERIES_KEY, historySeriesKey } from './chartHistories.js';
|
|
5
5
|
|
|
6
6
|
const ANIMATION_DURATION = 300;
|
|
@@ -37,7 +37,7 @@ function resolveQuantileBandFillForForecastLine(lineColor, forecastIndex) {
|
|
|
37
37
|
return mapped ?? getForecastQuantileBandColor(forecastIndex);
|
|
38
38
|
}
|
|
39
39
|
// Memoized component for chart lines - only re-renders when data/analyses/hiddenSeries change
|
|
40
|
-
const ChartLines = memo(({ chartData, forecastData, historyData, 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, }) => {
|
|
41
41
|
const dotStroke = isDarkTheme ? '#000000' : '#FFFFFF';
|
|
42
42
|
const activeDotHistorical = {
|
|
43
43
|
r: 6,
|
|
@@ -110,11 +110,17 @@ const ChartLines = memo(({ chartData, forecastData, historyData, hiddenSeries, i
|
|
|
110
110
|
const forecastAnimationActive = animationActive;
|
|
111
111
|
const animationDuration = disableAnimation ? 0 : ANIMATION_DURATION;
|
|
112
112
|
const valueAnimationEnabled = !disableAnimation;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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] }));
|
|
118
124
|
});
|
|
119
125
|
ChartLines.displayName = 'ChartLines';
|
|
120
126
|
|
|
@@ -3,9 +3,8 @@ import cn from 'classnames';
|
|
|
3
3
|
import ChartS from '../Chart/Chart.styl.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* Tooltip rows in series order, showing real zeros
|
|
7
|
-
*
|
|
8
|
-
* is its white stack stroke).
|
|
6
|
+
* Tooltip rows in series order, showing real zeros, and colouring each row
|
|
7
|
+
* from the chart config (an area's own colour is its white stack stroke).
|
|
9
8
|
*/
|
|
10
9
|
function StackedTooltip({ active, payload, label, config, valueFormatter, labelFormatter, }) {
|
|
11
10
|
const rows = (payload ?? []).filter(row => typeof row.value === 'number' && Number.isFinite(row.value));
|
|
@@ -1,32 +1,12 @@
|
|
|
1
1
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
2
2
|
import cn from 'classnames';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
|
-
import { LineChart, CartesianGrid, XAxis, YAxis,
|
|
5
|
-
import '../../ui/Chart/
|
|
6
|
-
import { ChartContainer } from '../../ui/Chart/components/ChartContainer.js';
|
|
7
|
-
import '../../ui/Chart/Chart.context.js';
|
|
8
|
-
import '../../ui/Chart/Chart.styl.js';
|
|
9
|
-
import '../../ui/AnalysisLineIcon/AnalysisLineIcon.styl.js';
|
|
10
|
-
import 'lucide-react';
|
|
11
|
-
import '../../ui/Chip/Chip.styl.js';
|
|
12
|
-
import '../../ui/LabelWithId/LabelWithId.styl.js';
|
|
13
|
-
import '../../ui/Select/Select.js';
|
|
14
|
-
import '../../ui/TextShimmer/TextShimmer.js';
|
|
15
|
-
import '@phosphor-icons/react';
|
|
16
|
-
import '../../ui/AnalysesSelector/AnalysesSelector.styl.js';
|
|
17
|
-
import '@radix-ui/react-slot';
|
|
18
|
-
import '../../ui/Button/Button.styl.js';
|
|
19
|
-
import '../../ui/Input/Input.js';
|
|
20
|
-
import '../../ui/Tooltip/Tooltip.js';
|
|
21
|
-
import '../../ui/Chart/components/CustomChartLegend/CustomChartLegend.styl.js';
|
|
22
|
-
import '../../ui/ChartAreaInteractive/ChartLines.js';
|
|
23
|
-
import '../../ui/Skeleton/Skeleton.styl.js';
|
|
24
|
-
import 'lightweight-charts';
|
|
25
|
-
import '../../ui/Chart/lightweight/LightweightForecastChart.styl.js';
|
|
26
|
-
import { ChartEmptyState } from '../../ui/Chart/components/ChartEmptyState/ChartEmptyState.js';
|
|
27
|
-
import '../../ui/Chart/components/QuantileBands.js';
|
|
4
|
+
import { LineChart, CartesianGrid, XAxis, YAxis, Line } from 'recharts';
|
|
5
|
+
import { ChartTooltip } from '../../ui/Chart/Chart.js';
|
|
28
6
|
import S from './DriverPerformanceChart.styl.js';
|
|
29
7
|
import { generateDriverChartData } from './driverPerformanceChartData.js';
|
|
8
|
+
import { ChartContainer } from '../../ui/Chart/components/ChartContainer.js';
|
|
9
|
+
import { ChartEmptyState } from '../../ui/Chart/components/ChartEmptyState/ChartEmptyState.js';
|
|
30
10
|
|
|
31
11
|
const driverChartConfig = {
|
|
32
12
|
value: {
|
|
@@ -80,7 +60,7 @@ function DriverPerformanceChart({ driver, }) {
|
|
|
80
60
|
}
|
|
81
61
|
return null;
|
|
82
62
|
};
|
|
83
|
-
return (jsxs("div", { className: S.driverChartContainer, children: [jsx(ChartContainer, { config: driverChartConfig, className: cn(S.chartContainer, noSeriesData && S.chartContainerDisabled), children: jsxs(LineChart, { data: chartData, margin: { left: 8, right: 8, top: 8, bottom: -20 }, children: [jsx(CartesianGrid, { vertical: false }), jsx(XAxis, { dataKey: "date", tickLine: false, axisLine: false, tick: false, tickMargin: 0, minTickGap: 0 }), jsx(YAxis, { tickLine: false, axisLine: false, tick: false, tickMargin: 0, minTickGap: 0, width: 0, domain: ['dataMin', 'dataMax'] }), jsx(
|
|
63
|
+
return (jsxs("div", { className: S.driverChartContainer, children: [jsx(ChartContainer, { config: driverChartConfig, className: cn(S.chartContainer, noSeriesData && S.chartContainerDisabled), children: jsxs(LineChart, { data: chartData, margin: { left: 8, right: 8, top: 8, bottom: -20 }, children: [jsx(CartesianGrid, { vertical: false }), jsx(XAxis, { dataKey: "date", tickLine: false, axisLine: false, tick: false, tickMargin: 0, minTickGap: 0 }), jsx(YAxis, { tickLine: false, axisLine: false, tick: false, tickMargin: 0, minTickGap: 0, width: 0, domain: ['dataMin', 'dataMax'] }), jsx(ChartTooltip, { cursor: false, content: renderTooltipContent }), jsx(Line, { dataKey: "value", type: "natural", stroke: "var(--color-value)" })] }) }), noSeriesData && (jsx(ChartEmptyState, { variant: "inline", align: "center", status: "No series data", className: S.noDataMessage }))] }));
|
|
84
64
|
}
|
|
85
65
|
|
|
86
66
|
export { DriverPerformanceChart };
|
package/dist/esm/src/index.js
CHANGED
|
@@ -159,6 +159,7 @@ export { useChartColors } from './components/ui/Chart/hooks/useChartColors.js';
|
|
|
159
159
|
export { useLegendState } from './components/ui/Chart/hooks/useLegendState.js';
|
|
160
160
|
export { ChartContainer, ChartStyle } from './components/ui/Chart/components/ChartContainer.js';
|
|
161
161
|
export { ChartTooltipContent } from './components/ui/Chart/components/ChartTooltipContent.js';
|
|
162
|
+
export { NARROW_CHART_PX } from './components/ui/Chart/components/ChartPlacedTooltip.js';
|
|
162
163
|
export { ChartLegendContent } from './components/ui/Chart/components/ChartLegendContent.js';
|
|
163
164
|
export { BaseChartWrapper } from './components/ui/Chart/components/BaseChartWrapper.js';
|
|
164
165
|
export { default as DialogStyles } from './components/ui/Dialog/Dialog.styl.js';
|
|
@@ -2,14 +2,16 @@ import * as RechartsPrimitive from 'recharts';
|
|
|
2
2
|
import { BaseChartWrapper, type BaseChartWrapperProps } from './components/BaseChartWrapper';
|
|
3
3
|
import { ChartContainer, ChartStyle } from './components/ChartContainer';
|
|
4
4
|
import { ChartLegendContent } from './components/ChartLegendContent';
|
|
5
|
+
import { ChartPlacedTooltip, NARROW_CHART_PX } from './components/ChartPlacedTooltip';
|
|
5
6
|
import { ChartTooltipContent } from './components/ChartTooltipContent';
|
|
6
|
-
|
|
7
|
+
/** recharts' Tooltip, opening under any chart narrower than {@link NARROW_CHART_PX}. */
|
|
8
|
+
declare const ChartTooltip: typeof ChartPlacedTooltip;
|
|
7
9
|
declare const ChartLegend: import("react").MemoExoticComponent<(outsideProps: RechartsPrimitive.LegendProps) => React.ReactPortal | null>;
|
|
8
10
|
export * from './Chart.types';
|
|
9
11
|
export { ChartTooltipItem } from './components/ChartTooltipItem';
|
|
10
12
|
export { ChartLegendItem } from './components/ChartLegendItem';
|
|
11
13
|
export { CustomChartLegend } from './components/CustomChartLegend/CustomChartLegend';
|
|
12
|
-
export { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, ChartStyle, BaseChartWrapper, type BaseChartWrapperProps, };
|
|
14
|
+
export { ChartContainer, ChartTooltip, ChartTooltipContent, NARROW_CHART_PX, ChartLegend, ChartLegendContent, ChartStyle, BaseChartWrapper, type BaseChartWrapperProps, };
|
|
13
15
|
export { LightweightForecastChart, type LightweightForecastChartProps, } from './lightweight/LightweightForecastChart';
|
|
14
16
|
export { ChartEmptyState, type ChartEmptyStateProps, type ChartEmptyStatusTone, } from './components/ChartEmptyState/ChartEmptyState';
|
|
15
17
|
export { ConfidenceBands } from './components/ConfidenceBands';
|
|
@@ -30,5 +30,10 @@ export type ChartTooltipContentProps = ComponentProps<'div'> & {
|
|
|
30
30
|
labelFormatter?: (label: unknown, payload: unknown[]) => ReactNode;
|
|
31
31
|
labelClassName?: string;
|
|
32
32
|
formatter?: (value: unknown, name: string, props: unknown, index: number, payload: unknown) => ReactNode;
|
|
33
|
+
/**
|
|
34
|
+
* Formats each row's number (both ends of a range row). Without it the
|
|
35
|
+
* value prints as is.
|
|
36
|
+
*/
|
|
37
|
+
valueFormatter?: (value: number) => string;
|
|
33
38
|
color?: string;
|
|
34
39
|
};
|
|
@@ -83,4 +83,11 @@ export interface QuantileBandConfig {
|
|
|
83
83
|
strokeOpacity?: number;
|
|
84
84
|
type?: 'monotone' | 'linear' | 'step' | 'stepBefore' | 'stepAfter' | 'basis' | 'natural';
|
|
85
85
|
fillPattern?: 'solid' | 'dots' | 'lines';
|
|
86
|
+
/**
|
|
87
|
+
* Fill across months with no range (default true). Read by the Recharts
|
|
88
|
+
* charts' bands (BaseChartWrapper, ChartAreaInteractive's default mode),
|
|
89
|
+
* not by LightweightForecastChart or the intervals and thresholds overlays,
|
|
90
|
+
* which build their own bands.
|
|
91
|
+
*/
|
|
92
|
+
connectNulls?: boolean;
|
|
86
93
|
}
|
|
@@ -40,6 +40,19 @@ export interface BaseChartWrapperProps {
|
|
|
40
40
|
yMax?: number;
|
|
41
41
|
autoScaleYAxis?: boolean;
|
|
42
42
|
formatNumber?: (value: number) => string;
|
|
43
|
+
/**
|
|
44
|
+
* Formats the numbers in the tooltip. Without it they print as is. Not
|
|
45
|
+
* `formatNumber`, which is the axis's and often compact ("1.2k").
|
|
46
|
+
*/
|
|
47
|
+
formatTooltipValue?: (value: number) => string;
|
|
48
|
+
/** Draw history lines across months with no value (default: a gap). */
|
|
49
|
+
connectHistoryNulls?: boolean;
|
|
50
|
+
/** Draw forecast lines across months with no value (default: a gap). */
|
|
51
|
+
connectForecastNulls?: boolean;
|
|
52
|
+
/** Draw history lines over the forecast lines (default: under them). */
|
|
53
|
+
historyOnTop?: boolean;
|
|
54
|
+
/** Mark each line's last point with a dot (default: on). */
|
|
55
|
+
showEndDots?: boolean;
|
|
43
56
|
formatDate?: (value: string, detailed?: boolean) => string;
|
|
44
57
|
labelFormatter?: (value: unknown) => string;
|
|
45
58
|
onLegendClick?: (data: LegendPayload, index: number, event: any) => void;
|
|
@@ -58,6 +71,10 @@ export interface BaseChartWrapperProps {
|
|
|
58
71
|
*/
|
|
59
72
|
disableLineDrawAnimation?: boolean;
|
|
60
73
|
showGrid?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* Draw the axes. Off, a hidden x-axis is kept so the tooltip still names
|
|
76
|
+
* the row's date.
|
|
77
|
+
*/
|
|
61
78
|
showAxes?: boolean;
|
|
62
79
|
showTooltip?: boolean;
|
|
63
80
|
showLegend?: boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -10,6 +10,13 @@ interface ChartAxesProps {
|
|
|
10
10
|
yMin?: number;
|
|
11
11
|
yMax?: number;
|
|
12
12
|
autoScaleYAxis?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Draw no axes. A hidden x-axis is kept, so the tooltip still names the
|
|
15
|
+
* row's date. The y-axis keeps fixed `yMin`/`yMax` (with `autoScaleYAxis`
|
|
16
|
+
* off) as its range, widened if the data goes past it; otherwise it is
|
|
17
|
+
* recharts' default, as without axes.
|
|
18
|
+
*/
|
|
19
|
+
hide?: boolean;
|
|
13
20
|
}
|
|
14
|
-
export declare function ChartAxes({ xAxisClassName, yAxisClassName, xAxisLabel, yAxisLabel, formatDate, xMin, xMax, yMin, yMax, autoScaleYAxis, }: ChartAxesProps): import("react/jsx-runtime").JSX.Element;
|
|
21
|
+
export declare function ChartAxes({ xAxisClassName, yAxisClassName, xAxisLabel, yAxisLabel, formatDate, formatNumber, xMin, xMax, yMin, yMax, autoScaleYAxis, hide, }: ChartAxesProps): import("react/jsx-runtime").JSX.Element;
|
|
15
22
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type ComponentProps } from 'react';
|
|
2
|
+
import { Tooltip } from 'recharts';
|
|
3
|
+
/** Charts narrower than this open their tooltip under the chart, not over it. */
|
|
4
|
+
export declare const NARROW_CHART_PX = 500;
|
|
5
|
+
/** Gap between a narrow chart's x-axis labels and its tooltip. */
|
|
6
|
+
export declare const NARROW_TOOLTIP_GAP_PX = 4;
|
|
7
|
+
/**
|
|
8
|
+
* Set to 1 on the tooltip wrapper's style while it sits under the chart, so
|
|
9
|
+
* code that moves the wrapper itself (BaseChartWrapper) leaves it alone
|
|
10
|
+
* instead of deciding again.
|
|
11
|
+
*/
|
|
12
|
+
export declare const TOOLTIP_UNDER_VAR = "--chart-tooltip-under";
|
|
13
|
+
/** Whether a chart this wide opens its tooltip under itself. */
|
|
14
|
+
export declare function opensTooltipUnder(chartWidth: number | undefined): boolean;
|
|
15
|
+
/** Whether ChartPlacedTooltip put this tooltip wrapper under its chart. */
|
|
16
|
+
export declare function isTooltipUnder(wrapper: HTMLElement): boolean;
|
|
17
|
+
type ChartPlacedTooltipProps = ComponentProps<typeof Tooltip>;
|
|
18
|
+
/**
|
|
19
|
+
* A recharts Tooltip that, on a chart narrower than {@link NARROW_CHART_PX},
|
|
20
|
+
* sits under the chart instead of over the lines, starting right under the
|
|
21
|
+
* x-axis labels (the chart's bottom margin is left out), so a small chart stays
|
|
22
|
+
* readable while it is hovered. It may then cover what follows the chart, be
|
|
23
|
+
* clipped by a parent that hides overflow, or run past the page edge; that is
|
|
24
|
+
* accepted. Under a chart it does not slide (no transition, whatever
|
|
25
|
+
* `wrapperStyle` says), and while no point is hovered it takes no room
|
|
26
|
+
* (`display: none`), so it never grows a scrolling parent. A caller's
|
|
27
|
+
* `position.x` and `position.y` each win, as does `isAnimationActive`. With
|
|
28
|
+
* `portal`, recharts places nothing, so neither does this.
|
|
29
|
+
*/
|
|
30
|
+
export declare function ChartPlacedTooltip(props: ChartPlacedTooltipProps): import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { ChartTooltipContentProps } from '#uilib/components/ui/Chart/Chart.types';
|
|
2
|
-
export declare function ChartTooltipContent({ active, className, indicator, hideLabel, hideIndicator, label, labelFormatter, labelClassName, payload, formatter, color, nameKey, labelKey, }: ChartTooltipContentProps): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare function ChartTooltipContent({ active, className, indicator, hideLabel, hideIndicator, label, labelFormatter, labelClassName, payload, formatter, valueFormatter, color, nameKey, labelKey, }: ChartTooltipContentProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -12,6 +12,7 @@ type ChartTooltipItemProps = {
|
|
|
12
12
|
color?: string;
|
|
13
13
|
nameKey?: string;
|
|
14
14
|
formatter?: (value: unknown, name: string, props: unknown, index: number, payload: unknown) => ReactNode;
|
|
15
|
+
valueFormatter?: (value: number) => string;
|
|
15
16
|
};
|
|
16
|
-
export declare function ChartTooltipItem({ item, index, config, indicator, hideIndicator, nestLabel, tooltipLabel, color, nameKey, formatter, }: ChartTooltipItemProps): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
export declare function ChartTooltipItem({ item, index, config, indicator, hideIndicator, nestLabel, tooltipLabel, color, nameKey, formatter, valueFormatter, }: ChartTooltipItemProps): import("react/jsx-runtime").JSX.Element;
|
|
17
18
|
export {};
|
|
@@ -50,7 +50,7 @@ export declare function getHistoryColor(index: number): string;
|
|
|
50
50
|
export declare function resolveHistoryLines(histories?: HistoryItemData[]): HistoryLine[];
|
|
51
51
|
/** Same tint logic as intervals/threshold overlays: band fill follows forecast line hex when known. */
|
|
52
52
|
export declare function resolveQuantileBandFillForForecastLine(lineColor: string, forecastIndex: number): string;
|
|
53
|
-
export declare const ChartLines: import("react").MemoExoticComponent<({ chartData, forecastData, historyData, hiddenSeries, isDarkTheme, shouldAnimate, historicalLineColor, showLegend, forecastLineStyle, disableAnimation, disableHistoricalAnimation, }: {
|
|
53
|
+
export declare const ChartLines: import("react").MemoExoticComponent<({ chartData, forecastData, historyData, hiddenSeries, isDarkTheme, shouldAnimate, historicalLineColor, showLegend, forecastLineStyle, disableAnimation, disableHistoricalAnimation, connectHistoryNulls, connectForecastNulls, historyOnTop, showEndDots, }: {
|
|
54
54
|
chartData: ChartDataPoint[];
|
|
55
55
|
forecastData?: ForecastItemData[];
|
|
56
56
|
/** Several history lines (one per product). Omit for the single `historical` line. */
|
|
@@ -63,4 +63,15 @@ export declare const ChartLines: import("react").MemoExoticComponent<({ chartDat
|
|
|
63
63
|
forecastLineStyle?: "dashed" | "solid";
|
|
64
64
|
disableAnimation?: boolean;
|
|
65
65
|
disableHistoricalAnimation?: boolean;
|
|
66
|
+
/** Draw each history line across months it has no value for. */
|
|
67
|
+
connectHistoryNulls?: boolean;
|
|
68
|
+
/** Draw each forecast line across months it has no value for. */
|
|
69
|
+
connectForecastNulls?: boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Draw the history lines after the forecast lines, over them (for many
|
|
72
|
+
* faint forecasts that would otherwise cover the history).
|
|
73
|
+
*/
|
|
74
|
+
historyOnTop?: boolean;
|
|
75
|
+
/** Mark each line's last point with a dot (default: on). */
|
|
76
|
+
showEndDots?: boolean;
|
|
66
77
|
}) => import("react/jsx-runtime").JSX.Element>;
|