@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
@@ -0,0 +1,85 @@
1
+ import { render } from '@testing-library/react';
2
+
3
+ import { ChartContext } from '../Chart.context';
4
+ import { ChartTooltipContent } from './ChartTooltipContent';
5
+
6
+ const payload = [
7
+ { dataKey: 'historical', name: 'History', value: 1234.5678, color: '#000' },
8
+ { dataKey: 'band', name: 'Range', value: [0.5, 2.25], color: '#0aa' },
9
+ { dataKey: 'driver', name: 'Driver', value: 0, color: '#a00' },
10
+ ];
11
+
12
+ function rows(valueFormatter?: (value: number) => string) {
13
+ const { container } = render(
14
+ <ChartContext.Provider value={{ config: {} }}>
15
+ <ChartTooltipContent
16
+ active
17
+ payload={payload}
18
+ label="2026-03-01"
19
+ valueFormatter={valueFormatter}
20
+ />
21
+ </ChartContext.Provider>,
22
+ );
23
+ return [...container.querySelectorAll('span')]
24
+ .map(s => s.textContent)
25
+ .filter(Boolean);
26
+ }
27
+
28
+ describe('ChartTooltipContent values', () => {
29
+ it('formats each number, both ends of a range, with valueFormatter', () => {
30
+ const fmt = (v: number) => `€${v.toFixed(1)}`;
31
+ expect(rows(fmt)).toEqual([
32
+ 'History',
33
+ '€1234.6',
34
+ 'Range',
35
+ '€0.5 – €2.3',
36
+ 'Driver',
37
+ '€0.0',
38
+ ]);
39
+ });
40
+
41
+ it('prints the raw value without one, zero included', () => {
42
+ const text = rows();
43
+ expect(text).toContain('Driver');
44
+ expect(text[text.indexOf('Driver') + 1]).toBe('0');
45
+ expect(text[text.indexOf('History') + 1]).toBe(
46
+ (1234.5678).toLocaleString(undefined, { maximumFractionDigits: 20 }),
47
+ );
48
+ });
49
+
50
+ it('shows a dash for a range end with no number', () => {
51
+ const { container } = render(
52
+ <ChartContext.Provider value={{ config: {} }}>
53
+ <ChartTooltipContent
54
+ active
55
+ payload={[
56
+ { dataKey: 'band', name: 'Range', value: [null, 5], color: '#0aa' },
57
+ ]}
58
+ label="2026-03-01"
59
+ />
60
+ </ChartContext.Provider>,
61
+ );
62
+ expect(container.textContent).toContain('— – 5');
63
+ });
64
+
65
+ it('prints a string value as is and leaves out NaN and empty ranges', () => {
66
+ const { container } = render(
67
+ <ChartContext.Provider value={{ config: {} }}>
68
+ <ChartTooltipContent
69
+ active
70
+ payload={[
71
+ { dataKey: 'a', name: 'Text', value: '12.5', color: '#000' },
72
+ { dataKey: 'b', name: 'Broken', value: Number.NaN, color: '#000' },
73
+ { dataKey: 'c', name: 'Empty', value: [null, null], color: '#000' },
74
+ ]}
75
+ label="2026-03-01"
76
+ valueFormatter={v => v.toFixed(2)}
77
+ />
78
+ </ChartContext.Provider>,
79
+ );
80
+ const values = [...container.querySelectorAll('span')]
81
+ .map(s => s.textContent)
82
+ .filter(Boolean);
83
+ expect(values).toEqual(['Text', '12.5', 'Broken', 'Empty']);
84
+ });
85
+ });
@@ -24,6 +24,7 @@ export function ChartTooltipContent({
24
24
  labelClassName,
25
25
  payload,
26
26
  formatter,
27
+ valueFormatter,
27
28
  color,
28
29
  nameKey,
29
30
  labelKey,
@@ -137,6 +138,7 @@ export function ChartTooltipContent({
137
138
  color={color}
138
139
  nameKey={nameKey}
139
140
  formatter={formatter}
141
+ valueFormatter={valueFormatter}
140
142
  />
141
143
  ))}
142
144
  </div>
@@ -1,7 +1,10 @@
1
1
  import cn from 'classnames';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
3
 
4
- import { getPayloadConfigFromPayload, type TooltipItem } from '../Chart.helpers';
4
+ import {
5
+ type TooltipItem,
6
+ getPayloadConfigFromPayload,
7
+ } from '../Chart.helpers';
5
8
  import S from '../Chart.styl';
6
9
  import { ChartConfig } from '../Chart.types';
7
10
 
@@ -22,8 +25,43 @@ type ChartTooltipItemProps = {
22
25
  index: number,
23
26
  payload: unknown,
24
27
  ) => ReactNode;
28
+ valueFormatter?: (value: number) => string;
25
29
  };
