@mui/x-charts 7.0.0-beta.0 → 7.0.0-beta.2

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 (258) hide show
  1. package/BarChart/BarChart.d.ts +2 -1
  2. package/BarChart/BarChart.js +33 -12
  3. package/BarChart/BarElement.d.ts +20 -13
  4. package/BarChart/BarElement.js +7 -3
  5. package/BarChart/BarPlot.d.ts +11 -6
  6. package/BarChart/BarPlot.js +28 -15
  7. package/BarChart/formatter.js +1 -1
  8. package/CHANGELOG.md +406 -1
  9. package/ChartContainer/ChartContainer.js +6 -4
  10. package/ChartsAxis/ChartsAxis.js +4 -4
  11. package/ChartsLegend/ChartsLegend.d.ts +5 -54
  12. package/ChartsLegend/ChartsLegend.js +2 -307
  13. package/ChartsLegend/DefaultChartsLegend.d.ts +60 -0
  14. package/ChartsLegend/DefaultChartsLegend.js +294 -0
  15. package/ChartsLegend/index.d.ts +1 -0
  16. package/ChartsLegend/index.js +11 -0
  17. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +20 -0
  18. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +83 -0
  19. package/ChartsOnAxisClickHandler/index.d.ts +1 -0
  20. package/ChartsOnAxisClickHandler/index.js +16 -0
  21. package/ChartsOnAxisClickHandler/package.json +6 -0
  22. package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  23. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  24. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  25. package/ChartsReferenceLine/common.d.ts +2 -1
  26. package/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  27. package/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  28. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
  29. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  30. package/ChartsTooltip/utils.d.ts +4 -1
  31. package/ChartsTooltip/utils.js +15 -0
  32. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
  33. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  34. package/ChartsXAxis/ChartsXAxis.js +13 -9
  35. package/ChartsYAxis/ChartsYAxis.js +1 -1
  36. package/LineChart/AnimatedArea.d.ts +1361 -0
  37. package/LineChart/AnimatedArea.js +111 -0
  38. package/LineChart/AnimatedLine.d.ts +1361 -0
  39. package/LineChart/AnimatedLine.js +113 -0
  40. package/LineChart/AreaElement.d.ts +19 -18
  41. package/LineChart/AreaElement.js +17 -34
  42. package/LineChart/AreaPlot.d.ts +12 -7
  43. package/LineChart/AreaPlot.js +91 -58
  44. package/LineChart/LineChart.d.ts +13 -4
  45. package/LineChart/LineChart.js +45 -14
  46. package/LineChart/LineElement.d.ts +19 -18
  47. package/LineChart/LineElement.js +16 -36
  48. package/LineChart/LineHighlightElement.d.ts +3 -2
  49. package/LineChart/LineHighlightElement.js +5 -3
  50. package/LineChart/LinePlot.d.ts +12 -7
  51. package/LineChart/LinePlot.js +89 -56
  52. package/LineChart/MarkElement.d.ts +8 -4
  53. package/LineChart/MarkElement.js +27 -13
  54. package/LineChart/MarkPlot.d.ts +8 -1
  55. package/LineChart/MarkPlot.js +80 -51
  56. package/LineChart/formatter.js +1 -1
  57. package/LineChart/index.d.ts +2 -0
  58. package/LineChart/index.js +22 -0
  59. package/PieChart/PieArc.d.ts +3 -2
  60. package/PieChart/PieArc.js +1 -0
  61. package/PieChart/PieArcLabel.d.ts +3 -2
  62. package/PieChart/PieArcLabel.js +1 -0
  63. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  64. package/PieChart/PieArcLabelPlot.js +2 -2
  65. package/PieChart/PieArcPlot.d.ts +2 -2
  66. package/PieChart/PieArcPlot.js +7 -7
  67. package/PieChart/PieChart.d.ts +1 -1
  68. package/PieChart/PieChart.js +14 -12
  69. package/PieChart/PiePlot.d.ts +1 -1
  70. package/PieChart/PiePlot.js +4 -4
  71. package/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  72. package/ScatterChart/Scatter.d.ts +7 -1
  73. package/ScatterChart/Scatter.js +17 -3
  74. package/ScatterChart/ScatterChart.d.ts +8 -2
  75. package/ScatterChart/ScatterChart.js +21 -10
  76. package/ScatterChart/ScatterPlot.d.ts +1 -1
  77. package/ScatterChart/ScatterPlot.js +10 -2
  78. package/SparkLineChart/SparkLineChart.d.ts +1 -1
  79. package/SparkLineChart/SparkLineChart.js +7 -4
  80. package/context/CartesianContextProvider.js +8 -6
  81. package/context/DrawingProvider.d.ts +6 -1
  82. package/context/DrawingProvider.js +9 -2
  83. package/context/InteractionProvider.d.ts +3 -3
  84. package/esm/BarChart/BarChart.js +33 -12
  85. package/esm/BarChart/BarElement.js +7 -3
  86. package/esm/BarChart/BarPlot.js +27 -15
  87. package/esm/BarChart/formatter.js +1 -1
  88. package/esm/ChartContainer/ChartContainer.js +6 -4
  89. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  90. package/esm/ChartsLegend/ChartsLegend.js +2 -307
  91. package/esm/ChartsLegend/DefaultChartsLegend.js +286 -0
  92. package/esm/ChartsLegend/index.js +1 -0
  93. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
  94. package/esm/ChartsOnAxisClickHandler/index.js +1 -0
  95. package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  96. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  97. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  98. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  99. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  100. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
  101. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  102. package/esm/ChartsTooltip/utils.js +12 -0
  103. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  104. package/esm/ChartsXAxis/ChartsXAxis.js +13 -9
  105. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  106. package/esm/LineChart/AnimatedArea.js +103 -0
  107. package/esm/LineChart/AnimatedLine.js +105 -0
  108. package/esm/LineChart/AreaElement.js +16 -33
  109. package/esm/LineChart/AreaPlot.js +92 -59
  110. package/esm/LineChart/LineChart.js +45 -14
  111. package/esm/LineChart/LineElement.js +16 -35
  112. package/esm/LineChart/LineHighlightElement.js +5 -3
  113. package/esm/LineChart/LinePlot.js +90 -57
  114. package/esm/LineChart/MarkElement.js +27 -13
  115. package/esm/LineChart/MarkPlot.js +80 -51
  116. package/esm/LineChart/formatter.js +1 -1
  117. package/esm/LineChart/index.js +2 -0
  118. package/esm/PieChart/PieArc.js +1 -0
  119. package/esm/PieChart/PieArcLabel.js +1 -0
  120. package/esm/PieChart/PieArcLabelPlot.js +2 -2
  121. package/esm/PieChart/PieArcPlot.js +7 -7
  122. package/esm/PieChart/PieChart.js +14 -12
  123. package/esm/PieChart/PiePlot.js +4 -4
  124. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  125. package/esm/ScatterChart/Scatter.js +17 -3
  126. package/esm/ScatterChart/ScatterChart.js +21 -10
  127. package/esm/ScatterChart/ScatterPlot.js +10 -2
  128. package/esm/SparkLineChart/SparkLineChart.js +7 -4
  129. package/esm/context/CartesianContextProvider.js +8 -6
  130. package/esm/context/DrawingProvider.js +9 -2
  131. package/esm/hooks/useDrawingArea.js +7 -3
  132. package/esm/index.js +1 -0
  133. package/esm/internals/geometry.js +1 -1
  134. package/esm/internals/useAnimatedPath.js +29 -0
  135. package/esm/internals/utils.js +7 -0
  136. package/hooks/useDrawingArea.d.ts +2 -0
  137. package/hooks/useDrawingArea.js +7 -3
  138. package/index.d.ts +1 -0
  139. package/index.js +12 -1
  140. package/internals/defaultizeColor.d.ts +16 -16
  141. package/internals/defaultizeValueFormatter.d.ts +4 -7
  142. package/internals/geometry.js +1 -1
  143. package/internals/stackSeries.d.ts +4 -7
  144. package/internals/useAnimatedPath.d.ts +1 -0
  145. package/internals/useAnimatedPath.js +38 -0
  146. package/internals/utils.d.ts +4 -0
  147. package/internals/utils.js +8 -0
  148. package/legacy/BarChart/BarChart.js +33 -12
  149. package/legacy/BarChart/BarElement.js +6 -2
  150. package/legacy/BarChart/BarPlot.js +28 -14
  151. package/legacy/BarChart/formatter.js +1 -1
  152. package/legacy/ChartContainer/ChartContainer.js +6 -4
  153. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  154. package/legacy/ChartsLegend/ChartsLegend.js +2 -323
  155. package/legacy/ChartsLegend/DefaultChartsLegend.js +302 -0
  156. package/legacy/ChartsLegend/index.js +1 -0
  157. package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  158. package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
  159. package/legacy/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  160. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  161. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  162. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +6 -7
  163. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  164. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -5
  165. package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  166. package/legacy/ChartsTooltip/utils.js +12 -0
  167. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
  168. package/legacy/ChartsXAxis/ChartsXAxis.js +12 -8
  169. package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
  170. package/legacy/LineChart/AnimatedArea.js +102 -0
  171. package/legacy/LineChart/AnimatedLine.js +104 -0
  172. package/legacy/LineChart/AreaElement.js +15 -35
  173. package/legacy/LineChart/AreaPlot.js +102 -66
  174. package/legacy/LineChart/LineChart.js +45 -14
  175. package/legacy/LineChart/LineElement.js +15 -37
  176. package/legacy/LineChart/LineHighlightElement.js +5 -3
  177. package/legacy/LineChart/LinePlot.js +97 -63
  178. package/legacy/LineChart/MarkElement.js +30 -12
  179. package/legacy/LineChart/MarkPlot.js +83 -53
  180. package/legacy/LineChart/formatter.js +1 -1
  181. package/legacy/LineChart/index.js +2 -0
  182. package/legacy/PieChart/PieArc.js +1 -0
  183. package/legacy/PieChart/PieArcLabel.js +1 -0
  184. package/legacy/PieChart/PieArcLabelPlot.js +2 -2
  185. package/legacy/PieChart/PieArcPlot.js +7 -7
  186. package/legacy/PieChart/PieChart.js +14 -12
  187. package/legacy/PieChart/PiePlot.js +4 -4
  188. package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  189. package/legacy/ScatterChart/Scatter.js +19 -3
  190. package/legacy/ScatterChart/ScatterChart.js +21 -10
  191. package/legacy/ScatterChart/ScatterPlot.js +10 -2
  192. package/legacy/SparkLineChart/SparkLineChart.js +8 -5
  193. package/legacy/context/CartesianContextProvider.js +8 -6
  194. package/legacy/context/DrawingProvider.js +11 -2
  195. package/legacy/hooks/useDrawingArea.js +7 -3
  196. package/legacy/index.js +2 -1
  197. package/legacy/internals/geometry.js +1 -1
  198. package/legacy/internals/useAnimatedPath.js +32 -0
  199. package/legacy/internals/utils.js +7 -0
  200. package/models/axis.d.ts +7 -2
  201. package/models/seriesType/common.d.ts +2 -1
  202. package/models/seriesType/config.d.ts +7 -12
  203. package/models/seriesType/line.d.ts +2 -2
  204. package/models/seriesType/pie.d.ts +7 -3
  205. package/models/seriesType/scatter.d.ts +5 -2
  206. package/modern/BarChart/BarChart.js +33 -12
  207. package/modern/BarChart/BarElement.js +7 -3
  208. package/modern/BarChart/BarPlot.js +27 -15
  209. package/modern/BarChart/formatter.js +1 -1
  210. package/modern/ChartContainer/ChartContainer.js +6 -4
  211. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  212. package/modern/ChartsLegend/ChartsLegend.js +2 -307
  213. package/modern/ChartsLegend/DefaultChartsLegend.js +286 -0
  214. package/modern/ChartsLegend/index.js +1 -0
  215. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  216. package/modern/ChartsOnAxisClickHandler/index.js +1 -0
  217. package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
  218. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  219. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  220. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +6 -5
  221. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +2 -2
  222. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +7 -5
  223. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -1
  224. package/modern/ChartsTooltip/utils.js +12 -0
  225. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  226. package/modern/ChartsXAxis/ChartsXAxis.js +13 -9
  227. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  228. package/modern/LineChart/AnimatedArea.js +103 -0
  229. package/modern/LineChart/AnimatedLine.js +105 -0
  230. package/modern/LineChart/AreaElement.js +16 -33
  231. package/modern/LineChart/AreaPlot.js +91 -58
  232. package/modern/LineChart/LineChart.js +45 -14
  233. package/modern/LineChart/LineElement.js +16 -35
  234. package/modern/LineChart/LineHighlightElement.js +5 -3
  235. package/modern/LineChart/LinePlot.js +89 -56
  236. package/modern/LineChart/MarkElement.js +27 -13
  237. package/modern/LineChart/MarkPlot.js +80 -51
  238. package/modern/LineChart/formatter.js +1 -1
  239. package/modern/LineChart/index.js +2 -0
  240. package/modern/PieChart/PieArc.js +1 -0
  241. package/modern/PieChart/PieArcLabel.js +1 -0
  242. package/modern/PieChart/PieArcLabelPlot.js +2 -2
  243. package/modern/PieChart/PieArcPlot.js +7 -7
  244. package/modern/PieChart/PieChart.js +14 -12
  245. package/modern/PieChart/PiePlot.js +4 -4
  246. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +6 -4
  247. package/modern/ScatterChart/Scatter.js +17 -3
  248. package/modern/ScatterChart/ScatterChart.js +21 -10
  249. package/modern/ScatterChart/ScatterPlot.js +10 -2
  250. package/modern/SparkLineChart/SparkLineChart.js +7 -4
  251. package/modern/context/CartesianContextProvider.js +8 -6
  252. package/modern/context/DrawingProvider.js +9 -2
  253. package/modern/hooks/useDrawingArea.js +7 -3
  254. package/modern/index.js +2 -1
  255. package/modern/internals/geometry.js +1 -1
  256. package/modern/internals/useAnimatedPath.js +29 -0
  257. package/modern/internals/utils.js +7 -0
  258. package/package.json +6 -5
