@mui/x-charts 7.19.0 → 7.21.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 (99) hide show
  1. package/BarChart/BarChart.d.ts +1 -1
  2. package/BarChart/BarChart.js +2 -2
  3. package/BarChart/BarPlot.d.ts +1 -1
  4. package/BarChart/BarPlot.js +6 -3
  5. package/BarChart/useBarChartProps.js +2 -2
  6. package/CHANGELOG.md +224 -43
  7. package/ChartContainer/ChartContainer.d.ts +3 -2
  8. package/ChartContainer/ChartContainer.js +11 -2
  9. package/ChartContainer/useChartContainerProps.d.ts +2 -0
  10. package/ChartContainer/useChartContainerProps.js +7 -5
  11. package/LineChart/AreaPlot.js +3 -1
  12. package/LineChart/LineChart.d.ts +1 -1
  13. package/LineChart/LineChart.js +1 -1
  14. package/LineChart/LinePlot.js +3 -1
  15. package/LineChart/MarkPlot.d.ts +1 -1
  16. package/LineChart/MarkPlot.js +10 -8
  17. package/LineChart/useLineChartProps.d.ts +10 -10
  18. package/LineChart/useLineChartProps.js +4 -5
  19. package/PieChart/PieChart.d.ts +1 -1
  20. package/PieChart/PieChart.js +4 -4
  21. package/PieChart/PiePlot.js +3 -1
  22. package/ResponsiveChartContainer/ResponsiveChartContainer.js +5 -0
  23. package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +1 -1
  24. package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +4 -2
  25. package/ScatterChart/ScatterChart.d.ts +1 -1
  26. package/ScatterChart/ScatterChart.js +6 -1
  27. package/ScatterChart/extremums.js +4 -4
  28. package/ScatterChart/formatter.js +22 -3
  29. package/SparkLineChart/SparkLineChart.js +5 -0
  30. package/context/AnimationProvider/Animation.types.d.ts +15 -0
  31. package/context/AnimationProvider/Animation.types.js +1 -0
  32. package/context/AnimationProvider/AnimationContext.d.ts +4 -0
  33. package/context/AnimationProvider/AnimationContext.js +10 -0
  34. package/context/AnimationProvider/AnimationProvider.d.ts +4 -0
  35. package/context/AnimationProvider/AnimationProvider.js +55 -0
  36. package/context/AnimationProvider/index.d.ts +4 -0
  37. package/context/AnimationProvider/index.js +4 -0
  38. package/context/AnimationProvider/useSkipAnimation.d.ts +6 -0
  39. package/context/AnimationProvider/useSkipAnimation.js +20 -0
  40. package/index.js +1 -1
  41. package/internals/defaultizeColor.d.ts +7 -1
  42. package/internals/index.d.ts +1 -1
  43. package/internals/index.js +1 -1
  44. package/models/seriesType/scatter.d.ts +25 -1
  45. package/modern/BarChart/BarChart.js +2 -2
  46. package/modern/BarChart/BarPlot.js +6 -3
  47. package/modern/BarChart/useBarChartProps.js +2 -2
  48. package/modern/ChartContainer/ChartContainer.js +11 -2
  49. package/modern/ChartContainer/useChartContainerProps.js +7 -5
  50. package/modern/LineChart/AreaPlot.js +3 -1
  51. package/modern/LineChart/LineChart.js +1 -1
  52. package/modern/LineChart/LinePlot.js +3 -1
  53. package/modern/LineChart/MarkPlot.js +10 -8
  54. package/modern/LineChart/useLineChartProps.js +4 -5
  55. package/modern/PieChart/PieChart.js +4 -4
  56. package/modern/PieChart/PiePlot.js +3 -1
  57. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +5 -0
  58. package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +4 -2
  59. package/modern/ScatterChart/ScatterChart.js +6 -1
  60. package/modern/ScatterChart/extremums.js +4 -4
  61. package/modern/ScatterChart/formatter.js +22 -3
  62. package/modern/SparkLineChart/SparkLineChart.js +5 -0
  63. package/modern/context/AnimationProvider/Animation.types.js +1 -0
  64. package/modern/context/AnimationProvider/AnimationContext.js +10 -0
  65. package/modern/context/AnimationProvider/AnimationProvider.js +55 -0
  66. package/modern/context/AnimationProvider/index.js +4 -0
  67. package/modern/context/AnimationProvider/useSkipAnimation.js +20 -0
  68. package/modern/index.js +1 -1
  69. package/modern/internals/index.js +1 -1
  70. package/node/BarChart/BarChart.js +2 -2
  71. package/node/BarChart/BarPlot.js +4 -2
  72. package/node/BarChart/useBarChartProps.js +2 -2
  73. package/node/ChartContainer/ChartContainer.js +11 -2
  74. package/node/ChartContainer/useChartContainerProps.js +7 -5
  75. package/node/LineChart/AreaPlot.js +3 -1
  76. package/node/LineChart/LineChart.js +1 -1
  77. package/node/LineChart/LinePlot.js +3 -1
  78. package/node/LineChart/MarkPlot.js +10 -8
  79. package/node/LineChart/useLineChartProps.js +4 -5
  80. package/node/PieChart/PieChart.js +4 -4
  81. package/node/PieChart/PiePlot.js +3 -1
  82. package/node/ResponsiveChartContainer/ResponsiveChartContainer.js +5 -0
  83. package/node/ResponsiveChartContainer/useResponsiveChartContainerProps.js +4 -2
  84. package/node/ScatterChart/ScatterChart.js +6 -1
  85. package/node/ScatterChart/extremums.js +4 -4
  86. package/node/ScatterChart/formatter.js +23 -3
  87. package/node/SparkLineChart/SparkLineChart.js +5 -0
  88. package/node/context/AnimationProvider/Animation.types.js +5 -0
  89. package/node/context/AnimationProvider/AnimationContext.js +17 -0
  90. package/node/context/AnimationProvider/AnimationProvider.js +60 -0
  91. package/node/context/AnimationProvider/index.js +49 -0
  92. package/node/context/AnimationProvider/useSkipAnimation.js +25 -0
  93. package/node/index.js +1 -1
  94. package/node/internals/index.js +12 -8
  95. package/package.json +7 -7
  96. package/hooks/useReducedMotion.d.ts +0 -8
  97. package/hooks/useReducedMotion.js +0 -39
  98. package/modern/hooks/useReducedMotion.js +0 -39
  99. package/node/hooks/useReducedMotion.js +0 -45
