@mui/x-charts 7.20.0 → 7.22.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 (93) hide show
  1. package/BarChart/BarChart.js +1 -1
  2. package/BarChart/BarPlot.d.ts +1 -1
  3. package/BarChart/BarPlot.js +6 -3
  4. package/BarChart/useBarChartProps.js +2 -2
  5. package/CHANGELOG.md +200 -31
  6. package/ChartContainer/ChartContainer.d.ts +3 -2
  7. package/ChartContainer/ChartContainer.js +11 -2
  8. package/ChartContainer/useChartContainerProps.d.ts +2 -0
  9. package/ChartContainer/useChartContainerProps.js +7 -5
  10. package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.d.ts +2 -2
  11. package/LineChart/AreaPlot.js +3 -1
  12. package/LineChart/LinePlot.js +3 -1
  13. package/LineChart/MarkPlot.d.ts +1 -1
  14. package/LineChart/MarkPlot.js +10 -8
  15. package/LineChart/useLineChartProps.d.ts +10 -10
  16. package/LineChart/useLineChartProps.js +4 -5
  17. package/PieChart/PieChart.js +3 -3
  18. package/PieChart/PiePlot.js +3 -1
  19. package/ResponsiveChartContainer/ResponsiveChartContainer.js +5 -0
  20. package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +1 -1
  21. package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +4 -2
  22. package/ScatterChart/ScatterChart.js +5 -0
  23. package/ScatterChart/extremums.js +4 -4
  24. package/ScatterChart/formatter.js +22 -3
  25. package/SparkLineChart/SparkLineChart.js +5 -0
  26. package/context/AnimationProvider/Animation.types.d.ts +15 -0
  27. package/context/AnimationProvider/Animation.types.js +1 -0
  28. package/context/AnimationProvider/AnimationContext.d.ts +4 -0
  29. package/context/AnimationProvider/AnimationContext.js +10 -0
  30. package/context/AnimationProvider/AnimationProvider.d.ts +4 -0
  31. package/context/AnimationProvider/AnimationProvider.js +55 -0
  32. package/context/AnimationProvider/index.d.ts +4 -0
  33. package/context/AnimationProvider/index.js +4 -0
  34. package/context/AnimationProvider/useSkipAnimation.d.ts +6 -0
  35. package/context/AnimationProvider/useSkipAnimation.js +20 -0
  36. package/index.js +1 -1
  37. package/internals/defaultizeColor.d.ts +7 -1
  38. package/internals/index.d.ts +1 -1
  39. package/internals/index.js +1 -1
  40. package/models/seriesType/scatter.d.ts +25 -1
  41. package/modern/BarChart/BarChart.js +1 -1
  42. package/modern/BarChart/BarPlot.js +6 -3
  43. package/modern/BarChart/useBarChartProps.js +2 -2
  44. package/modern/ChartContainer/ChartContainer.js +11 -2
  45. package/modern/ChartContainer/useChartContainerProps.js +7 -5
  46. package/modern/LineChart/AreaPlot.js +3 -1
  47. package/modern/LineChart/LinePlot.js +3 -1
  48. package/modern/LineChart/MarkPlot.js +10 -8
  49. package/modern/LineChart/useLineChartProps.js +4 -5
  50. package/modern/PieChart/PieChart.js +3 -3
  51. package/modern/PieChart/PiePlot.js +3 -1
  52. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +5 -0
  53. package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +4 -2
  54. package/modern/ScatterChart/ScatterChart.js +5 -0
  55. package/modern/ScatterChart/extremums.js +4 -4
  56. package/modern/ScatterChart/formatter.js +22 -3
  57. package/modern/SparkLineChart/SparkLineChart.js +5 -0
  58. package/modern/context/AnimationProvider/Animation.types.js +1 -0
  59. package/modern/context/AnimationProvider/AnimationContext.js +10 -0
  60. package/modern/context/AnimationProvider/AnimationProvider.js +55 -0
  61. package/modern/context/AnimationProvider/index.js +4 -0
  62. package/modern/context/AnimationProvider/useSkipAnimation.js +20 -0
  63. package/modern/index.js +1 -1
  64. package/modern/internals/index.js +1 -1
  65. package/node/BarChart/BarChart.js +1 -1
  66. package/node/BarChart/BarPlot.js +4 -2
  67. package/node/BarChart/useBarChartProps.js +2 -2
  68. package/node/ChartContainer/ChartContainer.js +11 -2
  69. package/node/ChartContainer/useChartContainerProps.js +7 -5
  70. package/node/LineChart/AreaPlot.js +3 -1
  71. package/node/LineChart/LinePlot.js +3 -1
  72. package/node/LineChart/MarkPlot.js +10 -8
  73. package/node/LineChart/useLineChartProps.js +4 -5
  74. package/node/PieChart/PieChart.js +3 -3
  75. package/node/PieChart/PiePlot.js +3 -1
  76. package/node/ResponsiveChartContainer/ResponsiveChartContainer.js +5 -0
  77. package/node/ResponsiveChartContainer/useResponsiveChartContainerProps.js +4 -2
  78. package/node/ScatterChart/ScatterChart.js +5 -0
  79. package/node/ScatterChart/extremums.js +4 -4
  80. package/node/ScatterChart/formatter.js +23 -3
  81. package/node/SparkLineChart/SparkLineChart.js +5 -0
  82. package/node/context/AnimationProvider/Animation.types.js +5 -0
  83. package/node/context/AnimationProvider/AnimationContext.js +17 -0
  84. package/node/context/AnimationProvider/AnimationProvider.js +60 -0
  85. package/node/context/AnimationProvider/index.js +49 -0
  86. package/node/context/AnimationProvider/useSkipAnimation.js +25 -0
  87. package/node/index.js +1 -1
  88. package/node/internals/index.js +12 -8
  89. package/package.json +4 -4
  90. package/hooks/useReducedMotion.d.ts +0 -8
  91. package/hooks/useReducedMotion.js +0 -39
  92. package/modern/hooks/useReducedMotion.js +0 -39
  93. package/node/hooks/useReducedMotion.js +0 -45
