@mui/x-charts 7.0.0-alpha.9 → 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 (214) hide show
  1. package/BarChart/BarChart.d.ts +2 -1
  2. package/BarChart/BarChart.js +24 -23
  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 +386 -38
  9. package/ChartContainer/ChartContainer.d.ts +12 -0
  10. package/ChartContainer/ChartContainer.js +197 -0
  11. package/ChartContainer/index.d.ts +1 -11
  12. package/ChartContainer/index.js +9 -63
  13. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +20 -0
  14. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +83 -0
  15. package/ChartsOnAxisClickHandler/index.d.ts +1 -0
  16. package/ChartsOnAxisClickHandler/index.js +16 -0
  17. package/ChartsOnAxisClickHandler/package.json +6 -0
  18. package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  19. package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  20. package/ChartsTooltip/ChartsAxisTooltipContent.js +8 -59
  21. package/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  22. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -58
  23. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
  24. package/ChartsTooltip/utils.d.ts +3 -1
  25. package/ChartsTooltip/utils.js +8 -0
  26. package/ChartsVoronoiHandler/ChartsVoronoiHandler.d.ts +7 -0
  27. package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  28. package/LineChart/AnimatedArea.d.ts +1361 -0
  29. package/LineChart/AnimatedArea.js +111 -0
  30. package/LineChart/AnimatedLine.d.ts +1361 -0
  31. package/LineChart/AnimatedLine.js +113 -0
  32. package/LineChart/AreaElement.d.ts +17 -17
  33. package/LineChart/AreaElement.js +17 -34
  34. package/LineChart/AreaPlot.d.ts +12 -7
  35. package/LineChart/AreaPlot.js +91 -58
  36. package/LineChart/LineChart.d.ts +13 -4
  37. package/LineChart/LineChart.js +36 -29
  38. package/LineChart/LineElement.d.ts +17 -17
  39. package/LineChart/LineElement.js +16 -36
  40. package/LineChart/LineHighlightElement.js +3 -2
  41. package/LineChart/LinePlot.d.ts +12 -7
  42. package/LineChart/LinePlot.js +89 -56
  43. package/LineChart/MarkElement.d.ts +5 -2
  44. package/LineChart/MarkElement.js +26 -13
  45. package/LineChart/MarkPlot.d.ts +8 -1
  46. package/LineChart/MarkPlot.js +80 -51
  47. package/LineChart/formatter.js +1 -1
  48. package/LineChart/index.d.ts +2 -0
  49. package/LineChart/index.js +22 -0
  50. package/PieChart/PieArcLabelPlot.d.ts +1 -1
  51. package/PieChart/PieArcLabelPlot.js +1 -1
  52. package/PieChart/PieArcPlot.d.ts +2 -2
  53. package/PieChart/PieArcPlot.js +6 -6
  54. package/PieChart/PieChart.d.ts +1 -1
  55. package/PieChart/PieChart.js +5 -50
  56. package/PieChart/PiePlot.d.ts +1 -1
  57. package/PieChart/PiePlot.js +4 -4
  58. package/README.md +2 -2
  59. package/ResponsiveChartContainer/ResponsiveChartContainer.d.ts +16 -0
  60. package/ResponsiveChartContainer/ResponsiveChartContainer.js +250 -0
  61. package/ResponsiveChartContainer/index.d.ts +1 -15
  62. package/ResponsiveChartContainer/index.js +8 -113
  63. package/ScatterChart/Scatter.d.ts +7 -1
  64. package/ScatterChart/Scatter.js +18 -23
  65. package/ScatterChart/ScatterChart.d.ts +8 -2
  66. package/ScatterChart/ScatterChart.js +12 -22
  67. package/ScatterChart/ScatterPlot.d.ts +1 -1
  68. package/ScatterChart/ScatterPlot.js +10 -2
  69. package/SparkLineChart/SparkLineChart.js +2 -0
  70. package/context/DrawingProvider.d.ts +6 -1
  71. package/context/DrawingProvider.js +9 -2
  72. package/context/InteractionProvider.d.ts +3 -3
  73. package/esm/BarChart/BarChart.js +24 -23
  74. package/esm/BarChart/BarElement.js +6 -3
  75. package/esm/BarChart/BarPlot.js +19 -5
  76. package/esm/BarChart/formatter.js +1 -1
  77. package/esm/ChartContainer/ChartContainer.js +189 -0
  78. package/esm/ChartContainer/index.js +1 -61
  79. package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +77 -0
  80. package/esm/ChartsOnAxisClickHandler/index.js +1 -0
  81. package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  82. package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  83. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +8 -59
  84. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  85. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +9 -58
  86. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
  87. package/esm/ChartsTooltip/utils.js +6 -0
  88. package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  89. package/esm/LineChart/AnimatedArea.js +103 -0
  90. package/esm/LineChart/AnimatedLine.js +105 -0
  91. package/esm/LineChart/AreaElement.js +16 -33
  92. package/esm/LineChart/AreaPlot.js +92 -59
  93. package/esm/LineChart/LineChart.js +36 -29
  94. package/esm/LineChart/LineElement.js +16 -35
  95. package/esm/LineChart/LineHighlightElement.js +3 -2
  96. package/esm/LineChart/LinePlot.js +90 -57
  97. package/esm/LineChart/MarkElement.js +26 -13
  98. package/esm/LineChart/MarkPlot.js +80 -51
  99. package/esm/LineChart/formatter.js +1 -1
  100. package/esm/LineChart/index.js +2 -0
  101. package/esm/PieChart/PieArcLabelPlot.js +1 -1
  102. package/esm/PieChart/PieArcPlot.js +6 -6
  103. package/esm/PieChart/PieChart.js +5 -50
  104. package/esm/PieChart/PiePlot.js +4 -4
  105. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +245 -0
  106. package/esm/ResponsiveChartContainer/index.js +1 -115
  107. package/esm/ScatterChart/Scatter.js +18 -23
  108. package/esm/ScatterChart/ScatterChart.js +12 -22
  109. package/esm/ScatterChart/ScatterPlot.js +10 -2
  110. package/esm/SparkLineChart/SparkLineChart.js +2 -0
  111. package/esm/context/DrawingProvider.js +9 -2
  112. package/esm/hooks/useDrawingArea.js +7 -3
  113. package/esm/index.js +1 -0
  114. package/esm/internals/geometry.js +1 -1
  115. package/esm/internals/useAnimatedPath.js +29 -0
  116. package/esm/internals/utils.js +7 -0
  117. package/hooks/useDrawingArea.d.ts +2 -0
  118. package/hooks/useDrawingArea.js +7 -3
  119. package/index.d.ts +1 -0
  120. package/index.js +12 -1
  121. package/internals/geometry.js +1 -1
  122. package/internals/useAnimatedPath.d.ts +1 -0
  123. package/internals/useAnimatedPath.js +38 -0
  124. package/internals/utils.d.ts +4 -0
  125. package/internals/utils.js +8 -0
  126. package/legacy/BarChart/BarChart.js +24 -23
  127. package/legacy/BarChart/BarElement.js +5 -2
  128. package/legacy/BarChart/BarPlot.js +18 -4
  129. package/legacy/BarChart/formatter.js +1 -1
  130. package/legacy/ChartContainer/ChartContainer.js +187 -0
  131. package/legacy/ChartContainer/index.js +1 -59
  132. package/legacy/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  133. package/legacy/ChartsOnAxisClickHandler/index.js +1 -0
  134. package/legacy/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  135. package/legacy/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  136. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +8 -61
  137. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  138. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +9 -58
  139. package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
  140. package/legacy/ChartsTooltip/utils.js +6 -0
  141. package/legacy/ChartsVoronoiHandler/ChartsVoronoiHandler.js +88 -44
  142. package/legacy/LineChart/AnimatedArea.js +102 -0
  143. package/legacy/LineChart/AnimatedLine.js +104 -0
  144. package/legacy/LineChart/AreaElement.js +15 -35
  145. package/legacy/LineChart/AreaPlot.js +102 -66
  146. package/legacy/LineChart/LineChart.js +36 -29
  147. package/legacy/LineChart/LineElement.js +15 -37
  148. package/legacy/LineChart/LineHighlightElement.js +3 -2
  149. package/legacy/LineChart/LinePlot.js +97 -63
  150. package/legacy/LineChart/MarkElement.js +29 -12
  151. package/legacy/LineChart/MarkPlot.js +83 -53
  152. package/legacy/LineChart/formatter.js +1 -1
  153. package/legacy/LineChart/index.js +2 -0
  154. package/legacy/PieChart/PieArcLabelPlot.js +1 -1
  155. package/legacy/PieChart/PieArcPlot.js +6 -6
  156. package/legacy/PieChart/PieChart.js +5 -50
  157. package/legacy/PieChart/PiePlot.js +4 -4
  158. package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +253 -0
  159. package/legacy/ResponsiveChartContainer/index.js +1 -123
  160. package/legacy/ScatterChart/Scatter.js +20 -23
  161. package/legacy/ScatterChart/ScatterChart.js +12 -22
  162. package/legacy/ScatterChart/ScatterPlot.js +10 -2
  163. package/legacy/SparkLineChart/SparkLineChart.js +2 -0
  164. package/legacy/context/DrawingProvider.js +11 -2
  165. package/legacy/hooks/useDrawingArea.js +7 -3
  166. package/legacy/index.js +2 -1
  167. package/legacy/internals/geometry.js +1 -1
  168. package/legacy/internals/useAnimatedPath.js +32 -0
  169. package/legacy/internals/utils.js +7 -0
  170. package/modern/BarChart/BarChart.js +24 -23
  171. package/modern/BarChart/BarElement.js +6 -3
  172. package/modern/BarChart/BarPlot.js +19 -5
  173. package/modern/BarChart/formatter.js +1 -1
  174. package/modern/ChartContainer/ChartContainer.js +189 -0
  175. package/modern/ChartContainer/index.js +1 -61
  176. package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +75 -0
  177. package/modern/ChartsOnAxisClickHandler/index.js +1 -0
  178. package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +1 -1
  179. package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +1 -1
  180. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +8 -59
  181. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  182. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +8 -58
  183. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -11
  184. package/modern/ChartsTooltip/utils.js +6 -0
  185. package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +92 -44
  186. package/modern/LineChart/AnimatedArea.js +103 -0
  187. package/modern/LineChart/AnimatedLine.js +105 -0
  188. package/modern/LineChart/AreaElement.js +16 -33
  189. package/modern/LineChart/AreaPlot.js +91 -58
  190. package/modern/LineChart/LineChart.js +36 -29
  191. package/modern/LineChart/LineElement.js +16 -35
  192. package/modern/LineChart/LineHighlightElement.js +3 -2
  193. package/modern/LineChart/LinePlot.js +89 -56
  194. package/modern/LineChart/MarkElement.js +26 -13
  195. package/modern/LineChart/MarkPlot.js +80 -51
  196. package/modern/LineChart/formatter.js +1 -1
  197. package/modern/LineChart/index.js +2 -0
  198. package/modern/PieChart/PieArcLabelPlot.js +1 -1
  199. package/modern/PieChart/PieArcPlot.js +6 -6
  200. package/modern/PieChart/PieChart.js +5 -50
  201. package/modern/PieChart/PiePlot.js +4 -4
  202. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +242 -0
  203. package/modern/ResponsiveChartContainer/index.js +1 -112
  204. package/modern/ScatterChart/Scatter.js +18 -23
  205. package/modern/ScatterChart/ScatterChart.js +12 -22
  206. package/modern/ScatterChart/ScatterPlot.js +10 -2
  207. package/modern/SparkLineChart/SparkLineChart.js +2 -0
  208. package/modern/context/DrawingProvider.js +9 -2
  209. package/modern/hooks/useDrawingArea.js +7 -3
  210. package/modern/index.js +2 -1
  211. package/modern/internals/geometry.js +1 -1
  212. package/modern/internals/useAnimatedPath.js +29 -0
  213. package/modern/internals/utils.js +7 -0
  214. package/package.json +6 -5