@@ -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,
@@ -128,9 +136,15 @@ process.env.NODE_ENV !== "production" ? MarkElement.propTypes = {
128
136
  faded: PropTypes.oneOf(['global', 'none', 'series']),
129
137
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
130
138
  }),
139
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
131
140
  /**
132
141
  * The shape of the marker.
133
142
  */
134
- shape: PropTypes.oneOf(['circle', 'cross', 'diamond', 'square', 'star', 'triangle', 'wye']).isRequired
143
+ shape: PropTypes.oneOf(['circle', 'cross', 'diamond', 'square', 'star', 'triangle', 'wye']).isRequired,
144
+ /**
145
+ * If `true`, animations are skipped.
146
+ * @default false
147
+ */
148
+ skipAnimation: PropTypes.bool
135
149
  } : void 0;
136
150
  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 {}
@@ -69,7 +69,7 @@ const formatter = (params, dataset) => {
69
69
  return {
70
70
  seriesOrder,
71
71
  stackingGroups,
72
- series: defaultizeValueFormatter(completedSeries, v => v === null ? '' : v.toLocaleString())
72
+ series: defaultizeValueFormatter(completedSeries, v => v == null ? '' : v.toLocaleString())
73
73
  };
74
74
  };
75
75
  export default formatter;
@@ -4,6 +4,8 @@ export * from './AreaPlot';
4
4
  export * from './MarkPlot';