@@ -0,0 +1,55 @@
1
+ 'use client';
2
+
3
+ import { Globals, useIsomorphicLayoutEffect } from '@react-spring/web';
4
+ import * as React from 'react';
5
+ import { AnimationContext } from "./AnimationContext.js";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ function AnimationProvider(props) {
8
+ // Part of the behavior was taken from:
9
+ // https://github.com/pmndrs/react-spring/blob/fd65b605b85c3a24143c4ce9dd322fdfca9c66be/packages/shared/src/hooks/useReducedMotion.ts
10
+ const {
11
+ children,
12
+ skipAnimation: inSkipAnimation
13
+ } = props;
14
+
15
+ // Skip animation test/jsdom
16
+ const isAnimationDisabledEnvironment = typeof window === 'undefined' || !window?.matchMedia;
17
+
18
+ // We use the value of `isAnimationDisabledEnvironment` as the initial value of `skipAnimation` to avoid
19
+ // re-rendering the component on environments where matchMedia is not supported, hence skipAnimation will always be true.
20
+ const [skipAnimation, setSkipAnimation] = React.useState(isAnimationDisabledEnvironment || undefined);
21
+ useIsomorphicLayoutEffect(() => {
22
+ if (isAnimationDisabledEnvironment) {
23
+ return undefined;
24
+ }
25
+ const handleMediaChange = event => {
26
+ // This hook can remove animation but never activate it.
27
+ const inputValue = event.matches || undefined;
28
+ setSkipAnimation(inputValue);
29
+ Globals.assign({
30
+ skipAnimation: inputValue
31
+ });
32
+ };
33
+ const mql = window.matchMedia('(prefers-reduced-motion)');
34
+ handleMediaChange(mql);
35
+
36
+ // MatchMedia is not fully supported in all environments, so we need to check if it exists before calling addEventListener
37
+ mql?.addEventListener?.('change', handleMediaChange);
38
+ return () => {
39
+ mql?.removeEventListener?.('change', handleMediaChange);
40
+ };
41
+ }, []);
42
+ const value = React.useMemo(() => ({
43
+ isInitialized: true,
44
+ data: {
45
+ // If dev sets `skipAnimation` to true, it will skip all animations.
46
+ // If dev sets `skipAnimation` to false, it will use user's preference.
47
+ skipAnimation: inSkipAnimation || skipAnimation
48
+ }
49
+ }), [skipAnimation, inSkipAnimation]);
50
+ return /*#__PURE__*/_jsx(AnimationContext.Provider, {
51
+ value: value,
52
+ children: children
53
+ });
54
+ }
55
+ export { AnimationProvider };
@@ -0,0 +1,4 @@
1
+ export * from "./Animation.types.js";
2
+ export * from "./AnimationContext.js";
3
+ export * from "./AnimationProvider.js";
4
+ export * from "./useSkipAnimation.js";
@@ -0,0 +1,20 @@
1
+ 'use client';
2
+
3
+ import * as React from 'react';
4
+ import { AnimationContext } from "./AnimationContext.js";
5
+
6
+ /**
7
+ * A hook to get if chart animations should be skipped.
8
+ *
9
+ * @returns {boolean|undefined} whether to skip animations
10
+ */
11
+ export function useSkipAnimation(skipAnimation) {
12
+ const {
13
+ isInitialized,
14
+ data
15
+ } = React.useContext(AnimationContext);
16
+ if (!isInitialized) {
17
+ 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'));
18
+ }
19
+ return skipAnimation || data.skipAnimation;
20
+ }
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.19.0
2
+ * @mui/x-charts v7.21.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 @@ export * from "../ResponsiveChartContainer/useChartContainerDimensions.js";
4
4
  export * from "../ResponsiveChartContainer/ResizableContainer.js";