@@ -1,16 +1,15 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps"];
3
+ var _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps", "onClick"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
7
7
  import { useSlotProps } from '@mui/base/utils';
8
8
  import generateUtilityClass from '@mui/utils/generateUtilityClass';
9
- import { styled } from '@mui/material/styles';
10
9
  import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
11
- import { color as d3Color } from 'd3-color';
12
10
  import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
13
11
  import { InteractionContext } from '../context/InteractionProvider';
12
+ import { AnimatedArea } from './AnimatedArea';
14
13
  import { jsx as _jsx } from "react/jsx-runtime";
15
14
  export function getAreaElementUtilityClass(slot) {
16
15
  return generateUtilityClass('MuiAreaElement', slot);
@@ -26,36 +25,6 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
26
25
  };
27
26
  return composeClasses(slots, getAreaElementUtilityClass, classes);
28
27
  };
29
- export var AreaElementPath = styled('path', {
30
- name: 'MuiAreaElement',
31
- slot: 'Root',
32
- overridesResolver: function overridesResolver(_, styles) {
33
- return styles.root;
34
- }
35
- })(function (_ref) {
36
- var ownerState = _ref.ownerState;
37
- return {
38
- stroke: 'none',
39
- fill: ownerState.isHighlighted ? d3Color(ownerState.color).brighter(1).formatHex() : d3Color(ownerState.color).brighter(0.5).formatHex(),
40
- transition: 'opacity 0.2s ease-in, fill 0.2s ease-in',
41
- opacity: ownerState.isFaded ? 0.3 : 1
42
- };
43
- });
44
- AreaElementPath.propTypes = {
45
- // ----------------------------- Warning --------------------------------
46
- // | These PropTypes are generated from the TypeScript type definitions |
47
- // | To update them edit the TypeScript types and run "yarn proptypes" |
48
- // ----------------------------------------------------------------------
49
- as: PropTypes.elementType,
50
- ownerState: PropTypes.shape({
51
- classes: PropTypes.object,
52
- color: PropTypes.string.isRequired,
53
- id: PropTypes.string.isRequired,
54
- isFaded: PropTypes.bool.isRequired,
55
- isHighlighted: PropTypes.bool.isRequired
56
- }).isRequired,
57
- sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
58
- };
59
28
  /**
60
29
  * Demos:
61
30
  *
@@ -74,6 +43,7 @@ function AreaElement(props) {
74
43
  highlightScope = props.highlightScope,
75
44
  slots = props.slots,
76
45
  slotProps = props.slotProps,
46
+ onClick = props.onClick,
77
47
  other = _objectWithoutProperties(props, _excluded);
78
48
  var getInteractionItemProps = useInteractionItemProps(highlightScope);
79
49
  var _React$useContext = React.useContext(InteractionContext),
@@ -94,7 +64,7 @@ function AreaElement(props) {
94
64
  isHighlighted: isHighlighted
95
65
  };
96
66
  var classes = useUtilityClasses(ownerState);
97
- var Area = (_slots$area = slots == null ? void 0 : slots.area) != null ? _slots$area : AreaElementPath;
67
+ var Area = (_slots$area = slots == null ? void 0 : slots.area) != null ? _slots$area : AnimatedArea;
98
68
  var areaProps = useSlotProps({
99
69
  elementType: Area,
100
70
  externalSlotProps: slotProps == null ? void 0 : slotProps.area,
@@ -102,7 +72,9 @@ function AreaElement(props) {
102
72
  type: 'line',
103
73
  seriesId: id
104
74
  }), {
105
- className: classes.root
75
+ className: classes.root,
76
+ onClick: onClick,
77
+ cursor: onClick ? 'pointer' : 'unset'
106
78
  }),
107
79
  ownerState: ownerState
108
80
  });
@@ -114,10 +86,18 @@ process.env.NODE_ENV !== "production" ? AreaElement.propTypes = {
114
86
  // | To update them edit the TypeScript types and run "yarn proptypes" |
115
87
  // ----------------------------------------------------------------------
116
88
  classes: PropTypes.object,
89
+ color: PropTypes.string.isRequired,
90
+ d: PropTypes.string.isRequired,
117
91
  highlightScope: PropTypes.shape({
118
92
  faded: PropTypes.oneOf(['global', 'none', 'series']),
119
93
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
120
94
  }),
95
+ id: PropTypes.string.isRequired,
96
+ /**
97
+ * If `true`, animations are skipped.
98
+ * @default false
99
+ */
100
+ skipAnimation: PropTypes.bool,
121
101
  /**
122
102
  * The props used for each component slot.
123
103
  * @default {}
@@ -1,6 +1,6 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["slots", "slotProps"];
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
+ var _excluded = ["slots", "slotProps", "onItemClick", "skipAnimation"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { area as d3Area } from 'd3-shape';
@@ -11,6 +11,71 @@ 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
+ var useAggregatedData = function useAggregatedData() {
15
+ var seriesData = React.useContext(SeriesContext).line;
16
+ var axisData = React.useContext(CartesianContext);
17
+ if (seriesData === undefined) {
18
+ return [];
19
+ }
20
+ var series = seriesData.series,
21
+ stackingGroups = seriesData.stackingGroups;
22
+ var xAxis = axisData.xAxis,
23
+ yAxis = axisData.yAxis,
24
+ xAxisIds = axisData.xAxisIds,
25
+ yAxisIds = axisData.yAxisIds;
26
+ var defaultXAxisId = xAxisIds[0];
27
+ var defaultYAxisId = yAxisIds[0];
28
+ return stackingGroups.flatMap(function (_ref) {
29
+ var groupIds = _ref.ids;
30
+ return groupIds.flatMap(function (seriesId) {
31
+ var _xData$map;
32
+ var _series$seriesId = series[seriesId],
33
+ _series$seriesId$xAxi = _series$seriesId.xAxisKey,
34
+ xAxisKey = _series$seriesId$xAxi === void 0 ? defaultXAxisId : _series$seriesId$xAxi,
35
+ _series$seriesId$yAxi = _series$seriesId.yAxisKey,
36
+ yAxisKey = _series$seriesId$yAxi === void 0 ? defaultYAxisId : _series$seriesId$yAxi,
37
+ stackedData = _series$seriesId.stackedData,
38
+ data = _series$seriesId.data,
39
+ connectNulls = _series$seriesId.connectNulls;
40
+ var xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
41
+ var yScale = yAxis[yAxisKey].scale;
42
+ var xData = xAxis[xAxisKey].data;
43
+ if (process.env.NODE_ENV !== 'production') {
44
+ if (xData === undefined) {
45
+ throw new Error("MUI X Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " should have data property to be able to display a line plot."));
46
+ }
47
+ if (xData.length < stackedData.length) {
48
+ throw new Error("MUI X Charts: The data length of the x axis (".concat(xData.length, " items) is lower than the length of series (").concat(stackedData.length, " items)."));
49
+ }
50
+ }
51
+ var areaPath = d3Area().x(function (d) {
52
+ return xScale(d.x);
53
+ }).defined(function (_, i) {
54
+ return connectNulls || data[i] != null;
55
+ }).y0(function (d) {
56
+ return d.y && yScale(d.y[0]);
57
+ }).y1(function (d) {
58
+ return d.y && yScale(d.y[1]);
59
+ });
60
+ var curve = getCurveFactory(series[seriesId].curve);
61
+ var formattedData = (_xData$map = xData == null ? void 0 : xData.map(function (x, index) {
62
+ return {
63
+ x: x,
64
+ y: stackedData[index]
65
+ };
66
+ })) != null ? _xData$map : [];
67
+ var d3Data = connectNulls ? formattedData.filter(function (_, i) {
68
+ return data[i] != null;
69
+ }) : formattedData;
70
+ var d = areaPath.curve(curve)(d3Data) || '';
71
+ return _extends({}, series[seriesId], {
72
+ d: d,
73
+ seriesId: seriesId
74
+ });
75
+ });
76
+ });
77
+ };
78
+
14
79
  /**
15
80
  * Demos:
16
81
  *
@@ -25,72 +90,32 @@ import { jsx as _jsx } from "react/jsx-runtime";
25
90
  function AreaPlot(props) {
26
91
  var slots = props.slots,
27
92
  slotProps = props.slotProps,
93
+ onItemClick = props.onItemClick,
94
+ skipAnimation = props.skipAnimation,
28
95
  other = _objectWithoutProperties(props, _excluded);
29
- var seriesData = React.useContext(SeriesContext).line;
30
- var axisData = React.useContext(CartesianContext);
31
- if (seriesData === undefined) {
32
- return null;
33
- }
34
- var series = seriesData.series,
35
- stackingGroups = seriesData.stackingGroups;
36
- var xAxis = axisData.xAxis,
37
- yAxis = axisData.yAxis,
38
- xAxisIds = axisData.xAxisIds,
39
- yAxisIds = axisData.yAxisIds;
40
- var defaultXAxisId = xAxisIds[0];
41
- var defaultYAxisId = yAxisIds[0];
96
+ var completedData = useAggregatedData();
42
97
  return /*#__PURE__*/_jsx("g", _extends({}, other, {
43
- children: stackingGroups.flatMap(function (_ref) {
44
- var groupIds = _ref.ids;
45
- return groupIds.flatMap(function (seriesId) {
46
- var _xData$map;
47
- var _series$seriesId = series[seriesId],
48
- _series$seriesId$xAxi = _series$seriesId.xAxisKey,
49
- xAxisKey = _series$seriesId$xAxi === void 0 ? defaultXAxisId : _series$seriesId$xAxi,
50
- _series$seriesId$yAxi = _series$seriesId.yAxisKey,
51
- yAxisKey = _series$seriesId$yAxi === void 0 ? defaultYAxisId : _series$seriesId$yAxi,
52
- stackedData = _series$seriesId.stackedData,
53
- data = _series$seriesId.data,
54
- connectNulls = _series$seriesId.connectNulls;
55
- var xScale = getValueToPositionMapper(xAxis[xAxisKey].scale);
56
- var yScale = yAxis[yAxisKey].scale;
57
- var xData = xAxis[xAxisKey].data;
58
- if (process.env.NODE_ENV !== 'production') {
59
- if (xData === undefined) {
60
- throw new Error("MUI X Charts: ".concat(xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : "The x-axis with id \"".concat(xAxisKey, "\""), " should have data property to be able to display a line plot."));
61
- }
62
- if (xData.length < stackedData.length) {
63
- throw new Error("MUI X Charts: The data length of the x axis (".concat(xData.length, " items) is lower than the length of series (").concat(stackedData.length, " items)."));
64
- }
65
- }
66
- var areaPath = d3Area().x(function (d) {
67
- return xScale(d.x);
68
- }).defined(function (_, i) {
69
- return connectNulls || data[i] != null;
70
- }).y0(function (d) {
71
- return d.y && yScale(d.y[0]);
72
- }).y1(function (d) {
73
- return d.y && yScale(d.y[1]);
74
- });
75
- var curve = getCurveFactory(series[seriesId].curve);
76
- var formattedData = (_xData$map = xData == null ? void 0 : xData.map(function (x, index) {
77
- return {
78
- x: x,
79
- y: stackedData[index]
80
- };
81
- })) != null ? _xData$map : [];
82
- var d3Data = connectNulls ? formattedData.filter(function (_, i) {
83
- return data[i] != null;
84
- }) : formattedData;
85
- return !!series[seriesId].area && /*#__PURE__*/_jsx(AreaElement, {
86
- id: seriesId,
87
- d: areaPath.curve(curve)(d3Data) || undefined,
88
- color: series[seriesId].color,
89
- highlightScope: series[seriesId].highlightScope,
90
- slots: slots,
91
- slotProps: slotProps
92
- }, seriesId);
93
- });
98
+ children: completedData.reverse().map(function (_ref2) {
99
+ var d = _ref2.d,
100
+ seriesId = _ref2.seriesId,
101
+ color = _ref2.color,
102
+ highlightScope = _ref2.highlightScope,
103
+ area = _ref2.area;
104
+ return !!area && /*#__PURE__*/_jsx(AreaElement, {
105
+ id: seriesId,
106
+ d: d,
107
+ color: color,
108
+ highlightScope: highlightScope,
109
+ slots: slots,
110
+ slotProps: slotProps,
111
+ onClick: onItemClick && function (event) {
112
+ return onItemClick(event, {
113
+ type: 'line',
114
+ seriesId: seriesId
115
+ });
116
+ },
117
+ skipAnimation: skipAnimation
118
+ }, seriesId);
94
119
  })
95
120
  }));
96
121
  }
@@ -99,6 +124,17 @@ process.env.NODE_ENV !== "production" ? AreaPlot.propTypes = {
99
124
  // | These PropTypes are generated from the TypeScript type definitions |
100
125
  // | To update them edit the TypeScript types and run "yarn proptypes" |
101
126
  // ----------------------------------------------------------------------
127
+ /**
128
+ * Callback fired when a line area item is clicked.
129
+ * @param {React.MouseEvent<SVGPathElement, MouseEvent>} event The event source of the callback.
130
+ * @param {LineItemIdentifier} lineItemIdentifier The line item identifier.
131
+ */
132
+ onItemClick: PropTypes.func,
133
+ /**
134
+ * If `true`, animations are skipped.
135
+ * @default false
136
+ */
137
+ skipAnimation: PropTypes.bool,
102
138
  /**
103
139
  * The props used for each component slot.
104
140
  * @default {}
@@ -14,6 +14,7 @@ import { ChartsLegend } from '../ChartsLegend';
14
14
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
15
15
  import { ChartsClipPath } from '../ChartsClipPath';
16
16
  import { LineHighlightPlot } from './LineHighlightPlot';
17
+ import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
17
18
  import { jsx as _jsx } from "react/jsx-runtime";
18
19
  import { jsxs as _jsxs } from "react/jsx-runtime";
19
20
  /**
@@ -37,6 +38,10 @@ var LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
37
38
  dataset = props.dataset,
38
39
  sx = props.sx,
39
40
  tooltip = props.tooltip,
41
+ onAxisClick = props.onAxisClick,
42
+ onAreaClick = props.onAreaClick,
43
+ onLineClick = props.onLineClick,
44
+ onMarkClick = props.onMarkClick,
40
45
  _props$axisHighlight = props.axisHighlight,
41
46
  axisHighlight = _props$axisHighlight === void 0 ? {
42
47
  x: 'line'
@@ -49,7 +54,8 @@ var LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
49
54
  bottomAxis = props.bottomAxis,
50
55
  children = props.children,
51
56
  slots = props.slots,
52
- slotProps = props.slotProps;
57
+ slotProps = props.slotProps,
58
+ skipAnimation = props.skipAnimation;
53
59
  var id = useId();
54
60
  var clipPathId = "".concat(id, "-clip-path");
55
61
  return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
@@ -79,15 +85,21 @@ var LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
79
85
  colors: colors,
80
86
  dataset: dataset,
81
87
  sx: sx,
82
- disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
83
- children: [/*#__PURE__*/_jsxs("g", {
88
+ disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none' && !onAxisClick,
89
+ children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
90
+ onAxisClick: onAxisClick
91
+ }), /*#__PURE__*/_jsxs("g", {
84
92
  clipPath: "url(#".concat(clipPathId, ")"),
85
93
  children: [/*#__PURE__*/_jsx(AreaPlot, {
86
94
  slots: slots,
87
- slotProps: slotProps
95
+ slotProps: slotProps,
96
+ onItemClick: onAreaClick,
97
+ skipAnimation: skipAnimation
88
98
  }), /*#__PURE__*/_jsx(LinePlot, {
89
99
  slots: slots,
90
- slotProps: slotProps
100
+ slotProps: slotProps,
101
+ onItemClick: onLineClick,
102
+ skipAnimation: skipAnimation
91
103
  })]
92
104
  }), /*#__PURE__*/_jsx(ChartsAxis, {
93
105
  topAxis: topAxis,
@@ -98,7 +110,9 @@ var LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
98
110
  slotProps: slotProps
99
111
  }), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), /*#__PURE__*/_jsx(MarkPlot, {
100
112
  slots: slots,
101
- slotProps: slotProps
113
+ slotProps: slotProps,
114
+ onItemClick: onMarkClick,
115
+ skipAnimation: skipAnimation
102
116
  }), /*#__PURE__*/_jsx(LineHighlightPlot, {
103
117
  slots: slots,
104
118
  slotProps: slotProps
@@ -237,6 +251,16 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
237
251
  right: PropTypes.number,
238
252
  top: PropTypes.number
239
253
  }),
254
+ onAreaClick: PropTypes.func,
255
+ /**
256
+ * The function called for onClick events.
257
+ * The second argument contains information about all line/bar elements at the current mouse position.
258
+ * @param {MouseEvent} event The mouse event recorded on the `<svg/>` element.
259
+ * @param {null | AxisData} data The data about the clicked axis and items associated with it.
260
+ */
261
+ onAxisClick: PropTypes.func,
262
+ onLineClick: PropTypes.func,
263
+ onMarkClick: PropTypes.func,
240
264
  /**
241
265
  * Indicate which axis to display the right of the charts.
242
266
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
@@ -264,29 +288,12 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
264
288
  tickNumber: PropTypes.number,
265
289
  tickSize: PropTypes.number
266
290
  }), PropTypes.string]),
267
- series: PropTypes.arrayOf(PropTypes.shape({
268
- area: PropTypes.bool,
269
- color: PropTypes.string,
270
- connectNulls: PropTypes.bool,
271
- curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
272
- data: PropTypes.arrayOf(PropTypes.number),
273
- dataKey: PropTypes.string,
274
- disableHighlight: PropTypes.bool,
275
- highlightScope: PropTypes.shape({
276
- faded: PropTypes.oneOf(['global', 'none', 'series']),
277
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
278
- }),
279
- id: PropTypes.string,
280
- label: PropTypes.string,
281
- showMark: PropTypes.oneOfType([PropTypes.func, PropTypes.bool]),
282
- stack: PropTypes.string,
283
- stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
284
- stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
285
- type: PropTypes.oneOf(['line']),
286
- valueFormatter: PropTypes.func,
287
- xAxisKey: PropTypes.string,
288
- yAxisKey: PropTypes.string
289
- })).isRequired,
291
+ series: PropTypes.arrayOf(PropTypes.object).isRequired,
292
+ /**
293
+ * If `true`, animations are skipped.
294
+ * @default false
295
+ */
296
+ skipAnimation: PropTypes.bool,
290
297
  /**
291
298
  * The props used for each component slot.
292
299
  * @default {}
@@ -1,16 +1,15 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["id", "classes", "color", "highlightScope", "slots", "slotProps"];
3
+ var _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);
@@ -26,38 +25,6 @@ var useUtilityClasses = function useUtilityClasses(ownerState) {
26
25
  };
27
26
  return composeClasses(slots, getLineElementUtilityClass, classes);
28
27
  };
29
- export var LineElementPath = styled('path', {
30
- name: 'MuiLineElement',
31
- slot: 'Root',
32
- overridesResolver: function overridesResolver(_, styles) {
33
- return styles.root;
34
- }
35
- })(function (_ref) {
36
- var ownerState = _ref.ownerState;
37
- return {
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
- });
46
- LineElementPath.propTypes = {
47
- // ----------------------------- Warning --------------------------------
48
- // | These PropTypes are generated from the TypeScript type definitions |
49
- // | To update them edit the TypeScript types and run "yarn proptypes" |
50
- // ----------------------------------------------------------------------
51
- as: PropTypes.elementType,
52
- ownerState: PropTypes.shape({
53
- classes: PropTypes.object,
54
- color: PropTypes.string.isRequired,
55
- id: PropTypes.string.isRequired,
56
- isFaded: PropTypes.bool.isRequired,
57
- isHighlighted: PropTypes.bool.isRequired
58
- }).isRequired,
59
- sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object])
60
- };
61
28
  /**
62
29
  * Demos:
63
30
  *
@@ -76,6 +43,7 @@ function LineElement(props) {
76
43
  highlightScope = props.highlightScope,
77
44
  slots = props.slots,
78
45
  slotProps = props.slotProps,
46
+ onClick = props.onClick,
79
47
  other = _objectWithoutProperties(props, _excluded);
80
48
  var getInteractionItemProps = useInteractionItemProps(highlightScope);
81
49
  var _React$useContext = React.useContext(InteractionContext),
@@ -96,7 +64,7 @@ function LineElement(props) {
96
64
  isHighlighted: isHighlighted
97
65
  };
98
66
  var classes = useUtilityClasses(ownerState);
99
- var Line = (_slots$line = slots == null ? void 0 : slots.line) != null ? _slots$line : LineElementPath;
67
+ var Line = (_slots$line = slots == null ? void 0 : slots.line) != null ? _slots$line : AnimatedLine;
100
68
  var lineProps = useSlotProps({
101
69
  elementType: Line,
102
70
  externalSlotProps: slotProps == null ? void 0 : slotProps.line,
@@ -104,7 +72,9 @@ function LineElement(props) {
104
72
  type: 'line',
105
73
  seriesId: id
106
74
  }), {
107
- className: classes.root
75
+ className: classes.root,
76
+ onClick: onClick,
77
+ cursor: onClick ? 'pointer' : 'unset'
108
78
  }),
109
79
  ownerState: ownerState
110
80
  });
@@ -116,10 +86,18 @@ process.env.NODE_ENV !== "production" ? LineElement.propTypes = {
116
86
  // | To update them edit the TypeScript types and run "yarn proptypes" |
117
87
  // ----------------------------------------------------------------------
118
88
  classes: PropTypes.object,
89
+ color: PropTypes.string.isRequired,
90
+ d: PropTypes.string.isRequired,
119
91
  highlightScope: PropTypes.shape({
120
92
  faded: PropTypes.oneOf(['global', 'none', 'series']),
121
93
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
122
94
  }),
95
+ id: PropTypes.string.isRequired,
96
+ /**
97
+ * If `true`, animations are skipped.
98
+ * @default false
99
+ */
100
+ skipAnimation: PropTypes.bool,
123
101
  /**
124
102
  * The props used for each component slot.
125
103
  * @default {}
@@ -59,13 +59,14 @@ function LineHighlightElement(props) {
59
59
  y: y
60
60
  };
61
61
  var classes = useUtilityClasses(ownerState);
62
- return /*#__PURE__*/_jsx(HighlightElement, _extends({}, other, {
62
+ return /*#__PURE__*/_jsx(HighlightElement, _extends({
63
+ pointerEvents: "none",
63
64
  ownerState: ownerState,
64
65
  className: classes.root,
65
66
  cx: 0,
66
67
  cy: 0,
67
68
  r: other.r === undefined ? 5 : other.r
68
- }));
69
+ }, other));
69
70
  }
70
71
  process.env.NODE_ENV !== "production" ? LineHighlightElement.propTypes = {
71
72
  // ----------------------------- Warning --------------------------------