5
5
  export * from './LineHighlightPlot';
6
6
  export * from './AreaElement';
7
+ export * from './AnimatedArea';
7
8
  export * from './LineElement';
9
+ export * from './AnimatedLine';
8
10
  export * from './MarkElement';
9
11
  export * from './LineHighlightElement';
@@ -95,6 +95,7 @@ process.env.NODE_ENV !== "production" ? PieArc.propTypes = {
95
95
  faded: PropTypes.oneOf(['global', 'none', 'series']),
96
96
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
97
97
  }),
98
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
98
99
  isFaded: PropTypes.bool.isRequired,
99
100
  isHighlighted: PropTypes.bool.isRequired
100
101
  } : void 0;
@@ -98,6 +98,7 @@ process.env.NODE_ENV !== "production" ? PieArcLabel.propTypes = {
98
98
  // ----------------------------------------------------------------------
99
99
  classes: PropTypes.object,
100
100
  formattedArcLabel: PropTypes.string,
101
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
101
102
  isFaded: PropTypes.bool.isRequired,
102
103
  isHighlighted: PropTypes.bool.isRequired
103
104
  } : void 0;
@@ -157,7 +157,7 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
157
157
  faded: PropTypes.oneOf(['global', 'none', 'series']),
158
158
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
159
159
  }),