@@ -12,8 +12,7 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
12
12
  var React = _interopRequireWildcard(require("react"));
13
13
  var _useForkRef = _interopRequireDefault(require("@mui/utils/useForkRef"));
14
14
  var _useDefaultizeAxis = require("./useDefaultizeAxis");
15
- var _useReducedMotion = require("../hooks/useReducedMotion");
16
- const _excluded = ["width", "height", "series", "margin", "xAxis", "yAxis", "zAxis", "colors", "dataset", "sx", "title", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "children"];
15
+ const _excluded = ["width", "height", "series", "margin", "xAxis", "yAxis", "zAxis", "colors", "dataset", "sx", "title", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "children", "skipAnimation"];
17
16
  const useChartContainerProps = (props, ref) => {
18
17
  const {
19
18
  width,
@@ -32,13 +31,12 @@ const useChartContainerProps = (props, ref) => {
32
31
  highlightedItem,
33
32
  onHighlightChange,
34
33
  plugins,
35
- children
34
+ children,
35
+ skipAnimation
36
36
  } = props,
37
37
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
38
38
  const svgRef = React.useRef(null);
39
39
  const chartSurfaceRef = (0, _useForkRef.default)(ref, svgRef);
40
- (0, _useReducedMotion.useReducedMotion)(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
41
-
42
40
  const [defaultizedXAxis, defaultizedYAxis] = (0, _useDefaultizeAxis.useDefaultizeAxis)(xAxis, yAxis, dataset);
43
41
  const drawingProviderProps = {
44
42
  width,
@@ -46,6 +44,9 @@ const useChartContainerProps = (props, ref) => {
46
44
  margin,
47
45
  svgRef
48
46
  };
47
+ const animationProviderProps = {
48
+ skipAnimation
49
+ };
49
50
  const pluginProviderProps = {
50
51
  plugins
51
52
  };
@@ -85,6 +86,7 @@ const useChartContainerProps = (props, ref) => {
85
86
  highlightedProviderProps,
86
87
  chartsSurfaceProps,
87
88
  pluginProviderProps,
89
+ animationProviderProps,
88
90
  xAxis: defaultizedXAxis,
89
91
  yAxis: defaultizedYAxis
90
92
  };
@@ -19,6 +19,7 @@ var _getCurve = _interopRequireDefault(require("../internals/getCurve"));
19
19
  var _constants = require("../constants");
20
20
  var _ChartsAxesGradients = require("../internals/components/ChartsAxesGradients");
21
21
  var _useSeries = require("../hooks/useSeries");
22
+ var _AnimationProvider = require("../context/AnimationProvider");
22
23
  var _jsxRuntime = require("react/jsx-runtime");
23
24
  const _excluded = ["slots", "slotProps", "onItemClick", "skipAnimation"];
24
25
  const useAggregatedData = () => {
@@ -121,9 +122,10 @@ function AreaPlot(props) {
121
122
  slots,
122
123
  slotProps,
123
124
  onItemClick,
124
- skipAnimation
125
+ skipAnimation: inSkipAnimation
125
126
  } = props,
126
127
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
128
+ const skipAnimation = (0, _AnimationProvider.useSkipAnimation)(inSkipAnimation);
127
129
  const getGradientId = (0, _ChartsAxesGradients.useChartGradient)();
128
130
  const completedData = useAggregatedData();
129
131
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", (0, _extends2.default)({}, other, {
@@ -19,6 +19,7 @@ var _getCurve = _interopRequireDefault(require("../internals/getCurve"));
19
19
  var _constants = require("../constants");
20
20
  var _ChartsAxesGradients = require("../internals/components/ChartsAxesGradients");
21
21
  var _useSeries = require("../hooks/useSeries");
22
+ var _AnimationProvider = require("../context/AnimationProvider");
22
23
  var _jsxRuntime = require("react/jsx-runtime");
23
24
  const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick"];
24
25
  const useAggregatedData = () => {
@@ -101,10 +102,11 @@ function LinePlot(props) {
101
102
  const {
102
103
  slots,
103
104
  slotProps,
104
- skipAnimation,
105
+ skipAnimation: inSkipAnimation,
105
106
  onItemClick
106
107
  } = props,
107
108
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
109
+ const skipAnimation = (0, _AnimationProvider.useSkipAnimation)(inSkipAnimation);
108
110
  const getGradientId = (0, _ChartsAxesGradients.useChartGradient)();
109
111
  const completedData = useAggregatedData();
110
112
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", (0, _extends2.default)({}, other, {
@@ -9,18 +9,19 @@ Object.defineProperty(exports, "__esModule", {
9
9
  exports.MarkPlot = MarkPlot;
10
10
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
11
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
12
- var React = _interopRequireWildcard(require("react"));
13
12
  var _propTypes = _interopRequireDefault(require("prop-types"));
13
+ var React = _interopRequireWildcard(require("react"));
14
+ var _constants = require("../constants");
15
+ var _AnimationProvider = require("../context/AnimationProvider");
14
16
  var _CartesianProvider = require("../context/CartesianProvider");
15
- var _MarkElement = require("./MarkElement");
16
- var _useScale = require("../hooks/useScale");
17
17
  var _useChartId = require("../hooks/useChartId");
18
- var _constants = require("../constants");
19
- var _cleanId = require("../internals/cleanId");
20
- var _getColor = _interopRequireDefault(require("./getColor"));
21
- var _useSeries = require("../hooks/useSeries");
22
18
  var _useDrawingArea = require("../hooks/useDrawingArea");
19
+ var _useScale = require("../hooks/useScale");
20
+ var _useSeries = require("../hooks/useSeries");
21
+ var _cleanId = require("../internals/cleanId");
23
22
  var _CircleMarkElement = require("./CircleMarkElement");
23
+ var _getColor = _interopRequireDefault(require("./getColor"));
24
+ var _MarkElement = require("./MarkElement");
24
25
  var _jsxRuntime = require("react/jsx-runtime");
25
26
  const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick", "experimentalRendering"];
26
27
  /**
@@ -37,11 +38,12 @@ function MarkPlot(props) {
37
38
  const {
38
39
  slots,
39
40
  slotProps,
40
- skipAnimation,
41
+ skipAnimation: inSkipAnimation,
41
42
  onItemClick,
42
43
  experimentalRendering
43
44
  } = props,
44
45
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
46
+ const skipAnimation = (0, _AnimationProvider.useSkipAnimation)(inSkipAnimation);
45
47
  const seriesData = (0, _useSeries.useLineSeries)();
46
48
  const axisData = (0, _CartesianProvider.useCartesianContext)();
47
49
  const chartId = (0, _useChartId.useChartId)();
@@ -77,7 +77,8 @@ const useLineChartProps = props => {
77
77
  highlightedItem,
78
78
  onHighlightChange,
79
79
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
80
- className
80
+ className,
81
+ skipAnimation
81
82
  });
82
83
  const axisClickHandlerProps = {
83
84
  onAxisClick
@@ -95,14 +96,12 @@ const useLineChartProps = props => {
95
96
  const areaPlotProps = {
96
97
  slots,
97
98
  slotProps,
98
- onItemClick: onAreaClick,
99
- skipAnimation
99
+ onItemClick: onAreaClick
100
100
  };
101
101
  const linePlotProps = {
102
102
  slots,
103
103
  slotProps,
104
- onItemClick: onLineClick,
105
- skipAnimation
104
+ onItemClick: onLineClick
106
105
  };
107
106
  const markPlotProps = {
108
107
  slots,
@@ -112,6 +112,7 @@ const PieChart = exports.PieChart = /*#__PURE__*/React.forwardRef(function PieCh
112
112
  highlightedItem: highlightedItem,
113
113
  onHighlightChange: onHighlightChange,
114
114
  className: className,
115
+ skipAnimation: skipAnimation,
115
116
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxis.ChartsAxis, {
116
117
  topAxis: topAxis,
117
118
  leftAxis: leftAxis,
@@ -122,8 +123,7 @@ const PieChart = exports.PieChart = /*#__PURE__*/React.forwardRef(function PieCh
122
123
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_PiePlot.PiePlot, {
123
124
  slots: slots,
124
125
  slotProps: slotProps,
125
- onItemClick: onItemClick,
126
- skipAnimation: skipAnimation
126
+ onItemClick: onItemClick
127
127
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsOverlay.ChartsOverlay, {
128
128
  loading: loading,
129
129
  slots: slots,
@@ -270,7 +270,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
270
270
  series: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
271
271
  /**
272
272
  * If `true`, animations are skipped.
273
- * @default false
273
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
274
274
  */
275
275
  skipAnimation: _propTypes.default.bool,
276
276
  /**
@@ -15,6 +15,7 @@ var _PieArcLabelPlot = require("./PieArcLabelPlot");
15
15
  var _getPercentageValue = require("../internals/getPercentageValue");
16
16
  var _getPieCoordinates = require("./getPieCoordinates");
17
17
  var _useSeries = require("../hooks/useSeries");
18
+ var _AnimationProvider = require("../context/AnimationProvider");
18
19
  var _jsxRuntime = require("react/jsx-runtime");
19
20
  /**
20
21
  * Demos:
@@ -28,7 +29,7 @@ var _jsxRuntime = require("react/jsx-runtime");
28
29
  */
29
30
  function PiePlot(props) {
30
31
  const {
31
- skipAnimation,
32
+ skipAnimation: inSkipAnimation,
32
33
  slots,
33
34
  slotProps,
34
35
  onItemClick
@@ -40,6 +41,7 @@ function PiePlot(props) {
40
41
  width,
41
42
  height
42
43
  } = React.useContext(_DrawingProvider.DrawingContext);
44
+ const skipAnimation = (0, _AnimationProvider.useSkipAnimation)(inSkipAnimation);
43
45
  if (seriesData === undefined) {
44
46
  return null;
45
47
  }
@@ -97,6 +97,11 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
97
97
  * Please refer to the appropriate docs page to learn more about it.
98
98
  */
99
99
  series: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
100
+ /**
101
+ * If `true`, animations are skipped.
102
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
103
+ */
104
+ skipAnimation: _propTypes.default.bool,
100
105
  sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
101
106
  title: _propTypes.default.string,
102
107
  viewBox: _propTypes.default.shape({
@@ -9,7 +9,7 @@ exports.useResponsiveChartContainerProps = void 0;
9
9
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
10
10
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
11
11
  var _useChartContainerDimensions = require("./useChartContainerDimensions");
12
- const _excluded = ["width", "height", "resolveSizeBeforeRender", "margin", "children", "series", "colors", "dataset", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "sx", "title", "viewBox", "xAxis", "yAxis", "zAxis"];
12
+ const _excluded = ["width", "height", "resolveSizeBeforeRender", "margin", "children", "series", "colors", "dataset", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "sx", "title", "viewBox", "xAxis", "yAxis", "zAxis", "skipAnimation"];
13
13
  const useResponsiveChartContainerProps = (props, ref) => {
14
14
  const {
15
15
  width,
@@ -30,7 +30,8 @@ const useResponsiveChartContainerProps = (props, ref) => {
30
30
  viewBox,
31
31
  xAxis,
32
32
  yAxis,
33
- zAxis
33
+ zAxis,
34
+ skipAnimation
34
35
  } = props,
35
36
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
36
37
  const {
@@ -62,6 +63,7 @@ const useResponsiveChartContainerProps = (props, ref) => {
62
63
  xAxis,
63
64
  yAxis,
64
65
  zAxis,
66
+ skipAnimation,
65
67
  width: dWidth,
66
68
  height: dHeight,
67
69
  ref
@@ -205,6 +205,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
205
205
  * An array of [[ScatterSeriesType]] objects.
206
206
  */
207
207
  series: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
208
+ /**
209
+ * If `true`, animations are skipped.
210
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
211
+ */
212
+ skipAnimation: _propTypes.default.bool,
208
213
  /**
209
214
  * The props used for each component slot.
210
215
  * @default {}
@@ -24,13 +24,13 @@ const getExtremumX = params => {
24
24
  seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey,
25
25
  seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey
26
26
  });
27
- const seriesMinMax = series[seriesId].data.reduce((accSeries, d, dataIndex) => {
27
+ const seriesMinMax = series[seriesId].data?.reduce((accSeries, d, dataIndex) => {
28
28
  if (filter && !filter(d, dataIndex)) {
29
29
  return accSeries;
30
30
  }
31
31
  return mergeMinMax(accSeries, [d.x, d.x]);
32
32
  }, [Infinity, -Infinity]);
33
- return mergeMinMax(acc, seriesMinMax);
33
+ return mergeMinMax(acc, seriesMinMax ?? [Infinity, -Infinity]);
34
34
  }, [Infinity, -Infinity]);
35
35
  };
36
36
  exports.getExtremumX = getExtremumX;
@@ -51,13 +51,13 @@ const getExtremumY = params => {
51
51
  seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey,
52
52
  seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey
53
53
  });
54
- const seriesMinMax = series[seriesId].data.reduce((accSeries, d, dataIndex) => {
54
+ const seriesMinMax = series[seriesId].data?.reduce((accSeries, d, dataIndex) => {
55
55
  if (filter && !filter(d, dataIndex)) {
56
56
  return accSeries;
57
57
  }
58
58
  return mergeMinMax(accSeries, [d.y, d.y]);
59
59
  }, [Infinity, -Infinity]);
60
- return mergeMinMax(acc, seriesMinMax);
60
+ return mergeMinMax(acc, seriesMinMax ?? [Infinity, -Infinity]);
61
61
  }, [Infinity, -Infinity]);
62
62
  };
63
63
  exports.getExtremumY = getExtremumY;
@@ -1,16 +1,36 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.default = void 0;
7
- var _defaultizeValueFormatter = require("../internals/defaultizeValueFormatter");
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
8
9
  const formatter = ({
9
10
  series,
10
11
  seriesOrder
11
- }) => {
12
+ }, dataset) => {
13
+ const completeSeries = Object.fromEntries(Object.entries(series).map(([seriesId, seriesData]) => {
14
+ const datasetKeys = seriesData?.datasetKeys;
15
+ const missingKeys = ['x', 'y', 'id'].filter(key => typeof datasetKeys?.[key] !== 'string');
16
+ if (seriesData?.datasetKeys && missingKeys.length > 0) {
17
+ throw new Error([`MUI X: scatter series with id='${seriesId}' has incomplete datasetKeys.`, `Properties ${missingKeys.map(key => `"${key}"`).join(', ')} are missing.`].join('\n'));
18
+ }
19
+ const data = !datasetKeys ? seriesData.data ?? [] : dataset?.map(d => {
20
+ return {
21
+ x: d[datasetKeys.x],
22
+ y: d[datasetKeys.y],
23
+ z: datasetKeys.z && d[datasetKeys.z],
24
+ id: d[datasetKeys.id]
25
+ };
26
+ }) ?? [];
27
+ return [seriesId, (0, _extends2.default)({}, seriesData, {
28
+ data,
29
+ valueFormatter: seriesData.valueFormatter ?? (v => `(${v.x}, ${v.y})`)
30
+ })];
31
+ }));
12
32
  return {
13
- series: (0, _defaultizeValueFormatter.defaultizeValueFormatter)(series, v => `(${v.x}, ${v.y})`),
33
+ series: completeSeries,
14
34
  seriesOrder
15
35
  };
16
36
  };
@@ -222,6 +222,11 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
222
222
  * @default false
223
223
  */
224
224
  showTooltip: _propTypes.default.bool,
225
+ /**
226
+ * If `true`, animations are skipped.
227
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
228
+ */
229
+ skipAnimation: _propTypes.default.bool,
225
230
  /**
226
231
  * The props used for each component slot.
227
232
  * @default {}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.AnimationContext = void 0;
8
+ var React = _interopRequireWildcard(require("react"));
9
+ const AnimationContext = exports.AnimationContext = /*#__PURE__*/React.createContext({
10
+ isInitialized: false,
11
+ data: {
12
+ skipAnimation: undefined
13
+ }
14
+ });
15
+ if (process.env.NODE_ENV !== 'production') {
16
+ AnimationContext.displayName = 'AnimationContext';
17
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.AnimationProvider = AnimationProvider;
9
+ var _web = require("@react-spring/web");
10
+ var React = _interopRequireWildcard(require("react"));
11
+ var _AnimationContext = require("./AnimationContext");
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ function AnimationProvider(props) {
14
+ // Part of the behavior was taken from:
15
+ // https://github.com/pmndrs/react-spring/blob/fd65b605b85c3a24143c4ce9dd322fdfca9c66be/packages/shared/src/hooks/useReducedMotion.ts
16
+ const {
17
+ children,
18
+ skipAnimation: inSkipAnimation
19
+ } = props;
20
+
21
+ // Skip animation test/jsdom
22
+ const isAnimationDisabledEnvironment = typeof window === 'undefined' || !window?.matchMedia;
23
+
24
+ // We use the value of `isAnimationDisabledEnvironment` as the initial value of `skipAnimation` to avoid
25
+ // re-rendering the component on environments where matchMedia is not supported, hence skipAnimation will always be true.
26
+ const [skipAnimation, setSkipAnimation] = React.useState(isAnimationDisabledEnvironment || undefined);
27
+ (0, _web.useIsomorphicLayoutEffect)(() => {
28
+ if (isAnimationDisabledEnvironment) {
29
+ return undefined;
30
+ }
31
+ const handleMediaChange = event => {
32
+ // This hook can remove animation but never activate it.
33
+ const inputValue = event.matches || undefined;
34
+ setSkipAnimation(inputValue);
35
+ _web.Globals.assign({
36
+ skipAnimation: inputValue
37
+ });
38
+ };
39
+ const mql = window.matchMedia('(prefers-reduced-motion)');
40
+ handleMediaChange(mql);
41
+
42
+ // MatchMedia is not fully supported in all environments, so we need to check if it exists before calling addEventListener
43
+ mql?.addEventListener?.('change', handleMediaChange);
44
+ return () => {
45
+ mql?.removeEventListener?.('change', handleMediaChange);
46
+ };
47
+ }, []);
48
+ const value = React.useMemo(() => ({
49
+ isInitialized: true,
50
+ data: {
51
+ // If dev sets `skipAnimation` to true, it will skip all animations.
52
+ // If dev sets `skipAnimation` to false, it will use user's preference.
53
+ skipAnimation: inSkipAnimation || skipAnimation
54
+ }
55
+ }), [skipAnimation, inSkipAnimation]);
56
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_AnimationContext.AnimationContext.Provider, {
57
+ value: value,
58
+ children: children
59
+ });
60
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _Animation = require("./Animation.types");
7
+ Object.keys(_Animation).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _Animation[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _Animation[key];
14
+ }
15
+ });
16
+ });
17
+ var _AnimationContext = require("./AnimationContext");
18
+ Object.keys(_AnimationContext).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _AnimationContext[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _AnimationContext[key];
25
+ }
26
+ });
27
+ });
28
+ var _AnimationProvider = require("./AnimationProvider");
29
+ Object.keys(_AnimationProvider).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _AnimationProvider[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _AnimationProvider[key];
36
+ }
37
+ });
38
+ });
39
+ var _useSkipAnimation = require("./useSkipAnimation");
40
+ Object.keys(_useSkipAnimation).forEach(function (key) {
41
+ if (key === "default" || key === "__esModule") return;
42
+ if (key in exports && exports[key] === _useSkipAnimation[key]) return;
43
+ Object.defineProperty(exports, key, {
44
+ enumerable: true,
45
+ get: function () {
46
+ return _useSkipAnimation[key];
47
+ }
48
+ });
49
+ });
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ 'use client';
3
+
4
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.useSkipAnimation = useSkipAnimation;
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _AnimationContext = require("./AnimationContext");
11
+ /**
12
+ * A hook to get if chart animations should be skipped.
13
+ *
14
+ * @returns {boolean|undefined} whether to skip animations
15
+ */
16
+ function useSkipAnimation(skipAnimation) {
17
+ const {
18
+ isInitialized,
19
+ data
20
+ } = React.useContext(_AnimationContext.AnimationContext);
21
+ if (!isInitialized) {
22
+ throw new Error(['MUI X: Could not find the animation ref context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
23
+ }
24
+ return skipAnimation || data.skipAnimation;
25
+ }
package/node/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.20.0
2
+ * @mui/x-charts v7.22.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
- useReducedMotion: true,
8
7
  useSeries: true,
9
8
  useInteractionItemProps: true,
10
9
  useDrawingArea: true,
@@ -58,12 +57,6 @@ Object.defineProperty(exports, "useLineChartProps", {
58
57
  return _useLineChartProps.useLineChartProps;
59
58
  }
60
59
  });
61
- Object.defineProperty(exports, "useReducedMotion", {
62
- enumerable: true,
63
- get: function () {
64
- return _useReducedMotion.useReducedMotion;
65
- }
66
- });
67
60
  Object.defineProperty(exports, "useResponsiveChartContainerProps", {
68
61
  enumerable: true,
69
62
  get: function () {
@@ -118,7 +111,6 @@ Object.keys(_ResizableContainer).forEach(function (key) {
118
111
  }
119
112
  });
120
113
  });
121
- var _useReducedMotion = require("../hooks/useReducedMotion");
122
114
  var _useSeries = require("../hooks/useSeries");
123
115
  var _useInteractionItemProps = require("../hooks/useInteractionItemProps");
124
116
  var _useDrawingArea = require("../hooks/useDrawingArea");
@@ -284,6 +276,18 @@ Object.keys(_PluginProvider).forEach(function (key) {
284
276
  }
285
277
  });
286
278
  });
279
+ var _AnimationProvider = require("../context/AnimationProvider");
280
+ Object.keys(_AnimationProvider).forEach(function (key) {
281
+ if (key === "default" || key === "__esModule") return;
282
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
283
+ if (key in exports && exports[key] === _AnimationProvider[key]) return;
284
+ Object.defineProperty(exports, key, {
285
+ enumerable: true,
286
+ get: function () {
287
+ return _AnimationProvider[key];
288
+ }
289
+ });
290
+ });
287
291
  var _getAxisExtremum = require("../context/CartesianProvider/getAxisExtremum");
288
292
  var _config = require("../models/seriesType/config");
289
293
  Object.keys(_config).forEach(function (key) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "7.20.0",
3
+ "version": "7.22.0",
4
4
  "description": "The community edition of the Charts components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./node/index.js",
@@ -31,12 +31,12 @@
31
31
  "dependencies": {
32
32
  "@babel/runtime": "^7.25.7",
33
33
  "@mui/utils": "^5.16.6 || ^6.0.0",
34
- "@react-spring/rafz": "^9.7.4",
35
- "@react-spring/web": "^9.7.4",
34
+ "@react-spring/rafz": "^9.7.5",
35
+ "@react-spring/web": "^9.7.5",
36
36
  "clsx": "^2.1.1",
37
37
  "prop-types": "^15.8.1",
38
38
  "@mui/x-charts-vendor": "7.20.0",
39
- "@mui/x-internals": "7.20.0"
39
+ "@mui/x-internals": "7.21.0"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "@emotion/react": "^11.9.0",
@@ -1,8 +0,0 @@
1
- /**
2
- * Returns `boolean` or `null`, used to automatically
3
- * set skipAnimations to the value of the user's
4
- * `prefers-reduced-motion` query.
5
- *
6
- * The return value, post-effect, is the value of their preferred setting
7
- */
8
- export declare const useReducedMotion: () => void;
@@ -1,39 +0,0 @@
1
- 'use client';
2
-
3
- import { useIsomorphicLayoutEffect, Globals } from '@react-spring/web';
4
- const handleMediaChange = event => {
5
- Globals.assign({
6
- // Modification such the react-spring implementation such that this hook can remove animation but never activate animation.
7
- skipAnimation: event.matches || undefined
8
- });
9
- };
10
-
11
- /**
12
- * Returns `boolean` or `null`, used to automatically
13
- * set skipAnimations to the value of the user's
14
- * `prefers-reduced-motion` query.
15
- *
16
- * The return value, post-effect, is the value of their preferred setting
17
- */
18
- export const useReducedMotion = () => {
19
- // Taken from: https://github.com/pmndrs/react-spring/blob/fd65b605b85c3a24143c4ce9dd322fdfca9c66be/packages/shared/src/hooks/useReducedMotion.ts
20
-
21
- useIsomorphicLayoutEffect(() => {
22
- // Skip animation test/jsdom
23
- const shouldSkipAnimation = !window?.matchMedia;
24
- if (shouldSkipAnimation) {
25
- handleMediaChange({
26
- matches: true
27
- });
28
- return undefined;
29
- }
30
- const mql = window.matchMedia('(prefers-reduced-motion)');
31
- handleMediaChange(mql);
32
-
33
- // MatchMedia is not fully supported in all environments, so we need to check if it exists before calling addEventListener
34
- mql.addEventListener?.('change', handleMediaChange);
35
- return () => {
36
- mql.removeEventListener?.('change', handleMediaChange);
37
- };
38
- }, []);
39
- };