26
30
 
31
+ const rawValue = (value: number) =>
32
+ value.toLocaleString(undefined, { maximumFractionDigits: 20 });
33
+
34
+ const isMissing = (value: unknown) =>
35
+ value == null || (typeof value === 'number' && Number.isNaN(value));
36
+
37
+ /**
38
+ * A row's value as text: numbers through `format`, anything else as is, and
39
+ * a missing one (null, NaN) as null. A range shows a missing end as a dash,
40
+ * and is missing itself when both ends are.
41
+ */
42
+ function valueText(
43
+ value: unknown,
44
+ format: (value: number) => string,
45
+ ): string | null {
46
+ const one = (v: unknown) =>
47
+ isMissing(v) ? null : typeof v === 'number' ? format(v) : String(v);
48
+ if (!Array.isArray(value)) return one(value);
49
+ const [low, high] = [one(value[0]), one(value[1])];
50
+ if (low == null && high == null) return null;
51
+ return `${low ?? '—'} – ${high ?? '—'}`;
52
+ }
53
+
54
+ function TooltipValue({
55
+ value,
56
+ format,
57
+ }: {
58
+ value: unknown;
59
+ format: (value: number) => string;
60
+ }) {
61
+ const text = valueText(value, format);
62
+ return text == null ? null : <span className={S.tooltipValue}>{text}</span>;
63
+ }
64
+
27
65
  export function ChartTooltipItem({
28
66
  item,
29
67
  index,
@@ -35,6 +73,7 @@ export function ChartTooltipItem({
35
73
  color,
36
74
  nameKey,
37
75
  formatter,
76
+ valueFormatter = rawValue,
38
77
  }: ChartTooltipItemProps) {
39
78
  const key = `${nameKey || item.name || item.dataKey || 'value'}`;
40
79
  const itemConfig = getPayloadConfigFromPayload(config, item, key);
@@ -88,15 +127,7 @@ export function ChartTooltipItem({
88
127
  </span>
89
128
  </div>
90
129
 
91
- {item.value && (
92
- <span className={S.tooltipValue}>
93
- {Array.isArray(item.value)
94
- ? `${item.value[0].toLocaleString(undefined, { maximumFractionDigits: 20 })} – ${item.value[1].toLocaleString(undefined, { maximumFractionDigits: 20 })}`
95
- : item.value.toLocaleString(undefined, {
96
- maximumFractionDigits: 20,
97
- })}
98
- </span>
99
- )}
130
+ <TooltipValue value={item.value} format={valueFormatter} />
100
131
  </div>
101
132
  </>
102
133
  )}
@@ -58,7 +58,7 @@ export function QuantileBands({
58
58
  fill={fillColor}
59
59
  // fillOpacity={band.opacity}
60
60
  legendType={showLegend === false ? 'none' : undefined}
61
- connectNulls
61
+ connectNulls={band.connectNulls ?? true}
62
62
  dot={false}
63
63
  activeDot={false}
64
64
  isAnimationActive={animate}
@@ -14,6 +14,8 @@ ChartAreaInteractive is the full chart shell for time series data, combining an
14
14
  ## Do
15
15
 
16
16
  - Pass loading while data is being fetched so the chart shows its skeleton state.
17
+ - Pass `formatTooltipValue` for the tooltip's numbers (they print raw without it). Lines leave a gap at a month with no value unless `connectHistoryNulls` / `connectForecastNulls` is set; a range band fills across unless its `connectNulls` is false.
18
+ - `historyOnTop` (passed through to BaseChartWrapper) draws the history lines over the forecasts, `showEndDots={false}` drops the last-point dots; `showAxes={false}` keeps a hidden x-axis so the tooltip still names the date.
17
19
  - For several products, pass `historyData` (one history line each, data key `historical_<id>` in `chartData`) and set each forecast's `continues` to the history it extends. A forecast joins a history only when `continues` names it or there is exactly one history; otherwise it starts on its own first point. Without `historyData`, the single `historical` line works as before.
18
20
 
19
21
  ## Host provides
@@ -1,6 +1,6 @@
1
1
  import { memo, useMemo } from 'react';
2
2
 
3
- import { Line } from 'recharts';
3
+ import { DefaultZIndexes, Line } from 'recharts';
4
4
 
5
5
  import { ChartDataPoint } from './ChartAreaInteractive.types';
6
6
  import {
@@ -106,6 +106,10 @@ export const ChartLines = memo(
106
106
  forecastLineStyle = 'dashed',
107
107
  disableAnimation = false,
108
108
  disableHistoricalAnimation = false,
109
+ connectHistoryNulls = false,
110
+ connectForecastNulls = false,
111
+ historyOnTop = false,
112
+ showEndDots = true,
109
113
  }: {
110
114
  chartData: ChartDataPoint[];
111
115
  forecastData?: ForecastItemData[];
@@ -119,6 +123,17 @@ export const ChartLines = memo(
119
123
  forecastLineStyle?: 'dashed' | 'solid';
120
124
  disableAnimation?: boolean;
121
125
  disableHistoricalAnimation?: boolean;
126
+ /** Draw each history line across months it has no value for. */
127
+ connectHistoryNulls?: boolean;
128
+ /** Draw each forecast line across months it has no value for. */
129
+ connectForecastNulls?: boolean;
130
+ /**
131
+ * Draw the history lines after the forecast lines, over them (for many
132
+ * faint forecasts that would otherwise cover the history).
133
+ */
134
+ historyOnTop?: boolean;
135
+ /** Mark each line's last point with a dot (default: on). */
136
+ showEndDots?: boolean;
122
137
  }) => {
123
138
  const dotStroke = isDarkTheme ? '#000000' : '#FFFFFF';
124
139
 
@@ -216,63 +231,78 @@ export const ChartLines = memo(
216
231
  const animationDuration = disableAnimation ? 0 : ANIMATION_DURATION;
217
232
  const valueAnimationEnabled = !disableAnimation;
218
233
 
219
- return (
220
- <>
221
- {/* History lines */}
222
- {historyLines.map(({ dataKey, name, color }) => (
234
+ // recharts draws each line into its z-index layer in mount order, not in
235
+ // JSX order: a layer above the forecasts keeps history on top through
236
+ // hiding, showing and added forecasts, and leaves the tooltip's order.
237
+ const historyZIndex = historyOnTop ? DefaultZIndexes.line + 1 : undefined;
238
+
239
+ const historyElements = historyLines.map(({ dataKey, name, color }) => (
240
+ <Line
241
+ key={dataKey}
242
+ zIndex={historyZIndex}
243
+ type="monotone"
244
+ dataKey={dataKey}
245
+ stroke={color}
246
+ strokeWidth={1}
247
+ dot={
248
+ showEndDots ? props => renderHistoryDot(props, dataKey, color) : false
249
+ }
250
+ activeDot={{ ...activeDotHistorical, fill: color }}
251
+ name={name}
252
+ legendType={showLegend === false ? 'none' : undefined}
253
+ strokeDasharray="0"
254
+ connectNulls={connectHistoryNulls}
255
+ hide={hiddenSeries?.has(dataKey)}
256
+ isAnimationActive={historicalAnimationActive}
257
+ animationDuration={animationDuration}
258
+ animateNewValues={valueAnimationEnabled}
259
+ animationBegin={0}
260
+ animationEasing="ease-out"
261
+ />
262
+ ));
263
+
264
+ const forecastElements = forecastData?.map(
265
+ (data: ForecastItemData, index: number) => {
266
+ const {
267
+ id,
268
+ name,
269
+ color = FORECAST_LINE_COLORS[index % FORECAST_LINE_COLORS.length],
270
+ } = data;
271
+ const dataKey = `forecast_${id}`;
272
+
273
+ return (
223
274
  <Line
224
- key={dataKey}
275
+ key={`forecast-${id}`}
225
276
  type="monotone"
226
277
  dataKey={dataKey}
227
278
  stroke={color}
228
279
  strokeWidth={1}
229
- dot={props => renderHistoryDot(props, dataKey, color)}
230
- activeDot={{ ...activeDotHistorical, fill: color }}
231
- name={name}
280
+ strokeDasharray={forecastLineStyle === 'dashed' ? '4 2' : '0'}
281
+ dot={
282
+ showEndDots ? props => renderForecastDot(props, id, color) : false
283
+ }
284
+ activeDot={activeDotForecast(color)}
285
+ name={`${name || `${id}`}`}
232
286
  legendType={showLegend === false ? 'none' : undefined}
233
- strokeDasharray="0"
287
+ connectNulls={connectForecastNulls}
234
288
  hide={hiddenSeries?.has(dataKey)}
235
- isAnimationActive={historicalAnimationActive}
289
+ isAnimationActive={forecastAnimationActive}
236
290
  animationDuration={animationDuration}
237
291
  animateNewValues={valueAnimationEnabled}
238
292
  animationBegin={0}
239
293
  animationEasing="ease-out"
294
+ className={
295
+ data.status === 'pending' ? 'chart-line-blinking' : undefined
296
+ }
240
297
  />
241
- ))}
242
-
243
- {/* Forecast Lines */}
244
- {forecastData?.map((data: ForecastItemData, index: number) => {
245
- const {
246
- id,
247
- name,
248
- color = FORECAST_LINE_COLORS[index % FORECAST_LINE_COLORS.length],
249
- } = data;
250
- const dataKey = `forecast_${id}`;
298
+ );
299
+ },
300
+ );
251
301
 
252
- return (
253
- <Line
254
- key={`forecast-${id}`}
255
- type="monotone"
256
- dataKey={dataKey}
257
- stroke={color}
258
- strokeWidth={1}
259
- strokeDasharray={forecastLineStyle === 'dashed' ? '4 2' : '0'}
260
- dot={props => renderForecastDot(props, id, color)}
261
- activeDot={activeDotForecast(color)}
262
- name={`${name || `${id}`}`}
263
- legendType={showLegend === false ? 'none' : undefined}
264
- hide={hiddenSeries?.has(dataKey)}
265
- isAnimationActive={forecastAnimationActive}
266
- animationDuration={animationDuration}
267
- animateNewValues={valueAnimationEnabled}
268
- animationBegin={0}
269
- animationEasing="ease-out"
270
- className={
271
- data.status === 'pending' ? 'chart-line-blinking' : undefined
272
- }
273
- />
274
- );
275
- })}
302
+ return (
303
+ <>
304
+ {historyElements}
305
+ {forecastElements}
276
306
  </>
277
307
  );
278
308
  },
@@ -12,9 +12,8 @@ export type TooltipRow = {
12
12
  };
13
13
 
14
14
  /**
15
- * Tooltip rows in series order, showing real zeros (ChartTooltipContent hides
16
- * them) and colouring each row from the chart config (an area's own colour
17
- * is its white stack stroke).
15
+ * Tooltip rows in series order, showing real zeros, and colouring each row
16
+ * from the chart config (an area's own colour is its white stack stroke).
18
17
  */
19
18
  export function StackedTooltip({
20
19
  active,
@@ -1,4 +1,4 @@
1
- TimeRangeControls renders a row of preset time range toggles, such as one month or one year, for switching the window of a chart. Control it with timeRange and onTimeRangeChange, and pass loading to disable the controls while data refreshes.
1
+ TimeRangeControls renders a row of preset time range toggles, such as one month or one year, for switching the window of a chart. Control it with timeRange and onTimeRangeChange, and pass loading to disable the controls while data refreshes. Below 768px the same presets show as a select instead of the toggle row, so the control stays on a phone; a range that is not a preset (one dragged on the chart) selects no toggle and shows "Custom" in the select.
2
2
 
3
3
  ## When to use
4
4
 
@@ -0,0 +1,40 @@
1
+ import { render, screen } from '@testing-library/react';
2
+
3
+ import { TimeRangeControls } from './TimeRangeControls';
4
+
5
+ const noop = () => {};
6
+
7
+ describe('TimeRangeControls', () => {
8
+ it('renders the toggle row and the select, so a phone still has the control', () => {
9
+ render(<TimeRangeControls timeRange="1y" onTimeRangeChange={noop} />);
10
+ expect(screen.getByRole('group')).toBeTruthy();
11
+ const select = screen.getByRole('combobox', { name: 'Time range' });
12
+ expect(select.textContent).toContain('1y');
13
+ });
14
+
15
+ it('says "Custom" for a range that is not a preset', () => {
16
+ const { rerender } = render(
17
+ <TimeRangeControls timeRange="1y" onTimeRangeChange={noop} />,
18
+ );
19
+ rerender(
20
+ <TimeRangeControls
21
+ timeRange="2024-01-01_2024-06-01"
22
+ onTimeRangeChange={noop}
23
+ />,
24
+ );
25
+ const select = screen.getByRole('combobox', { name: 'Time range' });
26
+ expect(select.textContent).toContain('Custom');
27
+ expect(select.textContent).not.toContain('1y');
28
+ });
29
+
30
+ it('disables both while loading', () => {
31
+ render(
32
+ <TimeRangeControls timeRange="1y" onTimeRangeChange={noop} loading />,
33
+ );
34
+ expect(
35
+ screen.getByRole('combobox', { name: 'Time range' }).hasAttribute(
36
+ 'disabled',
37
+ ),
38
+ ).toBe(true);
39
+ });
40
+ });
@@ -27,50 +27,25 @@ export type TimeRangeControlsProps = {
27
27
  loading?: boolean;
28
28
  };
29
29
 
30
- export const TimeRangeControls = memo(
31
- ({ timeRange, onTimeRangeChange, loading }: TimeRangeControlsProps) => (
32
- <div className={S.timeRangeContainer}>
33
- <ToggleGroup
34
- type="single"
35
- value={toggleValueForTimeRange(timeRange)}
36
- onValueChange={onTimeRangeChange}
37
- variant="outline"
38
- disabled={loading}
39
- className={S.timeRangeToggleGroup}
40
- >
41
- {TIME_RANGES.map(range => (
42
- <ToggleGroupItem
43
- key={range}
44
- value={range}
45
- className={S.timeRangeToggleItem}
46
- >
47
- {range}
48
- </ToggleGroupItem>
49
- ))}
50
- </ToggleGroup>
51
- </div>
52
- ),
53
- );
54
-
55
- TimeRangeControls.displayName = 'TimeRangeControls';
56
-
30
+ /**
31
+ * The preset ranges as a select. A range that is not a preset (one dragged on
32
+ * the chart) shows "Custom" rather than a preset it is not.
33
+ */
57
34
  export const TimeRangeSelect = memo(
58
- ({
59
- timeRange,
60
- onTimeRangeChange,
61
- loading,
62
- }: TimeRangeControlsProps & { loading: boolean }) => (
35
+ ({ timeRange, onTimeRangeChange, loading }: TimeRangeControlsProps) => (
63
36
  <Select
64
- value={toggleValueForTimeRange(timeRange) || undefined}
37
+ // An empty value shows the placeholder; undefined would leave the
38
+ // select uncontrolled and keep the last preset picked.
39
+ value={toggleValueForTimeRange(timeRange)}
65
40
  onValueChange={onTimeRangeChange}
66
41
  disabled={loading}
67
42
  >
68
43
  <SelectTrigger
69
44
  className={S.timeRangeSelectTrigger}
70
45
  size="sm"
71
- aria-label="Select a value"
46
+ aria-label="Time range"
72
47
  >
73
- <SelectValue placeholder="1 year" />
48
+ <SelectValue placeholder="Custom" />
74
49
  </SelectTrigger>
75
50
 
76
51
  <SelectContent className={S.timeRangeSelectContent}>
@@ -89,3 +64,39 @@ export const TimeRangeSelect = memo(
89
64
  );
90
65
 
91
66
  TimeRangeSelect.displayName = 'TimeRangeSelect';
67
+
68
+ /**
69
+ * The preset ranges as a toggle row from 768px up, and as a select below it
70
+ * (CSS shows one of the two), so the control stays on a phone.
71
+ */
72
+ export const TimeRangeControls = memo(
73
+ ({ timeRange, onTimeRangeChange, loading }: TimeRangeControlsProps) => (
74
+ <div className={S.timeRangeContainer}>
75
+ <ToggleGroup
76
+ type="single"
77
+ value={toggleValueForTimeRange(timeRange)}
78
+ onValueChange={onTimeRangeChange}
79
+ variant="outline"
80
+ disabled={loading}
81
+ className={S.timeRangeToggleGroup}
82
+ >
83
+ {TIME_RANGES.map(range => (
84
+ <ToggleGroupItem
85
+ key={range}
86
+ value={range}
87
+ className={S.timeRangeToggleItem}
88
+ >
89
+ {range}
90
+ </ToggleGroupItem>
91
+ ))}
92
+ </ToggleGroup>
93
+ <TimeRangeSelect
94
+ timeRange={timeRange}
95
+ onTimeRangeChange={onTimeRangeChange}
96
+ loading={loading}
97
+ />
98
+ </div>
99
+ ),
100
+ );
101
+
102
+ TimeRangeControls.displayName = 'TimeRangeControls';
@@ -5,7 +5,6 @@ import {
5
5
  CartesianGrid,
6
6
  Line,
7
7
  LineChart,
8
- Tooltip as RechartsTooltip,
9
8
  type TooltipContentProps,
10
9
  XAxis,
11
10
  YAxis,
@@ -15,6 +14,7 @@ import {
15
14
  type ChartConfig,
16
15
  ChartContainer,
17
16
  ChartEmptyState,
17
+ ChartTooltip,
18
18
  } from '../../ui/Chart/Chart';
19
19
  import type { DriverData } from '../DriverMap/driverMapGeography';
20
20
  import S from './DriverPerformanceChart.styl';
@@ -133,7 +133,7 @@ export function DriverPerformanceChart({
133
133
  width={0}
134
134
  domain={['dataMin', 'dataMax']}
135
135
  />
136
- <RechartsTooltip cursor={false} content={renderTooltipContent} />
136
+ <ChartTooltip cursor={false} content={renderTooltipContent} />
137
137
  <Line dataKey="value" type="natural" stroke="var(--color-value)" />
138
138
  </LineChart>
139
139
  </ChartContainer>