@mui/x-charts 8.14.0 → 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 (50) hide show
  1. package/BarChart/useBarPlotData.js +20 -33
  2. package/CHANGELOG.md +95 -0
  3. package/Gauge/Gauge.js +2 -9
  4. package/Gauge/GaugeReferenceArc.d.ts +4 -1
  5. package/Gauge/GaugeReferenceArc.js +12 -3
  6. package/Gauge/GaugeValueArc.d.ts +4 -1
  7. package/Gauge/GaugeValueArc.js +16 -8
  8. package/Gauge/GaugeValueText.js +3 -1
  9. package/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
  10. package/esm/BarChart/useBarPlotData.js +20 -33
  11. package/esm/Gauge/Gauge.js +2 -9
  12. package/esm/Gauge/GaugeReferenceArc.d.ts +4 -1
  13. package/esm/Gauge/GaugeReferenceArc.js +11 -2
  14. package/esm/Gauge/GaugeValueArc.d.ts +4 -1
  15. package/esm/Gauge/GaugeValueArc.js +16 -8
  16. package/esm/Gauge/GaugeValueText.js +3 -1
  17. package/esm/ScatterChart/seriesConfig/seriesProcessor.js +1 -1
  18. package/esm/index.js +1 -1
  19. package/esm/internals/Flatbush.bench.d.ts +1 -0
  20. package/esm/internals/Flatbush.bench.js +42 -0
  21. package/esm/internals/Flatbush.d.ts +63 -0
  22. package/esm/internals/Flatbush.js +468 -0
  23. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
  24. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
  25. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +19 -0
  26. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +41 -0
  27. package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
  28. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
  29. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +33 -0
  30. package/esm/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +40 -81
  31. package/esm/models/seriesType/scatter.d.ts +2 -0
  32. package/esm/themeAugmentation/components.d.ts +3 -0
  33. package/esm/themeAugmentation/overrides.d.ts +2 -0
  34. package/index.js +1 -1
  35. package/internals/Flatbush.bench.d.ts +1 -0
  36. package/internals/Flatbush.bench.js +44 -0
  37. package/internals/Flatbush.d.ts +63 -0
  38. package/internals/Flatbush.js +477 -0
  39. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.d.ts +6 -2
  40. package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -6
  41. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +19 -0
  42. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +43 -1
  43. package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +4 -1
  44. package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.d.ts +5 -0
  45. package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +39 -0
  46. package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.js +39 -80
  47. package/models/seriesType/scatter.d.ts +2 -0
  48. package/package.json +5 -4
  49. package/themeAugmentation/components.d.ts +3 -0
  50. 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)(() => {
@@ -23,6 +23,8 @@ export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType | n
23
23
  /**
24
24
  * If true, the interaction will not use element hover for this series.
25
25
  * @default false
26
+ * @deprecated This prop will be removed in a future version because it is ambiguous. You can select what to disable
27
+ * on hover by disabling the highlight or the tooltip separately.
26
28
  */
27
29
  disableHover?: boolean;
28
30
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "8.14.0",
3
+ "version": "8.14.1",
4
4
  "author": "MUI Team",
5
5
  "description": "The community edition of MUI X Charts components.",
6
6
  "license": "MIT",
@@ -31,12 +31,13 @@
31
31
  "@mui/utils": "^7.3.3",
32
32
  "bezier-easing": "^2.1.0",
33
33
  "clsx": "^2.1.1",
34
+ "flatqueue": "^3.0.0",
34
35
  "prop-types": "^15.8.1",
35
36
  "reselect": "^5.1.1",
36
37
  "use-sync-external-store": "^1.6.0",
37
- "@mui/x-charts-vendor": "8.14.0",
38
- "@mui/x-internal-gestures": "0.3.3",
39
- "@mui/x-internals": "8.14.0"
38
+ "@mui/x-charts-vendor": "8.14.1",
39
+ "@mui/x-internals": "8.14.0",
40
+ "@mui/x-internal-gestures": "0.3.3"
40
41
  },
41
42
  "peerDependencies": {
42
43
  "@emotion/react": "^11.9.0",
@@ -62,6 +62,9 @@ export interface ChartsComponents<Theme = unknown> {
62
62
  defaultProps?: ComponentsProps['MuiScatterChart'];
63
63
  };
64
64
  MuiScatter?: {};
65
+ MuiGauge?: {
66
+ styleOverrides?: ComponentsOverrides<Theme>['MuiGauge'];
67
+ };
65
68
  }
66
69
  declare module '@mui/material/styles' {
67
70
  interface Components<Theme = unknown> extends ChartsComponents<Theme> {}
@@ -1,3 +1,4 @@
1
+ import { GaugeClassKey } from "../Gauge/index.js";
1
2
  import { BarLabelClassKey } from "../BarChart/index.js";
2
3
  import { BarElementClassKey } from "../BarChart/barElementClasses.js";
3
4
  import { ChartsAxisHighlightClassKey } from "../ChartsAxisHighlight/index.js";
@@ -18,6 +19,7 @@ export interface ChartsComponentNameToClassKey {
18
19
  MuiAreaElement: AreaElementClassKey;
19
20
  MuiLineElement: LineElementClassKey;
20
21
  MuiMarkElement: MarkElementClassKey;
22
+ MuiGauge: GaugeClassKey;
21
23
  }
22
24
  declare module '@mui/material/styles' {
23
25
  interface ComponentNameToClassKey extends ChartsComponentNameToClassKey {}