@mui/x-charts 7.20.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.
- package/BarChart/BarChart.js +1 -1
- package/BarChart/BarPlot.d.ts +1 -1
- package/BarChart/BarPlot.js +6 -3
- package/BarChart/useBarChartProps.js +2 -2
- package/CHANGELOG.md +120 -31
- package/ChartContainer/ChartContainer.d.ts +3 -2
- package/ChartContainer/ChartContainer.js +11 -2
- package/ChartContainer/useChartContainerProps.d.ts +2 -0
- package/ChartContainer/useChartContainerProps.js +7 -5
- package/LineChart/AreaPlot.js +3 -1
- package/LineChart/LinePlot.js +3 -1
- package/LineChart/MarkPlot.d.ts +1 -1
- package/LineChart/MarkPlot.js +10 -8
- package/LineChart/useLineChartProps.d.ts +10 -10
- package/LineChart/useLineChartProps.js +4 -5
- package/PieChart/PieChart.js +3 -3
- package/PieChart/PiePlot.js +3 -1
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +5 -0
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +1 -1
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +4 -2
- package/ScatterChart/ScatterChart.js +5 -0
- package/ScatterChart/extremums.js +4 -4
- package/ScatterChart/formatter.js +22 -3
- package/SparkLineChart/SparkLineChart.js +5 -0
- package/context/AnimationProvider/Animation.types.d.ts +15 -0
- package/context/AnimationProvider/Animation.types.js +1 -0
- package/context/AnimationProvider/AnimationContext.d.ts +4 -0
- package/context/AnimationProvider/AnimationContext.js +10 -0
- package/context/AnimationProvider/AnimationProvider.d.ts +4 -0
- package/context/AnimationProvider/AnimationProvider.js +55 -0
- package/context/AnimationProvider/index.d.ts +4 -0
- package/context/AnimationProvider/index.js +4 -0
- package/context/AnimationProvider/useSkipAnimation.d.ts +6 -0
- package/context/AnimationProvider/useSkipAnimation.js +20 -0
- package/index.js +1 -1
- package/internals/defaultizeColor.d.ts +7 -1
- package/internals/index.d.ts +1 -1
- package/internals/index.js +1 -1
- package/models/seriesType/scatter.d.ts +25 -1
- package/modern/BarChart/BarChart.js +1 -1
- package/modern/BarChart/BarPlot.js +6 -3
- package/modern/BarChart/useBarChartProps.js +2 -2
- package/modern/ChartContainer/ChartContainer.js +11 -2
- package/modern/ChartContainer/useChartContainerProps.js +7 -5
- package/modern/LineChart/AreaPlot.js +3 -1
- package/modern/LineChart/LinePlot.js +3 -1
- package/modern/LineChart/MarkPlot.js +10 -8
- package/modern/LineChart/useLineChartProps.js +4 -5
- package/modern/PieChart/PieChart.js +3 -3
- package/modern/PieChart/PiePlot.js +3 -1
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +5 -0
- package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +4 -2
- package/modern/ScatterChart/ScatterChart.js +5 -0
- package/modern/ScatterChart/extremums.js +4 -4
- package/modern/ScatterChart/formatter.js +22 -3
- package/modern/SparkLineChart/SparkLineChart.js +5 -0
- package/modern/context/AnimationProvider/Animation.types.js +1 -0
- package/modern/context/AnimationProvider/AnimationContext.js +10 -0
- package/modern/context/AnimationProvider/AnimationProvider.js +55 -0
- package/modern/context/AnimationProvider/index.js +4 -0
- package/modern/context/AnimationProvider/useSkipAnimation.js +20 -0
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -1
- package/node/BarChart/BarChart.js +1 -1
- package/node/BarChart/BarPlot.js +4 -2
- package/node/BarChart/useBarChartProps.js +2 -2
- package/node/ChartContainer/ChartContainer.js +11 -2
- package/node/ChartContainer/useChartContainerProps.js +7 -5
- package/node/LineChart/AreaPlot.js +3 -1
- package/node/LineChart/LinePlot.js +3 -1
- package/node/LineChart/MarkPlot.js +10 -8
- package/node/LineChart/useLineChartProps.js +4 -5
- package/node/PieChart/PieChart.js +3 -3
- package/node/PieChart/PiePlot.js +3 -1
- package/node/ResponsiveChartContainer/ResponsiveChartContainer.js +5 -0
- package/node/ResponsiveChartContainer/useResponsiveChartContainerProps.js +4 -2
- package/node/ScatterChart/ScatterChart.js +5 -0
- package/node/ScatterChart/extremums.js +4 -4
- package/node/ScatterChart/formatter.js +23 -3
- package/node/SparkLineChart/SparkLineChart.js +5 -0
- package/node/context/AnimationProvider/Animation.types.js +5 -0
- package/node/context/AnimationProvider/AnimationContext.js +17 -0
- package/node/context/AnimationProvider/AnimationProvider.js +60 -0
- package/node/context/AnimationProvider/index.js +49 -0
- package/node/context/AnimationProvider/useSkipAnimation.js +25 -0
- package/node/index.js +1 -1
- package/node/internals/index.js +12 -8
- package/package.json +4 -4
- package/hooks/useReducedMotion.d.ts +0 -8
- package/hooks/useReducedMotion.js +0 -39
- package/modern/hooks/useReducedMotion.js +0 -39
- package/node/hooks/useReducedMotion.js +0 -45
|
@@ -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, {
|
|
@@ -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, {
|
|
@@ -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();
|
|
@@ -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,
|
|
@@ -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,
|
|
@@ -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
|
-
*
|
|
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({
|
|
@@ -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
|
|
@@ -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
|
|
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
|
|
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
|
|
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:
|
|
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 @@
|
|
|
1
|
+
export {};
|
|
@@ -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,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,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
|
@@ -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
|
|
@@ -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
|
-
*
|
|
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
|
/**
|
package/node/BarChart/BarPlot.js
CHANGED
|
@@ -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
|
|
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, {}),
|
|
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
|
-
|
|
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)();
|