@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
@@ -13,6 +13,7 @@ import { ChartsLegend } from '../ChartsLegend';
13
13
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
14
14
  import { ChartsClipPath } from '../ChartsClipPath';
15
15
  import { LineHighlightPlot } from './LineHighlightPlot';
16
+ import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
16
17
  import { jsx as _jsx } from "react/jsx-runtime";
17
18
  import { jsxs as _jsxs } from "react/jsx-runtime";
18
19
  /**
@@ -37,6 +38,10 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
37
38
  dataset,
38
39
  sx,
39
40
  tooltip,
41
+ onAxisClick,
42
+ onAreaClick,
43
+ onLineClick,
44
+ onMarkClick,
40
45
  axisHighlight = {
41
46
  x: 'line'
42
47
  },
@@ -48,7 +53,8 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
48
53
  bottomAxis,
49
54
  children,
50
55
  slots,
51
- slotProps
56
+ slotProps,
57
+ skipAnimation
52
58
  } = props;
53
59
  const id = useId();
54
60
  const clipPathId = `${id}-clip-path`;
@@ -72,15 +78,21 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
72
78
  colors: colors,
73
79
  dataset: dataset,
74
80
  sx: sx,
75
- disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
76
- children: [/*#__PURE__*/_jsxs("g", {
81
+ disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
82
+ children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
83
+ onAxisClick: onAxisClick
84
+ }), /*#__PURE__*/_jsxs("g", {
77
85
  clipPath: `url(#${clipPathId})`,
78
86
  children: [/*#__PURE__*/_jsx(AreaPlot, {
79
87
  slots: slots,
80
- slotProps: slotProps
88
+ slotProps: slotProps,
89
+ onItemClick: onAreaClick,
90
+ skipAnimation: skipAnimation
81
91
  }), /*#__PURE__*/_jsx(LinePlot, {
82
92
  slots: slots,
83
- slotProps: slotProps
93
+ slotProps: slotProps,
94
+ onItemClick: onLineClick,
95
+ skipAnimation: skipAnimation
84
96
  })]
85
97
  }), /*#__PURE__*/_jsx(ChartsAxis, {
86
98
  topAxis: topAxis,
@@ -91,7 +103,9 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
91
103
  slotProps: slotProps
92
104
  }), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(MarkPlot, {
93
105
  slots: slots,
94
- slotProps: slotProps
106
+ slotProps: slotProps,
107
+ onItemClick: onMarkClick,
108
+ skipAnimation: skipAnimation
95
109
  }), /*#__PURE__*/_jsx(LineHighlightPlot, {
96
110
  slots: slots,
97
111
  slotProps: slotProps
@@ -230,6 +244,16 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
230
244
  right: PropTypes.number,
231
245
  top: PropTypes.number
232
246
  }),
