@mui/x-charts 7.0.0-alpha.3 → 7.0.0-alpha.5

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 (160) hide show
  1. package/BarChart/BarPlot.js +7 -6
  2. package/BarChart/formatter.js +15 -3
  3. package/CHANGELOG.md +465 -0
  4. package/ChartsAxis/ChartsAxis.js +4 -4
  5. package/ChartsLegend/ChartsLegend.d.ts +1 -1
  6. package/ChartsLegend/ChartsLegend.js +3 -2
  7. package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  8. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  9. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  10. package/ChartsReferenceLine/common.d.ts +1 -1
  11. package/ChartsText/ChartsText.d.ts +17 -0
  12. package/{internals/components → ChartsText}/ChartsText.js +32 -17
  13. package/ChartsText/index.d.ts +3 -0
  14. package/ChartsText/index.js +12 -0
  15. package/ChartsText/package.json +6 -0
  16. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +14 -0
  17. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +174 -0
  18. package/ChartsVoronoiHandler/index.d.ts +1 -0
  19. package/ChartsVoronoiHandler/index.js +16 -0
  20. package/ChartsVoronoiHandler/package.json +6 -0
  21. package/ChartsXAxis/ChartsXAxis.js +3 -2
  22. package/ChartsYAxis/ChartsYAxis.js +1 -1
  23. package/LineChart/AreaPlot.js +3 -2
  24. package/LineChart/LineHighlightPlot.js +2 -1
  25. package/LineChart/LinePlot.js +3 -2
  26. package/LineChart/MarkPlot.js +2 -1
  27. package/LineChart/formatter.js +14 -2
  28. package/PieChart/PieArcLabelPlot.d.ts +2 -3
  29. package/PieChart/PieArcLabelPlot.js +0 -1
  30. package/PieChart/PieArcPlot.d.ts +2 -3
  31. package/PieChart/PieArcPlot.js +0 -1
  32. package/PieChart/PieChart.js +4 -4
  33. package/PieChart/PiePlot.js +20 -15
  34. package/PieChart/dataTransform/useTransformData.d.ts +2 -3
  35. package/ResponsiveChartContainer/index.js +2 -2
  36. package/ScatterChart/Scatter.js +14 -5
  37. package/ScatterChart/ScatterChart.d.ts +7 -1
  38. package/ScatterChart/ScatterChart.js +18 -1
  39. package/SparkLineChart/SparkLineChart.js +1 -0
  40. package/context/CartesianContextProvider.js +2 -2
  41. package/context/InteractionProvider.d.ts +10 -0
  42. package/context/InteractionProvider.js +21 -1
  43. package/context/SeriesContextProvider.js +1 -1
  44. package/esm/BarChart/BarPlot.js +7 -5
  45. package/esm/BarChart/formatter.js +20 -4
  46. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  47. package/esm/ChartsLegend/ChartsLegend.js +2 -1
  48. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  49. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  50. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  51. package/esm/{internals/components → ChartsText}/ChartsText.js +33 -16
  52. package/esm/ChartsText/index.js +1 -0
  53. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +168 -0
  54. package/esm/ChartsVoronoiHandler/index.js +1 -0
  55. package/esm/ChartsXAxis/ChartsXAxis.js +2 -1
  56. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  57. package/esm/LineChart/AreaPlot.js +3 -2
  58. package/esm/LineChart/LineHighlightPlot.js +2 -1
  59. package/esm/LineChart/LinePlot.js +3 -2
  60. package/esm/LineChart/MarkPlot.js +2 -1
  61. package/esm/LineChart/formatter.js +16 -3
  62. package/esm/PieChart/PieArcLabelPlot.js +0 -1
  63. package/esm/PieChart/PieArcPlot.js +0 -1
  64. package/esm/PieChart/PieChart.js +4 -4
  65. package/esm/PieChart/PiePlot.js +20 -15
  66. package/esm/ResponsiveChartContainer/index.js +2 -2
  67. package/esm/ScatterChart/Scatter.js +14 -5
  68. package/esm/ScatterChart/ScatterChart.js +18 -1
  69. package/esm/SparkLineChart/SparkLineChart.js +1 -0
  70. package/esm/context/CartesianContextProvider.js +2 -2
  71. package/esm/context/InteractionProvider.js +21 -1
  72. package/esm/context/SeriesContextProvider.js +1 -1
  73. package/esm/hooks/useAxisEvents.js +20 -27
  74. package/esm/hooks/useInteractionItemProps.js +4 -1
  75. package/esm/index.js +2 -0
  76. package/esm/internals/getWordsByLines.js +14 -0
  77. package/esm/internals/utils.js +40 -0
  78. package/hooks/useAxisEvents.js +20 -27
  79. package/hooks/useInteractionItemProps.d.ts +2 -2
  80. package/hooks/useInteractionItemProps.js +4 -1
  81. package/index.d.ts +2 -0
  82. package/index.js +23 -1
  83. package/internals/defaultizeColor.d.ts +5 -4
  84. package/internals/{components/ChartsText.d.ts → getWordsByLines.d.ts} +2 -11
  85. package/internals/getWordsByLines.js +21 -0
  86. package/internals/utils.d.ts +13 -0
  87. package/internals/utils.js +42 -0
  88. package/legacy/BarChart/BarPlot.js +7 -5
  89. package/legacy/BarChart/formatter.js +23 -9
  90. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  91. package/legacy/ChartsLegend/ChartsLegend.js +2 -1
  92. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  93. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  94. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  95. package/legacy/{internals/components → ChartsText}/ChartsText.js +38 -22
  96. package/legacy/ChartsText/index.js +1 -0
  97. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +162 -0
  98. package/legacy/ChartsVoronoiHandler/index.js +1 -0
  99. package/legacy/ChartsXAxis/ChartsXAxis.js +2 -1
  100. package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
  101. package/legacy/LineChart/AreaPlot.js +3 -2
  102. package/legacy/LineChart/LineHighlightPlot.js +2 -1
  103. package/legacy/LineChart/LinePlot.js +3 -2
  104. package/legacy/LineChart/MarkPlot.js +2 -1
  105. package/legacy/LineChart/formatter.js +19 -8
  106. package/legacy/PieChart/PieArcLabelPlot.js +0 -1
  107. package/legacy/PieChart/PieArcPlot.js +0 -1
  108. package/legacy/PieChart/PieChart.js +4 -4
  109. package/legacy/PieChart/PiePlot.js +20 -15
  110. package/legacy/ResponsiveChartContainer/index.js +2 -2
  111. package/legacy/ScatterChart/Scatter.js +17 -6
  112. package/legacy/ScatterChart/ScatterChart.js +18 -1
  113. package/legacy/SparkLineChart/SparkLineChart.js +1 -0
  114. package/legacy/context/CartesianContextProvider.js +2 -2
  115. package/legacy/context/InteractionProvider.js +21 -1
  116. package/legacy/context/SeriesContextProvider.js +1 -1
  117. package/legacy/hooks/useAxisEvents.js +20 -27
  118. package/legacy/hooks/useInteractionItemProps.js +6 -1
  119. package/legacy/index.js +3 -1
  120. package/legacy/internals/getWordsByLines.js +15 -0
  121. package/legacy/internals/utils.js +40 -0
  122. package/models/axis.d.ts +1 -1
  123. package/models/seriesType/config.d.ts +4 -3
  124. package/models/seriesType/pie.d.ts +29 -7
  125. package/models/seriesType/scatter.d.ts +5 -0
  126. package/modern/BarChart/BarPlot.js +7 -5
  127. package/modern/BarChart/formatter.js +15 -3
  128. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  129. package/modern/ChartsLegend/ChartsLegend.js +2 -1
  130. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  131. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  132. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  133. package/modern/{internals/components → ChartsText}/ChartsText.js +33 -16
  134. package/modern/ChartsText/index.js +1 -0
  135. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +166 -0
  136. package/modern/ChartsVoronoiHandler/index.js +1 -0
  137. package/modern/ChartsXAxis/ChartsXAxis.js +2 -1
  138. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  139. package/modern/LineChart/AreaPlot.js +3 -2
  140. package/modern/LineChart/LineHighlightPlot.js +2 -1
  141. package/modern/LineChart/LinePlot.js +3 -2
  142. package/modern/LineChart/MarkPlot.js +2 -1
  143. package/modern/LineChart/formatter.js +14 -2
  144. package/modern/PieChart/PieArcLabelPlot.js +0 -1
  145. package/modern/PieChart/PieArcPlot.js +0 -1
  146. package/modern/PieChart/PieChart.js +4 -4
  147. package/modern/PieChart/PiePlot.js +20 -15
  148. package/modern/ResponsiveChartContainer/index.js +2 -2
  149. package/modern/ScatterChart/Scatter.js +14 -5
  150. package/modern/ScatterChart/ScatterChart.js +18 -1
  151. package/modern/SparkLineChart/SparkLineChart.js +1 -0
  152. package/modern/context/CartesianContextProvider.js +2 -2
  153. package/modern/context/InteractionProvider.js +21 -1
  154. package/modern/context/SeriesContextProvider.js +1 -1
  155. package/modern/hooks/useAxisEvents.js +20 -27
  156. package/modern/hooks/useInteractionItemProps.js +4 -1
  157. package/modern/index.js +3 -1
  158. package/modern/internals/getWordsByLines.js +14 -0
  159. package/modern/internals/utils.js +40 -0
  160. package/package.json +6 -4
