@sybilion/uilib 1.8.0 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/esm/src/components/ui/Chart/Chart.js +4 -1
  2. package/dist/esm/src/components/ui/Chart/components/BaseChartWrapper.js +30 -8
  3. package/dist/esm/src/components/ui/Chart/components/ChartAxes.js +12 -11
  4. package/dist/esm/src/components/ui/Chart/components/ChartPlacedTooltip.js +65 -0
  5. package/dist/esm/src/components/ui/Chart/components/ChartTooltipContent.js +2 -2
  6. package/dist/esm/src/components/ui/Chart/components/ChartTooltipItem.js +22 -6
  7. package/dist/esm/src/components/ui/Chart/components/QuantileBands.js +1 -1
  8. package/dist/esm/src/components/ui/ChartAreaInteractive/ChartLines.js +14 -8
  9. package/dist/esm/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.js +2 -3
  10. package/dist/esm/src/components/ui/TimeRangeControls/TimeRangeControls.js +18 -4
  11. package/dist/esm/src/components/widgets/DriverCard/DriverPerformanceChart.js +5 -25
  12. package/dist/esm/src/index.js +1 -0
  13. package/dist/esm/types/src/components/ui/Chart/Chart.d.ts +4 -2
  14. package/dist/esm/types/src/components/ui/Chart/Chart.types.d.ts +5 -0
  15. package/dist/esm/types/src/components/ui/Chart/chartForecastVisualization.types.d.ts +7 -0
  16. package/dist/esm/types/src/components/ui/Chart/components/BaseChartWrapper.d.ts +17 -0
  17. package/dist/esm/types/src/components/ui/Chart/components/BaseChartWrapper.test.d.ts +1 -0
  18. package/dist/esm/types/src/components/ui/Chart/components/ChartAxes.d.ts +8 -1
  19. package/dist/esm/types/src/components/ui/Chart/components/ChartAxes.test.d.ts +1 -0
  20. package/dist/esm/types/src/components/ui/Chart/components/ChartPlacedTooltip.d.ts +31 -0
  21. package/dist/esm/types/src/components/ui/Chart/components/ChartPlacedTooltip.test.d.ts +1 -0
  22. package/dist/esm/types/src/components/ui/Chart/components/ChartTooltipContent.d.ts +1 -1
  23. package/dist/esm/types/src/components/ui/Chart/components/ChartTooltipContent.test.d.ts +1 -0
  24. package/dist/esm/types/src/components/ui/Chart/components/ChartTooltipItem.d.ts +2 -1
  25. package/dist/esm/types/src/components/ui/ChartAreaInteractive/ChartLines.d.ts +12 -1
  26. package/dist/esm/types/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.d.ts +2 -3
  27. package/dist/esm/types/src/components/ui/TimeRangeControls/TimeRangeControls.d.ts +9 -3
  28. package/dist/esm/types/src/components/ui/TimeRangeControls/TimeRangeControls.test.d.ts +1 -0
  29. package/package.json +2 -2
  30. package/src/components/ui/Chart/AGENT.md +5 -0
  31. package/src/components/ui/Chart/Chart.tsx +7 -1
  32. package/src/components/ui/Chart/Chart.types.ts +5 -0
  33. package/src/components/ui/Chart/chartForecastVisualization.types.ts +7 -0
  34. package/src/components/ui/Chart/components/BaseChartWrapper.test.tsx +344 -0
  35. package/src/components/ui/Chart/components/BaseChartWrapper.tsx +78 -36
  36. package/src/components/ui/Chart/components/ChartAxes.test.tsx +60 -0
  37. package/src/components/ui/Chart/components/ChartAxes.tsx +42 -45
  38. package/src/components/ui/Chart/components/ChartPlacedTooltip.test.tsx +160 -0
  39. package/src/components/ui/Chart/components/ChartPlacedTooltip.tsx +93 -0
  40. package/src/components/ui/Chart/components/ChartTooltipContent.test.tsx +85 -0
  41. package/src/components/ui/Chart/components/ChartTooltipContent.tsx +2 -0
  42. package/src/components/ui/Chart/components/ChartTooltipItem.tsx +41 -10
  43. package/src/components/ui/Chart/components/QuantileBands.tsx +1 -1
  44. package/src/components/ui/ChartAreaInteractive/AGENT.md +2 -0
  45. package/src/components/ui/ChartAreaInteractive/ChartLines.tsx +75 -45
  46. package/src/components/ui/StackedAreaChart/StackedAreaChart.tooltip.tsx +2 -3
  47. package/src/components/ui/TimeRangeControls/AGENT.md +1 -1
  48. package/src/components/ui/TimeRangeControls/TimeRangeControls.test.tsx +40 -0
  49. package/src/components/ui/TimeRangeControls/TimeRangeControls.tsx +46 -35
  50. 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
