@mui/x-charts 7.3.2 → 7.5.0

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 (128) hide show
  1. package/BarChart/BarChart.js +18 -11
  2. package/BarChart/BarClipPath.d.ts +14 -0
  3. package/BarChart/BarClipPath.js +50 -0
  4. package/BarChart/BarElement.d.ts +10 -5
  5. package/BarChart/BarElement.js +3 -2
  6. package/BarChart/BarPlot.d.ts +4 -0
  7. package/BarChart/BarPlot.js +102 -30
  8. package/BarChart/getRadius.d.ts +15 -0
  9. package/BarChart/getRadius.js +37 -0
  10. package/BarChart/legend.js +13 -6
  11. package/BarChart/types.d.ts +25 -0
  12. package/BarChart/types.js +5 -0
  13. package/CHANGELOG.md +160 -2
  14. package/ChartContainer/ChartContainer.js +10 -10
  15. package/ChartsGrid/ChartsGrid.js +22 -11
  16. package/ChartsOverlay/ChartsLoadingOverlay.js +3 -3
  17. package/ChartsOverlay/ChartsNoDataOverlay.js +2 -2
  18. package/ChartsOverlay/ChartsOverlay.d.ts +9 -0
  19. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +4 -2
  20. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +7 -3
  21. package/ChartsTooltip/utils.js +13 -8
  22. package/ChartsXAxis/ChartsXAxis.js +1 -2
  23. package/ChartsYAxis/ChartsYAxis.js +2 -2
  24. package/LineChart/AreaElement.d.ts +1 -1
  25. package/LineChart/AreaElement.js +3 -3
  26. package/LineChart/AreaPlot.js +3 -2
  27. package/LineChart/LineChart.js +11 -10
  28. package/LineChart/LineElement.d.ts +1 -1
  29. package/LineChart/LineElement.js +3 -3
  30. package/LineChart/LineHighlightElement.d.ts +1 -1
  31. package/LineChart/MarkElement.d.ts +1 -1
  32. package/LineChart/legend.js +13 -6
  33. package/PieChart/PieArc.d.ts +1 -1
  34. package/PieChart/PieArcLabel.d.ts +1 -1
  35. package/PieChart/PieArcLabel.js +3 -1
  36. package/PieChart/PieArcLabelPlot.js +14 -5
  37. package/PieChart/PieArcPlot.js +1 -1
  38. package/PieChart/PieChart.js +11 -10
  39. package/PieChart/formatter.js +4 -1
  40. package/PieChart/legend.js +15 -5
  41. package/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -10
  42. package/ScatterChart/ScatterChart.js +16 -15
  43. package/ScatterChart/legend.js +13 -6
  44. package/SparkLineChart/SparkLineChart.js +5 -5
  45. package/context/ZAxisContextProvider.js +5 -5
  46. package/esm/BarChart/BarChart.js +18 -11
  47. package/esm/BarChart/BarClipPath.js +42 -0
  48. package/esm/BarChart/BarElement.js +3 -2
  49. package/esm/BarChart/BarPlot.js +103 -31
  50. package/esm/BarChart/getRadius.js +30 -0
  51. package/esm/BarChart/legend.js +13 -6
  52. package/esm/BarChart/types.js +1 -0
  53. package/esm/ChartContainer/ChartContainer.js +10 -10
  54. package/esm/ChartsGrid/ChartsGrid.js +23 -12
  55. package/esm/ChartsOverlay/ChartsLoadingOverlay.js +3 -3
  56. package/esm/ChartsOverlay/ChartsNoDataOverlay.js +2 -2
  57. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +4 -2
  58. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +7 -3
  59. package/esm/ChartsTooltip/utils.js +13 -8
  60. package/esm/ChartsXAxis/ChartsXAxis.js +1 -2
  61. package/esm/ChartsYAxis/ChartsYAxis.js +2 -2
  62. package/esm/LineChart/AreaElement.js +3 -3
  63. package/esm/LineChart/AreaPlot.js +3 -2
  64. package/esm/LineChart/LineChart.js +11 -10
  65. package/esm/LineChart/LineElement.js +3 -3
  66. package/esm/LineChart/legend.js +13 -6
  67. package/esm/PieChart/PieArcLabel.js +3 -1
  68. package/esm/PieChart/PieArcLabelPlot.js +14 -5
  69. package/esm/PieChart/PieArcPlot.js +1 -1
  70. package/esm/PieChart/PieChart.js +11 -10
  71. package/esm/PieChart/formatter.js +4 -1
  72. package/esm/PieChart/legend.js +15 -5
  73. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -10
  74. package/esm/ScatterChart/ScatterChart.js +16 -15
  75. package/esm/ScatterChart/legend.js +13 -6
  76. package/esm/SparkLineChart/SparkLineChart.js +5 -5
  77. package/esm/context/ZAxisContextProvider.js +5 -5
  78. package/esm/hooks/useAxisEvents.js +12 -7
  79. package/esm/internals/getLabel.js +3 -0
  80. package/hooks/useAxisEvents.js +12 -7
  81. package/index.js +1 -1
  82. package/internals/defaultizeColor.d.ts +7 -5
  83. package/internals/getLabel.d.ts +1 -0
  84. package/internals/getLabel.js +9 -0
  85. package/internals/utils.d.ts +1 -1
  86. package/models/seriesType/bar.d.ts +4 -1
  87. package/models/seriesType/line.d.ts +4 -1
  88. package/models/seriesType/pie.d.ts +9 -4
  89. package/models/seriesType/scatter.d.ts +4 -1
  90. package/modern/BarChart/BarChart.js +18 -11
  91. package/modern/BarChart/BarClipPath.js +42 -0
  92. package/modern/BarChart/BarElement.js +3 -2
  93. package/modern/BarChart/BarPlot.js +103 -31
  94. package/modern/BarChart/getRadius.js +30 -0
  95. package/modern/BarChart/legend.js +13 -6
  96. package/modern/BarChart/types.js +1 -0
  97. package/modern/ChartContainer/ChartContainer.js +10 -10
  98. package/modern/ChartsGrid/ChartsGrid.js +23 -12
  99. package/modern/ChartsOverlay/ChartsLoadingOverlay.js +3 -3
  100. package/modern/ChartsOverlay/ChartsNoDataOverlay.js +2 -2
  101. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +4 -2
  102. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +7 -3
  103. package/modern/ChartsTooltip/utils.js +13 -8
  104. package/modern/ChartsXAxis/ChartsXAxis.js +1 -2
  105. package/modern/ChartsYAxis/ChartsYAxis.js +2 -2
  106. package/modern/LineChart/AreaElement.js +3 -3
  107. package/modern/LineChart/AreaPlot.js +3 -2
  108. package/modern/LineChart/LineChart.js +11 -10
  109. package/modern/LineChart/LineElement.js +3 -3
  110. package/modern/LineChart/legend.js +13 -6
  111. package/modern/PieChart/PieArcLabel.js +3 -1
  112. package/modern/PieChart/PieArcLabelPlot.js +14 -5
  113. package/modern/PieChart/PieArcPlot.js +1 -1
  114. package/modern/PieChart/PieChart.js +11 -10
  115. package/modern/PieChart/formatter.js +4 -1
  116. package/modern/PieChart/legend.js +15 -5
  117. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -10
  118. package/modern/ScatterChart/ScatterChart.js +16 -15
  119. package/modern/ScatterChart/legend.js +13 -6
  120. package/modern/SparkLineChart/SparkLineChart.js +5 -5
  121. package/modern/context/ZAxisContextProvider.js +5 -5
  122. package/modern/hooks/useAxisEvents.js +12 -7
  123. package/modern/index.js +1 -1
  124. package/modern/internals/getLabel.js +3 -0
  125. package/package.json +3 -3
  126. package/themeAugmentation/components.d.ts +4 -0
  127. package/themeAugmentation/overrides.d.ts +2 -0
  128. package/themeAugmentation/props.d.ts +2 -0