@@ -0,0 +1,166 @@
1
+ import * as React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { Delaunay } from 'd3-delaunay';
4
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
5
+ import { InteractionContext } from '../context/InteractionProvider';
6
+ import { CartesianContext } from '../context/CartesianContextProvider';
7
+ import { SVGContext, DrawingContext } from '../context/DrawingProvider';
8
+ import { SeriesContext } from '../context/SeriesContextProvider';
9
+ import { getValueToPositionMapper } from '../hooks/useScale';
10
+ import { getSVGPoint } from '../internals/utils';
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ function ChartsVoronoiHandler(props) {
13
+ const {
14
+ voronoiMaxRadius
15
+ } = props;
16
+ const svgRef = React.useContext(SVGContext);
17
+ const {
18
+ width,
19
+ height,
20
+ top,
21
+ left
22
+ } = React.useContext(DrawingContext);
23
+ const {
24
+ xAxis,
25
+ yAxis,
26
+ xAxisIds,
27
+ yAxisIds
28
+ } = React.useContext(CartesianContext);
29
+ const {
30
+ dispatch
31
+ } = React.useContext(InteractionContext);
32
+ const {
33
+ series,
34
+ seriesOrder
35
+ } = React.useContext(SeriesContext).scatter ?? {};
36
+ const voronoiRef = React.useRef({});
37
+ const defaultXAxisId = xAxisIds[0];
38
+ const defaultYAxisId = yAxisIds[0];
39
+ useEnhancedEffect(() => {
40
+ dispatch({
41
+ type: 'updateVoronoiUsage',
42
+ useVoronoiInteraction: true
43
+ });
44
+ return () => {
45
+ dispatch({
46
+ type: 'updateVoronoiUsage',
47
+ useVoronoiInteraction: false
48
+ });
49
+ };
50
+ }, [dispatch]);
51
+ useEnhancedEffect(() => {
52
+ if (seriesOrder === undefined || series === undefined) {
53
+ // If there is no scatter chart series
54
+ return;
55
+ }
56
+ voronoiRef.current = {};
57
+ let points = [];
58
+ seriesOrder.forEach(seriesId => {
59
+ const {
60
+ data,
61
+ xAxisKey,
62
+ yAxisKey
63
+ } = series[seriesId];
64
+ const xScale = xAxis[xAxisKey ?? defaultXAxisId].scale;
65
+ const yScale = yAxis[yAxisKey ?? defaultYAxisId].scale;
66
+ const getXPosition = getValueToPositionMapper(xScale);
67
+ const getYPosition = getValueToPositionMapper(yScale);
68
+ const seriesPoints = data.flatMap(({
69
+ x,
70
+ y
71
+ }) => [getXPosition(x), getYPosition(y)]);
72
+ voronoiRef.current[seriesId] = {
73
+ startIndex: points.length,
74
+ endIndex: points.length + seriesPoints.length
75
+ };
76
+ points = points.concat(seriesPoints);
77
+ });
78
+ voronoiRef.current.delauney = new Delaunay(points);
79
+ }, [defaultXAxisId, defaultYAxisId, series, seriesOrder, xAxis, yAxis]);
80
+ React.useEffect(() => {
81
+ const element = svgRef.current;
82
+ if (element === null) {
83
+ return undefined;
84
+ }
85
+ const handleMouseOut = () => {
86
+ dispatch({
87
+ type: 'exitChart'
88
+ });
89
+ };
90
+
91
+ // TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
92
+ const handleMouseMove = event => {
93
+ // Get mouse coordinate in global SVG space
94
+ const svgPoint = getSVGPoint(svgRef.current, event);
95
+ const outsideX = svgPoint.x < left || svgPoint.x > left + width;
96
+ const outsideY = svgPoint.y < top || svgPoint.y > top + height;
97
+ if (outsideX || outsideY) {
98
+ dispatch({
99
+ type: 'exitChart'
100
+ });
101
+ return;
102
+ }
103
+ if (!voronoiRef.current.delauney) {
104
+ return;
105
+ }
106
+ const closestPointIndex = voronoiRef.current.delauney?.find(svgPoint.x, svgPoint.y);
107
+ if (closestPointIndex !== undefined) {
108
+ const seriesId = Object.keys(voronoiRef.current).find(id => {
109
+ if (id === 'delauney') {
110
+ return false;
111
+ }
112
+ return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
113
+ });
114
+ if (seriesId === undefined) {
115
+ return;
116
+ }
117
+ const dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
118
+ if (voronoiMaxRadius !== undefined) {
119
+ const pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
120
+ const pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
121
+ const dist2 = (pointX - svgPoint.x) ** 2 + (pointY - svgPoint.y) ** 2;
122
+ if (dist2 > voronoiMaxRadius ** 2) {
123
+ // The closest point is too far to be considered.
124
+ dispatch({
125
+ type: 'leaveItem',
126
+ data: {
127
+ type: 'scatter',
128
+ seriesId,
129
+ dataIndex
130
+ }
131
+ });
132
+ return;
133
+ }
134
+ }
135
+ dispatch({
136
+ type: 'enterItem',
137
+ data: {
138
+ type: 'scatter',
139
+ seriesId,
140
+ dataIndex
141
+ }
142
+ });
143
+ }
144
+ };
145
+ element.addEventListener('mouseout', handleMouseOut);
146
+ element.addEventListener('mousemove', handleMouseMove);
147
+ return () => {
148
+ element.removeEventListener('mouseout', handleMouseOut);
149
+ element.removeEventListener('mousemove', handleMouseMove);
150
+ };
151
+ }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
152
+ return /*#__PURE__*/_jsx("g", {}); // Workaround to fix docs scripts
153
+ }
154
+ process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
155
+ // ----------------------------- Warning --------------------------------
156
+ // | These PropTypes are generated from the TypeScript type definitions |
157
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
158
+ // ----------------------------------------------------------------------
159
+ /**
160
+ * Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
161
+ * If `undefined`, the radius is assumed to be infinite.
162
+ * @default undefined
163
+ */
164
+ voronoiMaxRadius: PropTypes.number
165
+ } : void 0;
166
+ export { ChartsVoronoiHandler };
@@ -0,0 +1 @@
1
+ export * from './ChartsVoronoiHandler';
@@ -11,9 +11,10 @@ import { DrawingContext } from '../context/DrawingProvider';
11
11
  import useTicks from '../hooks/useTicks';