247
+ onAreaClick: PropTypes.func,
248
+ /**
249
+ * The function called for onClick events.
250
+ * The second argument contains information about all line/bar elements at the current mouse position.
251
+ * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
252
+ * @param {null | AxisData} data The data about the clicked axis and items associated with it.
253
+ */
254
+ onAxisClick: PropTypes.func,
255
+ onLineClick: PropTypes.func,
256
+ onMarkClick: PropTypes.func,
233
257
  /**
234
258
  * Indicate which axis to display the right of the charts.
235
259
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -258,6 +282,11 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
258
282
  tickSize: PropTypes.number
259
283
  }), PropTypes.string]),
260
284
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
285
+ /**
286
+ * If `true`, animations are skipped.
287
+ * @default false
288
+ */
289
+ skipAnimation: PropTypes.bool,
261
290
  /**
262
291
  * The props used for each component slot.
263
292
  * @default {}
@@ -1,16 +1,15 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps"];
3
+ const _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps", "onClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import { color as d3Color } from 'd3-color';
7
6
  import composeClasses from '@mui/utils/composeClasses';
8
7
  import { useSlotProps } from '@mui/base/utils';
9
8
  import generateUtilityClass from '@mui/utils/generateUtilityClass';
10
- import { styled } from '@mui/material/styles';
11
9
  import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
12
10
  import { InteractionContext } from '../context/InteractionProvider';
13
11
  import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
12
+ import { AnimatedLine } from './AnimatedLine';
14
13
  import { jsx as _jsx } from "react/jsx-runtime";
15
14
  export function getLineElementUtilityClass(slot) {
16
15
  return generateUtilityClass('MuiLineElement', slot);
@@ -28,35 +27,6 @@ const useUtilityClasses = ownerState => {
28
27
  };
29
28
  return composeClasses(slots, getLineElementUtilityClass, classes);
30
29
  };
31
- export const LineElementPath = styled('path', {
32
- name: 'MuiLineElement',
33
- slot: 'Root',
34
- overridesResolver: (_, styles) => styles.root
35
- })(({
36
- ownerState
37
- }) => ({
38
- strokeWidth: 2,
39
- strokeLinejoin: 'round',
40
- fill: 'none',
41
- stroke: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(0.5).formatHex() : ownerState.color,
42
- transition: 'opacity 0.2s ease-in, stroke 0.2s ease-in',
43
- opacity: ownerState.isFaded ? 0.3 : 1
44
- }));
45
- LineElementPath.propTypes = {
46
- // ----------------------------- Warning --------------------------------
47
- // | These PropTypes are generated from the TypeScript type definitions |
48
- // | To update them edit the TypeScript types and run "yarn proptypes" |
49
- // ----------------------------------------------------------------------
50
- as: PropTypes.elementType,
51
- ownerState: PropTypes.shape({
52
- classes: PropTypes.object,
53
- color: PropTypes.string.isRequired,
54
- id: PropTypes.string.isRequired,
55
- isFaded: PropTypes.bool.isRequired,
56
- isHighlighted: PropTypes.bool.isRequired
57
- }).isRequired,
58
- sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
59
- };
60
30
  /**
61
31
  * Demos:
62
32
  *
@@ -74,7 +44,8 @@ function LineElement(props) {
74
44
  color,
75
45
  highlightScope,
76
46
  slots,
77
- slotProps
47
+ slotProps,
48
+ onClick
78
49
  } = props,
79
50
  other = _objectWithoutPropertiesLoose(props, _excluded);
80
51
  const getInteractionItemProps = useInteractionItemProps(highlightScope);
@@ -97,7 +68,7 @@ function LineElement(props) {
97
68
  isHighlighted
98
69
  };
99
70
  const classes = useUtilityClasses(ownerState);
100
- const Line = slots?.line ?? LineElementPath;
71
+ const Line = slots?.line ?? AnimatedLine;
101
72
  const lineProps = useSlotProps({
102
73
  elementType: Line,
103
74
  externalSlotProps: slotProps?.line,
@@ -105,7 +76,9 @@ function LineElement(props) {
105
76
  type: 'line',
106
77
  seriesId: id
107
78
  }), {
108
- className: classes.root
79
+ className: classes.root,
80
+ onClick,
81
+ cursor: onClick ? 'pointer' : 'unset'
109
82
  }),
110
83
  ownerState
111
84
  });
@@ -117,10 +90,18 @@ process.env.NODE_ENV !== "production" ? LineElement.propTypes = {
117
90
  // | To update them edit the TypeScript types and run "yarn proptypes" |
118
91
  // ----------------------------------------------------------------------
119
92
  classes: PropTypes.object,
93
+ color: PropTypes.string.isRequired,
94
+ d: PropTypes.string.isRequired,
120
95
  highlightScope: PropTypes.shape({
121
96
  faded: PropTypes.oneOf(['global', 'none', 'series']),
122
97
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
123
98
  }),
99
+ id: PropTypes.string.isRequired,
100
+ /**
101
+ * If `true`, animations are skipped.
102
+ * @default false
103
+ */
104
+ skipAnimation: PropTypes.bool,
124
105
  /**
125
106
  * The props used for each component slot.
126
107
  * @default {}
@@ -60,13 +60,14 @@ function LineHighlightElement(props) {
60
60
  y
61
61
  };
62
62
  const classes = useUtilityClasses(ownerState);
63
- return /*#__PURE__*/_jsx(HighlightElement, _extends({}, other, {
63
+ return /*#__PURE__*/_jsx(HighlightElement, _extends({
64
+ pointerEvents: "none",
64
65
  ownerState: ownerState,
65
66
  className: classes.root,
66
67
  cx: 0,
67
68
  cy: 0,
68
69
  r: other.r === undefined ? 5 : other.r
69
- }));
70
+ }, other));
70
71
  }