- const ChartTooltip = RechartsPrimitive.Tooltip;
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 { Tooltip, LineChart, ComposedChart } from 'recharts';
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
- const chartWrapper = rootRef.current?.querySelector('.recharts-wrapper');
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
- 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, {}), showAxes && (jsx(ChartAxes, { formatDate: formatDateFn, formatNumber: formatNumber, xAxisClassName: xAxisClassName, yAxisClassName: yAxisClassName, xAxisLabel: xAxisLabel, yAxisLabel: yAxisLabel, xMin: xMin, xMax: xMax, yMin: yMin, yMax: yMax, autoScaleYAxis: effectiveAutoScale }))] }) })), jsx(ChartContainer, { config: chartConfig, className: cn(S.chartLayer, chartClassName), style: height ? { height: `${height}px` } : undefined, ...containerProps, children: jsxs(ChartComponent, { data: chartData, margin: margin, children: [showAxes && (jsx(ChartAxes, { formatDate: formatDateFn, formatNumber: formatNumber, xAxisClassName: cn(xAxisClassName), yAxisClassName: cn(yAxisClassName), xAxisLabel: xAxisLabel, yAxisLabel: yAxisLabel, xMin: xMin, xMax: xMax, yMin: yMin, yMax: yMax, autoScaleYAxis: effectiveAutoScale })), 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 }), showTooltip && (jsx("div", { children: jsx(Tooltip, { cursor: false, offset: TOOLTIP_OFFSET, allowEscapeViewBox: { x: false, y: false }, content: renderTooltipContent }) }))] }) }), overlayElements, jsxs("div", { className: cn(S.footer, footerClassName), children: [showLegend &&
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
- // formatNumber = formatYAxisNumber,
8
- xMin, xMax, yMin, yMax, autoScaleYAxis = false, }) {
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,20 +34,20 @@ 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) {
40
- yDomain = [
41
- (dataMin) => dataMin * 0.95,
42
- (dataMax) => dataMax * 1.05,
43
- ];
41
+ // recharts' own fit: nice round ticks just around the data, so a series
42
+ // moving 1000–1010 fills the chart (scaling the values by 0.95/1.05 left
43
+ // it flat) and a negative one is padded too.
44
+ yDomain = ['auto', 'auto'];
44
45
  }
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
- function ChartTooltipItem({ item, index, config, indicator, hideIndicator, nestLabel, tooltipLabel, color, nameKey, formatter, }) {
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 })] }), item.value && (jsx("span", { className: ChartS.tooltipValue, children: Array.isArray(item.value)
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, jsx } from 'react/jsx-runtime';
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
- return (jsxs(Fragment, { children: [historyLines.map(({ dataKey, name, color }) => (jsx(Line, { type: "monotone", dataKey: dataKey, stroke: color, strokeWidth: 1, dot: props => renderHistoryDot(props, dataKey, color), activeDot: { ...activeDotHistorical, fill: color }, name: name, legendType: showLegend === false ? 'none' : undefined, strokeDasharray: "0", hide: hiddenSeries?.has(dataKey), isAnimationActive: historicalAnimationActive, animationDuration: animationDuration, animateNewValues: valueAnimationEnabled, animationBegin: 0, animationEasing: "ease-out" }, dataKey))), forecastData?.map((data, index) => {
114
- const { id, name, color = FORECAST_LINE_COLORS[index % FORECAST_LINE_COLORS.length], } = data;
115
- const dataKey = `forecast_${id}`;
116
- return (jsx(Line, { type: "monotone", dataKey: dataKey, stroke: color, strokeWidth: 1, strokeDasharray: forecastLineStyle === 'dashed' ? '4 2' : '0', dot: props => renderForecastDot(props, id, color), activeDot: activeDotForecast(color), name: `${name || `${id}`}`, legendType: showLegend === false ? 'none' : undefined, 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}`));
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 (ChartTooltipContent hides
7
- * them) and colouring each row from the chart config (an area's own colour
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,4 +1,4 @@
1
- import { jsx, jsxs } from 'react/jsx-runtime';
1
+ import { jsxs, jsx } from 'react/jsx-runtime';
2
2
  import { memo } from 'react';
3
3
  import { Select, SelectTrigger, SelectValue, SelectContent, SelectItem } from '../Select/Select.js';
4
4
  import { ToggleGroup, ToggleGroupItem } from '../ToggleGroup/ToggleGroup.js';
@@ -10,9 +10,23 @@ function toggleValueForTimeRange(timeRange) {
10
10
  ? timeRange
11
11
  : '';
12
12
  }
13
- const TimeRangeControls = memo(({ timeRange, onTimeRangeChange, loading }) => (jsx("div", { className: S.timeRangeContainer, children: jsx(ToggleGroup, { type: "single", value: toggleValueForTimeRange(timeRange), onValueChange: onTimeRangeChange, variant: "outline", disabled: loading, className: S.timeRangeToggleGroup, children: TIME_RANGES.map(range => (jsx(ToggleGroupItem, { value: range, className: S.timeRangeToggleItem, children: range }, range))) }) })));
14
- TimeRangeControls.displayName = 'TimeRangeControls';
15
- const TimeRangeSelect = memo(({ timeRange, onTimeRangeChange, loading, }) => (jsxs(Select, { value: toggleValueForTimeRange(timeRange) || undefined, onValueChange: onTimeRangeChange, disabled: loading, children: [jsx(SelectTrigger, { className: S.timeRangeSelectTrigger, size: "sm", "aria-label": "Select a value", children: jsx(SelectValue, { placeholder: "1 year" }) }), jsx(SelectContent, { className: S.timeRangeSelectContent, children: TIME_RANGES.map(range => (jsx(SelectItem, { value: range, className: S.timeRangeSelectItem, children: range }, range))) })] })));
13
+ /**
14
+ * The preset ranges as a select. A range that is not a preset (one dragged on
15
+ * the chart) shows "Custom" rather than a preset it is not.
16
+ */
17
+ const TimeRangeSelect = memo(({ timeRange, onTimeRangeChange, loading }) => (jsxs(Select
18
+ // An empty value shows the placeholder; undefined would leave the
19
+ // select uncontrolled and keep the last preset picked.
20
+ , {
21
+ // An empty value shows the placeholder; undefined would leave the
22
+ // select uncontrolled and keep the last preset picked.
23
+ value: toggleValueForTimeRange(timeRange), onValueChange: onTimeRangeChange, disabled: loading, children: [jsx(SelectTrigger, { className: S.timeRangeSelectTrigger, size: "sm", "aria-label": "Time range", children: jsx(SelectValue, { placeholder: "Custom" }) }), jsx(SelectContent, { className: S.timeRangeSelectContent, children: TIME_RANGES.map(range => (jsx(SelectItem, { value: range, className: S.timeRangeSelectItem, children: range }, range))) })] })));
16
24
  TimeRangeSelect.displayName = 'TimeRangeSelect';
25
+ /**
26
+ * The preset ranges as a toggle row from 768px up, and as a select below it
27
+ * (CSS shows one of the two), so the control stays on a phone.
28
+ */
29
+ const TimeRangeControls = memo(({ timeRange, onTimeRangeChange, loading }) => (jsxs("div", { className: S.timeRangeContainer, children: [jsx(ToggleGroup, { type: "single", value: toggleValueForTimeRange(timeRange), onValueChange: onTimeRangeChange, variant: "outline", disabled: loading, className: S.timeRangeToggleGroup, children: TIME_RANGES.map(range => (jsx(ToggleGroupItem, { value: range, className: S.timeRangeToggleItem, children: range }, range))) }), jsx(TimeRangeSelect, { timeRange: timeRange, onTimeRangeChange: onTimeRangeChange, loading: loading })] })));
30
+ TimeRangeControls.displayName = 'TimeRangeControls';
17
31
 
18
32
  export { TimeRangeControls, TimeRangeSelect };
@@ -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, Tooltip, Line } from 'recharts';
5
- import '../../ui/Chart/components/BaseChartWrapper.js';
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(Tooltip, { 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 }))] }));
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 };
@@ -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
- declare const ChartTooltip: typeof RechartsPrimitive.Tooltip;
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;
@@ -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,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 {};