@mui/x-charts 7.17.0 → 7.19.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 +10 -0
- package/BarChart/BarElement.d.ts +1 -1
- package/BarChart/BarLabel/BarLabel.d.ts +1 -1
- package/BarChart/formatter.js +5 -4
- package/CHANGELOG.md +208 -5
- package/ChartContainer/useDefaultizeAxis.d.ts +4 -4
- package/ChartContainer/useDefaultizeAxis.js +1 -1
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsAxisHighlight/ChartsAxisHighlight.d.ts +1 -1
- package/ChartsGrid/styledCommonents.d.ts +2 -2
- package/ChartsLegend/ChartsLegend.d.ts +2 -2
- package/ChartsLegend/DefaultChartsLegend.js +1 -1
- package/ChartsLegend/LegendPerItem.d.ts +1 -1
- package/ChartsLegend/LegendPerItem.js +1 -1
- package/ChartsLegend/PiecewiseColorLegend.js +1 -1
- package/ChartsReferenceLine/common.d.ts +1 -1
- package/ChartsTooltip/ChartsTooltipTable.d.ts +5 -5
- package/ChartsTooltip/index.d.ts +3 -0
- package/ChartsTooltip/index.js +4 -1
- package/ChartsTooltip/useAxisTooltip.d.ts +18 -0
- package/ChartsTooltip/useAxisTooltip.js +84 -0
- package/ChartsTooltip/useItemTooltip.d.ts +10 -0
- package/ChartsTooltip/useItemTooltip.js +64 -0
- package/ChartsTooltip/utils.d.ts +2 -1
- package/LineChart/AnimatedArea.d.ts +1 -1
- package/LineChart/AnimatedArea.js +9 -45
- package/LineChart/AnimatedLine.d.ts +1 -1
- package/LineChart/AnimatedLine.js +9 -46
- package/LineChart/AppearingMask.d.ts +12 -0
- package/LineChart/AppearingMask.js +42 -0
- package/LineChart/LineChart.js +10 -0
- package/LineChart/formatter.js +5 -5
- package/PieChart/PieChart.js +10 -0
- package/ResponsiveChartContainer/ResizableContainer.d.ts +1 -1
- package/ResponsiveChartContainer/ResponsiveChartContainer.d.ts +10 -0
- package/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
- package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +1 -1
- package/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.d.ts +1 -1
- package/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
- package/ScatterChart/ScatterChart.js +10 -0
- package/SparkLineChart/SparkLineChart.d.ts +1 -1
- package/SparkLineChart/SparkLineChart.js +10 -0
- package/context/CartesianProvider/CartesianProvider.js +3 -3
- package/context/CartesianProvider/defaultizeAxis.d.ts +4 -4
- package/context/CartesianProvider/getAxisExtremum.d.ts +1 -1
- package/context/CartesianProvider/getAxisExtremum.js +5 -4
- package/context/CartesianProvider/index.d.ts +0 -5
- package/context/CartesianProvider/index.js +1 -6
- package/context/PluginProvider/ExtremumGetter.types.d.ts +1 -0
- package/context/PluginProvider/Plugin.types.d.ts +4 -0
- package/context/PluginProvider/PluginContext.js +3 -1
- package/context/PluginProvider/index.d.ts +2 -0
- package/context/PluginProvider/index.js +3 -1
- package/context/PluginProvider/mergePlugins.d.ts +14 -4
- package/context/PluginProvider/mergePlugins.js +11 -1
- package/context/PluginProvider/useRadiusExtremumGetter.d.ts +4 -0
- package/context/PluginProvider/useRadiusExtremumGetter.js +17 -0
- package/context/PluginProvider/useRotationExtremumGetter.d.ts +4 -0
- package/context/PluginProvider/useRotationExtremumGetter.js +17 -0
- package/context/PolarProvider/Polar.types.d.ts +42 -0
- package/context/PolarProvider/Polar.types.js +1 -0
- package/context/PolarProvider/PolarContext.d.ts +4 -0
- package/context/PolarProvider/PolarContext.js +13 -0
- package/context/PolarProvider/PolarProvider.d.ts +4 -0
- package/context/PolarProvider/PolarProvider.js +49 -0
- package/context/PolarProvider/getAxisExtremum.d.ts +4 -0
- package/context/PolarProvider/getAxisExtremum.js +20 -0
- package/context/PolarProvider/index.d.ts +0 -0
- package/context/PolarProvider/index.js +0 -0
- package/context/PolarProvider/usePolarContext.d.ts +2 -0
- package/context/PolarProvider/usePolarContext.js +10 -0
- package/context/ZAxisContextProvider.js +1 -1
- package/hooks/useReducedMotion.js +2 -2
- package/hooks/useSeries.d.ts +4 -4
- package/hooks/useSeries.js +4 -4
- package/index.js +1 -1
- package/internals/components/AxisSharedComponents.d.ts +1 -1
- package/internals/computeAxisValue.d.ts +38 -0
- package/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +28 -15
- package/internals/configInit.d.ts +1 -1
- package/internals/defaultizeColor.d.ts +8 -8
- package/internals/domUtils.js +1 -1
- package/internals/geometry.js +3 -5
- package/internals/getPercentageValue.js +1 -1
- package/internals/index.d.ts +1 -0
- package/internals/index.js +1 -0
- package/models/axis.d.ts +20 -0
- package/models/seriesType/config.d.ts +6 -2
- package/models/seriesType/line.d.ts +5 -0
- package/modern/BarChart/BarChart.js +10 -0
- package/modern/BarChart/formatter.js +5 -4
- package/modern/ChartContainer/useDefaultizeAxis.js +1 -1
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsLegend/DefaultChartsLegend.js +1 -1
- package/modern/ChartsLegend/LegendPerItem.js +1 -1
- package/modern/ChartsLegend/PiecewiseColorLegend.js +1 -1
- package/modern/ChartsTooltip/index.js +4 -1
- package/modern/ChartsTooltip/useAxisTooltip.js +84 -0
- package/modern/ChartsTooltip/useItemTooltip.js +64 -0
- package/modern/LineChart/AnimatedArea.js +9 -45
- package/modern/LineChart/AnimatedLine.js +9 -46
- package/modern/LineChart/AppearingMask.js +42 -0
- package/modern/LineChart/LineChart.js +10 -0
- package/modern/LineChart/formatter.js +5 -5
- package/modern/PieChart/PieChart.js +10 -0
- package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
- package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
- package/modern/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
- package/modern/ScatterChart/ScatterChart.js +10 -0
- package/modern/SparkLineChart/SparkLineChart.js +10 -0
- package/modern/context/CartesianProvider/CartesianProvider.js +3 -3
- package/modern/context/CartesianProvider/getAxisExtremum.js +5 -4
- package/modern/context/CartesianProvider/index.js +1 -6
- package/modern/context/PluginProvider/PluginContext.js +3 -1
- package/modern/context/PluginProvider/index.js +3 -1
- package/modern/context/PluginProvider/mergePlugins.js +11 -1
- package/modern/context/PluginProvider/useRadiusExtremumGetter.js +17 -0
- package/modern/context/PluginProvider/useRotationExtremumGetter.js +17 -0
- package/modern/context/PolarProvider/Polar.types.js +1 -0
- package/modern/context/PolarProvider/PolarContext.js +13 -0
- package/modern/context/PolarProvider/PolarProvider.js +49 -0
- package/modern/context/PolarProvider/getAxisExtremum.js +20 -0
- package/modern/context/PolarProvider/index.js +0 -0
- package/modern/context/PolarProvider/usePolarContext.js +10 -0
- package/modern/context/ZAxisContextProvider.js +1 -1
- package/modern/hooks/useReducedMotion.js +2 -2
- package/modern/hooks/useSeries.js +4 -4
- package/modern/index.js +1 -1
- package/modern/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +28 -15
- package/modern/internals/domUtils.js +1 -1
- package/modern/internals/geometry.js +3 -5
- package/modern/internals/getPercentageValue.js +1 -1
- package/modern/internals/index.js +1 -0
- package/node/BarChart/BarChart.js +10 -0
- package/node/BarChart/formatter.js +5 -4
- package/node/ChartContainer/useDefaultizeAxis.js +1 -1
- package/node/ChartsAxis/ChartsAxis.js +4 -4
- package/node/ChartsLegend/DefaultChartsLegend.js +1 -1
- package/node/ChartsLegend/LegendPerItem.js +1 -1
- package/node/ChartsLegend/PiecewiseColorLegend.js +1 -1
- package/node/ChartsTooltip/index.js +42 -1
- package/node/ChartsTooltip/useAxisTooltip.js +90 -0
- package/node/ChartsTooltip/useItemTooltip.js +71 -0
- package/node/LineChart/AnimatedArea.js +8 -44
- package/node/LineChart/AnimatedLine.js +8 -45
- package/node/LineChart/AppearingMask.js +48 -0
- package/node/LineChart/LineChart.js +10 -0
- package/node/LineChart/formatter.js +5 -5
- package/node/PieChart/PieChart.js +10 -0
- package/node/ResponsiveChartContainer/ResponsiveChartContainer.js +10 -0
- package/node/ResponsiveChartContainer/useChartContainerDimensions.js +32 -8
- package/node/ResponsiveChartContainer/useResponsiveChartContainerProps.js +3 -2
- package/node/ScatterChart/ScatterChart.js +10 -0
- package/node/SparkLineChart/SparkLineChart.js +10 -0
- package/node/context/CartesianProvider/CartesianProvider.js +3 -3
- package/node/context/CartesianProvider/getAxisExtremum.js +5 -4
- package/node/context/CartesianProvider/index.js +1 -13
- package/node/context/PluginProvider/PluginContext.js +3 -1
- package/node/context/PluginProvider/index.js +22 -0
- package/node/context/PluginProvider/mergePlugins.js +11 -1
- package/node/context/PluginProvider/useRadiusExtremumGetter.js +23 -0
- package/node/context/PluginProvider/useRotationExtremumGetter.js +23 -0
- package/node/context/PolarProvider/Polar.types.js +5 -0
- package/node/context/PolarProvider/PolarContext.js +20 -0
- package/node/context/PolarProvider/PolarProvider.js +54 -0
- package/node/context/PolarProvider/getAxisExtremum.js +27 -0
- package/node/context/PolarProvider/index.js +1 -0
- package/node/context/PolarProvider/usePolarContext.js +17 -0
- package/node/context/ZAxisContextProvider.js +1 -1
- package/node/hooks/useReducedMotion.js +2 -2
- package/node/hooks/useSeries.js +4 -4
- package/node/index.js +1 -1
- package/node/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +29 -16
- package/node/internals/domUtils.js +1 -1
- package/node/internals/geometry.js +3 -5
- package/node/internals/getPercentageValue.js +1 -1
- package/node/internals/index.js +12 -0
- package/package.json +4 -4
- package/context/CartesianProvider/computeValue.d.ts +0 -30
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { InteractionContext } from "../context/InteractionProvider.js";
|
|
6
|
+
import { useSeries } from "../hooks/useSeries.js";
|
|
7
|
+
import { useCartesianContext } from "../context/CartesianProvider/index.js";
|
|
8
|
+
import { ZAxisContext } from "../context/ZAxisContextProvider.js";
|
|
9
|
+
import { useColorProcessor } from "../context/PluginProvider/useColorProcessor.js";
|
|
10
|
+
import { getLabel } from "../internals/getLabel.js";
|
|
11
|
+
export function useItemTooltip() {
|
|
12
|
+
const {
|
|
13
|
+
item
|
|
14
|
+
} = React.useContext(InteractionContext);
|
|
15
|
+
const series = useSeries();
|
|
16
|
+
const {
|
|
17
|
+
xAxis,
|
|
18
|
+
yAxis,
|
|
19
|
+
xAxisIds,
|
|
20
|
+
yAxisIds
|
|
21
|
+
} = useCartesianContext();
|
|
22
|
+
const {
|
|
23
|
+
zAxis,
|
|
24
|
+
zAxisIds
|
|
25
|
+
} = React.useContext(ZAxisContext);
|
|
26
|
+
const colorProcessors = useColorProcessor();
|
|
27
|
+
const xAxisId = series.xAxisId ?? series.xAxisKey ?? xAxisIds[0];
|
|
28
|
+
const yAxisId = series.yAxisId ?? series.yAxisKey ?? yAxisIds[0];
|
|
29
|
+
const zAxisId = series.zAxisId ?? series.zAxisKey ?? zAxisIds[0];
|
|
30
|
+
if (!item || item.dataIndex === undefined) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const itemSeries = series[item.type].series[item.seriesId];
|
|
34
|
+
const getColor = colorProcessors[itemSeries.type]?.(itemSeries, xAxisId && xAxis[xAxisId], yAxisId && yAxis[yAxisId], zAxisId && zAxis[zAxisId]) ?? (() => '');
|
|
35
|
+
if (itemSeries.type === 'pie') {
|
|
36
|
+
const point = itemSeries.data[item.dataIndex];
|
|
37
|
+
const label = getLabel(point.label, 'tooltip');
|
|
38
|
+
const value = _extends({}, point, {
|
|
39
|
+
label
|
|
40
|
+
});
|
|
41
|
+
const formattedValue = itemSeries.valueFormatter?.(value, {
|
|
42
|
+
dataIndex: item.dataIndex
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
identifier: item,
|
|
46
|
+
color: getColor(item.dataIndex),
|
|
47
|
+
label,
|
|
48
|
+
value,
|
|
49
|
+
formattedValue
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const label = getLabel(itemSeries.label, 'tooltip');
|
|
53
|
+
const value = itemSeries.data[item.dataIndex];
|
|
54
|
+
const formattedValue = itemSeries.valueFormatter?.(value, {
|
|
55
|
+
dataIndex: item.dataIndex
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
identifier: item,
|
|
59
|
+
color: getColor(item.dataIndex),
|
|
60
|
+
label,
|
|
61
|
+
value,
|
|
62
|
+
formattedValue
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -8,10 +8,9 @@ import PropTypes from 'prop-types';
|
|
|
8
8
|
import { styled } from '@mui/material/styles';
|
|
9
9
|
import { animated, useTransition } from '@react-spring/web';
|
|
10
10
|
import { color as d3Color } from '@mui/x-charts-vendor/d3-color';
|
|
11
|
-
import { cleanId } from "../internals/cleanId.js";
|
|
12
|
-
import { useChartId, useDrawingArea } from "../hooks/index.js";
|
|
13
11
|
import { useStringInterpolator } from "../internals/useStringInterpolator.js";
|
|
14
|
-
import {
|
|
12
|
+
import { AppearingMask } from "./AppearingMask.js";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
14
|
export const AreaElementPath = styled(animated.path, {
|
|
16
15
|
name: 'MuiAreaElement',
|
|
17
16
|
slot: 'Root',
|
|
@@ -41,32 +40,7 @@ function AnimatedArea(props) {
|
|
|
41
40
|
ownerState
|
|
42
41
|
} = props,
|
|
43
42
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
44
|
-
const {
|
|
45
|
-
left,
|
|
46
|
-
top,
|
|
47
|
-
right,
|
|
48
|
-
bottom,
|
|
49
|
-
width,
|
|
50
|
-
height
|
|
51
|
-
} = useDrawingArea();
|
|
52
|
-
const chartId = useChartId();
|
|
53
43
|
const stringInterpolator = useStringInterpolator(d);
|
|
54
|
-
const transitionAppear = useTransition([1], {
|
|
55
|
-
from: {
|
|
56
|
-
animatedWidth: left
|
|
57
|
-
},
|
|
58
|
-
to: {
|
|
59
|
-
animatedWidth: width + left + right
|
|
60
|
-
},
|
|
61
|
-
enter: {
|
|
62
|
-
animatedWidth: width + left + right
|
|
63
|
-
},
|
|
64
|
-
leave: {
|
|
65
|
-
animatedWidth: left
|
|
66
|
-
},
|
|
67
|
-
reset: false,
|
|
68
|
-
immediate: skipAnimation
|
|
69
|
-
});
|
|
70
44
|
const transitionChange = useTransition([stringInterpolator], {
|
|
71
45
|
from: {
|
|
72
46
|
value: 0
|
|
@@ -80,23 +54,13 @@ function AnimatedArea(props) {
|
|
|
80
54
|
reset: false,
|
|
81
55
|
immediate: skipAnimation
|
|
82
56
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
width: style.animatedWidth,
|
|
91
|
-
height: top + height + bottom
|
|
92
|
-
}))
|
|
93
|
-
}), /*#__PURE__*/_jsx("g", {
|
|
94
|
-
clipPath: `url(#${clipId})`,
|
|
95
|
-
children: transitionChange((style, interpolator) => /*#__PURE__*/_jsx(AreaElementPath, _extends({}, other, {
|
|
96
|
-
ownerState: ownerState,
|
|
97
|
-
d: style.value.to(interpolator)
|
|
98
|
-
})))
|
|
99
|
-
})]
|
|
57
|
+
return /*#__PURE__*/_jsx(AppearingMask, {
|
|
58
|
+
skipAnimation: skipAnimation,
|
|
59
|
+
id: `${ownerState.id}-area-clip`,
|
|
60
|
+
children: transitionChange((style, interpolator) => /*#__PURE__*/_jsx(AreaElementPath, _extends({}, other, {
|
|
61
|
+
ownerState: ownerState,
|
|
62
|
+
d: style.value.to(interpolator)
|
|
63
|
+
})))
|
|
100
64
|
});
|
|
101
65
|
}
|
|
102
66
|
process.env.NODE_ENV !== "production" ? AnimatedArea.propTypes = {
|
|
@@ -8,11 +8,9 @@ import PropTypes from 'prop-types';
|
|
|
8
8
|
import { animated, useTransition } from '@react-spring/web';
|
|
9
9
|
import { color as d3Color } from '@mui/x-charts-vendor/d3-color';
|
|
10
10
|
import { styled } from '@mui/material/styles';
|
|
11
|
-
import { cleanId } from "../internals/cleanId.js";
|
|
12
|
-
import { useChartId } from "../hooks/useChartId.js";
|
|
13
|
-
import { useDrawingArea } from "../hooks/useDrawingArea.js";
|
|
14
11
|
import { useStringInterpolator } from "../internals/useStringInterpolator.js";
|
|
15
|
-
import {
|
|
12
|
+
import { AppearingMask } from "./AppearingMask.js";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
16
14
|
export const LineElementPath = styled(animated.path, {
|
|
17
15
|
name: 'MuiLineElement',
|
|
18
16
|
slot: 'Root',
|
|
@@ -44,32 +42,7 @@ function AnimatedLine(props) {
|
|
|
44
42
|
ownerState
|
|
45
43
|
} = props,
|
|
46
44
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
47
|
-
const {
|
|
48
|
-
left,
|
|
49
|
-
top,
|
|
50
|
-
bottom,
|
|
51
|
-
width,
|
|
52
|
-
height,
|
|
53
|
-
right
|
|
54
|
-
} = useDrawingArea();
|
|
55
|
-
const chartId = useChartId();
|
|
56
45
|
const stringInterpolator = useStringInterpolator(d);
|
|
57
|
-
const transitionAppear = useTransition([1], {
|
|
58
|
-
from: {
|
|
59
|
-
animatedWidth: left
|
|
60
|
-
},
|
|
61
|
-
to: {
|
|
62
|
-
animatedWidth: width + left + right
|
|
63
|
-
},
|
|
64
|
-
enter: {
|
|
65
|
-
animatedWidth: width + left + right
|
|
66
|
-
},
|
|
67
|
-
leave: {
|
|
68
|
-
animatedWidth: left
|
|
69
|
-
},
|
|
70
|
-
reset: false,
|
|
71
|
-
immediate: skipAnimation
|
|
72
|
-
});
|
|
73
46
|
const transitionChange = useTransition([stringInterpolator], {
|
|
74
47
|
from: {
|
|
75
48
|
value: 0
|
|
@@ -83,23 +56,13 @@ function AnimatedLine(props) {
|
|
|
83
56
|
reset: false,
|
|
84
57
|
immediate: skipAnimation
|
|
85
58
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
width: style.animatedWidth,
|
|
94
|
-
height: top + height + bottom
|
|
95
|
-
}))
|
|
96
|
-
}), /*#__PURE__*/_jsx("g", {
|
|
97
|
-
clipPath: `url(#${clipId})`,
|
|
98
|
-
children: transitionChange((style, interpolator) => /*#__PURE__*/_jsx(LineElementPath, _extends({}, other, {
|
|
99
|
-
ownerState: ownerState,
|
|
100
|
-
d: style.value.to(interpolator)
|
|
101
|
-
})))
|
|
102
|
-
})]
|
|
59
|
+
return /*#__PURE__*/_jsx(AppearingMask, {
|
|
60
|
+
skipAnimation: skipAnimation,
|
|
61
|
+
id: `${ownerState.id}-line-clip`,
|
|
62
|
+
children: transitionChange((style, interpolator) => /*#__PURE__*/_jsx(LineElementPath, _extends({}, other, {
|
|
63
|
+
ownerState: ownerState,
|
|
64
|
+
d: style.value.to(interpolator)
|
|
65
|
+
})))
|
|
103
66
|
});
|
|
104
67
|
}
|
|
105
68
|
process.env.NODE_ENV !== "production" ? AnimatedLine.propTypes = {
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { animated, useTransition } from '@react-spring/web';
|
|
5
|
+
import { cleanId } from "../internals/cleanId.js";
|
|
6
|
+
import { useChartId, useDrawingArea } from "../hooks/index.js";
|
|
7
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
8
|
+
/**
|
|
9
|
+
* @ignore - internal component.
|
|
10
|
+
*/
|
|
11
|
+
export function AppearingMask(props) {
|
|
12
|
+
const drawingArea = useDrawingArea();
|
|
13
|
+
const chartId = useChartId();
|
|
14
|
+
const transitionAppear = useTransition([drawingArea], {
|
|
15
|
+
from: v => ({
|
|
16
|
+
animatedWidth: v.left
|
|
17
|
+
}),
|
|
18
|
+
enter: v => ({
|
|
19
|
+
animatedWidth: v.width + v.left + v.right
|
|
20
|
+
}),
|
|
21
|
+
leave: v => ({
|
|
22
|
+
animatedWidth: v.width + v.left + v.right
|
|
23
|
+
}),
|
|
24
|
+
reset: false,
|
|
25
|
+
immediate: props.skipAnimation
|
|
26
|
+
});
|
|
27
|
+
const clipId = cleanId(`${chartId}-${props.id}`);
|
|
28
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
29
|
+
children: [/*#__PURE__*/_jsx("clipPath", {
|
|
30
|
+
id: clipId,
|
|
31
|
+
children: transitionAppear(style => /*#__PURE__*/_jsx(animated.rect, {
|
|
32
|
+
x: 0,
|
|
33
|
+
y: 0,
|
|
34
|
+
width: style.animatedWidth,
|
|
35
|
+
height: drawingArea.top + drawingArea.height + drawingArea.bottom
|
|
36
|
+
}))
|
|
37
|
+
}), /*#__PURE__*/_jsx("g", {
|
|
38
|
+
clipPath: `url(#${clipId})`,
|
|
39
|
+
children: props.children
|
|
40
|
+
})]
|
|
41
|
+
});
|
|
42
|
+
}
|
|
@@ -200,6 +200,16 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
200
200
|
* Callback fired when a mark element is clicked.
|
|
201
201
|
*/
|
|
202
202
|
onMarkClick: PropTypes.func,
|
|
203
|
+
/**
|
|
204
|
+
* The chart will try to wait for the parent container to resolve its size
|
|
205
|
+
* before it renders for the first time.
|
|
206
|
+
*
|
|
207
|
+
* This can be useful in some scenarios where the chart appear to grow after
|
|
208
|
+
* the first render, like when used inside a grid.
|
|
209
|
+
*
|
|
210
|
+
* @default false
|
|
211
|
+
*/
|
|
212
|
+
resolveSizeBeforeRender: PropTypes.bool,
|
|
203
213
|
/**
|
|
204
214
|
* Indicate which axis to display the right of the charts.
|
|
205
215
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { stack as d3Stack } from '@mui/x-charts-vendor/d3-shape';
|
|
3
|
+
import { warnOnce } from '@mui/x-internals/warning';
|
|
3
4
|
import { getStackingGroups } from "../internals/stackSeries.js";
|
|
4
5
|
import { defaultizeValueFormatter } from "../internals/defaultizeValueFormatter.js";
|
|
5
|
-
let warnedOnce = false;
|
|
6
|
-
|
|
7
6
|
// For now it's a copy past of bar charts formatter, but maybe will diverge later
|
|
8
7
|
const formatter = (params, dataset) => {
|
|
9
8
|
const {
|
|
@@ -54,9 +53,10 @@ const formatter = (params, dataset) => {
|
|
|
54
53
|
data: dataKey ? dataset.map(data => {
|
|
55
54
|
const value = data[dataKey];
|
|
56
55
|
if (typeof value !== 'number') {
|
|
57
|
-
if (process.env.NODE_ENV !== 'production'
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
57
|
+
if (value !== null) {
|
|
58
|
+
warnOnce([`MUI X: Your dataset key "${dataKey}" is used for plotting line, but contains nonnumerical elements.`, 'Line plots only support numbers and null values.']);
|
|
59
|
+
}
|
|
60
60
|
}
|
|
61
61
|
return null;
|
|
62
62
|
}
|
|
@@ -240,6 +240,16 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
240
240
|
* Callback fired when a pie arc is clicked.
|
|
241
241
|
*/
|
|
242
242
|
onItemClick: PropTypes.func,
|
|
243
|
+
/**
|
|
244
|
+
* The chart will try to wait for the parent container to resolve its size
|
|
245
|
+
* before it renders for the first time.
|
|
246
|
+
*
|
|
247
|
+
* This can be useful in some scenarios where the chart appear to grow after
|
|
248
|
+
* the first render, like when used inside a grid.
|
|
249
|
+
*
|
|
250
|
+
* @default false
|
|
251
|
+
*/
|
|
252
|
+
resolveSizeBeforeRender: PropTypes.bool,
|
|
243
253
|
/**
|
|
244
254
|
* Indicate which axis to display the right of the charts.
|
|
245
255
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -74,6 +74,16 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
|
|
|
74
74
|
* If not provided, the container supports line, bar, scatter and pie charts.
|
|
75
75
|
*/
|
|
76
76
|
plugins: PropTypes.arrayOf(PropTypes.object),
|
|
77
|
+
/**
|
|
78
|
+
* The chart will try to wait for the parent container to resolve its size
|
|
79
|
+
* before it renders for the first time.
|
|
80
|
+
*
|
|
81
|
+
* This can be useful in some scenarios where the chart appear to grow after
|
|
82
|
+
* the first render, like when used inside a grid.
|
|
83
|
+
*
|
|
84
|
+
* @default false
|
|
85
|
+
*/
|
|
86
|
+
resolveSizeBeforeRender: PropTypes.bool,
|
|
77
87
|
/**
|
|
78
88
|
* The array of series to display.
|
|
79
89
|
* Each type of series has its own specificity.
|
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
import * as React from 'react';
|
|
4
4
|
import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
|
|
5
5
|
import ownerWindow from '@mui/utils/ownerWindow';
|
|
6
|
-
export const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
7
|
-
const
|
|
6
|
+
export const useChartContainerDimensions = (inWidth, inHeight, resolveSizeBeforeRender) => {
|
|
7
|
+
const stateRef = React.useRef({
|
|
8
|
+
displayError: false,
|
|
9
|
+
initialCompute: true,
|
|
10
|
+
computeRun: 0
|
|
11
|
+
});
|
|
8
12
|
const rootRef = React.useRef(null);
|
|
9
13
|
const [width, setWidth] = React.useState(0);
|
|
10
14
|
const [height, setHeight] = React.useState(0);
|
|
@@ -13,7 +17,7 @@ export const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
|
13
17
|
const computeSize = React.useCallback(() => {
|
|
14
18
|
const mainEl = rootRef?.current;
|
|
15
19
|
if (!mainEl) {
|
|
16
|
-
return;
|
|
20
|
+
return {};
|
|
17
21
|
}
|
|
18
22
|
const win = ownerWindow(mainEl);
|
|
19
23
|
const computedStyle = win.getComputedStyle(mainEl);
|
|
@@ -21,11 +25,31 @@ export const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
|
21
25
|
const newWidth = Math.floor(parseFloat(computedStyle.width)) || 0;
|
|
22
26
|
setWidth(newWidth);
|
|
23
27
|
setHeight(newHeight);
|
|
28
|
+
return {
|
|
29
|
+
width: newWidth,
|
|
30
|
+
height: newHeight
|
|
31
|
+
};
|
|
24
32
|
}, []);
|
|
25
33
|
React.useEffect(() => {
|
|
26
34
|
// Ensure the error detection occurs after the first rendering.
|
|
27
|
-
|
|
35
|
+
stateRef.current.displayError = true;
|
|
28
36
|
}, []);
|
|
37
|
+
|
|
38
|
+
// This effect is used to compute the size of the container on the initial render.
|
|
39
|
+
// It is not bound to the raf loop to avoid an unwanted "resize" event.
|
|
40
|
+
// https://github.com/mui/mui-x/issues/13477#issuecomment-2336634785
|
|
41
|
+
useEnhancedEffect(() => {
|
|
42
|
+
// computeRun is used to avoid infinite loops.
|
|
43
|
+
if (!resolveSizeBeforeRender || !stateRef.current.initialCompute || stateRef.current.computeRun > 20) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const computedSize = computeSize();
|
|
47
|
+
if (computedSize.width !== width || computedSize.height !== height) {
|
|
48
|
+
stateRef.current.computeRun += 1;
|
|
49
|
+
} else if (stateRef.current.initialCompute) {
|
|
50
|
+
stateRef.current.initialCompute = false;
|
|
51
|
+
}
|
|
52
|
+
}, [width, height, computeSize, resolveSizeBeforeRender]);
|
|
29
53
|
useEnhancedEffect(() => {
|
|
30
54
|
if (inWidth !== undefined && inHeight !== undefined) {
|
|
31
55
|
return () => {};
|
|
@@ -55,13 +79,13 @@ export const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
|
55
79
|
};
|
|
56
80
|
}, [computeSize, inHeight, inWidth]);
|
|
57
81
|
if (process.env.NODE_ENV !== 'production') {
|
|
58
|
-
if (
|
|
82
|
+
if (stateRef.current.displayError && inWidth === undefined && width === 0) {
|
|
59
83
|
console.error(`MUI X: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
|
|
60
|
-
|
|
84
|
+
stateRef.current.displayError = false;
|
|
61
85
|
}
|
|
62
|
-
if (
|
|
86
|
+
if (stateRef.current.displayError && inHeight === undefined && height === 0) {
|
|
63
87
|
console.error(`MUI X: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
|
|
64
|
-
|
|
88
|
+
stateRef.current.displayError = false;
|
|
65
89
|
}
|
|
66
90
|
}
|
|
67
91
|
return {
|
|
@@ -2,12 +2,13 @@
|
|
|
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", "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"];
|
|
6
6
|
import { useChartContainerDimensions } from "./useChartContainerDimensions.js";
|
|
7
7
|
export const useResponsiveChartContainerProps = (props, ref) => {
|
|
8
8
|
const {
|
|
9
9
|
width,
|
|
10
10
|
height,
|
|
11
|
+
resolveSizeBeforeRender,
|
|
11
12
|
margin,
|
|
12
13
|
children,
|
|
13
14
|
series,
|
|
@@ -30,7 +31,7 @@ export const useResponsiveChartContainerProps = (props, ref) => {
|
|
|
30
31
|
containerRef,
|
|
31
32
|
width: dWidth,
|
|
32
33
|
height: dHeight
|
|
33
|
-
} = useChartContainerDimensions(width, height);
|
|
34
|
+
} = useChartContainerDimensions(width, height, resolveSizeBeforeRender);
|
|
34
35
|
const resizableChartContainerProps = _extends({}, other, {
|
|
35
36
|
ownerState: {
|
|
36
37
|
width,
|
|
@@ -177,6 +177,16 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
177
177
|
* @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
|
|
178
178
|
*/
|
|
179
179
|
onItemClick: PropTypes.func,
|
|
180
|
+
/**
|
|
181
|
+
* The chart will try to wait for the parent container to resolve its size
|
|
182
|
+
* before it renders for the first time.
|
|
183
|
+
*
|
|
184
|
+
* This can be useful in some scenarios where the chart appear to grow after
|
|
185
|
+
* the first render, like when used inside a grid.
|
|
186
|
+
*
|
|
187
|
+
* @default false
|
|
188
|
+
*/
|
|
189
|
+
resolveSizeBeforeRender: PropTypes.bool,
|
|
180
190
|
/**
|
|
181
191
|
* Indicate which axis to display the right of the charts.
|
|
182
192
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -193,6 +193,16 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
193
193
|
* @default 'line'
|
|
194
194
|
*/
|
|
195
195
|
plotType: PropTypes.oneOf(['bar', 'line']),
|
|
196
|
+
/**
|
|
197
|
+
* The chart will try to wait for the parent container to resolve its size
|
|
198
|
+
* before it renders for the first time.
|
|
199
|
+
*
|
|
200
|
+
* This can be useful in some scenarios where the chart appear to grow after
|
|
201
|
+
* the first render, like when used inside a grid.
|
|
202
|
+
*
|
|
203
|
+
* @default false
|
|
204
|
+
*/
|
|
205
|
+
resolveSizeBeforeRender: PropTypes.bool,
|
|
196
206
|
/**
|
|
197
207
|
* Set to `true` to highlight the value.
|
|
198
208
|
* With line, it shows a point.
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import * as React from 'react';
|
|
4
|
+
import { computeAxisValue } from "../../internals/computeAxisValue.js";
|
|
4
5
|
import { useDrawingArea } from "../../hooks/useDrawingArea.js";
|
|
5
6
|
import { useSeries } from "../../hooks/useSeries.js";
|
|
6
7
|
import { CartesianContext } from "./CartesianContext.js";
|
|
7
|
-
import { computeValue } from "./computeValue.js";
|
|
8
8
|
import { useXExtremumGetter } from "../PluginProvider/useXExtremumGetter.js";
|
|
9
9
|
import { useYExtremumGetter } from "../PluginProvider/index.js";
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -18,14 +18,14 @@ function CartesianProvider(props) {
|
|
|
18
18
|
const drawingArea = useDrawingArea();
|
|
19
19
|
const xExtremumGetters = useXExtremumGetter();
|
|
20
20
|
const yExtremumGetters = useYExtremumGetter();
|
|
21
|
-
const xValues = React.useMemo(() =>
|
|
21
|
+
const xValues = React.useMemo(() => computeAxisValue({
|
|
22
22
|
drawingArea,
|
|
23
23
|
formattedSeries,
|
|
24
24
|
axis: xAxis,
|
|
25
25
|
extremumGetters: xExtremumGetters,
|
|
26
26
|
axisDirection: 'x'
|
|
27
27
|
}), [drawingArea, formattedSeries, xAxis, xExtremumGetters]);
|
|
28
|
-
const yValues = React.useMemo(() =>
|
|
28
|
+
const yValues = React.useMemo(() => computeAxisValue({
|
|
29
29
|
drawingArea,
|
|
30
30
|
formattedSeries,
|
|
31
31
|
axis: yAxis,
|
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
const axisExtremumCallback = (acc, chartType, axis, getters,
|
|
1
|
+
const axisExtremumCallback = (acc, chartType, axis, getters, axisIndex, formattedSeries, getFilters) => {
|
|
2
2
|
const getter = getters[chartType];
|
|
3
3
|
const series = formattedSeries[chartType]?.series ?? {};
|
|
4
4
|
const [minChartTypeData, maxChartTypeData] = getter?.({
|
|
5
5
|
series,
|
|
6
6
|
axis,
|
|
7
|
-
|
|
7
|
+
axisIndex,
|
|
8
|
+
isDefaultAxis: axisIndex === 0,
|
|
8
9
|
getFilters
|
|
9
10
|
}) ?? [Infinity, -Infinity];
|
|
10
11
|
const [minData, maxData] = acc;
|
|
11
12
|
return [Math.min(minChartTypeData, minData), Math.max(maxChartTypeData, maxData)];
|
|
12
13
|
};
|
|
13
|
-
export const getAxisExtremum = (axis, getters,
|
|
14
|
+
export const getAxisExtremum = (axis, getters, axisIndex, formattedSeries, getFilters) => {
|
|
14
15
|
const charTypes = Object.keys(getters);
|
|
15
|
-
const extremums = charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters,
|
|
16
|
+
const extremums = charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, axisIndex, formattedSeries, getFilters), [Infinity, -Infinity]);
|
|
16
17
|
if (Number.isNaN(extremums[0]) || Number.isNaN(extremums[1])) {
|
|
17
18
|
return [Infinity, -Infinity];
|
|
18
19
|
}
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import { computeValue } from "./computeValue.js";
|
|
2
1
|
export * from "./CartesianProvider.js";
|
|
3
2
|
export * from "./CartesianContext.js";
|
|
4
3
|
export * from "./useCartesianContext.js";
|
|
5
|
-
export * from "./Cartesian.types.js";
|
|
6
|
-
const cartesianProviderUtils = {
|
|
7
|
-
computeValue
|
|
8
|
-
};
|
|
9
|
-
export { cartesianProviderUtils };
|
|
4
|
+
export * from "./Cartesian.types.js";
|
|
@@ -5,7 +5,9 @@ export const PluginContext = /*#__PURE__*/React.createContext({
|
|
|
5
5
|
colorProcessors: {},
|
|
6
6
|
seriesFormatters: {},
|
|
7
7
|
xExtremumGetters: {},
|
|
8
|
-
yExtremumGetters: {}
|
|
8
|
+
yExtremumGetters: {},
|
|
9
|
+
rotationExtremumGetters: {},
|
|
10
|
+
radiusExtremumGetters: {}
|
|
9
11
|
}
|
|
10
12
|
});
|
|
11
13
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -7,4 +7,6 @@ export * from "./ExtremumGetter.types.js";
|
|
|
7
7
|
export * from "./useColorProcessor.js";
|
|
8
8
|
export * from "./useSeriesFormatter.js";
|
|
9
9
|
export * from "./useXExtremumGetter.js";
|
|
10
|
-
export * from "./useYExtremumGetter.js";
|
|
10
|
+
export * from "./useYExtremumGetter.js";
|
|
11
|
+
export * from "./useRadiusExtremumGetter.js";
|
|
12
|
+
export * from "./useRotationExtremumGetter.js";
|
|
@@ -9,6 +9,8 @@ export function mergePlugins(plugins) {
|
|
|
9
9
|
const colorProcessors = {};
|
|
10
10
|
const xExtremumGetters = {};
|
|
11
11
|
const yExtremumGetters = {};
|
|
12
|
+
const rotationExtremumGetters = {};
|
|
13
|
+
const radiusExtremumGetters = {};
|
|
12
14
|
for (let i = 0; i < defaultizedPlugins.length; i += 1) {
|
|
13
15
|
const plugin = defaultizedPlugins[i];
|
|
14
16
|
const seriesType = plugin.seriesType;
|
|
@@ -20,11 +22,19 @@ export function mergePlugins(plugins) {
|
|
|
20
22
|
if (plugin.yExtremumGetter) {
|
|
21
23
|
yExtremumGetters[seriesType] = plugin.yExtremumGetter;
|
|
22
24
|
}
|
|
25
|
+
if (plugin.rotationExtremumGetter) {
|
|
26
|
+
rotationExtremumGetters[seriesType] = plugin.rotationExtremumGetter;
|
|
27
|
+
}
|
|
28
|
+
if (plugin.radiusExtremumGetter) {
|
|
29
|
+
radiusExtremumGetters[seriesType] = plugin.radiusExtremumGetter;
|
|
30
|
+
}
|
|
23
31
|
}
|
|
24
32
|
return {
|
|
25
33
|
seriesFormatters,
|
|
26
34
|
colorProcessors,
|
|
27
35
|
xExtremumGetters,
|
|
28
|
-
yExtremumGetters
|
|
36
|
+
yExtremumGetters,
|
|
37
|
+
rotationExtremumGetters,
|
|
38
|
+
radiusExtremumGetters
|
|
29
39
|
};
|
|
30
40
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { PluginContext } from "./PluginContext.js";
|
|
5
|
+
export function useRadiusExtremumGetter(seriesType) {
|
|
6
|
+
const {
|
|
7
|
+
isInitialized,
|
|
8
|
+
data
|
|
9
|
+
} = React.useContext(PluginContext);
|
|
10
|
+
if (!isInitialized) {
|
|
11
|
+
throw new Error(['MUI X: Could not find the plugin context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
|
|
12
|
+
}
|
|
13
|
+
if (!seriesType) {
|
|
14
|
+
return data.radiusExtremumGetters;
|
|
15
|
+
}
|
|
16
|
+
return data.radiusExtremumGetters[seriesType];
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { PluginContext } from "./PluginContext.js";
|
|
5
|
+
export function useRotationExtremumGetter(seriesType) {
|
|
6
|
+
const {
|
|
7
|
+
isInitialized,
|
|
8
|
+
data
|
|
9
|
+
} = React.useContext(PluginContext);
|
|
10
|
+
if (!isInitialized) {
|
|
11
|
+
throw new Error(['MUI X: Could not find the plugin context.', 'It looks like you rendered your component outside of a ChartsContainer parent component.'].join('\n'));
|
|
12
|
+
}
|
|
13
|
+
if (!seriesType) {
|
|
14
|
+
return data.rotationExtremumGetters;
|
|
15
|
+
}
|
|
16
|
+
return data.rotationExtremumGetters[seriesType];
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export const PolarContext = /*#__PURE__*/React.createContext({
|
|
3
|
+
isInitialized: false,
|
|
4
|
+
data: {
|
|
5
|
+
rotationAxis: {},
|
|
6
|
+
radiusAxis: {},
|
|
7
|
+
rotationAxisIds: [],
|
|
8
|
+
radiusAxisIds: []
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
12
|
+
PolarContext.displayName = 'PolarContext';
|
|
13
|
+
}
|