160
- id: PropTypes.string.isRequired,
160
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
161
161
  /**
162
162
  * The radius between circle center and the begining of the arc.
163
163
  * @default 0
@@ -173,7 +173,7 @@ process.env.NODE_ENV !== "production" ? PieArcLabelPlot.propTypes = {
173
173
  */
174
174
  paddingAngle: PropTypes.number,
175
175
  /**
176
- * If `true`, animations are skiped.
176
+ * If `true`, animations are skipped.
177
177
  * @default false
178
178
  */
179
179
  skipAnimation: PropTypes.bool,
@@ -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", "innerRadius", "outerRadius", "cornerRadius", "paddingAngle", "id", "highlightScope", "highlighted", "faded", "data", "onClick", "skipAnimation"],
3
+ const _excluded = ["slots", "slotProps", "innerRadius", "outerRadius", "cornerRadius", "paddingAngle", "id", "highlightScope", "highlighted", "faded", "data", "onItemClick", "skipAnimation"],
4
4
  _excluded2 = ["startAngle", "endAngle", "paddingAngle", "innerRadius", "arcLabelRadius", "outerRadius", "cornerRadius"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
@@ -24,7 +24,7 @@ function PieArcPlot(props) {
24
24
  additionalRadius: -5
25
25
  },
26
26
  data,
27
- onClick,
27
+ onItemClick,
28
28
  skipAnimation
29
29
  } = props,
