@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
@@ -12,6 +12,7 @@ import { ChartsAxesGradients } from "../internals/components/ChartsAxesGradients
12
12
  import { HighlightedProvider, ZAxisContextProvider } from "../context/index.js";
13
13
  import { PluginProvider } from "../context/PluginProvider/index.js";
14
14
  import { useChartContainerProps } from "./useChartContainerProps.js";
15
+ import { AnimationProvider } from "../context/AnimationProvider/index.js";
15
16
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
17
  const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(props, ref) {
17
18
  const {
@@ -22,7 +23,8 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
22
23
  zAxisContextProps,
23
24
  highlightedProviderProps,
24
25
  chartsSurfaceProps,
25
- pluginProviderProps
26
+ pluginProviderProps,
27
+ animationProviderProps
26
28
  } = useChartContainerProps(props, ref);
27
29
  return /*#__PURE__*/_jsx(DrawingProvider, _extends({}, drawingProviderProps, {
28
30
  children: /*#__PURE__*/_jsx(PluginProvider, _extends({}, pluginProviderProps, {
@@ -32,7 +34,9 @@ const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContainer(pro
32
34
  children: /*#__PURE__*/_jsx(InteractionProvider, {
33
35
  children: /*#__PURE__*/_jsx(HighlightedProvider, _extends({}, highlightedProviderProps, {
34
36
  children: /*#__PURE__*/_jsxs(ChartsSurface, _extends({}, chartsSurfaceProps, {
35
- children: [/*#__PURE__*/_jsx(ChartsAxesGradients, {}), children]
37
+ children: [/*#__PURE__*/_jsx(ChartsAxesGradients, {}), /*#__PURE__*/_jsx(AnimationProvider, _extends({}, animationProviderProps, {
38
+ children: children
39
+ }))]
36
40
  }))
37
41
  }))
38
42
  })
@@ -105,6 +109,11 @@ process.env.NODE_ENV !== "production" ? ChartContainer.propTypes = {
105
109
  * Please refer to the appropriate docs page to learn more about it.
106
110
  */
107
111
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
112
+ /**
113
+ * If `true`, animations are skipped.
114
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
115
+ */
116
+ skipAnimation: PropTypes.bool,
108
117
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
109
118
  title: PropTypes.string,
110
119
  viewBox: PropTypes.shape({
@@ -7,6 +7,7 @@ import type { ChartContainerProps } from './ChartContainer';
7
7
  import { HighlightedProviderProps } from '../context';
8
8
  import { ChartsSurfaceProps } from '../ChartsSurface';
9
9
  import { PluginProviderProps } from '../context/PluginProvider';
10
+ import { AnimationProviderProps } from '../context/AnimationProvider';
10
11
  export declare const useChartContainerProps: (props: ChartContainerProps, ref: React.ForwardedRef<unknown>) => {
11
12
  children: React.ReactNode;
12
13
  drawingProviderProps: Omit<DrawingProviderProps, "children">;
@@ -18,6 +19,7 @@ export declare const useChartContainerProps: (props: ChartContainerProps, ref: R
18
19
  ref: any;
19
20
  };
20
21
  pluginProviderProps: Omit<PluginProviderProps, "children">;
22
+ animationProviderProps: Omit<AnimationProviderProps, "children">;
21
23
  xAxis: {
22
24
  reverse?: boolean | undefined;
23
25
  fill?: string | undefined;
@@ -2,11 +2,10 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["width", "height", "series", "margin", "xAxis", "yAxis", "zAxis", "colors", "dataset", "sx", "title", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "children"];
5
+ const _excluded = ["width", "height", "series", "margin", "xAxis", "yAxis", "zAxis", "colors", "dataset", "sx", "title", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "children", "skipAnimation"];
6
6
  import * as React from 'react';
7
7
  import useForkRef from '@mui/utils/useForkRef';
8
8
  import { useDefaultizeAxis } from "./useDefaultizeAxis.js";
9
- import { useReducedMotion } from "../hooks/useReducedMotion.js";
10
9
  export const useChartContainerProps = (props, ref) => {
11
10
  const {
12
11
  width,
@@ -25,13 +24,12 @@ export const useChartContainerProps = (props, ref) => {
25
24
  highlightedItem,
26
25
  onHighlightChange,
27
26
  plugins,
28
- children
27
+ children,
28
+ skipAnimation
29
29
  } = props,
30
30
  other = _objectWithoutPropertiesLoose(props, _excluded);
31
31
  const svgRef = React.useRef(null);
32
32
  const chartSurfaceRef = useForkRef(ref, svgRef);
33
- useReducedMotion(); // a11y reduce motion (see: https://react-spring.dev/docs/utilities/use-reduced-motion)
34
-
35
33
  const [defaultizedXAxis, defaultizedYAxis] = useDefaultizeAxis(xAxis, yAxis, dataset);
36
34
  const drawingProviderProps = {
37
35
  width,
@@ -39,6 +37,9 @@ export const useChartContainerProps = (props, ref) => {
39
37
  margin,
40
38
  svgRef
41
39
  };
40
+ const animationProviderProps = {
41
+ skipAnimation
42
+ };
42
43
  const pluginProviderProps = {
43
44
  plugins
44
45
  };
@@ -78,6 +79,7 @@ export const useChartContainerProps = (props, ref) => {
78
79
  highlightedProviderProps,
79
80
  chartsSurfaceProps,
80
81
  pluginProviderProps,
82
+ animationProviderProps,
81
83
  xAxis: defaultizedXAxis,
82
84
  yAxis: defaultizedYAxis
83
85
  };
@@ -13,6 +13,7 @@ import getCurveFactory from "../internals/getCurve.js";
13
13
  import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
14
14
  import { useChartGradient } from "../internals/components/ChartsAxesGradients/index.js";
15
15
  import { useLineSeries } from "../hooks/useSeries.js";
16
+ import { useSkipAnimation } from "../context/AnimationProvider/index.js";
16
17
  import { jsx as _jsx } from "react/jsx-runtime";
17
18
  const useAggregatedData = () => {
18
19
  const seriesData = useLineSeries();
@@ -114,9 +115,10 @@ function AreaPlot(props) {
114
115
  slots,
115
116
  slotProps,
116
117
  onItemClick,
117
- skipAnimation
118
+ skipAnimation: inSkipAnimation
118
119
  } = props,
119
120
  other = _objectWithoutPropertiesLoose(props, _excluded);
121
+ const skipAnimation = useSkipAnimation(inSkipAnimation);
120
122
  const getGradientId = useChartGradient();
121
123
  const completedData = useAggregatedData();
122
124
  return /*#__PURE__*/_jsx("g", _extends({}, other, {
@@ -36,7 +36,7 @@ export interface LineChartProps extends Omit<ResponsiveChartContainerProps, 'ser
36
36
  grid?: Pick<ChartsGridProps, 'vertical' | 'horizontal'>;
37
37
  /**
38
38
  * The configuration of axes highlight.
39
- * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
39
+ * @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
40
40
  * @default { x: 'line' }
41
41
  */
42
42
  axisHighlight?: ChartsAxisHighlightProps;
@@ -69,7 +69,7 @@ process.env.NODE_ENV !== "production" ? LineChart.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: 'line' }
74
74
  */
75
75
  axisHighlight: PropTypes.shape({
@@ -13,6 +13,7 @@ import getCurveFactory from "../internals/getCurve.js";
13
13
  import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
14
14
  import { useChartGradient } from "../internals/components/ChartsAxesGradients/index.js";
15
15
  import { useLineSeries } from "../hooks/useSeries.js";
16
+ import { useSkipAnimation } from "../context/AnimationProvider/index.js";
16
17
  import { jsx as _jsx } from "react/jsx-runtime";
17
18
  const useAggregatedData = () => {
18
19
  const seriesData = useLineSeries();
@@ -94,10 +95,11 @@ function LinePlot(props) {
94
95
  const {
95
96
  slots,
96
97
  slotProps,
97
- skipAnimation,
98
+ skipAnimation: inSkipAnimation,
98
99
  onItemClick
99
100
  } = props,
100
101
  other = _objectWithoutPropertiesLoose(props, _excluded);
102
+ const skipAnimation = useSkipAnimation(inSkipAnimation);
101
103
  const getGradientId = useChartGradient();
102
104
  const completedData = useAggregatedData();
103
105
  return /*#__PURE__*/_jsx("g", _extends({}, other, {
@@ -1,6 +1,6 @@
1
1
  import * as React from 'react';
2
- import { MarkElementProps } from './MarkElement';
3
2
  import { LineItemIdentifier } from '../models/seriesType/line';
3
+ import { MarkElementProps } from './MarkElement';
4
4
  export interface MarkPlotSlots {
5
5
  mark?: React.JSXElementConstructor<MarkElementProps>;
6
6
  }
@@ -3,18 +3,19 @@
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
5
  const _excluded = ["slots", "slotProps", "skipAnimation", "onItemClick", "experimentalRendering"];
6
- import * as React from 'react';
7
6
  import PropTypes from 'prop-types';
7
+ import * as React from 'react';
8
+ import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
9
+ import { useSkipAnimation } from "../context/AnimationProvider/index.js";
8
10
  import { useCartesianContext } from "../context/CartesianProvider/index.js";
9
- import { MarkElement } from "./MarkElement.js";
10
- import { getValueToPositionMapper } from "../hooks/useScale.js";
11
11
  import { useChartId } from "../hooks/useChartId.js";
12
- import { DEFAULT_X_AXIS_KEY } from "../constants/index.js";
13
- import { cleanId } from "../internals/cleanId.js";
14
- import getColor from "./getColor.js";
15
- import { useLineSeries } from "../hooks/useSeries.js";
16
12
  import { useDrawingArea } from "../hooks/useDrawingArea.js";
13
+ import { getValueToPositionMapper } from "../hooks/useScale.js";
14
+ import { useLineSeries } from "../hooks/useSeries.js";
15
+ import { cleanId } from "../internals/cleanId.js";
17
16
  import { CircleMarkElement } from "./CircleMarkElement.js";
17
+ import getColor from "./getColor.js";
18
+ import { MarkElement } from "./MarkElement.js";
18
19
  import { jsx as _jsx } from "react/jsx-runtime";
19
20
  /**
20
21
  * Demos:
@@ -30,11 +31,12 @@ function MarkPlot(props) {
30
31
  const {
31
32
  slots,
32
33
  slotProps,
33
- skipAnimation,
34
+ skipAnimation: inSkipAnimation,
34
35
  onItemClick,
35
36
  experimentalRendering
36
37
  } = props,
37
38
  other = _objectWithoutPropertiesLoose(props, _excluded);
39
+ const skipAnimation = useSkipAnimation(inSkipAnimation);
38
40
  const seriesData = useLineSeries();
39
41
  const axisData = useCartesianContext();
40
42
  const chartId = useChartId();
@@ -1,17 +1,17 @@
1
- import type { LineChartProps } from './LineChart';
2
- import { ResponsiveChartContainerProps } from '../ResponsiveChartContainer';
3
- import { ChartsOnAxisClickHandlerProps } from '../ChartsOnAxisClickHandler';
4
- import { ChartsGridProps } from '../ChartsGrid';
5
- import { ChartsClipPathProps } from '../ChartsClipPath';
6
- import { AreaPlotProps } from './AreaPlot';
7
- import { LinePlotProps } from './LinePlot';
8
- import { MarkPlotProps } from './MarkPlot';
9
- import { ChartsOverlayProps } from '../ChartsOverlay';
10
1
  import { ChartsAxisProps } from '../ChartsAxis';
11
2
  import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
12
- import { LineHighlightPlotProps } from './LineHighlightPlot';
3
+ import { ChartsClipPathProps } from '../ChartsClipPath';
4
+ import { ChartsGridProps } from '../ChartsGrid';
13
5
  import { ChartsLegendProps } from '../ChartsLegend';
6
+ import { ChartsOnAxisClickHandlerProps } from '../ChartsOnAxisClickHandler';
7
+ import { ChartsOverlayProps } from '../ChartsOverlay';
14
8
  import { ChartsTooltipProps } from '../ChartsTooltip';
9
+ import { ResponsiveChartContainerProps } from '../ResponsiveChartContainer';
10
+ import { AreaPlotProps } from './AreaPlot';
11
+ import type { LineChartProps } from './LineChart';
12
+ import { LineHighlightPlotProps } from './LineHighlightPlot';
13
+ import { LinePlotProps } from './LinePlot';
14
+ import { MarkPlotProps } from './MarkPlot';
15
15
  /**
16
16
  * A helper function that extracts LineChartProps from the input props
17
17
  * and returns an object with props for the children components of LineChart.
@@ -71,7 +71,8 @@ export const useLineChartProps = props => {
71
71
  highlightedItem,
72
72
  onHighlightChange,
73
73
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none' && !onAxisClick,
74
- className
74
+ className,
75
+ skipAnimation
75
76
  });
76
77
  const axisClickHandlerProps = {
77
78
  onAxisClick
@@ -89,14 +90,12 @@ export const useLineChartProps = props => {
89
90
  const areaPlotProps = {
90
91
  slots,
91
92
  slotProps,
92
- onItemClick: onAreaClick,
93
- skipAnimation
93
+ onItemClick: onAreaClick
94
94
  };
95
95
  const linePlotProps = {
96
96
  slots,
97
97
  slotProps,
98
- onItemClick: onLineClick,
99
- skipAnimation
98
+ onItemClick: onLineClick
100
99
  };
101
100
  const markPlotProps = {
102
101
  slots,
@@ -40,7 +40,7 @@ export interface PieChartProps extends Omit<ResponsiveChartContainerProps, 'seri
40
40
  tooltip?: ChartsTooltipProps<'pie'>;
41
41
  /**
42
42
  * The configuration of axes highlight.
43
- * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
43
+ * @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
44
44
  * @default { x: 'none', y: 'none' }
45
45
  */
46
46
  axisHighlight?: ChartsAxisHighlightProps;
@@ -105,6 +105,7 @@ const PieChart = /*#__PURE__*/React.forwardRef(function PieChart(inProps, ref) {
105
105
  highlightedItem: highlightedItem,
106
106
  onHighlightChange: onHighlightChange,
107
107
  className: className,
108
+ skipAnimation: skipAnimation,
108
109
  children: [/*#__PURE__*/_jsx(ChartsAxis, {
109
110
  topAxis: topAxis,
110
111
  leftAxis: leftAxis,
@@ -115,8 +116,7 @@ const PieChart = /*#__PURE__*/React.forwardRef(function PieChart(inProps, ref) {
115
116
  }), /*#__PURE__*/_jsx(PiePlot, {
116
117
  slots: slots,
117
118
  slotProps: slotProps,
118
- onItemClick: onItemClick,
119
- skipAnimation: skipAnimation
119
+ onItemClick: onItemClick
120
120
  }), /*#__PURE__*/_jsx(ChartsOverlay, {
121
121
  loading: loading,
122
122
  slots: slots,
@@ -137,7 +137,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
137
137
  // ----------------------------------------------------------------------
138
138
  /**
139
139
  * The configuration of axes highlight.
140
- * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
140
+ * @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
141
141
  * @default { x: 'none', y: 'none' }
142
142
  */
143
143
  axisHighlight: PropTypes.shape({
@@ -263,7 +263,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
263
263
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
264
264
  /**
265
265
  * If `true`, animations are skipped.
266
- * @default false
266
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
267
267
  */
268
268
  skipAnimation: PropTypes.bool,
269
269
  /**
@@ -8,6 +8,7 @@ import { PieArcLabelPlot } from "./PieArcLabelPlot.js";
8
8
  import { getPercentageValue } from "../internals/getPercentageValue.js";
9
9
  import { getPieCoordinates } from "./getPieCoordinates.js";
10
10
  import { usePieSeries } from "../hooks/useSeries.js";
11
+ import { useSkipAnimation } from "../context/AnimationProvider/index.js";
11
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
13
  /**
13
14
  * Demos:
@@ -21,7 +22,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
21
22
  */
22
23
  function PiePlot(props) {
23
24
  const {
24
- skipAnimation,
25
+ skipAnimation: inSkipAnimation,
25
26
  slots,
26
27
  slotProps,
27
28
  onItemClick
@@ -33,6 +34,7 @@ function PiePlot(props) {
33
34
  width,
34
35
  height
35
36
  } = React.useContext(DrawingContext);
37
+ const skipAnimation = useSkipAnimation(inSkipAnimation);
36
38
  if (seriesData === undefined) {
37
39
  return null;
38
40
  }
@@ -90,6 +90,11 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
90
90
  * Please refer to the appropriate docs page to learn more about it.
91
91
  */
92
92
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
93
+ /**
94
+ * If `true`, animations are skipped.
95
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
96
+ */
97
+ skipAnimation: PropTypes.bool,
93
98
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
94
99
  title: PropTypes.string,
95
100
  viewBox: PropTypes.shape({
@@ -1,7 +1,7 @@
1
1
  import type { ResponsiveChartContainerProps } from './ResponsiveChartContainer';
2
2
  export declare const useResponsiveChartContainerProps: (props: ResponsiveChartContainerProps, ref: React.ForwardedRef<unknown>) => {
3
3
  hasIntrinsicSize: number;
4
- chartContainerProps: Omit<import("..").ChartsSurfaceProps & Omit<import("../internals").SeriesProviderProps, "seriesFormatters"> & Omit<import("../internals").DrawingProviderProps, "svgRef"> & Pick<import("../internals").CartesianProviderProps, "dataset"> & import("..").ZAxisContextProviderProps & import("..").HighlightedProviderProps & import("../internals").PluginProviderProps, "children"> & {
4
+ chartContainerProps: Omit<import("..").ChartsSurfaceProps & Omit<import("../internals").SeriesProviderProps, "seriesFormatters"> & Omit<import("../internals").DrawingProviderProps, "svgRef"> & Pick<import("../internals").CartesianProviderProps, "dataset"> & import("..").ZAxisContextProviderProps & import("..").HighlightedProviderProps & import("../internals").PluginProviderProps & import("../internals").AnimationProviderProps, "children"> & {
5
5
  xAxis?: import("../internals").MakeOptional<import("..").AxisConfig<import("..").ScaleName, any, import("..").ChartsXAxisProps>, "id">[];
6
6
  yAxis?: import("../internals").MakeOptional<import("..").AxisConfig<import("..").ScaleName, any, import("..").ChartsYAxisProps>, "id">[];
7
7
  children?: React.ReactNode;
@@ -2,7 +2,7 @@
2
2
 
3
3
  import _extends from "@babel/runtime/helpers/esm/extends";
4
4
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
5
- const _excluded = ["width", "height", "resolveSizeBeforeRender", "margin", "children", "series", "colors", "dataset", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "sx", "title", "viewBox", "xAxis", "yAxis", "zAxis"];
5
+ const _excluded = ["width", "height", "resolveSizeBeforeRender", "margin", "children", "series", "colors", "dataset", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "sx", "title", "viewBox", "xAxis", "yAxis", "zAxis", "skipAnimation"];
6
6
  import { useChartContainerDimensions } from "./useChartContainerDimensions.js";
7
7
  export const useResponsiveChartContainerProps = (props, ref) => {
8
8
  const {
@@ -24,7 +24,8 @@ export const useResponsiveChartContainerProps = (props, ref) => {
24
24
  viewBox,
25
25
  xAxis,
26
26
  yAxis,
27
- zAxis
27
+ zAxis,
28
+ skipAnimation
28
29
  } = props,
29
30
  other = _objectWithoutPropertiesLoose(props, _excluded);
30
31
  const {
@@ -56,6 +57,7 @@ export const useResponsiveChartContainerProps = (props, ref) => {
56
57
  xAxis,
57
58
  yAxis,
58
59
  zAxis,
60
+ skipAnimation,
59
61
  width: dWidth,
60
62
  height: dHeight,
61
63
  ref
@@ -30,7 +30,7 @@ export interface ScatterChartProps extends Omit<ResponsiveChartContainerProps, '
30
30
  tooltip?: ChartsTooltipProps<'scatter'>;
31
31
  /**
32
32
  * The configuration of axes highlight.
33
- * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
33
+ * @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
34
34
  * @default { x: 'none', y: 'none' }
35
35
  */
36
36
  axisHighlight?: ChartsAxisHighlightProps;
@@ -62,7 +62,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
62
62
  // ----------------------------------------------------------------------
63
63
  /**
64
64
  * The configuration of axes highlight.
65
- * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
65
+ * @see See {@link https://mui.com/x/react-charts/highlighting highlighting docs} for more details.
66
66
  * @default { x: 'none', y: 'none' }
67
67
  */
68
68
  axisHighlight: PropTypes.shape({
@@ -198,6 +198,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
198
198
  * An array of [[ScatterSeriesType]] objects.
199
199
  */
200
200
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
201
+ /**
202
+ * If `true`, animations are skipped.
203
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
204
+ */
205
+ skipAnimation: PropTypes.bool,
201
206
  /**
202
207
  * The props used for each component slot.
203
208
  * @default {}
@@ -18,13 +18,13 @@ export const getExtremumX = params => {
18
18
  seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey,
19
19
  seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey
20
20
  });
21
- const seriesMinMax = series[seriesId].data.reduce((accSeries, d, dataIndex) => {
21
+ const seriesMinMax = series[seriesId].data?.reduce((accSeries, d, dataIndex) => {
22
22
  if (filter && !filter(d, dataIndex)) {
23
23
  return accSeries;
24
24
  }
25
25
  return mergeMinMax(accSeries, [d.x, d.x]);
26
26
  }, [Infinity, -Infinity]);
27
- return mergeMinMax(acc, seriesMinMax);
27
+ return mergeMinMax(acc, seriesMinMax ?? [Infinity, -Infinity]);
28
28
  }, [Infinity, -Infinity]);
29
29
  };
30
30
  export const getExtremumY = params => {
@@ -44,12 +44,12 @@ export const getExtremumY = params => {
44
44
  seriesXAxisId: series[seriesId].xAxisId ?? series[seriesId].xAxisKey,
45
45
  seriesYAxisId: series[seriesId].yAxisId ?? series[seriesId].yAxisKey
46
46
  });
47
- const seriesMinMax = series[seriesId].data.reduce((accSeries, d, dataIndex) => {
47
+ const seriesMinMax = series[seriesId].data?.reduce((accSeries, d, dataIndex) => {
48
48
  if (filter && !filter(d, dataIndex)) {
49
49
  return accSeries;
50
50
  }
51
51
  return mergeMinMax(accSeries, [d.y, d.y]);
52
52
  }, [Infinity, -Infinity]);
53
- return mergeMinMax(acc, seriesMinMax);
53
+ return mergeMinMax(acc, seriesMinMax ?? [Infinity, -Infinity]);
54
54
  }, [Infinity, -Infinity]);
55
55
  };
@@ -1,10 +1,29 @@
1
- import { defaultizeValueFormatter } from "../internals/defaultizeValueFormatter.js";
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  const formatter = ({
3
3
  series,
4
4
  seriesOrder
5
- }) => {
5
+ }, dataset) => {
6
+ const completeSeries = Object.fromEntries(Object.entries(series).map(([seriesId, seriesData]) => {
7
+ const datasetKeys = seriesData?.datasetKeys;
8
+ const missingKeys = ['x', 'y', 'id'].filter(key => typeof datasetKeys?.[key] !== 'string');
9
+ if (seriesData?.datasetKeys && missingKeys.length > 0) {
10
+ throw new Error([`MUI X: scatter series with id='${seriesId}' has incomplete datasetKeys.`, `Properties ${missingKeys.map(key => `"${key}"`).join(', ')} are missing.`].join('\n'));
11
+ }
12
+ const data = !datasetKeys ? seriesData.data ?? [] : dataset?.map(d => {
13
+ return {
14
+ x: d[datasetKeys.x],
15
+ y: d[datasetKeys.y],
16
+ z: datasetKeys.z && d[datasetKeys.z],
17
+ id: d[datasetKeys.id]
18
+ };
19
+ }) ?? [];
20
+ return [seriesId, _extends({}, seriesData, {
21
+ data,
22
+ valueFormatter: seriesData.valueFormatter ?? (v => `(${v.x}, ${v.y})`)
23
+ })];
24
+ }));
6
25
  return {
7
- series: defaultizeValueFormatter(series, v => `(${v.x}, ${v.y})`),
26
+ series: completeSeries,
8
27
  seriesOrder
9
28
  };
10
29
  };
@@ -215,6 +215,11 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
215
215
  * @default false
216
216
  */
217
217
  showTooltip: PropTypes.bool,
218
+ /**
219
+ * If `true`, animations are skipped.
220
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
221
+ */
222
+ skipAnimation: PropTypes.bool,
218
223
  /**
219
224
  * The props used for each component slot.
220
225
  * @default {}
@@ -0,0 +1,15 @@
1
+ export type AnimationProviderProps = {
2
+ /**
3
+ * If `true`, animations are skipped.
4
+ * If unset or `false`, the animations respects the user's `prefers-reduced-motion` setting.
5
+ */
6
+ skipAnimation?: boolean;
7
+ children: React.ReactNode;
8
+ };
9
+ export type AnimationState = {
10
+ /**
11
+ * If `true`, animations are skipped.
12
+ * @default undefined
13
+ */
14
+ skipAnimation?: boolean;
15
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import { Initializable } from '../context.types';
3
+ import { AnimationState } from './Animation.types';
4
+ export declare const AnimationContext: React.Context<Initializable<AnimationState>>;
@@ -0,0 +1,10 @@
1
+ import * as React from 'react';
2
+ export const AnimationContext = /*#__PURE__*/React.createContext({
3
+ isInitialized: false,
4
+ data: {
5
+ skipAnimation: undefined
6
+ }
7
+ });
8
+ if (process.env.NODE_ENV !== 'production') {
9
+ AnimationContext.displayName = 'AnimationContext';
10
+ }
@@ -0,0 +1,4 @@
1
+ import * as React from 'react';
2
+ import { AnimationProviderProps } from './Animation.types';
3
+ declare function AnimationProvider(props: AnimationProviderProps): React.JSX.Element;
4
+ export { AnimationProvider };
@@ -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';
2
+ export * from './AnimationContext';
3
+ export * from './AnimationProvider';
4
+ export * from './useSkipAnimation';
@@ -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,6 @@
1
+ /**
2
+ * A hook to get if chart animations should be skipped.
3
+ *
4
+ * @returns {boolean|undefined} whether to skip animations
5
+ */
6
+ export declare function useSkipAnimation(skipAnimation?: boolean): boolean | undefined;