5
5
 
6
6
  // hooks
7
- export { useReducedMotion } from "../hooks/useReducedMotion.js";
8
7
  export { useSeries } from "../hooks/useSeries.js";
9
8
  export { useInteractionItemProps } from "../hooks/useInteractionItemProps.js";
10
9
  export { useDrawingArea } from "../hooks/useDrawingArea.js";
@@ -32,6 +31,7 @@ export * from "../context/InteractionProvider.js";
32
31
  export * from "../context/SeriesProvider/index.js";
33
32
  export * from "../context/ZAxisContextProvider.js";
34
33
  export * from "../context/PluginProvider/index.js";
34
+ export * from "../context/AnimationProvider/index.js";
35
35
  export { getAxisExtremum } from "../context/CartesianProvider/getAxisExtremum.js";
36
36
 
37
37
  // series configuration
@@ -70,7 +70,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
70
70
  * The configuration of axes highlight.
71
71
  * Default is set to 'band' in the bar direction.
72
72
  * Depends on `layout` prop.
73
- * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
73
+ * @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
74
74
  */
75
75
  axisHighlight: _propTypes.default.shape({
76
76
  x: _propTypes.default.oneOf(['band', 'line', 'none']),
@@ -226,7 +226,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
226
226
  series: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
227
227
  /**
228
228
  * If `true`, animations are skipped.
229
- * @default false
229
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
230
230
  */
231
231
  skipAnimation: _propTypes.default.bool,
232
232
  /**
@@ -20,6 +20,7 @@ var _BarClipPath = require("./BarClipPath");
20
20
  var _BarLabelPlot = require("./BarLabel/BarLabelPlot");
21
21
  var _checkScaleErrors = require("./checkScaleErrors");
22
22
  var _useSeries = require("../hooks/useSeries");
23
+ var _AnimationProvider = require("../context/AnimationProvider");
23
24
  var _jsxRuntime = require("react/jsx-runtime");
24
25
  const _excluded = ["skipAnimation", "onItemClick", "borderRadius", "barLabel"];
25
26
  /**
@@ -194,12 +195,13 @@ function BarPlot(props) {
194
195
  masksData
195
196
  } = useAggregatedData();
196
197
  const {
197
- skipAnimation,
198
+ skipAnimation: inSkipAnimation,
198
199
  onItemClick,
199
200
  borderRadius,
200
201
  barLabel
201
202
  } = props,
202
203
  other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
204
+ const skipAnimation = (0, _AnimationProvider.useSkipAnimation)(inSkipAnimation);
203
205
  const withoutBorderRadius = !borderRadius || borderRadius <= 0;
204
206
  const transition = (0, _web.useTransition)(completedData, {
205
207
  keys: bar => `${bar.seriesId}-${bar.dataIndex}`,
@@ -291,7 +293,7 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
291
293
  onItemClick: _propTypes.default.func,
292
294
  /**
293
295
  * If `true`, animations are skipped.
294
- * @default false
296
+ * @default undefined
295
297
  */
296
298
  skipAnimation: _propTypes.default.bool,
297
299
  /**
@@ -82,13 +82,13 @@ const useBarChartProps = props => {
82
82
  highlightedItem,
83
83
  onHighlightChange,
84
84
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
85
- className
85
+ className,
86
+ skipAnimation
86
87
  });
87
88
  const barPlotProps = {
88
89
  onItemClick,
89
90
  slots,
90
91
  slotProps,
91
- skipAnimation,
92
92
  borderRadius,
93
93
  barLabel
94
94
  };
@@ -19,6 +19,7 @@ var _ChartsAxesGradients = require("../internals/components/ChartsAxesGradients"
19
19
  var _context = require("../context");
20
20
  var _PluginProvider = require("../context/PluginProvider");
21
21
  var _useChartContainerProps = require("./useChartContainerProps");
22
+ var _AnimationProvider = require("../context/AnimationProvider");
22
23
  var _jsxRuntime = require("react/jsx-runtime");
23
24
  const ChartContainer = exports.ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
24
25
  const {
@@ -29,7 +30,8 @@ const ChartContainer = exports.ChartContainer = /*#__PURE__*/React.forwardRef(fu
29
30
  zAxisContextProps,
30
31
  highlightedProviderProps,
31
32
  chartsSurfaceProps,
32
- pluginProviderProps
33
+ pluginProviderProps,
34
+ animationProviderProps
33
35
  } = (0, _useChartContainerProps.useChartContainerProps)(props, ref);
34
36
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_DrawingProvider.DrawingProvider, (0, _extends2.default)({}, drawingProviderProps, {
35
37
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_PluginProvider.PluginProvider, (0, _extends2.default)({}, pluginProviderProps, {
@@ -39,7 +41,9 @@ const ChartContainer = exports.ChartContainer = /*#__PURE__*/React.forwardRef(fu
39
41
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_InteractionProvider.InteractionProvider, {
40
42
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_context.HighlightedProvider, (0, _extends2.default)({}, highlightedProviderProps, {
41
43
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ChartsSurface.ChartsSurface, (0, _extends2.default)({}, chartsSurfaceProps, {
42
- children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxesGradients.ChartsAxesGradients, {}), children]
44
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxesGradients.ChartsAxesGradients, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_AnimationProvider.AnimationProvider, (0, _extends2.default)({}, animationProviderProps, {
45
+ children: children
46
+ }))]
43
47
  }))
44
48
  }))
45
49
  })
