@mui/x-charts 7.17.0 → 7.18.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/CHANGELOG.md +98 -5
- package/ChartsLegend/ChartsLegend.d.ts +2 -2
- 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/AnimatedLine.js +12 -22
- package/LineChart/LineChart.js +10 -0
- package/PieChart/PieChart.js +10 -0
- 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.js +3 -2
- package/ScatterChart/ScatterChart.js +10 -0
- package/SparkLineChart/SparkLineChart.js +10 -0
- package/context/CartesianProvider/CartesianProvider.js +3 -3
- 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 +10 -0
- 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/index.js +1 -1
- package/internals/computeAxisValue.d.ts +38 -0
- package/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +28 -15
- 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/modern/BarChart/BarChart.js +10 -0
- package/modern/ChartsTooltip/index.js +4 -1
- package/modern/ChartsTooltip/useAxisTooltip.js +84 -0
- package/modern/ChartsTooltip/useItemTooltip.js +64 -0
- package/modern/LineChart/AnimatedLine.js +12 -22
- package/modern/LineChart/LineChart.js +10 -0
- 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/index.js +1 -1
- package/modern/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +28 -15
- package/modern/internals/index.js +1 -0
- package/node/BarChart/BarChart.js +10 -0
- package/node/ChartsTooltip/index.js +42 -1
- package/node/ChartsTooltip/useAxisTooltip.js +90 -0
- package/node/ChartsTooltip/useItemTooltip.js +71 -0
- package/node/LineChart/AnimatedLine.js +12 -22
- package/node/LineChart/LineChart.js +10 -0
- 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/index.js +1 -1
- package/node/{context/CartesianProvider/computeValue.js → internals/computeAxisValue.js} +29 -16
- package/node/internals/index.js +12 -0
- package/package.json +4 -4
- package/context/CartesianProvider/computeValue.d.ts +0 -30
package/modern/index.js
CHANGED
|
@@ -1,15 +1,29 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { scaleBand, scalePoint, scaleTime } from '@mui/x-charts-vendor/d3-scale';
|
|
3
|
-
import { isBandScaleConfig, isPointScaleConfig } from "
|
|
4
|
-
import { getColorScale, getOrdinalColorScale } from "
|
|
5
|
-
import { getTickNumber } from "
|
|
6
|
-
import { getScale } from "
|
|
7
|
-
import { zoomScaleRange } from "
|
|
8
|
-
import { getAxisExtremum } from "
|
|
9
|
-
|
|
3
|
+
import { isBandScaleConfig, isPointScaleConfig } from "../models/axis.js";
|
|
4
|
+
import { getColorScale, getOrdinalColorScale } from "./colorScale.js";
|
|
5
|
+
import { getTickNumber } from "../hooks/useTicks.js";
|
|
6
|
+
import { getScale } from "./getScale.js";
|
|
7
|
+
import { zoomScaleRange } from "../context/CartesianProvider/zoom.js";
|
|
8
|
+
import { getAxisExtremum } from "../context/CartesianProvider/getAxisExtremum.js";
|
|
9
|
+
function getRange(drawingArea, axisDirection, axis) {
|
|
10
|
+
if (axisDirection === 'rotation') {
|
|
11
|
+
const {
|
|
12
|
+
startAngle = 0,
|
|
13
|
+
endAngle = startAngle + 360
|
|
14
|
+
} = axis;
|
|
15
|
+
return axis.reverse ? [Math.PI * startAngle / 180, Math.PI * endAngle / 180] : [Math.PI * endAngle / 180, Math.PI * startAngle / 180];
|
|
16
|
+
}
|
|
17
|
+
if (axisDirection === 'radius') {
|
|
18
|
+
const {
|
|
19
|
+
minRadius = 0,
|
|
20
|
+
maxRadius = Math.min(drawingArea.width, drawingArea.height) / 2
|
|
21
|
+
} = axis;
|
|
22
|
+
return [minRadius, maxRadius];
|
|
23
|
+
}
|
|
10
24
|
const range = axisDirection === 'x' ? [drawingArea.left, drawingArea.left + drawingArea.width] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
11
|
-
return
|
|
12
|
-
}
|
|
25
|
+
return axis.reverse ? [range[1], range[0]] : range;
|
|
26
|
+
}
|
|
13
27
|
const isDateData = data => data?.[0] instanceof Date;
|
|
14
28
|
function createDateFormatter(axis, range) {
|
|
15
29
|
const timeScale = scaleTime(axis.data, range);
|
|
@@ -19,7 +33,7 @@ function createDateFormatter(axis, range) {
|
|
|
19
33
|
}
|
|
20
34
|
const DEFAULT_CATEGORY_GAP_RATIO = 0.2;
|
|
21
35
|
const DEFAULT_BAR_GAP_RATIO = 0.1;
|
|
22
|
-
export function
|
|
36
|
+
export function computeAxisValue({
|
|
23
37
|
drawingArea,
|
|
24
38
|
formattedSeries,
|
|
25
39
|
axis: allAxis,
|
|
@@ -32,21 +46,20 @@ export function computeValue({
|
|
|
32
46
|
const completeAxis = {};
|
|
33
47
|
allAxis.forEach((eachAxis, axisIndex) => {
|
|
34
48
|
const axis = eachAxis;
|
|
35
|
-
const isDefaultAxis = axisIndex === 0;
|
|
36
49
|
const zoomOption = zoomOptions?.[axis.id];
|
|
37
50
|
const zoom = zoomData?.find(({
|
|
38
51
|
axisId
|
|
39
52
|
}) => axisId === axis.id);
|
|
40
53
|
const zoomRange = zoom ? [zoom.start, zoom.end] : [0, 100];
|
|
41
|
-
const range = getRange(drawingArea, axisDirection, axis
|
|
42
|
-
const [minData, maxData] = getAxisExtremum(axis, extremumGetters,
|
|
54
|
+
const range = getRange(drawingArea, axisDirection, axis);
|
|
55
|
+
const [minData, maxData] = getAxisExtremum(axis, extremumGetters, axisIndex, formattedSeries, zoom === undefined && !zoomOption ? getFilters : undefined // Do not apply filtering if zoom is already defined.
|
|
43
56
|
);
|
|
44
57
|
const data = axis.data ?? [];
|
|
45
58
|
if (isBandScaleConfig(axis)) {
|
|
46
59
|
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
47
60
|
const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
|
|
48
61
|
// Reverse range because ordinal scales are presented from top to bottom on y-axis
|
|
49
|
-
const scaleRange = axisDirection === '
|
|
62
|
+
const scaleRange = axisDirection === 'y' ? [range[1], range[0]] : range;
|
|
50
63
|
const zoomedRange = zoomScaleRange(scaleRange, zoomRange);
|
|
51
64
|
completeAxis[axis.id] = _extends({
|
|
52
65
|
categoryGapRatio,
|
|
@@ -65,7 +78,7 @@ export function computeValue({
|
|
|
65
78
|
}
|
|
66
79
|
}
|
|
67
80
|
if (isPointScaleConfig(axis)) {
|
|
68
|
-
const scaleRange = axisDirection === '
|
|
81
|
+
const scaleRange = axisDirection === 'y' ? [...range].reverse() : range;
|
|
69
82
|
const zoomedRange = zoomScaleRange(scaleRange, zoomRange);
|
|
70
83
|
completeAxis[axis.id] = _extends({}, axis, {
|
|
71
84
|
data,
|
|
@@ -203,6 +203,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
203
203
|
* @param {BarItemIdentifier} barItemIdentifier The bar item identifier.
|
|
204
204
|
*/
|
|
205
205
|
onItemClick: _propTypes.default.func,
|
|
206
|
+
/**
|
|
207
|
+
* The chart will try to wait for the parent container to resolve its size
|
|
208
|
+
* before it renders for the first time.
|
|
209
|
+
*
|
|
210
|
+
* This can be useful in some scenarios where the chart appear to grow after
|
|
211
|
+
* the first render, like when used inside a grid.
|
|
212
|
+
*
|
|
213
|
+
* @default false
|
|
214
|
+
*/
|
|
215
|
+
resolveSizeBeforeRender: _propTypes.default.bool,
|
|
206
216
|
/**
|
|
207
217
|
* Indicate which axis to display the right of the charts.
|
|
208
218
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -3,9 +3,19 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
useMouseTracker: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "useMouseTracker", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _utils.useMouseTracker;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
6
15
|
var _ChartsTooltip = require("./ChartsTooltip");
|
|
7
16
|
Object.keys(_ChartsTooltip).forEach(function (key) {
|
|
8
17
|
if (key === "default" || key === "__esModule") return;
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
9
19
|
if (key in exports && exports[key] === _ChartsTooltip[key]) return;
|
|
10
20
|
Object.defineProperty(exports, key, {
|
|
11
21
|
enumerable: true,
|
|
@@ -17,6 +27,7 @@ Object.keys(_ChartsTooltip).forEach(function (key) {
|
|
|
17
27
|
var _chartsTooltipClasses = require("./chartsTooltipClasses");
|
|
18
28
|
Object.keys(_chartsTooltipClasses).forEach(function (key) {
|
|
19
29
|
if (key === "default" || key === "__esModule") return;
|
|
30
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
20
31
|
if (key in exports && exports[key] === _chartsTooltipClasses[key]) return;
|
|
21
32
|
Object.defineProperty(exports, key, {
|
|
22
33
|
enumerable: true,
|
|
@@ -28,6 +39,7 @@ Object.keys(_chartsTooltipClasses).forEach(function (key) {
|
|
|
28
39
|
var _ChartsAxisTooltipContent = require("./ChartsAxisTooltipContent");
|
|
29
40
|
Object.keys(_ChartsAxisTooltipContent).forEach(function (key) {
|
|
30
41
|
if (key === "default" || key === "__esModule") return;
|
|
42
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
31
43
|
if (key in exports && exports[key] === _ChartsAxisTooltipContent[key]) return;
|
|
32
44
|
Object.defineProperty(exports, key, {
|
|
33
45
|
enumerable: true,
|
|
@@ -39,6 +51,7 @@ Object.keys(_ChartsAxisTooltipContent).forEach(function (key) {
|
|
|
39
51
|
var _ChartsItemTooltipContent = require("./ChartsItemTooltipContent");
|
|
40
52
|
Object.keys(_ChartsItemTooltipContent).forEach(function (key) {
|
|
41
53
|
if (key === "default" || key === "__esModule") return;
|
|
54
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
42
55
|
if (key in exports && exports[key] === _ChartsItemTooltipContent[key]) return;
|
|
43
56
|
Object.defineProperty(exports, key, {
|
|
44
57
|
enumerable: true,
|
|
@@ -50,6 +63,7 @@ Object.keys(_ChartsItemTooltipContent).forEach(function (key) {
|
|
|
50
63
|
var _DefaultChartsAxisTooltipContent = require("./DefaultChartsAxisTooltipContent");
|
|
51
64
|
Object.keys(_DefaultChartsAxisTooltipContent).forEach(function (key) {
|
|
52
65
|
if (key === "default" || key === "__esModule") return;
|
|
66
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
53
67
|
if (key in exports && exports[key] === _DefaultChartsAxisTooltipContent[key]) return;
|
|
54
68
|
Object.defineProperty(exports, key, {
|
|
55
69
|
enumerable: true,
|
|
@@ -61,6 +75,7 @@ Object.keys(_DefaultChartsAxisTooltipContent).forEach(function (key) {
|
|
|
61
75
|
var _DefaultChartsItemTooltipContent = require("./DefaultChartsItemTooltipContent");
|
|
62
76
|
Object.keys(_DefaultChartsItemTooltipContent).forEach(function (key) {
|
|
63
77
|
if (key === "default" || key === "__esModule") return;
|
|
78
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
64
79
|
if (key in exports && exports[key] === _DefaultChartsItemTooltipContent[key]) return;
|
|
65
80
|
Object.defineProperty(exports, key, {
|
|
66
81
|
enumerable: true,
|
|
@@ -72,6 +87,7 @@ Object.keys(_DefaultChartsItemTooltipContent).forEach(function (key) {
|
|
|
72
87
|
var _ChartsTooltipTable = require("./ChartsTooltipTable");
|
|
73
88
|
Object.keys(_ChartsTooltipTable).forEach(function (key) {
|
|
74
89
|
if (key === "default" || key === "__esModule") return;
|
|
90
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
75
91
|
if (key in exports && exports[key] === _ChartsTooltipTable[key]) return;
|
|
76
92
|
Object.defineProperty(exports, key, {
|
|
77
93
|
enumerable: true,
|
|
@@ -79,4 +95,29 @@ Object.keys(_ChartsTooltipTable).forEach(function (key) {
|
|
|
79
95
|
return _ChartsTooltipTable[key];
|
|
80
96
|
}
|
|
81
97
|
});
|
|
82
|
-
});
|
|
98
|
+
});
|
|
99
|
+
var _useItemTooltip = require("./useItemTooltip");
|
|
100
|
+
Object.keys(_useItemTooltip).forEach(function (key) {
|
|
101
|
+
if (key === "default" || key === "__esModule") return;
|
|
102
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
103
|
+
if (key in exports && exports[key] === _useItemTooltip[key]) return;
|
|
104
|
+
Object.defineProperty(exports, key, {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function () {
|
|
107
|
+
return _useItemTooltip[key];
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
var _useAxisTooltip = require("./useAxisTooltip");
|
|
112
|
+
Object.keys(_useAxisTooltip).forEach(function (key) {
|
|
113
|
+
if (key === "default" || key === "__esModule") return;
|
|
114
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
115
|
+
if (key in exports && exports[key] === _useAxisTooltip[key]) return;
|
|
116
|
+
Object.defineProperty(exports, key, {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () {
|
|
119
|
+
return _useAxisTooltip[key];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
var _utils = require("./utils");
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useAxisTooltip = useAxisTooltip;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _InteractionProvider = require("../context/InteractionProvider");
|
|
11
|
+
var _useSeries = require("../hooks/useSeries");
|
|
12
|
+
var _CartesianProvider = require("../context/CartesianProvider");
|
|
13
|
+
var _ZAxisContextProvider = require("../context/ZAxisContextProvider");
|
|
14
|
+
var _useColorProcessor = require("../context/PluginProvider/useColorProcessor");
|
|
15
|
+
var _getLabel = require("../internals/getLabel");
|
|
16
|
+
var _isCartesian = require("../internals/isCartesian");
|
|
17
|
+
var _utils = require("./utils");
|
|
18
|
+
function useAxisTooltip() {
|
|
19
|
+
const {
|
|
20
|
+
axis
|
|
21
|
+
} = React.useContext(_InteractionProvider.InteractionContext);
|
|
22
|
+
const series = (0, _useSeries.useSeries)();
|
|
23
|
+
const {
|
|
24
|
+
xAxis,
|
|
25
|
+
yAxis,
|
|
26
|
+
xAxisIds,
|
|
27
|
+
yAxisIds
|
|
28
|
+
} = (0, _CartesianProvider.useCartesianContext)();
|
|
29
|
+
const {
|
|
30
|
+
zAxis,
|
|
31
|
+
zAxisIds
|
|
32
|
+
} = React.useContext(_ZAxisContextProvider.ZAxisContext);
|
|
33
|
+
const colorProcessors = (0, _useColorProcessor.useColorProcessor)();
|
|
34
|
+
|
|
35
|
+
// By default use the x-axis
|
|
36
|
+
const isXaxis = axis.x !== null && axis.x.index !== -1;
|
|
37
|
+
const axisData = isXaxis ? axis.x && axis.x : axis.y && axis.y;
|
|
38
|
+
if (axisData === null) {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
const {
|
|
42
|
+
index: dataIndex,
|
|
43
|
+
value: axisValue
|
|
44
|
+
} = axisData;
|
|
45
|
+
const USED_AXIS_ID = isXaxis ? xAxisIds[0] : yAxisIds[0];
|
|
46
|
+
const usedAxis = isXaxis ? xAxis[USED_AXIS_ID] : yAxis[USED_AXIS_ID];
|
|
47
|
+
const relevantSeries = Object.keys(series).filter(_isCartesian.isCartesianSeriesType).flatMap(seriesType => {
|
|
48
|
+
const seriesOfType = series[seriesType];
|
|
49
|
+
if (!seriesOfType) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
return seriesOfType.seriesOrder.map(seriesId => {
|
|
53
|
+
const seriesToAdd = seriesOfType.series[seriesId];
|
|
54
|
+
const providedXAxisId = seriesToAdd.xAxisId ?? seriesToAdd.xAxisKey;
|
|
55
|
+
const providedYAxisId = seriesToAdd.yAxisId ?? seriesToAdd.yAxisKey;
|
|
56
|
+
const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
|
|
57
|
+
|
|
58
|
+
// Test if the series uses the default axis
|
|
59
|
+
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
60
|
+
const xAxisId = providedXAxisId ?? xAxisIds[0];
|
|
61
|
+
const yAxisId = providedYAxisId ?? yAxisIds[0];
|
|
62
|
+
const zAxisId = seriesToAdd.zAxisId ?? seriesToAdd.zAxisKey ?? zAxisIds[0];
|
|
63
|
+
const color = colorProcessors[seriesType]?.(seriesToAdd, xAxis[xAxisId], yAxis[yAxisId], zAxisId && zAxis[zAxisId])(dataIndex) ?? '';
|
|
64
|
+
const value = seriesToAdd.data[dataIndex] ?? null;
|
|
65
|
+
const formattedValue = seriesToAdd.valueFormatter(value, {
|
|
66
|
+
dataIndex
|
|
67
|
+
});
|
|
68
|
+
const formattedLabel = (0, _getLabel.getLabel)(seriesToAdd.label, 'tooltip') ?? null;
|
|
69
|
+
return {
|
|
70
|
+
seriesId,
|
|
71
|
+
color,
|
|
72
|
+
value,
|
|
73
|
+
formattedValue,
|
|
74
|
+
formattedLabel
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return undefined;
|
|
78
|
+
});
|
|
79
|
+
}).filter(item => item != null);
|
|
80
|
+
const axisFormatter = usedAxis.valueFormatter ?? (v => usedAxis.scaleType === 'utc' ? (0, _utils.utcFormatter)(v) : v.toLocaleString());
|
|
81
|
+
const axisFormattedValue = axisFormatter(axisValue, {
|
|
82
|
+
location: 'tooltip'
|
|
83
|
+
});
|
|
84
|
+
return {
|
|
85
|
+
identifier: axis,
|
|
86
|
+
seriesItems: relevantSeries,
|
|
87
|
+
axisValue,
|
|
88
|
+
axisFormattedValue
|
|
89
|
+
};
|
|
90
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
6
|
+
Object.defineProperty(exports, "__esModule", {
|
|
7
|
+
value: true
|
|
8
|
+
});
|
|
9
|
+
exports.useItemTooltip = useItemTooltip;
|
|
10
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
+
var React = _interopRequireWildcard(require("react"));
|
|
12
|
+
var _InteractionProvider = require("../context/InteractionProvider");
|
|
13
|
+
var _useSeries = require("../hooks/useSeries");
|
|
14
|
+
var _CartesianProvider = require("../context/CartesianProvider");
|
|
15
|
+
var _ZAxisContextProvider = require("../context/ZAxisContextProvider");
|
|
16
|
+
var _useColorProcessor = require("../context/PluginProvider/useColorProcessor");
|
|
17
|
+
var _getLabel = require("../internals/getLabel");
|
|
18
|
+
function useItemTooltip() {
|
|
19
|
+
const {
|
|
20
|
+
item
|
|
21
|
+
} = React.useContext(_InteractionProvider.InteractionContext);
|
|
22
|
+
const series = (0, _useSeries.useSeries)();
|
|
23
|
+
const {
|
|
24
|
+
xAxis,
|
|
25
|
+
yAxis,
|
|
26
|
+
xAxisIds,
|
|
27
|
+
yAxisIds
|
|
28
|
+
} = (0, _CartesianProvider.useCartesianContext)();
|
|
29
|
+
const {
|
|
30
|
+
zAxis,
|
|
31
|
+
zAxisIds
|
|
32
|
+
} = React.useContext(_ZAxisContextProvider.ZAxisContext);
|
|
33
|
+
const colorProcessors = (0, _useColorProcessor.useColorProcessor)();
|
|
34
|
+
const xAxisId = series.xAxisId ?? series.xAxisKey ?? xAxisIds[0];
|
|
35
|
+
const yAxisId = series.yAxisId ?? series.yAxisKey ?? yAxisIds[0];
|
|
36
|
+
const zAxisId = series.zAxisId ?? series.zAxisKey ?? zAxisIds[0];
|
|
37
|
+
if (!item || item.dataIndex === undefined) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
const itemSeries = series[item.type].series[item.seriesId];
|
|
41
|
+
const getColor = colorProcessors[itemSeries.type]?.(itemSeries, xAxisId && xAxis[xAxisId], yAxisId && yAxis[yAxisId], zAxisId && zAxis[zAxisId]) ?? (() => '');
|
|
42
|
+
if (itemSeries.type === 'pie') {
|
|
43
|
+
const point = itemSeries.data[item.dataIndex];
|
|
44
|
+
const label = (0, _getLabel.getLabel)(point.label, 'tooltip');
|
|
45
|
+
const value = (0, _extends2.default)({}, point, {
|
|
46
|
+
label
|
|
47
|
+
});
|
|
48
|
+
const formattedValue = itemSeries.valueFormatter?.(value, {
|
|
49
|
+
dataIndex: item.dataIndex
|
|
50
|
+
});
|
|
51
|
+
return {
|
|
52
|
+
identifier: item,
|
|
53
|
+
color: getColor(item.dataIndex),
|
|
54
|
+
label,
|
|
55
|
+
value,
|
|
56
|
+
formattedValue
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
const label = (0, _getLabel.getLabel)(itemSeries.label, 'tooltip');
|
|
60
|
+
const value = itemSeries.data[item.dataIndex];
|
|
61
|
+
const formattedValue = itemSeries.valueFormatter?.(value, {
|
|
62
|
+
dataIndex: item.dataIndex
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
identifier: item,
|
|
66
|
+
color: getColor(item.dataIndex),
|
|
67
|
+
label,
|
|
68
|
+
value,
|
|
69
|
+
formattedValue
|
|
70
|
+
};
|
|
71
|
+
}
|
|
@@ -52,29 +52,19 @@ function AnimatedLine(props) {
|
|
|
52
52
|
ownerState
|
|
53
53
|
} = props,
|
|
54
54
|
other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
|
|
55
|
-
const
|
|
56
|
-
left,
|
|
57
|
-
top,
|
|
58
|
-
bottom,
|
|
59
|
-
width,
|
|
60
|
-
height,
|
|
61
|
-
right
|
|
62
|
-
} = (0, _useDrawingArea.useDrawingArea)();
|
|
55
|
+
const drawingArea = (0, _useDrawingArea.useDrawingArea)();
|
|
63
56
|
const chartId = (0, _useChartId.useChartId)();
|
|
64
57
|
const stringInterpolator = (0, _useStringInterpolator.useStringInterpolator)(d);
|
|
65
|
-
const transitionAppear = (0, _web.useTransition)([
|
|
66
|
-
from: {
|
|
67
|
-
animatedWidth: left
|
|
68
|
-
},
|
|
69
|
-
|
|
70
|
-
animatedWidth: width + left + right
|
|
71
|
-
},
|
|
72
|
-
|
|
73
|
-
animatedWidth: width + left + right
|
|
74
|
-
},
|
|
75
|
-
leave: {
|
|
76
|
-
animatedWidth: left
|
|
77
|
-
},
|
|
58
|
+
const transitionAppear = (0, _web.useTransition)([drawingArea], {
|
|
59
|
+
from: v => ({
|
|
60
|
+
animatedWidth: v.left
|
|
61
|
+
}),
|
|
62
|
+
enter: v => ({
|
|
63
|
+
animatedWidth: v.width + v.left + v.right
|
|
64
|
+
}),
|
|
65
|
+
leave: v => ({
|
|
66
|
+
animatedWidth: v.width + v.left + v.right
|
|
67
|
+
}),
|
|
78
68
|
reset: false,
|
|
79
69
|
immediate: skipAnimation
|
|
80
70
|
});
|
|
@@ -99,7 +89,7 @@ function AnimatedLine(props) {
|
|
|
99
89
|
x: 0,
|
|
100
90
|
y: 0,
|
|
101
91
|
width: style.animatedWidth,
|
|
102
|
-
height: top + height + bottom
|
|
92
|
+
height: drawingArea.top + drawingArea.height + drawingArea.bottom
|
|
103
93
|
}))
|
|
104
94
|
}), /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
|
|
105
95
|
clipPath: `url(#${clipId})`,
|
|
@@ -207,6 +207,16 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
207
207
|
* Callback fired when a mark element is clicked.
|
|
208
208
|
*/
|
|
209
209
|
onMarkClick: _propTypes.default.func,
|
|
210
|
+
/**
|
|
211
|
+
* The chart will try to wait for the parent container to resolve its size
|
|
212
|
+
* before it renders for the first time.
|
|
213
|
+
*
|
|
214
|
+
* This can be useful in some scenarios where the chart appear to grow after
|
|
215
|
+
* the first render, like when used inside a grid.
|
|
216
|
+
*
|
|
217
|
+
* @default false
|
|
218
|
+
*/
|
|
219
|
+
resolveSizeBeforeRender: _propTypes.default.bool,
|
|
210
220
|
/**
|
|
211
221
|
* Indicate which axis to display the right of the charts.
|
|
212
222
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -247,6 +247,16 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
247
247
|
* Callback fired when a pie arc is clicked.
|
|
248
248
|
*/
|
|
249
249
|
onItemClick: _propTypes.default.func,
|
|
250
|
+
/**
|
|
251
|
+
* The chart will try to wait for the parent container to resolve its size
|
|
252
|
+
* before it renders for the first time.
|
|
253
|
+
*
|
|
254
|
+
* This can be useful in some scenarios where the chart appear to grow after
|
|
255
|
+
* the first render, like when used inside a grid.
|
|
256
|
+
*
|
|
257
|
+
* @default false
|
|
258
|
+
*/
|
|
259
|
+
resolveSizeBeforeRender: _propTypes.default.bool,
|
|
250
260
|
/**
|
|
251
261
|
* Indicate which axis to display the right of the charts.
|
|
252
262
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -81,6 +81,16 @@ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
|
|
|
81
81
|
* If not provided, the container supports line, bar, scatter and pie charts.
|
|
82
82
|
*/
|
|
83
83
|
plugins: _propTypes.default.arrayOf(_propTypes.default.object),
|
|
84
|
+
/**
|
|
85
|
+
* The chart will try to wait for the parent container to resolve its size
|
|
86
|
+
* before it renders for the first time.
|
|
87
|
+
*
|
|
88
|
+
* This can be useful in some scenarios where the chart appear to grow after
|
|
89
|
+
* the first render, like when used inside a grid.
|
|
90
|
+
*
|
|
91
|
+
* @default false
|
|
92
|
+
*/
|
|
93
|
+
resolveSizeBeforeRender: _propTypes.default.bool,
|
|
84
94
|
/**
|
|
85
95
|
* The array of series to display.
|
|
86
96
|
* Each type of series has its own specificity.
|
|
@@ -10,8 +10,12 @@ exports.useChartContainerDimensions = void 0;
|
|
|
10
10
|
var React = _interopRequireWildcard(require("react"));
|
|
11
11
|
var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
|
|
12
12
|
var _ownerWindow = _interopRequireDefault(require("@mui/utils/ownerWindow"));
|
|
13
|
-
const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
14
|
-
const
|
|
13
|
+
const useChartContainerDimensions = (inWidth, inHeight, resolveSizeBeforeRender) => {
|
|
14
|
+
const stateRef = React.useRef({
|
|
15
|
+
displayError: false,
|
|
16
|
+
initialCompute: true,
|
|
17
|
+
computeRun: 0
|
|
18
|
+
});
|
|
15
19
|
const rootRef = React.useRef(null);
|
|
16
20
|
const [width, setWidth] = React.useState(0);
|
|
17
21
|
const [height, setHeight] = React.useState(0);
|
|
@@ -20,7 +24,7 @@ const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
|
20
24
|
const computeSize = React.useCallback(() => {
|
|
21
25
|
const mainEl = rootRef?.current;
|
|
22
26
|
if (!mainEl) {
|
|
23
|
-
return;
|
|
27
|
+
return {};
|
|
24
28
|
}
|
|
25
29
|
const win = (0, _ownerWindow.default)(mainEl);
|
|
26
30
|
const computedStyle = win.getComputedStyle(mainEl);
|
|
@@ -28,11 +32,31 @@ const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
|
28
32
|
const newWidth = Math.floor(parseFloat(computedStyle.width)) || 0;
|
|
29
33
|
setWidth(newWidth);
|
|
30
34
|
setHeight(newHeight);
|
|
35
|
+
return {
|
|
36
|
+
width: newWidth,
|
|
37
|
+
height: newHeight
|
|
38
|
+
};
|
|
31
39
|
}, []);
|
|
32
40
|
React.useEffect(() => {
|
|
33
41
|
// Ensure the error detection occurs after the first rendering.
|
|
34
|
-
|
|
42
|
+
stateRef.current.displayError = true;
|
|
35
43
|
}, []);
|
|
44
|
+
|
|
45
|
+
// This effect is used to compute the size of the container on the initial render.
|
|
46
|
+
// It is not bound to the raf loop to avoid an unwanted "resize" event.
|
|
47
|
+
// https://github.com/mui/mui-x/issues/13477#issuecomment-2336634785
|
|
48
|
+
(0, _useEnhancedEffect.default)(() => {
|
|
49
|
+
// computeRun is used to avoid infinite loops.
|
|
50
|
+
if (!resolveSizeBeforeRender || !stateRef.current.initialCompute || stateRef.current.computeRun > 20) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const computedSize = computeSize();
|
|
54
|
+
if (computedSize.width !== width || computedSize.height !== height) {
|
|
55
|
+
stateRef.current.computeRun += 1;
|
|
56
|
+
} else if (stateRef.current.initialCompute) {
|
|
57
|
+
stateRef.current.initialCompute = false;
|
|
58
|
+
}
|
|
59
|
+
}, [width, height, computeSize, resolveSizeBeforeRender]);
|
|
36
60
|
(0, _useEnhancedEffect.default)(() => {
|
|
37
61
|
if (inWidth !== undefined && inHeight !== undefined) {
|
|
38
62
|
return () => {};
|
|
@@ -62,13 +86,13 @@ const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
|
62
86
|
};
|
|
63
87
|
}, [computeSize, inHeight, inWidth]);
|
|
64
88
|
if (process.env.NODE_ENV !== 'production') {
|
|
65
|
-
if (
|
|
89
|
+
if (stateRef.current.displayError && inWidth === undefined && width === 0) {
|
|
66
90
|
console.error(`MUI X: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
|
|
67
|
-
|
|
91
|
+
stateRef.current.displayError = false;
|
|
68
92
|
}
|
|
69
|
-
if (
|
|
93
|
+
if (stateRef.current.displayError && inHeight === undefined && height === 0) {
|
|
70
94
|
console.error(`MUI X: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
|
|
71
|
-
|
|
95
|
+
stateRef.current.displayError = false;
|
|
72
96
|
}
|
|
73
97
|
}
|
|
74
98
|
return {
|
|
@@ -9,11 +9,12 @@ exports.useResponsiveChartContainerProps = void 0;
|
|
|
9
9
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
10
10
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
11
11
|
var _useChartContainerDimensions = require("./useChartContainerDimensions");
|
|
12
|
-
const _excluded = ["width", "height", "margin", "children", "series", "colors", "dataset", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "sx", "title", "viewBox", "xAxis", "yAxis", "zAxis"];
|
|
12
|
+
const _excluded = ["width", "height", "resolveSizeBeforeRender", "margin", "children", "series", "colors", "dataset", "desc", "disableAxisListener", "highlightedItem", "onHighlightChange", "plugins", "sx", "title", "viewBox", "xAxis", "yAxis", "zAxis"];
|
|
13
13
|
const useResponsiveChartContainerProps = (props, ref) => {
|
|
14
14
|
const {
|
|
15
15
|
width,
|
|
16
16
|
height,
|
|
17
|
+
resolveSizeBeforeRender,
|
|
17
18
|
margin,
|
|
18
19
|
children,
|
|
19
20
|
series,
|
|
@@ -36,7 +37,7 @@ const useResponsiveChartContainerProps = (props, ref) => {
|
|
|
36
37
|
containerRef,
|
|
37
38
|
width: dWidth,
|
|
38
39
|
height: dHeight
|
|
39
|
-
} = (0, _useChartContainerDimensions.useChartContainerDimensions)(width, height);
|
|
40
|
+
} = (0, _useChartContainerDimensions.useChartContainerDimensions)(width, height, resolveSizeBeforeRender);
|
|
40
41
|
const resizableChartContainerProps = (0, _extends2.default)({}, other, {
|
|
41
42
|
ownerState: {
|
|
42
43
|
width,
|
|
@@ -184,6 +184,16 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
184
184
|
* @param {ScatterItemIdentifier} scatterItemIdentifier The scatter item identifier.
|
|
185
185
|
*/
|
|
186
186
|
onItemClick: _propTypes.default.func,
|
|
187
|
+
/**
|
|
188
|
+
* The chart will try to wait for the parent container to resolve its size
|
|
189
|
+
* before it renders for the first time.
|
|
190
|
+
*
|
|
191
|
+
* This can be useful in some scenarios where the chart appear to grow after
|
|
192
|
+
* the first render, like when used inside a grid.
|
|
193
|
+
*
|
|
194
|
+
* @default false
|
|
195
|
+
*/
|
|
196
|
+
resolveSizeBeforeRender: _propTypes.default.bool,
|
|
187
197
|
/**
|
|
188
198
|
* Indicate which axis to display the right of the charts.
|
|
189
199
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
|
|
@@ -200,6 +200,16 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
|
200
200
|
* @default 'line'
|
|
201
201
|
*/
|
|
202
202
|
plotType: _propTypes.default.oneOf(['bar', 'line']),
|
|
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.default.bool,
|
|
203
213
|
/**
|
|
204
214
|
* Set to `true` to highlight the value.
|
|
205
215
|
* With line, it shows a point.
|
|
@@ -7,10 +7,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.CartesianProvider = CartesianProvider;
|
|
9
9
|
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _computeAxisValue = require("../../internals/computeAxisValue");
|
|
10
11
|
var _useDrawingArea = require("../../hooks/useDrawingArea");
|
|
11
12
|
var _useSeries = require("../../hooks/useSeries");
|
|
12
13
|
var _CartesianContext = require("./CartesianContext");
|
|
13
|
-
var _computeValue = require("./computeValue");
|
|
14
14
|
var _useXExtremumGetter = require("../PluginProvider/useXExtremumGetter");
|
|
15
15
|
var _PluginProvider = require("../PluginProvider");
|
|
16
16
|
var _jsxRuntime = require("react/jsx-runtime");
|
|
@@ -24,14 +24,14 @@ function CartesianProvider(props) {
|
|
|
24
24
|
const drawingArea = (0, _useDrawingArea.useDrawingArea)();
|
|
25
25
|
const xExtremumGetters = (0, _useXExtremumGetter.useXExtremumGetter)();
|
|
26
26
|
const yExtremumGetters = (0, _PluginProvider.useYExtremumGetter)();
|
|
27
|
-
const xValues = React.useMemo(() => (0,
|
|
27
|
+
const xValues = React.useMemo(() => (0, _computeAxisValue.computeAxisValue)({
|
|
28
28
|
drawingArea,
|
|
29
29
|
formattedSeries,
|
|
30
30
|
axis: xAxis,
|
|
31
31
|
extremumGetters: xExtremumGetters,
|
|
32
32
|
axisDirection: 'x'
|
|
33
33
|
}), [drawingArea, formattedSeries, xAxis, xExtremumGetters]);
|
|
34
|
-
const yValues = React.useMemo(() => (0,
|
|
34
|
+
const yValues = React.useMemo(() => (0, _computeAxisValue.computeAxisValue)({
|
|
35
35
|
drawingArea,
|
|
36
36
|
formattedSeries,
|
|
37
37
|
axis: yAxis,
|