@mui/x-charts 8.13.1 → 8.14.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.
Files changed (134) hide show
  1. package/BarChart/BarChart.js +44 -36
  2. package/BarChart/useBarPlotData.js +20 -33
  3. package/CHANGELOG.md +204 -1
  4. package/ChartContainer/ChartContainer.js +68 -56
  5. package/ChartsTooltip/ChartsTooltipContainer.js +2 -0
  6. package/ChartsXAxis/useAxisTicksProps.d.ts +197 -355
  7. package/ChartsYAxis/useAxisTicksProps.d.ts +197 -355
  8. package/Gauge/Gauge.js +2 -9
  9. package/Gauge/GaugeReferenceArc.d.ts +4 -1
  10. package/Gauge/GaugeReferenceArc.js +12 -3
  11. package/Gauge/GaugeValueArc.d.ts +4 -1
  12. package/Gauge/GaugeValueArc.js +16 -8
  13. package/Gauge/GaugeValueText.js +3 -1
  14. package/LineChart/LineChart.js +44 -36
  15. package/PieChart/PieArc.d.ts +18 -4
  16. package/PieChart/PieArc.js +11 -5
  17. package/PieChart/PieArcPlot.js +3 -1
  18. package/ScatterChart/ScatterChart.js +44 -36
  19. package/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
  20. package/SparkLineChart/SparkLineChart.js +44 -36
  21. package/esm/BarChart/BarChart.js +44 -36
  22. package/esm/BarChart/useBarPlotData.js +20 -33
  23. package/esm/ChartContainer/ChartContainer.js +68 -56
  24. package/esm/ChartsTooltip/ChartsTooltipContainer.js +2 -0
  25. package/esm/ChartsXAxis/useAxisTicksProps.d.ts +197 -355
  26. package/esm/ChartsYAxis/useAxisTicksProps.d.ts +197 -355
  27. package/esm/Gauge/Gauge.js +2 -9
  28. package/esm/Gauge/GaugeReferenceArc.d.ts +4 -1
  29. package/esm/Gauge/GaugeReferenceArc.js +11 -2
  30. package/esm/Gauge/GaugeValueArc.d.ts +4 -1
  31. package/esm/Gauge/GaugeValueArc.js +16 -8
  32. package/esm/Gauge/GaugeValueText.js +3 -1
  33. package/esm/LineChart/LineChart.js +44 -36
  34. package/esm/PieChart/PieArc.d.ts +18 -4
  35. package/esm/PieChart/PieArc.js +11 -5
  36. package/esm/PieChart/PieArcPlot.js +3 -1
  37. package/esm/ScatterChart/ScatterChart.js +44 -36
  38. package/esm/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
  39. package/esm/SparkLineChart/SparkLineChart.js +44 -36
  40. package/esm/hooks/animation/useAnimate.js +5 -3
  41. package/esm/hooks/useScale.d.ts +5 -1
  42. package/esm/index.js +1 -1
  43. package/esm/internals/Flatbush.bench.d.ts +1 -0
  44. package/esm/internals/Flatbush.bench.js +42 -0
  45. package/esm/internals/Flatbush.d.ts +63 -0
  46. package/esm/internals/Flatbush.js +468 -0
  47. package/esm/internals/animation/useAnimateInternal.d.ts +1 -1
  48. package/esm/internals/animation/useAnimateInternal.js +1 -1
  49. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +8 -8
  50. package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +4 -2
  51. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.d.ts +9 -11
  52. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +4 -28
  53. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +4 -5
  54. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +3 -24
  55. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/domain.d.ts +20 -0
  56. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/domain.js +77 -0
  57. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.d.ts +4 -65
  58. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.js +7 -104
  59. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
  60. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
  61. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.d.ts +3 -3
  62. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +31 -39
  63. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +185 -6
  64. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +199 -47
  65. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
  66. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
  67. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +33 -0
  68. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +40 -81
  69. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.js +10 -3
  70. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +4 -4
  71. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +3 -2
  72. package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.types.d.ts +6 -0
  73. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +5 -1
  74. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +9 -1
  75. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +10 -1
  76. package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +2 -1
  77. package/esm/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
  78. package/esm/internals/scaleGuards.d.ts +12 -6
  79. package/esm/internals/symlogScale.js +5 -0
  80. package/esm/locales/enUS.js +4 -4
  81. package/esm/locales/ptBR.js +97 -99
  82. package/esm/models/axis.d.ts +39 -17
  83. package/esm/models/axis.js +3 -0
  84. package/esm/models/seriesType/scatter.d.ts +2 -0
  85. package/esm/themeAugmentation/components.d.ts +3 -0
  86. package/esm/themeAugmentation/overrides.d.ts +2 -0
  87. package/hooks/animation/useAnimate.js +4 -3
  88. package/hooks/useScale.d.ts +5 -1
  89. package/index.js +1 -1
  90. package/internals/Flatbush.bench.d.ts +1 -0
  91. package/internals/Flatbush.bench.js +44 -0
  92. package/internals/Flatbush.d.ts +63 -0
  93. package/internals/Flatbush.js +477 -0
  94. package/internals/animation/useAnimateInternal.d.ts +1 -1
  95. package/internals/animation/useAnimateInternal.js +1 -1
  96. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +7 -7
  97. package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +4 -2
  98. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.d.ts +9 -11
  99. package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +4 -28
  100. package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +4 -5
  101. package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +3 -25
  102. package/internals/plugins/featurePlugins/useChartCartesianAxis/domain.d.ts +20 -0
  103. package/internals/plugins/featurePlugins/useChartCartesianAxis/domain.js +84 -0
  104. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.d.ts +4 -65
  105. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisScale.js +8 -108
  106. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
  107. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
  108. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.d.ts +3 -3
  109. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +29 -37
  110. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +185 -6
  111. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +200 -47
  112. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
  113. package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
  114. package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +39 -0
  115. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +39 -80
  116. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.js +10 -3
  117. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.d.ts +4 -4
  118. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +3 -2
  119. package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.types.d.ts +6 -0
  120. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.js +5 -1
  121. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.d.ts +9 -1
  122. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +11 -2
  123. package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.types.d.ts +2 -1
  124. package/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +1 -1
  125. package/internals/scaleGuards.d.ts +12 -6
  126. package/internals/symlogScale.js +5 -0
  127. package/locales/enUS.js +4 -4
  128. package/locales/ptBR.js +97 -99
  129. package/models/axis.d.ts +39 -17
  130. package/models/axis.js +4 -0
  131. package/models/seriesType/scatter.d.ts +2 -0
  132. package/package.json +7 -6
  133. package/themeAugmentation/components.d.ts +3 -0
  134. package/themeAugmentation/overrides.d.ts +2 -0
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.findClosestPoints = findClosestPoints;
7
+ var _scaleGuards = require("../../../scaleGuards");
8
+ function findClosestPoints(flatbush, drawingArea, seriesData, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPointX, svgPointY, maxRadius = Infinity, maxResults = 1) {
9
+ const originalXScale = xScale.copy();
10
+ const originalYScale = yScale.copy();
11
+ originalXScale.range([0, 1]);
12
+ originalYScale.range([0, 1]);
13
+ const excludeIfOutsideDrawingArea = function excludeIfOutsideDrawingArea(index) {
14
+ const x = originalXScale(seriesData[index].x);
15
+ const y = originalYScale(seriesData[index].y);
16
+ return x >= xZoomStart && x <= xZoomEnd && y >= yZoomStart && y <= yZoomEnd;
17
+ };
18
+
19
+ // We need to convert the distance from the original range [0, 1] to the current drawing area
20
+ // so the comparison is done on pixels instead of normalized values.
21
+ // fx and fy are the factors to convert the distance from [0, 1] to the current drawing area.
22
+ const fx = xScale.range()[1] - xScale.range()[0];
23
+ const fy = yScale.range()[1] - yScale.range()[0];
24
+ const fxSq = fx * fx;
25
+ const fySq = fy * fy;
26
+ function sqDistFn(dx, dy) {
27
+ return fxSq * dx * dx + fySq * dy * dy;
28
+ }
29
+ const pointX = originalXScale(invertScale(xScale, svgPointX, dataIndex => seriesData[dataIndex].x));
30
+ const pointY = originalYScale(invertScale(yScale, svgPointY, dataIndex => seriesData[dataIndex].y));
31
+ return flatbush.neighbors(pointX, pointY, maxResults, maxRadius != null ? maxRadius * maxRadius : Infinity, excludeIfOutsideDrawingArea, sqDistFn);
32
+ }
33
+ function invertScale(scale, value, getDataPoint) {
34
+ if ((0, _scaleGuards.isOrdinalScale)(scale)) {
35
+ const dataIndex = scale.bandwidth() === 0 ? Math.floor((value - Math.min(...scale.range()) + scale.step() / 2) / scale.step()) : Math.floor((value - Math.min(...scale.range())) / scale.step());
36
+ return getDataPoint(dataIndex);
37
+ }
38
+ return scale.invert(value);
39
+ }
@@ -11,13 +11,12 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
11
11
  var React = _interopRequireWildcard(require("react"));