12
12
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
13
13
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
14
- import { ChartsText, getWordsByLines } from '../internals/components/ChartsText';
14
+ import { ChartsText } from '../ChartsText';
15
15
  import { getMinXTranslation } from '../internals/geometry';
16
16
  import { useMounted } from '../hooks/useMounted';
17
+ import { getWordsByLines } from '../internals/getWordsByLines';
17
18
  import { jsx as _jsx } from "react/jsx-runtime";
18
19
  import { jsxs as _jsxs } from "react/jsx-runtime";
19
20
  const useUtilityClasses = ownerState => {
@@ -10,7 +10,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
10
10
  import { DrawingContext } from '../context/DrawingProvider';
11
11
  import useTicks from '../hooks/useTicks';
12
12
  import { AxisRoot } from '../internals/components/AxisSharedComponents';
13
- import { ChartsText } from '../internals/components/ChartsText';
13
+ import { ChartsText } from '../ChartsText';
14
14
  import { getAxisUtilityClass } from '../ChartsAxis/axisClasses';
15
15
  import { jsx as _jsx } from "react/jsx-runtime";
16
16
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -9,6 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { AreaElement } from './AreaElement';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import getCurveFactory from '../internals/getCurve';
12
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
13
14
  /**
14
15
  * Demos:
@@ -61,10 +62,10 @@ function AreaPlot(props) {
61
62
  const xData = xAxis[xAxisKey].data;
62
63
  if (process.env.NODE_ENV !== 'production') {
63
64
  if (xData === undefined) {
64
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
65
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
65
66
  }
66
67
  if (xData.length < stackedData.length) {
67
- throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
68
+ throw new Error(`MUI-X-Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
68
69
  }
69
70
  }
70
71
  const areaPath = d3Area().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y0(d => d.y && yScale(d.y[0])).y1(d => d.y && yScale(d.y[1]));
@@ -8,6 +8,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
8
8
  import { LineHighlightElement } from './LineHighlightElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
10
  import { InteractionContext } from '../context/InteractionProvider';
11
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  /**
13
14
  * Demos:
@@ -69,7 +70,7 @@ function LineHighlightPlot(props) {
69
70
  const yScale = yAxis[yAxisKey].scale;
70
71
  const xData = xAxis[xAxisKey].data;
71
72
  if (xData === undefined) {
72
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot.`);
73
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot.`);
73
74
  }
74
75
  const x = xScale(xData[highlightedIndex]);
75
76
  const y = yScale(stackedData[highlightedIndex][1]); // This should not be undefined since y should not be a band scale
@@ -9,6 +9,7 @@ import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { LineElement } from './LineElement';
10
10
  import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import getCurveFactory from '../internals/getCurve';
12
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
12
13
  import { jsx as _jsx } from "react/jsx-runtime";
13
14
  /**
14
15
  * Demos:
@@ -60,10 +61,10 @@ function LinePlot(props) {
60
61
  const xData = xAxis[xAxisKey].data;
61
62
  if (process.env.NODE_ENV !== 'production') {
62
63
  if (xData === undefined) {
63
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
64
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot`);
64
65
  }
65
66
  if (xData.length < stackedData.length) {
66
- throw new Error(`MUI: data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
67
+ throw new Error(`MUI-X-Charts: The data length of the x axis (${xData.length} items) is lower than the length of series (${stackedData.length} items)`);
67
68
  }
68
69
  }
69
70
  const linePath = d3Line().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y(d => yScale(d.y[1]));
@@ -7,6 +7,7 @@ import { SeriesContext } from '../context/SeriesContextProvider';
7
7
  import { CartesianContext } from '../context/CartesianContextProvider';
8
8
  import { MarkElement } from './MarkElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
+ import { DEFAULT_X_AXIS_KEY } from '../constants';
10
11
  import { jsx as _jsx } from "react/jsx-runtime";
11
12
  /**
12
13
  * Demos:
@@ -75,7 +76,7 @@ function MarkPlot(props) {
75
76
  return true;
76
77
  };
77
78
  if (xData === undefined) {
78
- throw new Error(`Axis of id "${xAxisKey}" should have data property to be able to display a line plot`);
79
+ throw new Error(`MUI-X-Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property to be able to display a line plot`);
79
80
  }
80
81
  return xData?.map((x, index) => {
81
82
  const value = data[index] == null ? null : stackedData[index][1];
@@ -2,6 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { stack as d3Stack } from 'd3-shape';
3
3
  import { getStackingGroups } from '../internals/stackSeries';
4
4
  import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
5
+ let warnedOnce = false;
6
+
5
7
  // For now it's a copy past of bar charts formatter, but maybe will diverge later
6
8
  const formatter = (params, dataset) => {
7
9
  const {
@@ -25,7 +27,7 @@ const formatter = (params, dataset) => {
25
27
  }
26
28
  });
27
29
  } else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
28
- throw new Error([`MUI: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
30
+ throw new Error([`MUI-X-Charts: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
29
31
  }
30
32
  });
31
33
  const completedSeries = {};
@@ -45,7 +47,17 @@ const formatter = (params, dataset) => {
45
47
  ids.forEach((id, index) => {
46
48
  const dataKey = series[id].dataKey;
47
49
  completedSeries[id] = _extends({}, series[id], {
48
- data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
50
+ data: dataKey ? dataset.map(data => {
51
+ const value = data[dataKey];
52
+ if (typeof value !== 'number') {
53
+ if (process.env.NODE_ENV !== 'production' && !warnedOnce && value !== null) {
54
+ warnedOnce = true;
55
+ console.error([`MUI-X charts: your dataset key "${dataKey}" is used for plotting line, but contains nonnumerical elements.`, 'Line plots only support numbers and null values.']);
56
+ }
57
+ return 0;
58
+ }
59
+ return value;
60
+ }) : series[id].data,
49
61
  stackedData: stackedSeries[index].map(([a, b]) => [a, b])
50
62
  });
51
63
  });
@@ -152,7 +152,6 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
152
152
  innerRadius: PropTypes.number,
153
153
  /**
154
154
  * The radius between circle center and the end of the arc.
155
- * @default R_max The maximal radius that fit into the drawing area.
156
155
  */
157
156
  outerRadius: PropTypes.number.isRequired,
158
157
  /**
@@ -144,7 +144,6 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
144
144
  onClick: PropTypes.func,
145
145
  /**
146
146
  * The radius between circle center and the end of the arc.
147
- * @default R_max The maximal radius that fit into the drawing area.
148
147
  */
149
148
  outerRadius: PropTypes.number.isRequired,
150
149
  /**
@@ -240,8 +240,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
240
240
  arcLabelMinAngle: PropTypes.number,
241
241
  color: PropTypes.string,
242
242
  cornerRadius: PropTypes.number,
243
- cx: PropTypes.number,
244
- cy: PropTypes.number,
243
+ cx: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
244
+ cy: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
245
245
  data: PropTypes.arrayOf(PropTypes.shape({
246
246
  color: PropTypes.string,
247
247
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
@@ -270,8 +270,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
270
270
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
271
271
  }),
272
272
  id: PropTypes.string,
273
- innerRadius: PropTypes.number,
274
- outerRadius: PropTypes.number,
273
+ innerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
274
+ outerRadius: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
275
275
  paddingAngle: PropTypes.number,
276
276
  sortingValues: PropTypes.oneOfType([PropTypes.oneOf(['asc', 'desc', 'none']), PropTypes.func]),
277
277
  startAngle: PropTypes.number,
@@ -4,6 +4,7 @@ import { SeriesContext } from '../context/SeriesContextProvider';
4
4
  import { DrawingContext } from '../context/DrawingProvider';
5
5
  import { PieArcPlot } from './PieArcPlot';
6
6
  import { PieArcLabelPlot } from './PieArcLabelPlot';
7
+ import { getPercentageValue } from '../internals/utils';
7
8
  import { jsx as _jsx } from "react/jsx-runtime";
8
9
  import { jsxs as _jsxs } from "react/jsx-runtime";
9
10
  /**
@@ -34,10 +35,6 @@ function PiePlot(props) {
34
35
  return null;
35
36
  }
36
37
  const availableRadius = Math.min(width, height) / 2;
37
- const center = {
38
- x: left + width / 2,
39
- y: top + height / 2
40
- };
41
38
  const {
42
39
  series,
43
40
  seriesOrder
@@ -45,22 +42,26 @@ function PiePlot(props) {
45
42
  return /*#__PURE__*/_jsxs("g", {
46
43
  children: [seriesOrder.map(seriesId => {
47
44
  const {
48
- innerRadius,
49
- outerRadius,
45
+ innerRadius: innerRadiusParam,
46
+ outerRadius: outerRadiusParam,
50
47
  cornerRadius,
51
48
  paddingAngle,
52
49
  data,
53
- cx,
54
- cy,
50
+ cx: cxParam,
51
+ cy: cyParam,
55
52
  highlighted,
56
53
  faded,
57
54
  highlightScope
58
55
  } = series[seriesId];
56
+ const outerRadius = getPercentageValue(outerRadiusParam ?? availableRadius, availableRadius);
57
+ const innerRadius = getPercentageValue(innerRadiusParam ?? 0, availableRadius);
58
+ const cx = getPercentageValue(cxParam ?? '50%', width);
59
+ const cy = getPercentageValue(cyParam ?? '50%', height);
59
60
  return /*#__PURE__*/_jsx("g", {
60
- transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
61
+ transform: `translate(${left + cx}, ${top + cy})`,
61
62
  children: /*#__PURE__*/_jsx(PieArcPlot, {
62
63
  innerRadius: innerRadius,
63
- outerRadius: outerRadius ?? availableRadius,
64
+ outerRadius: outerRadius,
64
65
  cornerRadius: cornerRadius,
65
66
  paddingAngle: paddingAngle,
66
67
  id: seriesId,
@@ -76,19 +77,23 @@ function PiePlot(props) {
76
77
  }, seriesId);
77
78
  }), seriesOrder.map(seriesId => {
78
79
  const {
79
- innerRadius,
80
- outerRadius,
80
+ innerRadius: innerRadiusParam,
81
+ outerRadius: outerRadiusParam,
81
82
  cornerRadius,
82
83
  paddingAngle,
83
84
  arcLabel,
84
85
  arcLabelMinAngle,
85
86
  data,
86
- cx,
87
- cy,
87
+ cx: cxParam,
88
+ cy: cyParam,
88
89
  highlightScope
89
90
  } = series[seriesId];
91
+ const outerRadius = getPercentageValue(outerRadiusParam ?? availableRadius, availableRadius);
92
+ const innerRadius = getPercentageValue(innerRadiusParam ?? 0, availableRadius);
93
+ const cx = getPercentageValue(cxParam ?? '50%', width);
94
+ const cy = getPercentageValue(cyParam ?? '50%', height);
90
95
  return /*#__PURE__*/_jsx("g", {
91
- transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
96
+ transform: `translate(${left + cx}, ${top + cy})`,
92
97
  children: /*#__PURE__*/_jsx(PieArcLabelPlot, {
93
98
  innerRadius: innerRadius,
94
99
  outerRadius: outerRadius ?? availableRadius,
@@ -60,11 +60,11 @@ const useChartDimensions = (inWidth, inHeight) => {
60
60
  }, [computeSize, inHeight, inWidth]);
61
61
  if (process.env.NODE_ENV !== 'production') {
62
62
  if (displayError.current && inWidth === undefined && width === 0) {
63
- console.error(`MUI: Charts does not have \`width\` prop, and its container has no \`width\` defined.`);
63
+ console.error(`MUI-X-Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
64
64
  displayError.current = false;
65
65
  }
66
66
  if (displayError.current && inHeight === undefined && height === 0) {
67
- console.error(`MUI: Charts does not have \`height\` prop, and its container has no \`height\` defined.`);
67
+ console.error(`MUI-X-Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
68
68
  displayError.current = false;
69
69
  }
70
70
  }
@@ -23,10 +23,16 @@ function Scatter(props) {
23
23
  color,
24
24
  markerSize
25
25
  } = props;
26
+ const highlightScope = React.useMemo(() => _extends({
27
+ highlighted: 'item',
28
+ faded: 'global'
29
+ }, series.highlightScope), [series.highlightScope]);
26
30
  const {
27
- item
31
+ item,
32
+ useVoronoiInteraction
28
33
  } = React.useContext(InteractionContext);
29
- const getInteractionItemProps = useInteractionItemProps(series.highlightScope);
34
+ const skipInteractionHandlers = useVoronoiInteraction || series.disableHover;
35
+ const getInteractionItemProps = useInteractionItemProps(highlightScope, skipInteractionHandlers);
30
36
  const cleanData = React.useMemo(() => {
31
37
  const getXPosition = getValueToPositionMapper(xScale);
32
38
  const getYPosition = getValueToPositionMapper(yScale);
@@ -48,22 +54,24 @@ function Scatter(props) {
48
54
  dataIndex: i
49
55
  };
50
56
  if (isInRange) {
57
+ const isHighlighted = getIsHighlighted(item, pointCtx, highlightScope);
51
58
  temp.push({
52
59
  x,
53
60
  y,
54
- isFaded: !getIsHighlighted(item, pointCtx, series.highlightScope) && getIsFaded(item, pointCtx, series.highlightScope),
61
+ isHighlighted,
62
+ isFaded: !isHighlighted && getIsFaded(item, pointCtx, highlightScope),
55
63
  interactionProps: getInteractionItemProps(pointCtx),
56
64
  id: scatterPoint.id
57
65
  });
58
66
  }
59
67
  }
60
68
  return temp;
61
- }, [yScale, xScale, getInteractionItemProps, item, series.data, series.highlightScope, series.id]);
69
+ }, [xScale, yScale, series.data, series.id, item, highlightScope, getInteractionItemProps]);
62
70
  return /*#__PURE__*/_jsx("g", {
63
71
  children: cleanData.map(dataPoint => /*#__PURE__*/_jsx("circle", _extends({
64
72
  cx: 0,
65
73
  cy: 0,
66
- r: markerSize,
74
+ r: (dataPoint.isHighlighted ? 1.2 : 1) * markerSize,
67
75
  transform: `translate(${dataPoint.x}, ${dataPoint.y})`,
68
76
  fill: color,
69
77
  opacity: dataPoint.isFaded && 0.3 || 1
@@ -84,6 +92,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
84
92
  x: PropTypes.number.isRequired,
85
93
  y: PropTypes.number.isRequired
86
94
  })).isRequired,
95
+ disableHover: PropTypes.bool,
87
96
  highlightScope: PropTypes.shape({
88
97
  faded: PropTypes.oneOf(['global', 'none', 'series']),
89
98
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
@@ -7,6 +7,7 @@ import { ChartsAxis } from '../ChartsAxis';
7
7
  import { ChartsTooltip } from '../ChartsTooltip';
8
8
  import { ChartsLegend } from '../ChartsLegend';
9
9
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
10
+ import { ChartsVoronoiHandler } from '../ChartsVoronoiHandler/ChartsVoronoiHandler';
10
11
  import { jsx as _jsx } from "react/jsx-runtime";
11
12
  import { jsxs as _jsxs } from "react/jsx-runtime";
12
13
  /**
@@ -26,6 +27,8 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
26
27
  series,
27
28
  tooltip,
28
29
  axisHighlight,
30
+ voronoiMaxRadius,
31
+ disableVoronoi,
29
32
  legend,
30
33
  width,
31
34
  height,
@@ -52,7 +55,9 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
52
55
  xAxis: xAxis,
53
56
  yAxis: yAxis,
54
57
  sx: sx,
55
- children: [/*#__PURE__*/_jsx(ChartsAxis, {
58
+ children: [!disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, {
59
+ voronoiMaxRadius: voronoiMaxRadius
60
+ }), /*#__PURE__*/_jsx(ChartsAxis, {
56
61
  topAxis: topAxis,
57
62
  leftAxis: leftAxis,
58
63
  rightAxis: rightAxis,
@@ -126,6 +131,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
126
131
  * @default false
127
132
  */
128
133
  disableAxisListener: PropTypes.bool,
134
+ /**
135
+ * If true, the interaction will not use the Voronoi cell and fall back to hover events.
136
+ * @default false
137
+ */
138
+ disableVoronoi: PropTypes.bool,
129
139
  /**
130
140
  * The height of the chart in px. If not defined, it takes the height of the parent element.
131
141
  * @default undefined
@@ -218,6 +228,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
218
228
  x: PropTypes.number.isRequired,
219
229
  y: PropTypes.number.isRequired
220
230
  })).isRequired,
231
+ disableHover: PropTypes.bool,
221
232
  highlightScope: PropTypes.shape({
222
233
  faded: PropTypes.oneOf(['global', 'none', 'series']),
223
234
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
@@ -283,6 +294,12 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
283
294
  x: PropTypes.number,
284
295
  y: PropTypes.number
285
296
  }),
297
+ /**
298
+ * Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
299
+ * If `undefined`, the radius is assumed to be infinite.
300
+ * @default undefined
301
+ */
302
+ voronoiMaxRadius: PropTypes.number,
286
303
  /**
287
304
  * The width of the chart in px. If not defined, it takes the width of the parent element.
288
305
  * @default undefined
@@ -78,6 +78,7 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
78
78
  sx: sx,
79
79
  disableAxisListener: (!showTooltip || tooltip?.trigger !== 'axis') && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
80
80
  children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {
81
+ skipAnimation: true,
81
82
  slots: slots,
82
83
  slotProps: slotProps,
83
84
  sx: {
@@ -52,7 +52,7 @@ function CartesianContextProvider({
52
52
  return axisConfig;
53
53
  }
54
54
  if (dataset === undefined) {
55
- throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
55
+ throw Error('MUI-X-Charts: x-axis uses `dataKey` but no `dataset` is provided.');
56
56
  }
57
57
  return _extends({}, axisConfig, {
58
58
  data: dataset.map(d => d[dataKey])
@@ -64,7 +64,7 @@ function CartesianContextProvider({
64
64
  return axisConfig;
65
65
  }
66
66
  if (dataset === undefined) {
67
- throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
67
+ throw Error('MUI-X-Charts: y-axis uses `dataKey` but no `dataset` is provided.');
68
68
  }
69
69
  return _extends({}, axisConfig, {
70
70
  data: dataset.map(d => d[dataKey])
@@ -7,6 +7,7 @@ export const InteractionContext = /*#__PURE__*/React.createContext({
7
7
  x: null,
8
8
  y: null
9
9
  },
10
+ useVoronoiInteraction: false,
10
11
  dispatch: () => null
11
12
  });
12
13
  const dataReducer = (prevState, action) => {
@@ -15,6 +16,21 @@ const dataReducer = (prevState, action) => {
15
16
  return _extends({}, prevState, {
16
17
  item: action.data
17
18
  });
19
+ case 'exitChart':
20
+ if (prevState.item === null && prevState.axis.x === null && prevState.axis.y === null) {
21
+ return prevState;
22
+ }
23
+ return _extends({}, prevState, {
24
+ axis: {
25
+ x: null,
26
+ y: null
27
+ },
28
+ item: null
29
+ });
30
+ case 'updateVoronoiUsage':
31
+ return _extends({}, prevState, {
32
+ useVoronoiInteraction: action.useVoronoiInteraction
33
+ });
18
34
  case 'leaveItem':
19
35
  if (prevState.item === null || Object.keys(action.data).some(key => action.data[key] !== prevState.item[key])) {
20
36
  // The item is already something else
@@ -24,6 +40,9 @@ const dataReducer = (prevState, action) => {
24
40
  item: null
25
41
  });
26
42
  case 'updateAxis':
43
+ if (action.data.x === prevState.axis.x && action.data.y === prevState.axis.y) {
44
+ return prevState;
45
+ }
27
46
  return _extends({}, prevState, {
28
47
  axis: action.data
29
48
  });
@@ -39,7 +58,8 @@ export function InteractionProvider({
39
58
  axis: {
40
59
  x: null,
41
60
  y: null
42
- }
61
+ },
62
+ useVoronoiInteraction: false
43
63
  });
44
64
  const value = React.useMemo(() => _extends({}, data, {
45
65
  dispatch
@@ -39,7 +39,7 @@ const formatSeries = (series, colors, dataset) => {
39
39
  };
40
40
  }
41
41
  if (seriesGroups[type]?.series[id] !== undefined) {
42
- throw new Error(`MUI: series' id "${id}" is not unique`);
42
+ throw new Error(`MUI-X-Charts: series' id "${id}" is not unique`);
43
43
  }
44
44
  seriesGroups[type].series[id] = _extends({
45
45
  id