@mui/x-charts 7.0.0-beta.0 → 7.0.0-beta.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 (185) hide show
  1. package/BarChart/BarChart.d.ts +2 -1
  2. package/BarChart/BarChart.js +23 -4
  3. package/BarChart/BarElement.d.ts +1 -1
  4. package/BarChart/BarElement.js +6 -3
  5. package/BarChart/BarPlot.d.ts +8 -1
  6. package/BarChart/BarPlot.js +19 -5
  7. package/BarChart/formatter.js +1 -1
  8. package/CHANGELOG.md +247 -0
  9. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +20 -0
  10. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +83 -0
  11. package/ChartsOnAxisClickHandler/index.d.ts +1 -0
  12. package/ChartsOnAxisClickHandler/index.js +16 -0
  13. package/ChartsOnAxisClickHandler/package.json +6 -0
  14. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  15. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  16. package/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  17. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -4
  18. package/ChartsTooltip/utils.d.ts +3 -1
  19. package/ChartsTooltip/utils.js +8 -0
  20. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
  21. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  22. package/LineChart/AnimatedArea.d.ts +1361 -0
  23. package/LineChart/AnimatedArea.js +111 -0
  24. package/LineChart/AnimatedLine.d.ts +1361 -0
  25. package/LineChart/AnimatedLine.js +113 -0
  26. package/LineChart/AreaElement.d.ts +17 -17
  27. package/LineChart/AreaElement.js +17 -34
  28. package/LineChart/AreaPlot.d.ts +12 -7
  29. package/LineChart/AreaPlot.js +91 -58
  30. package/LineChart/LineChart.d.ts +13 -4
  31. package/LineChart/LineChart.js +35 -6
  32. package/LineChart/LineElement.d.ts +17 -17
  33. package/LineChart/LineElement.js +16 -36
  34. package/LineChart/LineHighlightElement.js +3 -2
  35. package/LineChart/LinePlot.d.ts +12 -7
  36. package/LineChart/LinePlot.js +89 -56
  37. package/LineChart/MarkElement.d.ts +5 -2
  38. package/LineChart/MarkElement.js +26 -13
  39. package/LineChart/MarkPlot.d.ts +8 -1
  40. package/LineChart/MarkPlot.js +80 -51
  41. package/LineChart/formatter.js +1 -1
  42. package/LineChart/index.d.ts +2 -0
  43. package/LineChart/index.js +22 -0
  44. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  45. package/PieChart/PieArcLabelPlot.js +1 -1
  46. package/PieChart/PieArcPlot.d.ts +2 -2
  47. package/PieChart/PieArcPlot.js +6 -6
  48. package/PieChart/PieChart.d.ts +1 -1
  49. package/PieChart/PieChart.js +4 -4
  50. package/PieChart/PiePlot.d.ts +1 -1
  51. package/PieChart/PiePlot.js +4 -4
  52. package/ScatterChart/Scatter.d.ts +7 -1
  53. package/ScatterChart/Scatter.js +17 -3
  54. package/ScatterChart/ScatterChart.d.ts +8 -2
  55. package/ScatterChart/ScatterChart.js +11 -2
  56. package/ScatterChart/ScatterPlot.d.ts +1 -1
  57. package/ScatterChart/ScatterPlot.js +10 -2
  58. package/SparkLineChart/SparkLineChart.js +2 -0
  59. package/context/DrawingProvider.d.ts +6 -1
  60. package/context/DrawingProvider.js +9 -2
  61. package/context/InteractionProvider.d.ts +3 -3
  62. package/esm/BarChart/BarChart.js +23 -4
  63. package/esm/BarChart/BarElement.js +6 -3
  64. package/esm/BarChart/BarPlot.js +19 -5
  65. package/esm/BarChart/formatter.js +1 -1
  66. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
  67. package/esm/ChartsOnAxisClickHandler/index.js +1 -0
  68. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  69. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  70. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  71. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -4
  72. package/esm/ChartsTooltip/utils.js +6 -0
  73. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  74. package/esm/LineChart/AnimatedArea.js +103 -0
  75. package/esm/LineChart/AnimatedLine.js +105 -0
  76. package/esm/LineChart/AreaElement.js +16 -33
  77. package/esm/LineChart/AreaPlot.js +92 -59
  78. package/esm/LineChart/LineChart.js +35 -6
  79. package/esm/LineChart/LineElement.js +16 -35
  80. package/esm/LineChart/LineHighlightElement.js +3 -2
  81. package/esm/LineChart/LinePlot.js +90 -57
  82. package/esm/LineChart/MarkElement.js +26 -13
  83. package/esm/LineChart/MarkPlot.js +80 -51
  84. package/esm/LineChart/formatter.js +1 -1
  85. package/esm/LineChart/index.js +2 -0
  86. package/esm/PieChart/PieArcLabelPlot.js +1 -1
  87. package/esm/PieChart/PieArcPlot.js +6 -6
  88. package/esm/PieChart/PieChart.js +4 -4
  89. package/esm/PieChart/PiePlot.js +4 -4
  90. package/esm/ScatterChart/Scatter.js +17 -3
  91. package/esm/ScatterChart/ScatterChart.js +11 -2
  92. package/esm/ScatterChart/ScatterPlot.js +10 -2
  93. package/esm/SparkLineChart/SparkLineChart.js +2 -0
  94. package/esm/context/DrawingProvider.js +9 -2
  95. package/esm/hooks/useDrawingArea.js +7 -3
  96. package/esm/index.js +1 -0
  97. package/esm/internals/geometry.js +1 -1
  98. package/esm/internals/useAnimatedPath.js +29 -0
  99. package/esm/internals/utils.js +7 -0
  100. package/hooks/useDrawingArea.d.ts +2 -0
  101. package/hooks/useDrawingArea.js +7 -3
  102. package/index.d.ts +1 -0
  103. package/index.js +12 -1
  104. package/internals/geometry.js +1 -1
  105. package/internals/useAnimatedPath.d.ts +1 -0
  106. package/internals/useAnimatedPath.js +38 -0
  107. package/internals/utils.d.ts +4 -0
  108. package/internals/utils.js +8 -0
  109. package/legacy/BarChart/BarChart.js +23 -4
  110. package/legacy/BarChart/BarElement.js +5 -2
  111. package/legacy/BarChart/BarPlot.js +18 -4
  112. package/legacy/BarChart/formatter.js +1 -1
  113. package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  114. package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
  115. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  116. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  117. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +6 -7
  118. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -4
  119. package/legacy/ChartsTooltip/utils.js +6 -0
  120. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
  121. package/legacy/LineChart/AnimatedArea.js +102 -0
  122. package/legacy/LineChart/AnimatedLine.js +104 -0
  123. package/legacy/LineChart/AreaElement.js +15 -35
  124. package/legacy/LineChart/AreaPlot.js +102 -66
  125. package/legacy/LineChart/LineChart.js +35 -6
  126. package/legacy/LineChart/LineElement.js +15 -37
  127. package/legacy/LineChart/LineHighlightElement.js +3 -2
  128. package/legacy/LineChart/LinePlot.js +97 -63
  129. package/legacy/LineChart/MarkElement.js +29 -12
  130. package/legacy/LineChart/MarkPlot.js +83 -53
  131. package/legacy/LineChart/formatter.js +1 -1
  132. package/legacy/LineChart/index.js +2 -0
  133. package/legacy/PieChart/PieArcLabelPlot.js +1 -1
  134. package/legacy/PieChart/PieArcPlot.js +6 -6
  135. package/legacy/PieChart/PieChart.js +4 -4
  136. package/legacy/PieChart/PiePlot.js +4 -4
  137. package/legacy/ScatterChart/Scatter.js +19 -3
  138. package/legacy/ScatterChart/ScatterChart.js +11 -2
  139. package/legacy/ScatterChart/ScatterPlot.js +10 -2
  140. package/legacy/SparkLineChart/SparkLineChart.js +2 -0
  141. package/legacy/context/DrawingProvider.js +11 -2
  142. package/legacy/hooks/useDrawingArea.js +7 -3
  143. package/legacy/index.js +2 -1
  144. package/legacy/internals/geometry.js +1 -1
  145. package/legacy/internals/useAnimatedPath.js +32 -0
  146. package/legacy/internals/utils.js +7 -0
  147. package/modern/BarChart/BarChart.js +23 -4
  148. package/modern/BarChart/BarElement.js +6 -3
  149. package/modern/BarChart/BarPlot.js +19 -5
  150. package/modern/BarChart/formatter.js +1 -1
  151. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  152. package/modern/ChartsOnAxisClickHandler/index.js +1 -0
  153. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  154. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  155. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  156. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +6 -4
  157. package/modern/ChartsTooltip/utils.js +6 -0
  158. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  159. package/modern/LineChart/AnimatedArea.js +103 -0
  160. package/modern/LineChart/AnimatedLine.js +105 -0
  161. package/modern/LineChart/AreaElement.js +16 -33
  162. package/modern/LineChart/AreaPlot.js +91 -58
  163. package/modern/LineChart/LineChart.js +35 -6
  164. package/modern/LineChart/LineElement.js +16 -35
  165. package/modern/LineChart/LineHighlightElement.js +3 -2
  166. package/modern/LineChart/LinePlot.js +89 -56
  167. package/modern/LineChart/MarkElement.js +26 -13
  168. package/modern/LineChart/MarkPlot.js +80 -51
  169. package/modern/LineChart/formatter.js +1 -1
  170. package/modern/LineChart/index.js +2 -0
  171. package/modern/PieChart/PieArcLabelPlot.js +1 -1
  172. package/modern/PieChart/PieArcPlot.js +6 -6
  173. package/modern/PieChart/PieChart.js +4 -4
  174. package/modern/PieChart/PiePlot.js +4 -4
  175. package/modern/ScatterChart/Scatter.js +17 -3
  176. package/modern/ScatterChart/ScatterChart.js +11 -2
  177. package/modern/ScatterChart/ScatterPlot.js +10 -2
  178. package/modern/SparkLineChart/SparkLineChart.js +2 -0
  179. package/modern/context/DrawingProvider.js +9 -2
  180. package/modern/hooks/useDrawingArea.js +7 -3
  181. package/modern/index.js +2 -1
  182. package/modern/internals/geometry.js +1 -1
  183. package/modern/internals/useAnimatedPath.js +29 -0
  184. package/modern/internals/utils.js +7 -0
  185. package/package.json +6 -5