30
30
  other = _objectWithoutPropertiesLoose(props, _excluded);
@@ -71,8 +71,8 @@ function PieArcPlot(props) {
71
71
  highlightScope: highlightScope,
72
72
  isFaded: item.isFaded,
73
73
  isHighlighted: item.isHighlighted,
74
- onClick: onClick && (event => {
75
- onClick(event, {
74
+ onClick: onItemClick && (event => {
75
+ onItemClick(event, {
76
76
  type: 'pie',
77
77
  seriesId: id,
78
78
  dataIndex: index
@@ -137,7 +137,7 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
137
137
  faded: PropTypes.oneOf(['global', 'none', 'series']),
138
138
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
139
139
  }),
140
- id: PropTypes.string.isRequired,
140
+ id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
141
141
  /**
142
142
  * The radius between circle center and the begining of the arc.
143
143
  * @default 0
@@ -149,7 +149,7 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
149
149
  * @param {PieItemIdentifier} pieItemIdentifier The pie item identifier.
150
150
  * @param {DefaultizedPieValueType} item The pie item.
151
151
  */
152
- onClick: PropTypes.func,
152
+ onItemClick: PropTypes.func,
153
153
  /**
154
154
  * The radius between circle center and the end of the arc.
155
155
  */
@@ -160,7 +160,7 @@ process.env.NODE_ENV !== "production" ? PieArcPlot.propTypes = {
160
160
  */
161
161
  paddingAngle: PropTypes.number,
162
162
  /**
163
- * If `true`, animations are skiped.
163
+ * If `true`, animations are skipped.
164
164
  * @default false
165
165
  */
166
166
  skipAnimation: PropTypes.bool,