12
12
  var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
13
13
  var _useEventCallback = _interopRequireDefault(require("@mui/utils/useEventCallback"));
14
- var _d3Delaunay = require("@mui/x-charts-vendor/d3-delaunay");
15
- var _useScale = require("../../../../hooks/useScale");
16
14
  var _getSVGPoint = require("../../../getSVGPoint");
17
15
  var _useSelector = require("../../../store/useSelector");
18
16
  var _useChartCartesianAxis = require("../useChartCartesianAxis");
19
17
  var _useChartSeries = require("../../corePlugins/useChartSeries/useChartSeries.selectors");
20
18
  var _useChartDimensions = require("../../corePlugins/useChartDimensions");
19
+ var _findClosestPoints = require("./findClosestPoints");
21
20
  const useChartClosestPoint = ({
22
21
  svgRef,
23
22
  params,
@@ -43,9 +42,7 @@ const useChartClosestPoint = ({
43
42
  series,
44
43
  seriesOrder
45
44
  } = (0, _useSelector.useSelector)(store, _useChartSeries.selectorChartSeriesProcessed)?.scatter ?? {};
46
- const voronoiRef = React.useRef({});
47
- const delauneyRef = React.useRef(undefined);
48
- const lastFind = React.useRef(undefined);
45
+ const flatbushMap = (0, _useSelector.useSelector)(store, zoomIsInteracting ? _useChartCartesianAxis.selectorChartSeriesEmptyFlatbushMap : _useChartCartesianAxis.selectorChartSeriesFlatbushMap);
49
46
  const defaultXAxisId = xAxisIds[0];
50
47
  const defaultYAxisId = yAxisIds[0];
51
48
  (0, _useEnhancedEffect.default)(() => {
@@ -55,52 +52,6 @@ const useChartClosestPoint = ({
55
52
  }
56
53
  }));
57
54
  }, [store, disableVoronoi]);
58
- (0, _useEnhancedEffect.default)(() => {
59
- // This effect generate and store the Delaunay object that's used to map coordinate to closest point.
60
-
61
- if (zoomIsInteracting || seriesOrder === undefined || series === undefined || disableVoronoi) {
62
- // If there is no scatter chart series
63
- return;
64
- }
65
- voronoiRef.current = {};
66
- let points = [];
67
- seriesOrder.forEach(seriesId => {
68
- const {
69
- data,
70
- xAxisId,
71
- yAxisId
72
- } = series[seriesId];
73
- const xScale = xAxis[xAxisId ?? defaultXAxisId].scale;
74
- const yScale = yAxis[yAxisId ?? defaultYAxisId].scale;
75
- const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
76
- const getYPosition = (0, _useScale.getValueToPositionMapper)(yScale);
77
- const seriesPoints = [];
78
- const seriesIndexes = [];
79
- for (let dataIndex = 0; dataIndex < data.length; dataIndex += 1) {
80
- const {
81
- x,
82
- y
83
- } = data[dataIndex];
84
- const pointX = getXPosition(x);
85
- const pointY = getYPosition(y);
86
- if (instance.isPointInside(pointX, pointY)) {
87
- seriesPoints.push(pointX);
88
- seriesPoints.push(pointY);
89
- seriesIndexes.push(dataIndex);
90
- }
91
- }
92
- voronoiRef.current[seriesId] = {
93
- seriesId,
94
- seriesIndexes,
95
- startIndex: points.length,
96
- endIndex: points.length + seriesPoints.length,
97
- markerSize: series[seriesId].markerSize
98
- };
99
- points = points.concat(seriesPoints);
100
- });
101
- delauneyRef.current = new _d3Delaunay.Delaunay(points);
102
- lastFind.current = undefined;
103
- }, [zoomIsInteracting, defaultXAxisId, defaultYAxisId, series, seriesOrder, xAxis, yAxis, drawingArea, instance, disableVoronoi]);
104
55
  React.useEffect(() => {
105
56
  if (svgRef.current === null || disableVoronoi) {
106
57
  return undefined;
@@ -110,40 +61,48 @@ const useChartClosestPoint = ({
110
61
  // Get mouse coordinate in global SVG space
111
62
  const svgPoint = (0, _getSVGPoint.getSVGPoint)(element, event);
112
63
  if (!instance.isPointInside(svgPoint.x, svgPoint.y)) {
113
- lastFind.current = undefined;
114
64
  return 'outside-chart';
115
65
  }
116
- if (!delauneyRef.current) {
117
- return 'no-point-found';
118
- }
119
- const closestPointIndex = delauneyRef.current.find(svgPoint.x, svgPoint.y, lastFind.current);
120
- if (closestPointIndex === undefined) {
121
- return 'no-point-found';
66
+ let closestPoint = undefined;
67
+ for (const seriesId of seriesOrder ?? []) {
68
+ const aSeries = (series ?? {})[seriesId];
69
+ const flatbush = flatbushMap.get(seriesId);
70
+ if (!flatbush) {
71
+ continue;
72
+ }
73
+ const xAxisId = aSeries.xAxisId ?? defaultXAxisId;
74
+ const yAxisId = aSeries.yAxisId ?? defaultYAxisId;
75
+ const xAxisZoom = (0, _useChartCartesianAxis.selectorChartAxisZoomData)(store.getSnapshot(), xAxisId);
76
+ const yAxisZoom = (0, _useChartCartesianAxis.selectorChartAxisZoomData)(store.getSnapshot(), yAxisId);
77
+ const maxRadius = voronoiMaxRadius === 'item' ? aSeries.markerSize : voronoiMaxRadius;
78
+ const xZoomStart = (xAxisZoom?.start ?? 0) / 100;
79
+ const xZoomEnd = (xAxisZoom?.end ?? 100) / 100;
80
+ const yZoomStart = (yAxisZoom?.start ?? 0) / 100;
81
+ const yZoomEnd = (yAxisZoom?.end ?? 100) / 100;
82
+ const xScale = xAxis[xAxisId].scale;
83
+ const yScale = yAxis[yAxisId].scale;
84
+ const closestPointIndex = (0, _findClosestPoints.findClosestPoints)(flatbush, drawingArea, aSeries.data, xScale, yScale, xZoomStart, xZoomEnd, yZoomStart, yZoomEnd, svgPoint.x, svgPoint.y, maxRadius)[0];
85
+ if (closestPointIndex === undefined) {
86
+ continue;
87
+ }
88
+ const point = aSeries.data[closestPointIndex];
89
+ const scaledX = xScale(point.x);
90
+ const scaledY = yScale(point.y);
91
+ const distSq = (scaledX - svgPoint.x) ** 2 + (scaledY - svgPoint.y) ** 2;
92
+ if (closestPoint === undefined || distSq < closestPoint.distanceSq) {
93
+ closestPoint = {
94
+ dataIndex: closestPointIndex,
95
+ seriesId,
96
+ distanceSq: distSq
97
+ };
98
+ }
122
99
  }
123
- lastFind.current = closestPointIndex;
124
- const closestSeries = Object.values(voronoiRef.current).find(value => {
125
- return 2 * closestPointIndex >= value.startIndex && 2 * closestPointIndex < value.endIndex;
126
- });
127
- if (closestSeries === undefined) {
100
+ if (closestPoint === undefined) {
128
101
  return 'no-point-found';
129
102
  }
130
-
131
- // The point index in the series with id=closestSeries.seriesId.
132
- const seriesPointIndex = (2 * closestPointIndex - voronoiRef.current[closestSeries.seriesId].startIndex) / 2;
133
- const dataIndex = voronoiRef.current[closestSeries.seriesId].seriesIndexes[seriesPointIndex];
134
- const maxRadius = voronoiMaxRadius === 'item' ? closestSeries.markerSize : voronoiMaxRadius;
135
- if (maxRadius !== undefined) {
136
- const pointX = delauneyRef.current.points[2 * closestPointIndex];
137
- const pointY = delauneyRef.current.points[2 * closestPointIndex + 1];
138
- const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
139
- if (dist2 > maxRadius ** 2) {
140
- // The closest point is too far to be considered.
141
- return 'outside-voronoi-max-radius';
142
- }
143
- }
144
103
  return {
145
- seriesId: closestSeries.seriesId,
146
- dataIndex
104
+ seriesId: closestPoint.seriesId,
105
+ dataIndex: closestPoint.dataIndex
147
106
  };
148
107
  }
149
108
 
@@ -218,7 +177,7 @@ const useChartClosestPoint = ({
218
177
  pressHandler.cleanup();
219
178
  pressEndHandler.cleanup();
220
179
  };
221
- }, [svgRef, yAxis, xAxis, voronoiMaxRadius, onItemClick, disableVoronoi, drawingArea, instance]);
180
+ }, [svgRef, yAxis, xAxis, voronoiMaxRadius, onItemClick, disableVoronoi, drawingArea, instance, seriesOrder, series, flatbushMap, defaultXAxisId, defaultYAxisId, store]);
222
181
 
223
182
  // Instance implementation
224
183
  const enableVoronoiCallback = (0, _useEventCallback.default)(() => {
@@ -30,9 +30,14 @@ const useChartHighlight = ({
30
30
  }, [store, params.highlightedItem]);
31
31
  const clearHighlight = (0, _useEventCallback.default)(() => {
32
32
  params.onHighlightChange?.(null);
33
+ const prevItem = store.getSnapshot().highlight.item;
34
+ if (prevItem === null) {
35
+ return;
36
+ }
33
37
  store.update(prev => (0, _extends2.default)({}, prev, {
34
38
  highlight: {
35
- item: null
39
+ item: null,
40
+ lastUpdate: 'pointer'
36
41
  }
37
42
  }));
38
43
  });
@@ -44,7 +49,8 @@ const useChartHighlight = ({
44
49
  params.onHighlightChange?.(newItem);
45
50
  store.update(prev => (0, _extends2.default)({}, prev, {
46
51
  highlight: {
47
- item: newItem
52
+ item: newItem,
53
+ lastUpdate: 'pointer'
48
54
  }
49
55
  }));
50
56
  });
@@ -63,7 +69,8 @@ useChartHighlight.getDefaultizedParams = ({
63
69
  });
64
70
  useChartHighlight.getInitialState = params => ({
65
71
  highlight: {
66
- item: params.highlightedItem
72
+ item: params.highlightedItem,
73
+ lastUpdate: 'pointer'
67
74
  }
68
75
  });
69
76
  useChartHighlight.params = {
@@ -8,24 +8,24 @@ export declare const selectorChartsHighlightScopePerSeriesId: import("reselect")
8
8
  }, Map<SeriesId, Partial<HighlightScope> | undefined>, any[]>;
9
9
  export declare const selectorChartsHighlightedItem: import("reselect").Selector<import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & import("./useChartHighlight.types.js").UseChartHighlightState & Partial<{}> & {
10
10
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
11
- } & {
11
+ } & Partial<import("../useChartKeyboardNavigation/useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
12
12
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
13
13
  }, HighlightItemData | null, any[]>;
14
14
  export declare const selectorChartsHighlightScope: import("reselect").Selector<import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<{}> & {
15
15
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
16
16
  } & {
17
17
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
18
- } & import("./useChartHighlight.types.js").UseChartHighlightState, Partial<HighlightScope> | null, any[]>;
18
+ } & import("./useChartHighlight.types.js").UseChartHighlightState & Partial<import("../useChartKeyboardNavigation/useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState>, Partial<HighlightScope> | null, any[]>;
19
19
  export declare const selectorChartsIsHighlightedCallback: import("reselect").Selector<import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<{}> & {
20
20
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
21
21
  } & {
22
22
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
23
- } & import("./useChartHighlight.types.js").UseChartHighlightState, (item: HighlightItemData | null) => boolean, any[]>;
23
+ } & import("./useChartHighlight.types.js").UseChartHighlightState & Partial<import("../useChartKeyboardNavigation/useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState>, (item: HighlightItemData | null) => boolean, any[]>;
24
24
  export declare const selectorChartsIsFadedCallback: import("reselect").Selector<import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<{}> & {
25
25
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
26
26
  } & {
27
27
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
28
- } & import("./useChartHighlight.types.js").UseChartHighlightState, (item: HighlightItemData | null) => boolean, any[]>;
28
+ } & import("./useChartHighlight.types.js").UseChartHighlightState & Partial<import("../useChartKeyboardNavigation/useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState>, (item: HighlightItemData | null) => boolean, any[]>;
29
29
  export declare const selectorChartsIsHighlighted: import("reselect").Selector<any, boolean, [item: HighlightItemData | null]>;
30
30
  export declare const selectorChartIsSeriesHighlighted: import("reselect").Selector<any, boolean, [seriesId: SeriesId]>;
31
31
  export declare const selectorChartIsSeriesFaded: import("reselect").Selector<any, boolean, [seriesId: SeriesId]>;
@@ -8,6 +8,7 @@ var _selectors = require("../../utils/selectors");
8
8
  var _createIsHighlighted = require("./createIsHighlighted");
9
9
  var _createIsFaded = require("./createIsFaded");
10
10
  var _highlightStates = require("./highlightStates");
11
+ var _useChartKeyboardNavigation = require("../useChartKeyboardNavigation");
11
12
  const selectHighlight = state => state.highlight;
12
13
  const selectSeries = state => state.series;
13
14
  const selectorChartsHighlightScopePerSeriesId = exports.selectorChartsHighlightScopePerSeriesId = (0, _selectors.createSelector)([selectSeries], series => {
@@ -21,8 +22,8 @@ const selectorChartsHighlightScopePerSeriesId = exports.selectorChartsHighlightS
21
22
  });
22
23
  return map;
23
24
  });
24
- const selectorChartsHighlightedItem = exports.selectorChartsHighlightedItem = (0, _selectors.createSelector)([selectHighlight], function selectorChartsHighlightedItem(highlight) {
25
- return highlight.item;
25
+ const selectorChartsHighlightedItem = exports.selectorChartsHighlightedItem = (0, _selectors.createSelector)([selectHighlight, _useChartKeyboardNavigation.selectorChartsKeyboardItem], function selectorChartsHighlightedItem(highlight, keyboardItem) {
26
+ return highlight.lastUpdate === 'pointer' ? highlight.item : keyboardItem;
26
27
  });
27
28
  const selectorChartsHighlightScope = exports.selectorChartsHighlightScope = (0, _selectors.createSelector)([selectorChartsHighlightScopePerSeriesId, selectorChartsHighlightedItem], function selectorChartsHighlightScope(seriesIdToHighlightScope, highlightedItem) {
28
29
  if (!highlightedItem) {
@@ -28,6 +28,7 @@ export type HighlightItemData = {
28
28
  */
29
29
  dataIndex?: number;
30
30
  };
31
+ export type HighlightUpdateSource = 'pointer' | 'keyboard';
31
32
  export interface UseChartHighlightInstance {
32
33
  /**
33
34
  * Remove all highlight.
@@ -59,6 +60,11 @@ export interface UseChartHighlightState {
59
60
  * The item currently highlighted.
60
61
  */
61
62
  item: HighlightItemData | null;
63
+ /**
64
+ * The last interaction highlight update.
65
+ * Used to decide if highlight should be based on pointer position or keyboard navigation.
66
+ */
67
+ lastUpdate: HighlightUpdateSource;
62
68
  };
63
69
  }
64
70
  export type UseChartHighlightSignature = ChartPluginSignature<{
@@ -139,7 +139,11 @@ const useChartKeyboardNavigation = ({
139
139
  }
140
140
  if (newFocusedItem !== prevState.keyboardNavigation.item) {
141
141
  event.preventDefault();
142
- return (0, _extends2.default)({}, prevState, prevState.interaction && {
142
+ return (0, _extends2.default)({}, prevState, prevState.highlight && {
143
+ highlight: (0, _extends2.default)({}, prevState.highlight, {
144
+ lastUpdate: 'keyboard'
145
+ })
146
+ }, prevState.interaction && {
143
147
  interaction: (0, _extends2.default)({}, prevState.interaction, {
144
148
  lastUpdate: 'keyboard'
145
149
  })
@@ -34,4 +34,12 @@ export declare const selectorChartsKeyboardYAxisIndex: import("reselect").Select
34
34
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
35
35
  } & {
36
36
  cacheKey: import("../../models/index.js").ChartStateCacheKey;
37
- } & Partial<import("../useChartCartesianAxis/index.js").UseChartCartesianAxisState> & Partial<{}>, AxisItemIdentifier | undefined, any[]>;
37
+ } & Partial<import("../useChartCartesianAxis/index.js").UseChartCartesianAxisState> & Partial<{}>, AxisItemIdentifier | undefined, any[]>;
38
+ export declare const selectorChartsKeyboardItem: import("reselect").Selector<import("../../corePlugins/useChartId/useChartId.types.js").UseChartIdState & import("../../corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.types.js").UseChartExperimentalFeaturesState & import("../../corePlugins/useChartDimensions/useChartDimensions.types.js").UseChartDimensionsState & import("../../corePlugins/useChartSeries/useChartSeries.types.js").UseChartSeriesState<keyof import("../../../index.js").ChartsSeriesConfig> & import("../../corePlugins/useChartAnimation/useChartAnimation.types.js").UseChartAnimationState & import("../../../index.js").UseChartInteractionListenerState & Partial<import("./useChartKeyboardNavigation.types.js").UseChartKeyboardNavigationState> & {
39
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
40
+ } & {
41
+ cacheKey: import("../../models/index.js").ChartStateCacheKey;
42
+ }, {
43
+ seriesId: SeriesId;
44
+ dataIndex: number | undefined;
45
+ } | null, any[]>;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.selectorChartsKeyboardYAxisIndex = exports.selectorChartsKeyboardXAxisIndex = exports.selectorChartsIsKeyboardNavigationEnabled = exports.selectorChartsHasFocusedItem = exports.selectorChartsFocusedSeriesType = exports.selectorChartsFocusedSeriesId = exports.selectorChartsFocusedDataIndex = void 0;
6
+ exports.selectorChartsKeyboardYAxisIndex = exports.selectorChartsKeyboardXAxisIndex = exports.selectorChartsKeyboardItem = exports.selectorChartsIsKeyboardNavigationEnabled = exports.selectorChartsHasFocusedItem = exports.selectorChartsFocusedSeriesType = exports.selectorChartsFocusedSeriesId = exports.selectorChartsFocusedDataIndex = void 0;
7
7
  var _selectors = require("../../utils/selectors");
8
8
  var _useChartSeries = require("../../corePlugins/useChartSeries");
9
9
  var _useChartCartesianAxisRendering = require("../useChartCartesianAxis/useChartCartesianAxisRendering.selectors");
@@ -36,4 +36,13 @@ const createSelectAxisHighlight = direction => (type, seriesId, dataIndex, axis,
36
36
  };
37
37
  };
38
38
  const selectorChartsKeyboardXAxisIndex = exports.selectorChartsKeyboardXAxisIndex = (0, _selectors.createSelector)([selectorChartsFocusedSeriesType, selectorChartsFocusedSeriesId, selectorChartsFocusedDataIndex, _useChartCartesianAxisRendering.selectorChartXAxis, _useChartSeries.selectorChartSeriesProcessed], createSelectAxisHighlight('x'));
39
- const selectorChartsKeyboardYAxisIndex = exports.selectorChartsKeyboardYAxisIndex = (0, _selectors.createSelector)([selectorChartsFocusedSeriesType, selectorChartsFocusedSeriesId, selectorChartsFocusedDataIndex, _useChartCartesianAxisRendering.selectorChartYAxis, _useChartSeries.selectorChartSeriesProcessed], createSelectAxisHighlight('y'));
39
+ const selectorChartsKeyboardYAxisIndex = exports.selectorChartsKeyboardYAxisIndex = (0, _selectors.createSelector)([selectorChartsFocusedSeriesType, selectorChartsFocusedSeriesId, selectorChartsFocusedDataIndex, _useChartCartesianAxisRendering.selectorChartYAxis, _useChartSeries.selectorChartSeriesProcessed], createSelectAxisHighlight('y'));
40
+ const selectorChartsKeyboardItem = exports.selectorChartsKeyboardItem = (0, _selectors.createSelector)([selectorChartsFocusedSeriesType, selectorChartsFocusedSeriesId, selectorChartsFocusedDataIndex], function selectorChartsKeyboardItem(seriesType, seriesId, dataIndex) {
41
+ if (seriesId === undefined) {
42
+ return null;
43
+ }
44
+ return {
45
+ seriesId,
46
+ dataIndex: seriesType === 'line' ? undefined : dataIndex
47
+ };
48
+ });
@@ -2,6 +2,7 @@ import { ChartPluginSignature } from "../../models/index.js";
2
2
  import { ChartSeriesType } from "../../../../models/seriesType/config.js";
3
3
  import { SeriesId } from "../../../../models/seriesType/common.js";
4
4
  import { UseChartInteractionSignature } from "../useChartInteraction/index.js";
5
+ import { UseChartHighlightSignature } from "../useChartHighlight/index.js";
5
6
  export interface UseChartKeyboardNavigationInstance {}
6
7
  type SeriesItemIdentifier = {
7
8
  /**
@@ -31,6 +32,6 @@ export type UseChartKeyboardNavigationSignature = ChartPluginSignature<{
31
32
  defaultizedParams: UseChartKeyboardNavigationParameters;
32
33
  instance: UseChartKeyboardNavigationInstance;
33
34
  state: UseChartKeyboardNavigationState;
34
- optionalDependencies: [UseChartInteractionSignature];
35
+ optionalDependencies: [UseChartInteractionSignature, UseChartHighlightSignature];
35
36
  }>;
36
37
  export {};
@@ -91,7 +91,7 @@ function computeAxisValue({
91
91
  completeAxis[axis.id].valueFormatter = axis.valueFormatter ?? dateFormatter;
92
92
  }
93
93
  }
94
- if (axis.scaleType === 'band' || axis.scaleType === 'point') {
94
+ if (!(0, _axis.isContinuousScaleConfig)(axis)) {
95
95
  // Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
96
96
  return;
97
97
  }
@@ -1,11 +1,17 @@
1
1
  import type { ScaleBand } from '@mui/x-charts-vendor/d3-scale';
2
2
  import { D3OrdinalScale, D3Scale } from "../models/axis.js";
3
- export declare function isOrdinalScale<T extends {
3
+ export declare function isOrdinalScale<Domain extends {
4
4
  toString(): string;
5
- }>(scale: D3Scale<T>): scale is D3OrdinalScale<T>;
6
- export declare function isBandScale<T extends {
5
+ } = {
7
6
  toString(): string;
8
- }>(scale: D3Scale<T>): scale is ScaleBand<T>;
9
- export declare function isPointScale<T extends {
7
+ }, Range = number, Output = number>(scale: D3Scale<Domain, Range, Output>): scale is D3OrdinalScale<Domain>;
8
+ export declare function isBandScale<Domain extends {
10
9
  toString(): string;
11
- }>(scale: D3Scale<T>): scale is D3OrdinalScale<T>;
10
+ } = {
11
+ toString(): string;
12
+ }, Range = number, Output = number>(scale: D3Scale<Domain, Range, Output>): scale is ScaleBand<Domain>;
13
+ export declare function isPointScale<Domain extends {
14
+ toString(): string;
15
+ } = {
16
+ toString(): string;
17
+ }, Range = number, Output = number>(scale: D3Scale<Domain, Range, Output>): scale is D3OrdinalScale<Domain>;
@@ -81,6 +81,11 @@ function scaleSymlog(_domain, _range) {
81
81
  return tickFormat(tick);
82
82
  };
83
83
  };
84
+
85
+ /* Adaptation of https://github.com/d3/d3-scale/blob/d6904a4bde09e16005e0ad8ca3e25b10ce54fa0d/src/symlog.js#L30 */
86
+ scale.copy = () => {
87
+ return scaleSymlog(scale.domain(), scale.range()).constant(scale.constant());
88
+ };
84
89
  return scale;
85
90
  }
86
91
  function generateScales(scale) {
package/locales/enUS.js CHANGED
@@ -9,17 +9,17 @@ var _getChartsLocalization = require("./utils/getChartsLocalization");
9
9
  // This object is not Partial<ChartsLocaleText> because it is the default values
10
10
 
11
11
  const enUSLocaleText = exports.enUSLocaleText = {
12
- /* Overlay */
12
+ // Overlay
13
13
  loading: 'Loading data…',
14
14
  noData: 'No data to display',
15
- /* Toolbar */
15
+ // Toolbar
16
16
  zoomIn: 'Zoom in',
17
17
  zoomOut: 'Zoom out',
18
18
  toolbarExport: 'Export',
19
- /* Toolbar Export Menu */
19
+ // Toolbar Export Menu
20
20
  toolbarExportPrint: 'Print',
21
21
  toolbarExportImage: mimeType => `Export as ${_imageMimeTypes.imageMimeTypes[mimeType] ?? mimeType}`,
22
- /* Charts renderer configuration */
22
+ // Charts renderer configuration
23
23
  chartTypeBar: 'Bar',
24
24
  chartTypeColumn: 'Column',
25
25
  chartTypeLine: 'Line',