@@ -0,0 +1,75 @@
1
+ import * as React from 'react';
2
+ import PropTypes from 'prop-types';
3
+ import { SVGContext } from '../context/DrawingProvider';
4
+ import { InteractionContext } from '../context/InteractionProvider';
5
+ import { CartesianContext } from '../context/CartesianContextProvider';
6
+ import { SeriesContext } from '../context/SeriesContextProvider';
7
+ import { jsx as _jsx } from "react/jsx-runtime";
8
+ function ChartsOnAxisClickHandler(props) {
9
+ var onAxisClick = props.onAxisClick;
10
+ var svgRef = React.useContext(SVGContext);
11
+ var series = React.useContext(SeriesContext);
12
+ var _React$useContext = React.useContext(InteractionContext),
13
+ axis = _React$useContext.axis;
14
+ var _React$useContext2 = React.useContext(CartesianContext),
15
+ xAxisIds = _React$useContext2.xAxisIds,
16
+ xAxis = _React$useContext2.xAxis,
17
+ yAxisIds = _React$useContext2.yAxisIds,
18
+ yAxis = _React$useContext2.yAxis;
19
+ React.useEffect(function () {
20
+ var element = svgRef.current;
21
+ if (element === null || !onAxisClick) {
22
+ return function () {};
23
+ }
24
+ var handleMouseClick = function handleMouseClick(event) {
25
+ var _USED_AXIS_ID$data;
26
+ event.preventDefault();
27
+ var isXaxis = (axis.x && axis.x.index) !== undefined;
28
+ var USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
29
+ var dataIndex = isXaxis ? axis.x && axis.x.index : axis.y && axis.y.index;
30
+ if (dataIndex == null) {
31
+ return;
32
+ }
33
+ var seriesValues = {};
34
+ Object.keys(series).filter(function (seriesType) {
35
+ return ['bar', 'line'].includes(seriesType);
36
+ }).forEach(function (seriesType) {
37
+ var _series$seriesType;
38
+ (_series$seriesType = series[seriesType]) == null || _series$seriesType.seriesOrder.forEach(function (seriesId) {
39
+ var seriesItem = series[seriesType].series[seriesId];
40
+ var axisKey = isXaxis ? seriesItem.xAxisKey : seriesItem.yAxisKey;
41
+ if (axisKey === undefined || axisKey === USED_AXIS_ID) {
42
+ seriesValues[seriesId] = seriesItem.data[dataIndex];
43
+ }
44
+ });
45
+ });
46
+ var axisValue = (_USED_AXIS_ID$data = (isXaxis ? xAxis : yAxis)[USED_AXIS_ID].data) == null ? void 0 : _USED_AXIS_ID$data[dataIndex];
47
+ onAxisClick(event, {
48
+ dataIndex: dataIndex,
49
+ axisValue: axisValue,
50
+ seriesValues: seriesValues
51
+ });
52
+ };
53
+ element.addEventListener('click', handleMouseClick);
54
+ return function () {
55
+ element.removeEventListener('click', handleMouseClick);
56
+ };
57
+ }, [axis.x, axis.y, onAxisClick, series, svgRef, xAxis, xAxisIds, yAxis, yAxisIds]);
58
+
59
+ // eslint-disable-next-line react/jsx-no-useless-fragment
60
+ return /*#__PURE__*/_jsx(React.Fragment, {});
61
+ }
62
+ process.env.NODE_ENV !== "production" ? ChartsOnAxisClickHandler.propTypes = {
63
+ // ----------------------------- Warning --------------------------------
64
+ // | These PropTypes are generated from the TypeScript type definitions |
65
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
66
+ // ----------------------------------------------------------------------
67
+ /**
68
+ * The function called for onClick events.
69
+ * The second argument contains information about all line/bar elements at the current mouse position.
70
+ * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
71
+ * @param {null | AxisData} data The data about the clicked axis and items associated with it.
72
+ */
73
+ onAxisClick: PropTypes.func
74
+ } : void 0;
75
+ export { ChartsOnAxisClickHandler };
@@ -0,0 +1 @@
1
+ export * from './ChartsOnAxisClickHandler';
@@ -70,7 +70,7 @@ function ChartsXReferenceLine(props) {
70
70
  if (process.env.NODE_ENV !== 'production') {
71
71
  if (!warnedOnce) {
72
72
  warnedOnce = true;
73
- console.error("MUI X: the value ".concat(x, " does not exist in the data of x axis with id ").concat(axisId, "."));
73
+ console.error("MUI X Charts: the value ".concat(x, " does not exist in the data of x axis with id ").concat(axisId, "."));
74
74
  }
75
75
  }
76
76
  return null;
@@ -70,7 +70,7 @@ function ChartsYReferenceLine(props) {
70
70
  if (process.env.NODE_ENV !== 'production') {
71
71
  if (!warnedOnce) {
72
72
  warnedOnce = true;
73
- console.error("MUI X: the value ".concat(y, " does not exist in the data of y axis with id ").concat(axisId, "."));
73
+ console.error("MUI X Charts: the value ".concat(y, " does not exist in the data of y axis with id ").concat(axisId, "."));
74
74
  }
75
75
  }
76
76
  return null;
@@ -5,6 +5,7 @@ import { useSlotProps } from '@mui/base/utils';
5
5
  import { SeriesContext } from '../context/SeriesContextProvider';
6
6
  import { CartesianContext } from '../context/CartesianContextProvider';
7
7
  import { DefaultChartsAxisTooltipContent } from './DefaultChartsAxisTooltipContent';
8
+ import { isCartesianSeriesType } from './utils';
8
9
  import { jsx as _jsx } from "react/jsx-runtime";
9
10
  function ChartsAxisTooltipContent(props) {
10
11
  var content = props.content,
@@ -24,9 +25,7 @@ function ChartsAxisTooltipContent(props) {
24
25
  var USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
25
26
  var relevantSeries = React.useMemo(function () {
26
27
  var rep = [];
27
- Object.keys(series).filter(function (seriesType) {
28
- return ['bar', 'line', 'scatter'].includes(seriesType);
29
- }).forEach(function (seriesType) {
28
+ Object.keys(series).filter(isCartesianSeriesType).forEach(function (seriesType) {
30
29
  series[seriesType].seriesOrder.forEach(function (seriesId) {
31
30
  var item = series[seriesType].series[seriesId];
32
31
  var axisKey = isXaxis ? item.xAxisKey : item.yAxisKey;
@@ -65,11 +64,11 @@ process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
65
64
  axisData: PropTypes.shape({
66
65
  x: PropTypes.shape({
67
66
  index: PropTypes.number,
68
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
67
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
69
68
  }),
70
69
  y: PropTypes.shape({
71
70
  index: PropTypes.number,
72
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
71
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
73
72
  })
74
73
  }).isRequired,
75
74
  classes: PropTypes.object.isRequired,
@@ -79,11 +78,11 @@ process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
79
78
  axisData: PropTypes.shape({
80
79
  x: PropTypes.shape({
81
80
  index: PropTypes.number,
82
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
81
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
83
82
  }),
84
83
  y: PropTypes.shape({
85
84
  index: PropTypes.number,
86
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
85
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
87
86
  })
88
87
  }),
89
88
  axisValue: PropTypes.any,
@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import clsx from 'clsx';
4
4
  import Typography from '@mui/material/Typography';
5
5
  import { ChartsTooltipCell, ChartsTooltipPaper, ChartsTooltipTable, ChartsTooltipMark, ChartsTooltipRow } from './ChartsTooltipTable';
6
+ import { isCartesianSeries } from './utils';
6
7
  import { jsx as _jsx } from "react/jsx-runtime";
7
8
  import { jsxs as _jsxs } from "react/jsx-runtime";
8
9
  function DefaultChartsAxisTooltipContent(props) {
@@ -34,13 +35,15 @@ function DefaultChartsAxisTooltipContent(props) {
34
35
  })
35
36
  })
36
37
  }), /*#__PURE__*/_jsx("tbody", {
37
- children: series.map(function (_ref) {
38
+ children: series.filter(isCartesianSeries).map(function (_ref) {
39
+ var _data$dataIndex;
38
40
  var color = _ref.color,
39
41
  id = _ref.id,
40
42
  label = _ref.label,
41
43
  valueFormatter = _ref.valueFormatter,
42
44
  data = _ref.data;
43
- var formattedValue = valueFormatter(data[dataIndex]);
45
+ // @ts-ignore
46
+ var formattedValue = valueFormatter((_data$dataIndex = data[dataIndex]) != null ? _data$dataIndex : null);
44
47
  if (formattedValue == null) {
45
48
  return null;
46
49
  }
@@ -87,11 +90,11 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
87
90
  axisData: PropTypes.shape({
88
91
  x: PropTypes.shape({
89
92
  index: PropTypes.number,
90
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
93
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
91
94
  }),
92
95
  y: PropTypes.shape({
93
96
  index: PropTypes.number,
94
- value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired
97
+ value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
95
98
  })
96
99
  }).isRequired,
97
100
  /**
@@ -88,4 +88,10 @@ export function getTooltipHasData(trigger, displayedData) {
88
88
  var hasAxisXData = displayedData.x !== null;
89
89
  var hasAxisYData = displayedData.y !== null;
90
90
  return hasAxisXData || hasAxisYData;
91
+ }
92
+ export function isCartesianSeriesType(seriesType) {
93
+ return ['bar', 'line', 'scatter'].includes(seriesType);
94
+ }
95
+ export function isCartesianSeries(series) {
96
+ return isCartesianSeriesType(series.type);
91
97
  }
@@ -11,7 +11,8 @@ import { getSVGPoint } from '../internals/utils';
11
11
  import { jsx as _jsx } from "react/jsx-runtime";
12
12
  function ChartsVoronoiHandler(props) {
13
13
  var _React$useContext$sca;
14
- var voronoiMaxRadius = props.voronoiMaxRadius;
14
+ var voronoiMaxRadius = props.voronoiMaxRadius,
15
+ onItemClick = props.onItemClick;
15
16
  var svgRef = React.useContext(SVGContext);
16
17
  var _React$useContext = React.useContext(DrawingContext),
17
18
  width = _React$useContext.width,
@@ -44,6 +45,8 @@ function ChartsVoronoiHandler(props) {
44
45
  };
45
46
  }, [dispatch]);
46
47
  useEnhancedEffect(function () {
48
+ // This effect generate and store the Delaunay object that's used to map coordinate to closest point.
49
+
47
50
  if (seriesOrder === undefined || series === undefined) {
48
51
  // If there is no scatter chart series
49
52
  return;
@@ -77,81 +80,122 @@ function ChartsVoronoiHandler(props) {
77
80
  if (element === null) {
78
81
  return undefined;
79
82
  }
80
- var handleMouseOut = function handleMouseOut() {
81
- dispatch({
82
- type: 'exitChart'
83
- });
84
- };
85
83
 
86
84
  // TODO: A perf optimisation of voronoi could be to use the last point as the intial point for the next search.
87
- var handleMouseMove = function handleMouseMove(event) {
85
+ function getClosestPoint(event) {
88
86
  var _voronoiRef$current$d;
89
87
  // Get mouse coordinate in global SVG space
90
88
  var svgPoint = getSVGPoint(svgRef.current, event);
91
89
  var outsideX = svgPoint.x < left || svgPoint.x > left + width;
92
90
  var outsideY = svgPoint.y < top || svgPoint.y > top + height;
93
91
  if (outsideX || outsideY) {
94
- dispatch({
95
- type: 'exitChart'
96
- });
97
- return;
92
+ return 'outside-chart';
98
93
  }
99
94
  if (!voronoiRef.current.delauney) {
100
- return;
95
+ return 'no-point-found';
101
96
  }
102
97
  var closestPointIndex = (_voronoiRef$current$d = voronoiRef.current.delauney) == null ? void 0 : _voronoiRef$current$d.find(svgPoint.x, svgPoint.y);
103
- if (closestPointIndex !== undefined) {
104
- var seriesId = Object.keys(voronoiRef.current).find(function (id) {
105
- if (id === 'delauney') {
106
- return false;
107
- }
108
- return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
109
- });
110
- if (seriesId === undefined) {
111
- return;
98
+ if (closestPointIndex === undefined) {
99
+ return 'no-point-found';
100
+ }
101
+ var seriesId = Object.keys(voronoiRef.current).find(function (id) {
102
+ if (id === 'delauney') {
103
+ return false;
112
104
  }
113
- var dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
114
- if (voronoiMaxRadius !== undefined) {
115
- var pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
116
- var pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
117
- var dist2 = Math.pow(pointX - svgPoint.x, 2) + Math.pow(pointY - svgPoint.y, 2);
118
- if (dist2 > Math.pow(voronoiMaxRadius, 2)) {
119
- // The closest point is too far to be considered.
120
- dispatch({
121
- type: 'leaveItem',
122
- data: {
123
- type: 'scatter',
124
- seriesId: seriesId,
125
- dataIndex: dataIndex
126
- }
127
- });
128
- return;
129
- }
105
+ return 2 * closestPointIndex >= voronoiRef.current[id].startIndex && 2 * closestPointIndex < voronoiRef.current[id].endIndex;
106
+ });
107
+ if (seriesId === undefined) {
108
+ return 'no-point-found';
109
+ }
110
+ var dataIndex = (2 * closestPointIndex - voronoiRef.current[seriesId].startIndex) / 2;
111
+ if (voronoiMaxRadius !== undefined) {
112
+ var pointX = voronoiRef.current.delauney.points[2 * closestPointIndex];
113
+ var pointY = voronoiRef.current.delauney.points[2 * closestPointIndex + 1];
114
+ var dist2 = Math.pow(pointX - svgPoint.x, 2) + Math.pow(pointY - svgPoint.y, 2);
115
+ if (dist2 > Math.pow(voronoiMaxRadius, 2)) {
116
+ // The closest point is too far to be considered.
117
+ return 'outside-voronoi-max-radius';
130
118
  }
119
+ }
120
+ return {
121
+ seriesId: seriesId,
122
+ dataIndex: dataIndex
123
+ };
124
+ }
125
+ var handleMouseOut = function handleMouseOut() {
126
+ dispatch({
127
+ type: 'exitChart'
128
+ });
129
+ };
130
+ var handleMouseMove = function handleMouseMove(event) {
131
+ var closestPoint = getClosestPoint(event);
132
+ if (closestPoint === 'outside-chart') {
131
133
  dispatch({
132
- type: 'enterItem',
134
+ type: 'exitChart'
135
+ });
136
+ return;
137
+ }
138
+ if (closestPoint === 'outside-voronoi-max-radius' || closestPoint === 'no-point-found') {
139
+ dispatch({
140
+ type: 'leaveItem',
133
141
  data: {
134
- type: 'scatter',
135
- seriesId: seriesId,
136
- dataIndex: dataIndex
142
+ type: 'scatter'
137
143
  }
138
144
  });
145
+ return;
146
+ }
147
+ var seriesId = closestPoint.seriesId,
148
+ dataIndex = closestPoint.dataIndex;
149
+ dispatch({
150
+ type: 'enterItem',
151
+ data: {
152
+ type: 'scatter',
153
+ seriesId: seriesId,
154
+ dataIndex: dataIndex
155
+ }
156
+ });
157
+ };
158
+ var handleMouseClick = function handleMouseClick(event) {
159
+ if (!onItemClick) {
160
+ return;
139
161
  }
162
+ var closestPoint = getClosestPoint(event);
163
+ if (typeof closestPoint === 'string') {
164
+ // No point fond for any reason
165
+ return;
166
+ }
167
+ var seriesId = closestPoint.seriesId,
168
+ dataIndex = closestPoint.dataIndex;
169
+ onItemClick(event, {
170
+ type: 'scatter',
171
+ seriesId: seriesId,
172
+ dataIndex: dataIndex
173
+ });
140
174
  };
141
175
  element.addEventListener('mouseout', handleMouseOut);
142
176
  element.addEventListener('mousemove', handleMouseMove);
177
+ element.addEventListener('click', handleMouseClick);
143
178
  return function () {
144
179
  element.removeEventListener('mouseout', handleMouseOut);
145
180
  element.removeEventListener('mousemove', handleMouseMove);
181
+ element.removeEventListener('click', handleMouseClick);
146
182
  };
147
- }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius]);
148
- return /*#__PURE__*/_jsx("g", {}); // Workaround to fix docs scripts
183
+ }, [svgRef, dispatch, left, width, top, height, yAxis, xAxis, voronoiMaxRadius, onItemClick]);
184
+
185
+ // eslint-disable-next-line react/jsx-no-useless-fragment
186
+ return /*#__PURE__*/_jsx(React.Fragment, {});
149
187
  }
150
188
  process.env.NODE_ENV !== "production" ? ChartsVoronoiHandler.propTypes = {
151
189
  // ----------------------------- Warning --------------------------------
152
190
  // | These PropTypes are generated from the TypeScript type definitions |
153
191
  // | To update them edit the TypeScript types and run "yarn proptypes" |
154
192
  // ----------------------------------------------------------------------
193
+ /**
194
+ * Callback fired when clicking on a scatter item.
195
+ * @param {MouseEvent} event Mouse event catched at the svg level
196
+ * @param {ScatterItemIdentifier} scatterItemIdentifier Identify whihc item got clicked
197
+ */
198
+ onItemClick: PropTypes.func,
155
199
  /**
156
200
  * Defines the maximal distance between a scatter point and the pointer that triggers the interaction.
157
201
  * If `undefined`, the radius is assumed to be infinite.
@@ -0,0 +1,102 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["d", "skipAnimation", "ownerState"];
4
+ import * as React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import { styled } from '@mui/material/styles';
7
+ import { color as d3Color } from 'd3-color';
8
+ import { animated, useSpring } from '@react-spring/web';
9
+ import { useAnimatedPath } from '../internals/useAnimatedPath';
10
+ import { DrawingContext } from '../context/DrawingProvider';
11
+ import { cleanId } from '../internals/utils';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ export var AreaElementPath = styled(animated.path, {
15
+ name: 'MuiAreaElement',
16
+ slot: 'Root',
17
+ overridesResolver: function overridesResolver(_, styles) {
18
+ return styles.root;
19
+ }
20
+ })(function (_ref) {
21
+ var ownerState = _ref.ownerState;
22
+ return {
23
+ stroke: 'none',
24
+ fill: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(1).formatHex() : d3Color(ownerState.color).brighter(0.5).formatHex(),
25
+ transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
26
+ opacity: ownerState.isFaded ? 0.3 : 1
27
+ };
28
+ });
29
+ /**
30
+ * Demos:
31
+ *
32
+ * - [Lines](https://mui.com/x/react-charts/lines/)
33
+ * - [Areas demonstration](https://mui.com/x/react-charts/areas-demo/)
34
+ *
35
+ * API:
36
+ *
37
+ * - [AreaElement API](https://mui.com/x/api/charts/animated-area/)
38
+ */
39
+ function AnimatedArea(props) {
40
+ var d = props.d,
41
+ skipAnimation = props.skipAnimation,
42
+ ownerState = props.ownerState,
43
+ other = _objectWithoutProperties(props, _excluded);
44
+ var _React$useContext = React.useContext(DrawingContext),
45
+ left = _React$useContext.left,
46
+ top = _React$useContext.top,
47
+ right = _React$useContext.right,
48
+ bottom = _React$useContext.bottom,
49
+ width = _React$useContext.width,
50
+ height = _React$useContext.height,
51
+ chartId = _React$useContext.chartId;
52
+ var path = useAnimatedPath(d, skipAnimation);
53
+ var _useSpring = useSpring({
54
+ from: {
55
+ animatedWidth: left
56
+ },
57
+ to: {
58
+ animatedWidth: width + left + right
59
+ },
60
+ reset: false,
61
+ immediate: skipAnimation
62
+ }),
63
+ animatedWidth = _useSpring.animatedWidth;
64
+ var clipId = cleanId("".concat(chartId, "-").concat(ownerState.id, "-area-clip"));
65
+ return /*#__PURE__*/_jsxs(React.Fragment, {
66
+ children: [/*#__PURE__*/_jsx("clipPath", {
67
+ id: clipId,
68
+ children: /*#__PURE__*/_jsx(animated.rect, {
69
+ x: 0,
70
+ y: 0,
71
+ width: animatedWidth,
72
+ height: top + height + bottom
73
+ })
74
+ }), /*#__PURE__*/_jsx("g", {
75
+ clipPath: "url(#".concat(clipId, ")"),
76
+ children: /*#__PURE__*/_jsx(AreaElementPath, _extends({}, other, {
77
+ ownerState: ownerState,
78
+ d: path
79
+ }))
80
+ })]
81
+ });
82
+ }
83
+ process.env.NODE_ENV !== "production" ? AnimatedArea.propTypes = {
84
+ // ----------------------------- Warning --------------------------------
85
+ // | These PropTypes are generated from the TypeScript type definitions |
86
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
87
+ // ----------------------------------------------------------------------
88
+ d: PropTypes.string.isRequired,
89
+ ownerState: PropTypes.shape({
90
+ classes: PropTypes.object,
91
+ color: PropTypes.string.isRequired,
92
+ id: PropTypes.string.isRequired,
93
+ isFaded: PropTypes.bool.isRequired,
94
+ isHighlighted: PropTypes.bool.isRequired
95
+ }).isRequired,
96
+ /**
97
+ * If `true`, animations are skipped.
98
+ * @default false
99
+ */
100
+ skipAnimation: PropTypes.bool
101
+ } : void 0;
102
+ export { AnimatedArea };
@@ -0,0 +1,104 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["d", "skipAnimation", "ownerState"];
4
+ import * as React from 'react';
5
+ import PropTypes from 'prop-types';
6
+ import { animated, useSpring } from '@react-spring/web';
7
+ import { color as d3Color } from 'd3-color';
8
+ import { styled } from '@mui/material/styles';
9
+ import { useAnimatedPath } from '../internals/useAnimatedPath';
10
+ import { DrawingContext } from '../context/DrawingProvider';
11
+ import { cleanId } from '../internals/utils';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { jsxs as _jsxs } from "react/jsx-runtime";
14
+ export var LineElementPath = styled(animated.path, {
15
+ name: 'MuiLineElement',
16
+ slot: 'Root',
17
+ overridesResolver: function overridesResolver(_, styles) {
18
+ return styles.root;
19
+ }
20
+ })(function (_ref) {
21
+ var ownerState = _ref.ownerState;
22
+ return {
23
+ strokeWidth: 2,
24
+ strokeLinejoin: 'round',
25
+ fill: 'none',
26
+ stroke: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(0.5).formatHex() : ownerState.color,
27
+ transition: 'opacity 0.2s ease-in, stroke 0.2s ease-in',
28
+ opacity: ownerState.isFaded ? 0.3 : 1
29
+ };
30
+ });
31
+ /**
32
+ * Demos:
33
+ *
34
+ * - [Lines](https://mui.com/x/react-charts/lines/)
35
+ * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
36
+ *
37
+ * API:
38
+ *
39
+ * - [AnimatedLine API](https://mui.com/x/api/charts/animated-line/)
40
+ */
41
+ function AnimatedLine(props) {
42
+ var d = props.d,
43
+ skipAnimation = props.skipAnimation,
44
+ ownerState = props.ownerState,
45
+ other = _objectWithoutProperties(props, _excluded);
46
+ var _React$useContext = React.useContext(DrawingContext),
47
+ left = _React$useContext.left,
48
+ top = _React$useContext.top,
49
+ bottom = _React$useContext.bottom,
50
+ width = _React$useContext.width,
51
+ height = _React$useContext.height,
52
+ right = _React$useContext.right,
53
+ chartId = _React$useContext.chartId;
54
+ var path = useAnimatedPath(d, skipAnimation);
55
+ var _useSpring = useSpring({
56
+ from: {
57
+ animatedWidth: left
58
+ },
59
+ to: {
60
+ animatedWidth: width + left + right
61
+ },
62
+ reset: false,
63
+ immediate: skipAnimation
64
+ }),
65
+ animatedWidth = _useSpring.animatedWidth;
66
+ var clipId = cleanId("".concat(chartId, "-").concat(ownerState.id, "-line-clip"));
67
+ return /*#__PURE__*/_jsxs(React.Fragment, {
68
+ children: [/*#__PURE__*/_jsx("clipPath", {
69
+ id: clipId,
70
+ children: /*#__PURE__*/_jsx(animated.rect, {
71
+ x: 0,
72
+ y: 0,
73
+ width: animatedWidth,
74
+ height: top + height + bottom
75
+ })
76
+ }), /*#__PURE__*/_jsx("g", {
77
+ clipPath: "url(#".concat(clipId, ")"),
78
+ children: /*#__PURE__*/_jsx(LineElementPath, _extends({}, other, {
79
+ ownerState: ownerState,
80
+ d: path
81
+ }))
82
+ })]
83
+ });
84
+ }
85
+ process.env.NODE_ENV !== "production" ? AnimatedLine.propTypes = {
86
+ // ----------------------------- Warning --------------------------------
87
+ // | These PropTypes are generated from the TypeScript type definitions |
88
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
89
+ // ----------------------------------------------------------------------
90
+ d: PropTypes.string.isRequired,
91
+ ownerState: PropTypes.shape({
92
+ classes: PropTypes.object,
93
+ color: PropTypes.string.isRequired,
94
+ id: PropTypes.string.isRequired,
95
+ isFaded: PropTypes.bool.isRequired,
96
+ isHighlighted: PropTypes.bool.isRequired
97
+ }).isRequired,
98
+ /**
99
+ * If `true`, animations are skipped.
100
+ * @default false
101
+ */
102
+ skipAnimation: PropTypes.bool
103
+ } : void 0;
104
+ export { AnimatedLine };