@@ -1,6 +1,6 @@
1
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
2
  import _extends from "@babel/runtime/helpers/esm/extends";
3
- const _excluded = ["skipAnimation", "onItemClick"];
3
+ const _excluded = ["skipAnimation", "onItemClick", "borderRadius"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { useTransition } from '@react-spring/web';
@@ -10,6 +10,8 @@ import { BarElement } from './BarElement';
10
10
  import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
11
11
  import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
12
12
  import getColor from './getColor';
13
+ import { useChartId } from '../hooks';
14
+ import { BarClipPath } from './BarClipPath';
13
15
 
14
16
  /**
15
17
  * Solution of the equations
@@ -20,7 +22,7 @@ import getColor from './getColor';
20
22
  * @param gapRatio The ratio of the gap between bars over the bar width.
21
23
  * @returns The bar width and the offset between bars.
22
24
  */
23
- import { jsx as _jsx } from "react/jsx-runtime";
25
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
24
26
  function getBandSize({
25
27
  bandWidth: W,
26
28
  numberOfGroups: N,
@@ -46,6 +48,7 @@ const useAggregatedData = () => {
46
48
  seriesOrder: []
47
49
  };
48
50
  const axisData = React.useContext(CartesianContext);
51
+ const chartId = useChartId();
49
52
  const {
50
53
  series,
51
54
  stackingGroups
@@ -58,6 +61,7 @@ const useAggregatedData = () => {
58
61
  } = axisData;
59
62
  const defaultXAxisId = xAxisIds[0];
60
63
  const defaultYAxisId = yAxisIds[0];
64
+ const masks = {};
61
65
  const data = stackingGroups.flatMap(({
62
66
  ids: groupIds
63
67
  }, groupIndex) => {
@@ -111,7 +115,8 @@ const useAggregatedData = () => {
111
115
  const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
112
116
  const minValueCoord = Math.round(Math.min(...valueCoordinates));
113
117
  const maxValueCoord = Math.round(Math.max(...valueCoordinates));
114
- return {
118
+ const stackId = series[seriesId].stack;
119
+ const result = {
115
120
  seriesId,
116
121
  dataIndex,
117
122
  layout: series[seriesId].layout,
@@ -122,14 +127,41 @@ const useAggregatedData = () => {
122
127
  height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
123
128
  width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
124
129
  color: colorGetter(dataIndex),
125
- highlightScope: series[seriesId].highlightScope
130
+ highlightScope: series[seriesId].highlightScope,
131
+ value: series[seriesId].data[dataIndex],
132
+ maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
126
133
  };
134
+ if (!masks[result.maskId]) {
135
+ masks[result.maskId] = {
136
+ id: result.maskId,
137
+ width: 0,
138
+ height: 0,
139
+ hasNegative: false,
140
+ hasPositive: false,
141
+ layout: result.layout,
142
+ xOrigin: xScale(0),
143
+ yOrigin: yScale(0),
144
+ x: 0,
145
+ y: 0
146
+ };
147
+ }
148
+ const mask = masks[result.maskId];
149
+ mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
150
+ mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
151
+ mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
152
+ mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
153
+ mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
154
+ mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
155
+ return result;
127
156
  });
128
157
  });
129
158
  });
130
- return data;
159
+ return {
160
+ completedData: data,
161
+ masksData: Object.values(masks)
162
+ };
131
163
  };
132
- const getOutStyle = ({
164
+ const leaveStyle = ({
133
165
  layout,
134
166
  yOrigin,
135
167
  x,
@@ -148,7 +180,7 @@ const getOutStyle = ({
148
180
  height,
149
181
  width: 0
150
182
  });
151
- const getInStyle = ({
183
+ const enterStyle = ({
152
184
  x,
153
185
  width,
154
186
  y,
@@ -172,41 +204,77 @@ const getInStyle = ({
172
204
  * - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
173
205
  */
174
206
  function BarPlot(props) {
175
- const completedData = useAggregatedData();
207
+ const {
208
+ completedData,
209
+ masksData
210
+ } = useAggregatedData();
176
211
  const {
177
212
  skipAnimation,
178
- onItemClick
213
+ onItemClick,
214
+ borderRadius
179
215
  } = props,
180
216
  other = _objectWithoutPropertiesLoose(props, _excluded);
181
217
  const transition = useTransition(completedData, {
182
218
  keys: bar => `${bar.seriesId}-${bar.dataIndex}`,
183
- from: getOutStyle,
184
- leave: getOutStyle,
185
- enter: getInStyle,
186
- update: getInStyle,
219
+ from: leaveStyle,
220
+ leave: leaveStyle,
221
+ enter: enterStyle,
222
+ update: enterStyle,
223
+ immediate: skipAnimation
224
+ });
225
+ const maskTransition = useTransition(masksData, {
226
+ keys: v => v.id,
227
+ from: leaveStyle,
228
+ leave: leaveStyle,
229
+ enter: enterStyle,
230
+ update: enterStyle,
187
231
  immediate: skipAnimation
188
232
  });
189
- return /*#__PURE__*/_jsx(React.Fragment, {
190
- children: transition((style, {
233
+ return /*#__PURE__*/_jsxs(React.Fragment, {
234
+ children: [maskTransition((style, {
235
+ id,
236
+ hasPositive,
237
+ hasNegative,
238
+ layout
239
+ }) => {
240
+ return /*#__PURE__*/_jsx(BarClipPath, {
241
+ maskId: id,
242
+ borderRadius: borderRadius,
243
+ hasNegative: hasNegative,
244
+ hasPositive: hasPositive,
245
+ layout: layout,
246
+ style: style
247
+ });
248
+ }), transition((style, {
191
249
  seriesId,
192
250
  dataIndex,
193
251
  color,
194
- highlightScope
195
- }) => /*#__PURE__*/_jsx(BarElement, _extends({
196
- id: seriesId,
197
- dataIndex: dataIndex,
198
- highlightScope: highlightScope,
199
- color: color
200
- }, other, {
201
- onClick: onItemClick && (event => {
202
- onItemClick(event, {
203
- type: 'bar',
204
- seriesId,
205
- dataIndex
206
- });
207
- }),
208
- style: style
209
- })))
252
+ highlightScope,
253
+ maskId
254
+ }) => {
255
+ const barElement = /*#__PURE__*/_jsx(BarElement, _extends({
256
+ id: seriesId,
257
+ dataIndex: dataIndex,
258
+ color: color,
259
+ highlightScope: highlightScope
260
+ }, other, {
261
+ onClick: onItemClick && (event => {
262
+ onItemClick(event, {
263
+ type: 'bar',
264
+ seriesId,
265
+ dataIndex
266
+ });
267
+ }),
268
+ style: style
269
+ }));
270
+ if (!borderRadius || borderRadius <= 0) {
271
+ return barElement;
272
+ }
273
+ return /*#__PURE__*/_jsx("g", {
274
+ clipPath: `url(#${maskId})`,
275
+ children: barElement
276
+ });
277
+ })]
210
278
  });
211
279
  }
212
280
  process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
@@ -214,6 +282,10 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
214
282
  // | These PropTypes are generated from the TypeScript type definitions |
215
283
  // | To update them edit the TypeScript types and run "yarn proptypes" |
216
284
  // ----------------------------------------------------------------------
285
+ /**
286
+ * Defines the border radius of the bar element.
287
+ */
288
+ borderRadius: PropTypes.number,
217
289
  /**
218
290
  * Callback fired when a bar item is clicked.
219
291
  * @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Returns if the corner should have a radius or not based on the layout and the data.
3
+ * @param {GetRadiusCorner} corner The corner to check.
4
+ * @param {GetRadiusData} cornerData The data for the corner.
5
+ * @returns {number} The radius for the corner.
6
+ */
7
+ export const getRadius = (corner, {
8
+ hasNegative,
9
+ hasPositive,
10
+ borderRadius,
11
+ layout
12
+ }) => {
13
+ if (!borderRadius) {
14
+ return 0;
15
+ }
16
+ const isVertical = layout === 'vertical';
17
+ if (corner === 'top-left' && (isVertical && hasPositive || !isVertical && hasNegative)) {
18
+ return borderRadius;
19
+ }
20
+ if (corner === 'top-right' && (isVertical && hasPositive || !isVertical && hasPositive)) {
21
+ return borderRadius;
22
+ }
23
+ if (corner === 'bottom-right' && (isVertical && hasNegative || !isVertical && hasPositive)) {
24
+ return borderRadius;
25
+ }
26
+ if (corner === 'bottom-left' && (isVertical && hasNegative || !isVertical && hasNegative)) {
27
+ return borderRadius;
28
+ }
29
+ return 0;
30
+ };
@@ -1,13 +1,20 @@
1
+ import { getLabel } from '../internals/getLabel';
1
2
  const legendGetter = params => {
2
3
  const {
3
4
  seriesOrder,
4
5
  series
5
6
  } = params;
6
- const data = seriesOrder.map(seriesId => ({
7
- color: series[seriesId].color,
8
- label: series[seriesId].label,
9
- id: seriesId
10
- }));
11
- return data.filter(item => item.label !== undefined);
7
+ return seriesOrder.reduce((acc, seriesId) => {
8
+ const formattedLabel = getLabel(series[seriesId].label, 'legend');
9
+ if (formattedLabel === undefined) {
10
+ return acc;
11
+ }
12
+ acc.push({
13
+ color: series[seriesId].color,
14
+ label: formattedLabel,
15
+ id: seriesId
16
+ });
17
+ return acc;
18
+ }, []);
12
19
  };
13
20
  export default legendGetter;
@@ -0,0 +1 @@
1
+ export {};
@@ -127,6 +127,11 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
127
127
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
128
128
  classes: PropTypes.object,
129
129
  colorMap: PropTypes.oneOfType([PropTypes.shape({
130
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
131
+ type: PropTypes.oneOf(['ordinal']).isRequired,
132
+ unknownColor: PropTypes.string,
133
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
134
+ }), PropTypes.shape({
130
135
  color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
131
136
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
132
137
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -135,11 +140,6 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
135
140
  colors: PropTypes.arrayOf(PropTypes.string).isRequired,
136
141
  thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
137
142
  type: PropTypes.oneOf(['piecewise']).isRequired
138
- }), PropTypes.shape({
139
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
140
- type: PropTypes.oneOf(['ordinal']).isRequired,
141
- unknownColor: PropTypes.string,
142
- values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
143
143
  })]),
144
144
  data: PropTypes.array,
145
145
  dataKey: PropTypes.string,
@@ -180,6 +180,11 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
180
180
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
181
181
  classes: PropTypes.object,
182
182
  colorMap: PropTypes.oneOfType([PropTypes.shape({
183
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
184
+ type: PropTypes.oneOf(['ordinal']).isRequired,
185
+ unknownColor: PropTypes.string,
186
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
187
+ }), PropTypes.shape({
183
188
  color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
184
189
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
185
190
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -188,11 +193,6 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
188
193
  colors: PropTypes.arrayOf(PropTypes.string).isRequired,
189
194
  thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
190
195
  type: PropTypes.oneOf(['piecewise']).isRequired
191
- }), PropTypes.shape({
192
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
193
- type: PropTypes.oneOf(['ordinal']).isRequired,
194
- unknownColor: PropTypes.string,
195
- values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
196
196
  })]),
197
197
  data: PropTypes.array,
198
198
  dataKey: PropTypes.string,
@@ -4,7 +4,7 @@ const _excluded = ["vertical", "horizontal"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import composeClasses from '@mui/utils/composeClasses';
7
- import { styled } from '@mui/material/styles';
7
+ import { styled, useThemeProps } from '@mui/material/styles';
8
8
  import { CartesianContext } from '../context/CartesianContextProvider';
9
9
  import { useTicks } from '../hooks/useTicks';
10
10
  import { getChartsGridUtilityClass, chartsGridClasses } from './chartsGridClasses';
@@ -12,15 +12,22 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
12
  const GridRoot = styled('g', {
13
13
  name: 'MuiChartsGrid',
14
14
  slot: 'Root',
15
- overridesResolver: (props, styles) => styles.root
15
+ overridesResolver: (props, styles) => [{
16
+ [`&.${chartsGridClasses.verticalLine}`]: styles.verticalLine
17
+ }, {
18
+ [`&.${chartsGridClasses.horizontalLine}`]: styles.horizontalLine
19
+ }, styles.root]
20
+ })({});
21
+ const GridLine = styled('line', {
22
+ name: 'MuiChartsGrid',
23
+ slot: 'Line',
24
+ overridesResolver: (props, styles) => styles.line
16
25
  })(({
17
26
  theme
18
27
  }) => ({
19
- [`& .${chartsGridClasses.line}`]: {
20
- stroke: (theme.vars || theme).palette.divider,
21
- shapeRendering: 'crispEdges',
22
- strokeWidth: 1
23
- }
28
+ stroke: (theme.vars || theme).palette.divider,
29
+ shapeRendering: 'crispEdges',
30
+ strokeWidth: 1
24
31
  }));
25
32
  const useUtilityClasses = ({
26
33
  classes
@@ -42,18 +49,22 @@ const useUtilityClasses = ({
42
49
  * - [ChartsGrid API](https://mui.com/x/api/charts/charts-axis/)
43
50
  */
44
51
  function ChartsGrid(props) {
52
+ const themeProps = useThemeProps({
53
+ props,
54
+ name: 'MuiChartsGrid'
55
+ });
45
56
  const {
46
57
  vertical,
47
58
  horizontal
48
- } = props,
49
- other = _objectWithoutPropertiesLoose(props, _excluded);
59
+ } = themeProps,
60
+ other = _objectWithoutPropertiesLoose(themeProps, _excluded);
50
61
  const {
51
62
  xAxis,
52
63
  xAxisIds,
53
64
  yAxis,
54
65
  yAxisIds
55
66
  } = React.useContext(CartesianContext);
56
- const classes = useUtilityClasses(props);
67
+ const classes = useUtilityClasses(themeProps);
57
68
  const horizontalAxisId = yAxisIds[0];
58
69
  const verticalAxisId = xAxisIds[0];
59
70
  const {
@@ -81,7 +92,7 @@ function ChartsGrid(props) {
81
92
  children: [vertical && xTicks.map(({
82
93
  formattedValue,
83
94
  offset
84
- }) => /*#__PURE__*/_jsx("line", {
95
+ }) => /*#__PURE__*/_jsx(GridLine, {
85
96
  y1: yScale.range()[0],
86
97
  y2: yScale.range()[1],
87
98
  x1: offset,
@@ -90,7 +101,7 @@ function ChartsGrid(props) {
90
101
  }, `vertical-${formattedValue}`)), horizontal && yTicks.map(({
91
102
  formattedValue,
92
103
  offset
93
- }) => /*#__PURE__*/_jsx("line", {
104
+ }) => /*#__PURE__*/_jsx(GridLine, {
94
105
  y1: offset,
95
106
  y2: offset,
96
107
  x1: xScale.range()[0],
@@ -1,5 +1,5 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["message"];
4
4
  import * as React from 'react';
5
5
  import { styled } from '@mui/material/styles';
@@ -7,7 +7,7 @@ import { useDrawingArea } from '../hooks/useDrawingArea';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  const StyledText = styled('text')(({
9
9
  theme
10
- }) => ({
10
+ }) => _extends({}, theme.typography.body2, {
11
11
  stroke: 'none',
12
12
  fill: theme.palette.text.primary,
13
13
  shapeRendering: 'crispEdges',
@@ -29,6 +29,6 @@ export function ChartsLoadingOverlay(props) {
29
29
  x: left + width / 2,
30
30
  y: top + height / 2
31
31
  }, other, {
32
- children: message ?? 'Loading data ...'
32
+ children: message ?? 'Loading data'
33
33
  }));
34
34
  }
@@ -1,5 +1,5 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
1
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
2
+ import _extends from "@babel/runtime/helpers/esm/extends";
3
3
  const _excluded = ["message"];
4
4
  import * as React from 'react';
5
5
  import { styled } from '@mui/material/styles';
@@ -7,7 +7,7 @@ import { useDrawingArea } from '../hooks/useDrawingArea';
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  const StyledText = styled('text')(({
9
9
  theme
10
- }) => ({
10
+ }) => _extends({}, theme.typography.body2, {
11
11
  stroke: 'none',
12
12
  fill: theme.palette.text.primary,
13
13
  shapeRendering: 'crispEdges',
@@ -4,6 +4,7 @@ import clsx from 'clsx';
4
4
  import Typography from '@mui/material/Typography';
5
5
  import { ChartsTooltipCell, ChartsTooltipPaper, ChartsTooltipTable, ChartsTooltipMark, ChartsTooltipRow } from './ChartsTooltipTable';
6
6
  import { isCartesianSeries, utcFormatter } from './utils';
7
+ import { getLabel } from '../internals/getLabel';
7
8
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
8
9
  function DefaultChartsAxisTooltipContent(props) {
9
10
  const {
@@ -50,6 +51,7 @@ function DefaultChartsAxisTooltipContent(props) {
50
51
  if (formattedValue == null) {
51
52
  return null;
52
53
  }
54
+ const formattedLabel = getLabel(label, 'tooltip');
53
55
  return /*#__PURE__*/_jsxs(ChartsTooltipRow, {
54
56
  className: classes.row,
55
57
  children: [/*#__PURE__*/_jsx(ChartsTooltipCell, {
@@ -60,8 +62,8 @@ function DefaultChartsAxisTooltipContent(props) {
60
62
  })
61
63
  }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
62
64
  className: clsx(classes.labelCell, classes.cell),
63
- children: label ? /*#__PURE__*/_jsx(Typography, {
64
- children: label
65
+ children: formattedLabel ? /*#__PURE__*/_jsx(Typography, {
66
+ children: formattedLabel
65
67
  }) : null
66
68
  }), /*#__PURE__*/_jsx(ChartsTooltipCell, {
67
69
  className: clsx(classes.valueCell, classes.cell),
@@ -1,7 +1,9 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
1
2
  import * as React from 'react';
2
3
  import PropTypes from 'prop-types';
3
4
  import clsx from 'clsx';
4
5
  import { ChartsTooltipTable, ChartsTooltipCell, ChartsTooltipMark, ChartsTooltipPaper, ChartsTooltipRow } from './ChartsTooltipTable';
6
+ import { getLabel } from '../internals/getLabel';
5
7
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
6
8
  function DefaultChartsItemTooltipContent(props) {
7
9
  const {
@@ -19,12 +21,14 @@ function DefaultChartsItemTooltipContent(props) {
19
21
  color
20
22
  } = series.type === 'pie' ? {
21
23
  color: getColor(itemData.dataIndex),
22
- displayedLabel: series.data[itemData.dataIndex].label
24
+ displayedLabel: getLabel(series.data[itemData.dataIndex].label, 'tooltip')
23
25
  } : {
24
26
  color: getColor(itemData.dataIndex) ?? series.color,
25
- displayedLabel: series.label
27
+ displayedLabel: getLabel(series.label, 'tooltip')
26
28
  };
27
- const value = series.data[itemData.dataIndex];
29
+ const value = series.type === 'pie' ? _extends({}, series.data[itemData.dataIndex], {
30
+ label: getLabel(series.data[itemData.dataIndex].label, 'tooltip')
31
+ }) : series.data[itemData.dataIndex];
28
32
  const formattedValue = series.valueFormatter?.(value, {
29
33
  dataIndex: itemData.dataIndex
30
34
  });
@@ -53,20 +53,25 @@ export function useMouseTracker() {
53
53
  if (element === null) {
54
54
  return () => {};
55
55
  }
56
- const handleMouseOut = () => {
56
+ const handleOut = () => {
57
57
  setMousePosition(null);
58
58
  };
59
- const handleMouseMove = event => {
59
+ const handleMove = event => {
60
+ const target = 'targetTouches' in event ? event.targetTouches[0] : event;
60
61
  setMousePosition({
61
- x: event.clientX,
62
- y: event.clientY
62
+ x: target.clientX,
63
+ y: target.clientY
63
64
  });
64
65
  };
65
- element.addEventListener('mouseout', handleMouseOut);
66
- element.addEventListener('mousemove', handleMouseMove);
66
+ element.addEventListener('mouseout', handleOut);
67
+ element.addEventListener('mousemove', handleMove);
68
+ element.addEventListener('touchend', handleOut);
69
+ element.addEventListener('touchmove', handleMove);
67
70
  return () => {
68
- element.removeEventListener('mouseout', handleMouseOut);
69
- element.removeEventListener('mousemove', handleMouseMove);
71
+ element.removeEventListener('mouseout', handleOut);
72
+ element.removeEventListener('mousemove', handleMove);
73
+ element.addEventListener('touchend', handleOut);
74
+ element.addEventListener('touchmove', handleMove);
70
75
  };
71
76
  }, [svgRef]);
72
77
  return mousePosition;
@@ -167,8 +167,7 @@ function ChartsXAxis(inProps) {
167
167
  textAnchor: 'middle',
168
168
  dominantBaseline: position === 'bottom' ? 'hanging' : 'auto',
169
169
  fontSize: tickFontSize ?? 12
170
- }, tickLabelStyle),
171
- className: classes.tickLabel
170
+ }, tickLabelStyle)
172
171
  },
173
172
  className: classes.tickLabel,
174
173
  ownerState: {}
@@ -120,9 +120,9 @@ function ChartsYAxis(inProps) {
120
120
  fontSize: tickFontSize,
121
121
  textAnchor: position === 'right' ? 'start' : 'end',
122
122
  dominantBaseline: 'central'
123
- }, tickLabelStyle),
124
- className: classes.tickLabel
123
+ }, tickLabelStyle)
125
124
  },
125
+ className: classes.tickLabel,
126
126
  ownerState: {}
127
127
  });
128
128
  const axisLabelProps = useSlotProps({
@@ -74,17 +74,17 @@ function AreaElement(props) {
74
74
  const areaProps = useSlotProps({
75
75
  elementType: Area,
76
76
  externalSlotProps: slotProps?.area,
77
- additionalProps: _extends({}, other, getInteractionItemProps({
77
+ additionalProps: _extends({}, getInteractionItemProps({
78
78
  type: 'line',
79
79
  seriesId: id
80
80
  }), {
81
- className: classes.root,
82
81
  onClick,
83
82
  cursor: onClick ? 'pointer' : 'unset'
84
83
  }),
84
+ className: classes.root,
85
85
  ownerState
86
86
  });
87
- return /*#__PURE__*/_jsx(Area, _extends({}, areaProps));
87
+ return /*#__PURE__*/_jsx(Area, _extends({}, other, areaProps));
88
88
  }
89
89
  process.env.NODE_ENV !== "production" ? AreaElement.propTypes = {
90
90
  // ----------------------------- Warning --------------------------------
@@ -33,7 +33,8 @@ const useAggregatedData = () => {
33
33
  return stackingGroups.flatMap(({
34
34
  ids: groupIds
35
35
  }) => {
36
- return groupIds.flatMap(seriesId => {
36
+ return [...groupIds].reverse() // Revert stacked area for a more pleasant animation
37
+ .map(seriesId => {
37
38
  const {
38
39
  xAxisKey = defaultXAxisId,
39
40
  yAxisKey = defaultYAxisId,
@@ -92,7 +93,7 @@ function AreaPlot(props) {
92
93
  const getGradientId = useChartGradient();
93
94
  const completedData = useAggregatedData();
94
95
  return /*#__PURE__*/_jsx("g", _extends({}, other, {
95
- children: completedData.reverse().map(({
96
+ children: completedData.map(({
96
97
  d,
97
98
  seriesId,
98
99
  color,
@@ -205,6 +205,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
205
205
  }),
206
206
  /**
207
207
  * If `true`, a loading overlay is displayed.
208
+ * @default false
208
209
  */
209
210
  loading: PropTypes.bool,
210
211
  /**
@@ -304,6 +305,11 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
304
305
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
305
306
  classes: PropTypes.object,
306
307
  colorMap: PropTypes.oneOfType([PropTypes.shape({
308
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
309
+ type: PropTypes.oneOf(['ordinal']).isRequired,
310
+ unknownColor: PropTypes.string,
311
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
312
+ }), PropTypes.shape({
307
313
  color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
308
314
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
309
315
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -312,11 +318,6 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
312
318
  colors: PropTypes.arrayOf(PropTypes.string).isRequired,
313
319
  thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
314
320
  type: PropTypes.oneOf(['piecewise']).isRequired
315
- }), PropTypes.shape({
316
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
317
- type: PropTypes.oneOf(['ordinal']).isRequired,
318
- unknownColor: PropTypes.string,
319
- values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
320
321
  })]),
321
322
  data: PropTypes.array,
322
323
  dataKey: PropTypes.string,
@@ -357,6 +358,11 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
357
358
  axisId: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
358
359
  classes: PropTypes.object,
359
360
  colorMap: PropTypes.oneOfType([PropTypes.shape({
361
+ colors: PropTypes.arrayOf(PropTypes.string).isRequired,
362
+ type: PropTypes.oneOf(['ordinal']).isRequired,
363
+ unknownColor: PropTypes.string,
364
+ values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
365
+ }), PropTypes.shape({
360
366
  color: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string.isRequired), PropTypes.func]).isRequired,
361
367
  max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
362
368
  min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
@@ -365,11 +371,6 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
365
371
  colors: PropTypes.arrayOf(PropTypes.string).isRequired,
366
372
  thresholds: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]).isRequired).isRequired,
367
373
  type: PropTypes.oneOf(['piecewise']).isRequired
368
- }), PropTypes.shape({
369
- colors: PropTypes.arrayOf(PropTypes.string).isRequired,
370
- type: PropTypes.oneOf(['ordinal']).isRequired,
371
- unknownColor: PropTypes.string,
372
- values: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired)
373
374
  })]),
374
375
  data: PropTypes.array,
375
376
  dataKey: PropTypes.string,