71
72
  process.env.NODE_ENV !== "production" ? LineHighlightElement.propTypes = {
72
73
  // ----------------------------- Warning --------------------------------
@@ -1,6 +1,6 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["slots", "slotProps"];
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { line as d3Line } from 'd3-shape';
@@ -11,26 +11,11 @@ import { getValueToPositionMapper } from '../hooks/useScale';
11
11
  import getCurveFactory from '../internals/getCurve';
12
12
  import { DEFAULT_X_AXIS_KEY } from '../constants';
13
13
  import { jsx as _jsx } from "react/jsx-runtime";
14
- /**
15
- * Demos:
16
- *
17
- * - [Lines](https://mui.com/x/react-charts/lines/)
18
- * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
19
- *
20
- * API:
21
- *
22
- * - [LinePlot API](https://mui.com/x/api/charts/line-plot/)
23
- */
24
- function LinePlot(props) {
25
- const {
26
- slots,
27
- slotProps
28
- } = props,
29
- other = _objectWithoutPropertiesLoose(props, _excluded);
14
+ const useAggregatedData = () => {
30
15
  const seriesData = React.useContext(SeriesContext).line;
31
16
  const axisData = React.useContext(CartesianContext);
32
17
  if (seriesData === undefined) {
33
- return null;
18
+ return [];
34
19
  }
35
20
  const {
36
21
  series,
@@ -44,45 +29,82 @@ function LinePlot(props) {
44
29
  } = axisData;
45
30
  const defaultXAxisId = xAxisIds[0];
46
31
  const defaultYAxisId = yAxisIds[0];
47
- return /*#__PURE__*/_jsx("g", _extends({}, other, {
48
- children: stackingGroups.flatMap(({
49
- ids: groupIds
50
- }) => {
51
- return groupIds.flatMap(seriesId => {
52
- const {
53
- xAxisKey = defaultXAxisId,
54
- yAxisKey = defaultYAxisId,
55
- stackedData,
56
- data,
57
- connectNulls
58
- } = series[seriesId];
59
- const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
60
- const yScale = yAxis[yAxisKey].scale;
61
- const xData = xAxis[xAxisKey].data;
62
- if (process.env.NODE_ENV !== 'production') {
63
- if (xData === undefined) {
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.`);
65
- }
66
- if (xData.length < stackedData.length) {
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).`);
68
- }
32
+ return stackingGroups.flatMap(({
33
+ ids: groupIds
34
+ }) => {
35
+ return groupIds.flatMap(seriesId => {
36
+ const {
37
+ xAxisKey = defaultXAxisId,
38
+ yAxisKey = defaultYAxisId,
39
+ stackedData,
40
+ data,
41
+ connectNulls
42
+ } = series[seriesId];
43
+ const xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
44
+ const yScale = yAxis[yAxisKey].scale;
45
+ const xData = xAxis[xAxisKey].data;
46
+ if (process.env.NODE_ENV !== 'production') {
47
+ if (xData === undefined) {
48
+ 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.`);
69
49
  }
70
- const linePath = d3Line().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y(d => yScale(d.y[1]));
71
- const curve = getCurveFactory(series[seriesId].curve);
72
- const formattedData = xData?.map((x, index) => ({
73
- x,
74
- y: stackedData[index]
75
- })) ?? [];
76
- const d3Data = connectNulls ? formattedData.filter((_, i) => data[i] != null) : formattedData;
77
- return /*#__PURE__*/_jsx(LineElement, {
78
- id: seriesId,
79
- d: linePath.curve(curve)(d3Data) || undefined,
80
- color: series[seriesId].color,
81
- highlightScope: series[seriesId].highlightScope,
82
- slots: slots,
83
- slotProps: slotProps
84
- }, seriesId);
50
+ if (xData.length < stackedData.length) {
51
+ 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).`);
52
+ }
53
+ }
54
+ const linePath = d3Line().x(d => xScale(d.x)).defined((_, i) => connectNulls || data[i] != null).y(d => yScale(d.y[1]));
55
+ const formattedData = xData?.map((x, index) => ({
56
+ x,
57
+ y: stackedData[index]
58
+ })) ?? [];
59
+ const d3Data = connectNulls ? formattedData.filter((_, i) => data[i] != null) : formattedData;
60
+ const d = linePath.curve(getCurveFactory(series[seriesId].curve))(d3Data) || '';
61
+ return _extends({}, series[seriesId], {
62
+ d,
63
+ seriesId
85
64
  });
65
+ });
66
+ });
67
+ };
68
+
69
+ /**
70
+ * Demos:
71
+ *
72
+ * - [Lines](https://mui.com/x/react-charts/lines/)
73
+ * - [Line demonstration](https://mui.com/x/react-charts/line-demo/)
74
+ *
75
+ * API:
76
+ *
77
+ * - [LinePlot API](https://mui.com/x/api/charts/line-plot/)
78
+ */
79
+ function LinePlot(props) {
80
+ const {
81
+ slots,
82
+ slotProps,
83
+ skipAnimation,
84
+ onItemClick
85
+ } = props,
86
+ other = _objectWithoutPropertiesLoose(props, _excluded);
87
+ const completedData = useAggregatedData();
88
+ return /*#__PURE__*/_jsx("g", _extends({}, other, {
89
+ children: completedData.map(({
90
+ d,
91
+ seriesId,
92
+ color,
93
+ highlightScope
94
+ }) => {
95
+ return /*#__PURE__*/_jsx(LineElement, {
96
+ id: seriesId,
97
+ d: d,
98
+ color: color,
99
+ highlightScope: highlightScope,
100
+ skipAnimation: skipAnimation,
101
+ slots: slots,
102
+ slotProps: slotProps,
103
+ onClick: onItemClick && (event => onItemClick(event, {
104
+ type: 'line',
105
+ seriesId
106
+ }))
107
+ }, seriesId);
86
108
  })
87
109
  }));
88
110
  }
@@ -91,6 +113,17 @@ process.env.NODE_ENV !== "production" ? LinePlot.propTypes = {
91
113
  // | These PropTypes are generated from the TypeScript type definitions |
92
114
  // | To update them edit the TypeScript types and run "yarn proptypes" |
93
115
  // ----------------------------------------------------------------------
116
+ /**
117
+ * Callback fired when a line item is clicked.
118
+ * @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
119
+ * @param {LineItemIdentifier} lineItemIdentifier The line item identifier.
120
+ */
121
+ onItemClick: PropTypes.func,
122
+ /**
123
+ * If `true`, animations are skipped.
124
+ * @default false
125
+ */
126
+ skipAnimation: PropTypes.bool,
94
127
  /**
95
128
  * The props used for each component slot.
96
129
  * @default {}
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["x", "y", "id", "classes", "color", "shape", "dataIndex", "highlightScope"];
3
+ const _excluded = ["x", "y", "id", "classes", "color", "shape", "dataIndex", "highlightScope", "onClick", "skipAnimation"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
@@ -8,6 +8,7 @@ import generateUtilityClass from '@mui/utils/generateUtilityClass';
8
8
  import { styled } from '@mui/material/styles';
9
9
  import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
10
10
  import { symbol as d3Symbol, symbolsFill as d3SymbolsFill } from 'd3-shape';
11
+ import { animated, to, useSpring } from '@react-spring/web';
11
12
  import { getSymbol } from '../internals/utils';
12
13
  import { InteractionContext } from '../context/InteractionProvider';
13
14
  import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
@@ -28,7 +29,7 @@ const useUtilityClasses = ownerState => {
28
29
  };
29
30
  return composeClasses(slots, getMarkElementUtilityClass, classes);
30
31
  };
31
- const MarkElementPath = styled('path', {
32
+ const MarkElementPath = styled(animated.path, {
32
33
  name: 'MuiMarkElement',
33
34
  slot: 'Root',
34
35
  overridesResolver: (_, styles) => styles.root
@@ -36,8 +37,6 @@ const MarkElementPath = styled('path', {
36
37
  ownerState,
37
38
  theme
38
39
  }) => ({
39
- transform: `translate(${ownerState.x}px, ${ownerState.y}px)`,
40
- transformOrigin: `${ownerState.x}px ${ownerState.y}px`,
41
40
  fill: (theme.vars || theme).palette.background.paper,
42
41
  stroke: ownerState.color,
43
42
  strokeWidth: 2
@@ -53,9 +52,7 @@ MarkElementPath.propTypes = {
53
52
  color: PropTypes.string.isRequired,
54
53
  id: PropTypes.string.isRequired,
55
54
  isFaded: PropTypes.bool.isRequired,
56
- isHighlighted: PropTypes.bool.isRequired,
57
- x: PropTypes.number.isRequired,
58
- y: PropTypes.number.isRequired
55
+ isHighlighted: PropTypes.bool.isRequired
59
56
  }).isRequired,
60
57
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
61
58
  };
@@ -78,7 +75,9 @@ function MarkElement(props) {
78
75
  color,
79
76
  shape,
80
77
  dataIndex,
81
- highlightScope
78
+ highlightScope,
79
+ onClick,
80
+ skipAnimation
82
81
  } = props,
83
82
  other = _objectWithoutPropertiesLoose(props, _excluded);
84
83
  const getInteractionItemProps = useInteractionItemProps(highlightScope);
@@ -94,20 +93,29 @@ function MarkElement(props) {
94
93
  type: 'line',
95
94
  seriesId: id
96
95
  }, highlightScope);
96
+ const position = useSpring({
97
+ x,
98
+ y,
99
+ immediate: skipAnimation
100
+ });
97
101
  const ownerState = {
98
102
  id,
99
103
  classes: innerClasses,
100
104
  isHighlighted,
101
105
  isFaded,
102
- color,
103
- x,
104
- y
106
+ color
105
107
  };
106
108
  const classes = useUtilityClasses(ownerState);
107
109
  return /*#__PURE__*/_jsx(MarkElementPath, _extends({}, other, {
110
+ style: {
111
+ transform: to([position.x, position.y], (pX, pY) => `translate(${pX}px, ${pY}px)`),
112
+ transformOrigin: to([position.x, position.y], (pX, pY) => `${pX}px ${pY}px`)
113
+ },
108
114
  ownerState: ownerState,
109
115
  className: classes.root,
110
- d: d3Symbol(d3SymbolsFill[getSymbol(shape)])()
116
+ d: d3Symbol(d3SymbolsFill[getSymbol(shape)])(),
117
+ onClick: onClick,
118
+ cursor: onClick ? 'pointer' : 'unset'
111
119
  }, getInteractionItemProps({
112
120
  type: 'line',
113
121
  seriesId: id,
@@ -131,6 +139,11 @@ process.env.NODE_ENV !== "production" ? MarkElement.propTypes = {
131
139
  /**
132
140
  * The shape of the marker.
133
141
  */
134
- shape: PropTypes.oneOf(['circle', 'cross', 'diamond', 'square', 'star', 'triangle', 'wye']).isRequired
142
+ shape: PropTypes.oneOf(['circle', 'cross', 'diamond', 'square', 'star', 'triangle', 'wye']).isRequired,
143
+ /**
144
+ * If `true`, animations are skipped.
145
+ * @default false
146
+ */
147
+ skipAnimation: PropTypes.bool
135
148
  } : void 0;
136
149
  export { MarkElement };
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["slots", "slotProps"];
3
+ const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { SeriesContext } from '../context/SeriesContextProvider';
@@ -8,6 +8,8 @@ import { CartesianContext } from '../context/CartesianContextProvider';
8
8
  import { MarkElement } from './MarkElement';
9
9
  import { getValueToPositionMapper } from '../hooks/useScale';
10
10
  import { DEFAULT_X_AXIS_KEY } from '../constants';
11
+ import { DrawingContext } from '../context/DrawingProvider';
12
+ import { cleanId } from '../internals/utils';
11
13
  import { jsx as _jsx } from "react/jsx-runtime";
12
14
  /**
13
15
  * Demos:
@@ -22,11 +24,16 @@ import { jsx as _jsx } from "react/jsx-runtime";
22
24
  function MarkPlot(props) {
23
25
  const {
24
26
  slots,
25
- slotProps
27
+ slotProps,
28
+ skipAnimation,
29
+ onItemClick
26
30
  } = props,
27
31
  other = _objectWithoutPropertiesLoose(props, _excluded);
28
32
  const seriesData = React.useContext(SeriesContext).line;
29
33
  const axisData = React.useContext(CartesianContext);
34
+ const {
35
+ chartId
36
+ } = React.useContext(DrawingContext);
30
37
  const Mark = slots?.mark ?? MarkElement;
31
38
  if (seriesData === undefined) {
32
39
  return null;
@@ -47,7 +54,7 @@ function MarkPlot(props) {
47
54
  children: stackingGroups.flatMap(({
48
55
  ids: groupIds
49
56
  }) => {
50
- return groupIds.flatMap(seriesId => {
57
+ return groupIds.map(seriesId => {
51
58
  const {
52
59
  xAxisKey = defaultXAxisId,
53
60
  yAxisKey = defaultYAxisId,
@@ -78,59 +85,70 @@ function MarkPlot(props) {
78
85
  if (xData === undefined) {
79
86
  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.`);
80
87
  }
81
- return xData?.map((x, index) => {
82
- const value = data[index] == null ? null : stackedData[index][1];
83
- return {
84
- x: xScale(x),
85
- y: value === null ? null : yScale(value),
86
- position: x,
87
- value,
88
- index
89
- };
90
- }).filter(({
91
- x,
92
- y,
93
- index,
94
- position,
95
- value
96
- }) => {
97
- if (value === null || y === null) {
98
- // Remove missing data point
99
- return false;
100
- }
101
- if (!isInRange({
102
- x,
103
- y
104
- })) {
105
- // Remove out of range
106
- return false;
107
- }
108
- if (showMark === true) {
109
- return true;
110
- }
111
- return showMark({
88
+ const clipId = cleanId(`${chartId}-${seriesId}-line-clip`); // We assume that if displaying line mark, the line will also be rendered
89
+
90
+ return /*#__PURE__*/_jsx("g", {
91
+ clipPath: `url(#${clipId})`,
92
+ children: xData?.map((x, index) => {
93
+ const value = data[index] == null ? null : stackedData[index][1];
94
+ return {
95
+ x: xScale(x),
96
+ y: value === null ? null : yScale(value),
97
+ position: x,
98
+ value,
99
+ index
100
+ };
101
+ }).filter(({
112
102
  x,
113
103
  y,
114
104
  index,
115
105
  position,
116
106
  value
117
- });
118
- }).map(({
119
- x,
120
- y,
121
- index
122
- }) => {
123
- return /*#__PURE__*/_jsx(Mark, _extends({
124
- id: seriesId,
125
- dataIndex: index,
126
- shape: "circle",
127
- color: series[seriesId].color,
128
- x: x,
129
- y: y // Don't knwo why TS don't get from the filter that y can't be null
130
- ,
131
- highlightScope: series[seriesId].highlightScope
132
- }, slotProps?.mark), `${seriesId}-${index}`);
133
- });
107
+ }) => {
108
+ if (value === null || y === null) {
109
+ // Remove missing data point
110
+ return false;
111
+ }
112
+ if (!isInRange({
113
+ x,
114
+ y
115
+ })) {
116
+ // Remove out of range
117
+ return false;
118
+ }
119
+ if (showMark === true) {
120
+ return true;
121
+ }
122
+ return showMark({
123
+ x,
124
+ y,
125
+ index,
126
+ position,
127
+ value
128
+ });
129
+ }).map(({
130
+ x,
131
+ y,
132
+ index
133
+ }) => {
134
+ return /*#__PURE__*/_jsx(Mark, _extends({
135
+ id: seriesId,
136
+ dataIndex: index,
137
+ shape: "circle",
138
+ color: series[seriesId].color,
139
+ x: x,
140
+ y: y // Don't know why TS doesn't get from the filter that y can't be null
141
+ ,
142
+ highlightScope: series[seriesId].highlightScope,
143
+ skipAnimation: skipAnimation,
144
+ onClick: onItemClick && (event => onItemClick(event, {
145
+ type: 'line',
146
+ seriesId,
147
+ dataIndex: index
148
+ }))
149
+ }, slotProps?.mark), `${seriesId}-${index}`);
150
+ })
151
+ }, seriesId);
134
152
  });
135
153
  })
136
154
  }));
@@ -140,6 +158,17 @@ process.env.NODE_ENV !== "production" ? MarkPlot.propTypes = {
140
158
  // | These PropTypes are generated from the TypeScript type definitions |
141
159
  // | To update them edit the TypeScript types and run "yarn proptypes" |
142
160
  // ----------------------------------------------------------------------
161
+ /**
162
+ * Callback fired when a line mark item is clicked.
163
+ * @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
164
+ * @param {LineItemIdentifier} lineItemIdentifier The line mark item identifier.
165
+ */
166
+ onItemClick: PropTypes.func,
167
+ /**
168
+ * If `true`, animations are skipped.
169
+ * @default false
170
+ */
171
+ skipAnimation: PropTypes.bool,
143
172
  /**
144
173
  * The props used for each component slot.
145
174
  * @default {}