@@ -112,6 +116,11 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
112
116
  * Please refer to the appropriate docs page to learn more about it.
113
117
  */
114
118
  series: _propTypes.default.arrayOf(_propTypes.default.object).isRequired,
119
+ /**
120
+ * If `true`, animations are skipped.
121
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
122
+ */
123
+ skipAnimation: _propTypes.default.bool,
115
124
  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]),
116
125
  title: _propTypes.default.string,
117
126
  viewBox: _propTypes.default.shape({
@@ -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, {
@@ -76,7 +76,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
76
76
  // ----------------------------------------------------------------------
77
77
  /**
78
78
  * The configuration of axes highlight.
79
- * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
79
+ * @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
80
80
  * @default { x: 'line' }
81
81
  */
82
82
  axisHighlight: _propTypes.default.shape({
@@ -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,
@@ -144,7 +144,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
144
144
  // ----------------------------------------------------------------------
145
145
  /**
146
146
  * The configuration of axes highlight.
147
- * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
147
+ * @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
148
148
  * @default { x: 'none', y: 'none' }
149
149
  */
150
150
  axisHighlight: _propTypes.default.shape({
@@ -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
@@ -69,7 +69,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
69
69
  // ----------------------------------------------------------------------
70
70
  /**
71
71
  * The configuration of axes highlight.
72
- * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
72
+ * @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
73
73
  * @default { x: 'none', y: 'none' }
74
74
  */
75
75
  axisHighlight: _propTypes.default.shape({
@@ -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
+ }