@mui/x-charts 7.11.0 → 7.11.1
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/BarElement.d.ts +2 -1
- package/BarChart/BarLabel/BarLabelItem.d.ts +2 -1
- package/BarChart/BarPlot.js +8 -8
- package/BarChart/checkScaleErrors.d.ts +4 -4
- package/BarChart/checkScaleErrors.js +11 -11
- package/BarChart/extremums.js +4 -1
- package/BarChart/formatter.js +2 -2
- package/CHANGELOG.md +84 -0
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/ChartsOverlay/ChartsOverlay.d.ts +3 -2
- package/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/ChartsReferenceLine/ChartsXReferenceLine.js +1 -2
- package/ChartsReferenceLine/ChartsYReferenceLine.js +1 -2
- package/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/ChartsVoronoiHandler/ChartsVoronoiHandler.js +4 -2
- package/LineChart/AreaElement.d.ts +2 -1
- package/LineChart/AreaPlot.js +10 -6
- package/LineChart/LineChart.js +4 -1
- package/LineChart/LineElement.d.ts +2 -1
- package/LineChart/LineHighlightPlot.d.ts +2 -1
- package/LineChart/LineHighlightPlot.js +9 -5
- package/LineChart/LinePlot.js +10 -6
- package/LineChart/MarkPlot.js +9 -5
- package/LineChart/extremums.js +4 -1
- package/LineChart/formatter.js +2 -2
- package/PieChart/PieArc.js +1 -0
- package/ResponsiveChartContainer/useChartContainerDimensions.js +2 -2
- package/ScatterChart/ScatterChart.js +4 -1
- package/ScatterChart/ScatterPlot.js +6 -3
- package/ScatterChart/extremums.js +8 -2
- package/context/CartesianProvider/CartesianContext.d.ts +1 -1
- package/context/CartesianProvider/normalizeAxis.js +1 -1
- package/context/DrawingProvider.d.ts +2 -1
- package/context/DrawingProvider.js +7 -1
- package/context/SeriesContextProvider.js +1 -1
- package/context/ZAxisContextProvider.d.ts +1 -1
- package/context/ZAxisContextProvider.js +1 -1
- package/esm/BarChart/BarPlot.js +8 -8
- package/esm/BarChart/checkScaleErrors.js +11 -11
- package/esm/BarChart/extremums.js +4 -1
- package/esm/BarChart/formatter.js +2 -2
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +4 -2
- package/esm/LineChart/AreaPlot.js +10 -6
- package/esm/LineChart/LineChart.js +4 -1
- package/esm/LineChart/LineHighlightPlot.js +9 -5
- package/esm/LineChart/LinePlot.js +10 -6
- package/esm/LineChart/MarkPlot.js +9 -5
- package/esm/LineChart/extremums.js +4 -1
- package/esm/LineChart/formatter.js +2 -2
- package/esm/PieChart/PieArc.js +1 -0
- package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +2 -2
- package/esm/ScatterChart/ScatterChart.js +4 -1
- package/esm/ScatterChart/ScatterPlot.js +6 -3
- package/esm/ScatterChart/extremums.js +8 -2
- package/esm/context/CartesianProvider/normalizeAxis.js +1 -1
- package/esm/context/DrawingProvider.js +7 -1
- package/esm/context/SeriesContextProvider.js +1 -1
- package/esm/context/ZAxisContextProvider.js +1 -1
- package/esm/hooks/useAxisEvents.js +12 -8
- package/esm/internals/SlotComponentPropsFromProps.js +1 -0
- package/esm/internals/geometry.js +1 -1
- package/esm/internals/getPercentageValue.js +1 -1
- package/esm/internals/warning.js +19 -11
- package/hooks/useAxisEvents.js +12 -8
- package/index.js +1 -1
- package/internals/SlotComponentPropsFromProps.d.ts +1 -0
- package/internals/SlotComponentPropsFromProps.js +5 -0
- package/internals/defaultizeColor.d.ts +7 -0
- package/internals/geometry.js +1 -1
- package/internals/getPercentageValue.js +1 -1
- package/internals/warning.d.ts +2 -1
- package/internals/warning.js +21 -12
- package/models/seriesType/common.d.ts +10 -0
- package/models/seriesType/scatter.d.ts +5 -0
- package/modern/BarChart/BarPlot.js +8 -8
- package/modern/BarChart/checkScaleErrors.js +11 -11
- package/modern/BarChart/extremums.js +4 -1
- package/modern/BarChart/formatter.js +2 -2
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsAxisHighlight/ChartsAxisHighlight.js +1 -1
- package/modern/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +3 -1
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +2 -2
- package/modern/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
- package/modern/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +7 -3
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +4 -4
- package/modern/ChartsVoronoiHandler/ChartsVoronoiHandler.js +4 -2
- package/modern/LineChart/AreaPlot.js +10 -6
- package/modern/LineChart/LineChart.js +4 -1
- package/modern/LineChart/LineHighlightPlot.js +9 -5
- package/modern/LineChart/LinePlot.js +10 -6
- package/modern/LineChart/MarkPlot.js +9 -5
- package/modern/LineChart/extremums.js +4 -1
- package/modern/LineChart/formatter.js +2 -2
- package/modern/PieChart/PieArc.js +1 -0
- package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +2 -2
- package/modern/ScatterChart/ScatterChart.js +4 -1
- package/modern/ScatterChart/ScatterPlot.js +6 -3
- package/modern/ScatterChart/extremums.js +8 -2
- package/modern/context/CartesianProvider/normalizeAxis.js +1 -1
- package/modern/context/DrawingProvider.js +7 -1
- package/modern/context/SeriesContextProvider.js +1 -1
- package/modern/context/ZAxisContextProvider.js +1 -1
- package/modern/hooks/useAxisEvents.js +12 -8
- package/modern/index.js +1 -1
- package/modern/internals/SlotComponentPropsFromProps.js +1 -0
- package/modern/internals/geometry.js +1 -1
- package/modern/internals/getPercentageValue.js +1 -1
- package/modern/internals/warning.js +19 -11
- package/package.json +3 -3
|
@@ -24,7 +24,10 @@ export const getExtremumY = params => {
|
|
|
24
24
|
axis,
|
|
25
25
|
isDefaultAxis
|
|
26
26
|
} = params;
|
|
27
|
-
return Object.keys(series).filter(seriesId =>
|
|
27
|
+
return Object.keys(series).filter(seriesId => {
|
|
28
|
+
const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
|
|
29
|
+
return yAxisId === axis.id || isDefaultAxis && yAxisId === undefined;
|
|
30
|
+
}).reduce((acc, seriesId) => {
|
|
28
31
|
const {
|
|
29
32
|
area,
|
|
30
33
|
stackedData
|
|
@@ -31,7 +31,7 @@ const formatter = (params, dataset) => {
|
|
|
31
31
|
}
|
|
32
32
|
});
|
|
33
33
|
} else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
|
|
34
|
-
throw new Error([`MUI X
|
|
34
|
+
throw new Error([`MUI X: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
const completedSeries = {};
|
|
@@ -56,7 +56,7 @@ const formatter = (params, dataset) => {
|
|
|
56
56
|
if (typeof value !== 'number') {
|
|
57
57
|
if (process.env.NODE_ENV !== 'production' && !warnedOnce && value !== null) {
|
|
58
58
|
warnedOnce = true;
|
|
59
|
-
console.error([`MUI X
|
|
59
|
+
console.error([`MUI X: Your dataset key "${dataKey}" is used for plotting line, but contains nonnumerical elements.`, 'Line plots only support numbers and null values.']);
|
|
60
60
|
}
|
|
61
61
|
return null;
|
|
62
62
|
}
|
package/esm/PieChart/PieArc.js
CHANGED
|
@@ -54,11 +54,11 @@ export const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
|
54
54
|
}, [computeSize, inHeight, inWidth]);
|
|
55
55
|
if (process.env.NODE_ENV !== 'production') {
|
|
56
56
|
if (displayError.current && inWidth === undefined && width === 0) {
|
|
57
|
-
console.error(`MUI X
|
|
57
|
+
console.error(`MUI X: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
|
|
58
58
|
displayError.current = false;
|
|
59
59
|
}
|
|
60
60
|
if (displayError.current && inHeight === undefined && height === 0) {
|
|
61
|
-
console.error(`MUI X
|
|
61
|
+
console.error(`MUI X: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
|
|
62
62
|
displayError.current = false;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -41,7 +41,10 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
|
|
|
41
41
|
ref: ref
|
|
42
42
|
}, chartContainerProps, {
|
|
43
43
|
children: /*#__PURE__*/_jsxs(ZAxisContextProvider, _extends({}, zAxisProps, {
|
|
44
|
-
children: [!props.disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, _extends({}, voronoiHandlerProps)), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), props.grid && /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsx(
|
|
44
|
+
children: [!props.disableVoronoi && /*#__PURE__*/_jsx(ChartsVoronoiHandler, _extends({}, voronoiHandlerProps)), /*#__PURE__*/_jsx(ChartsAxis, _extends({}, chartsAxisProps)), props.grid && /*#__PURE__*/_jsx(ChartsGrid, _extends({}, gridProps)), /*#__PURE__*/_jsx("g", {
|
|
45
|
+
"data-drawing-container": true,
|
|
46
|
+
children: /*#__PURE__*/_jsx(ScatterPlot, _extends({}, scatterPlotProps))
|
|
47
|
+
}), /*#__PURE__*/_jsx(ChartsOverlay, _extends({}, overlayProps)), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legendProps)), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlightProps)), !props.loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltipProps)), children]
|
|
45
48
|
}))
|
|
46
49
|
}));
|
|
47
50
|
});
|
|
@@ -53,12 +53,15 @@ function ScatterPlot(props) {
|
|
|
53
53
|
xAxisKey,
|
|
54
54
|
yAxisKey,
|
|
55
55
|
zAxisKey,
|
|
56
|
+
xAxisId,
|
|
57
|
+
yAxisId,
|
|
58
|
+
zAxisId,
|
|
56
59
|
markerSize,
|
|
57
60
|
color
|
|
58
61
|
} = series[seriesId];
|
|
59
|
-
const colorGetter = getColor(series[seriesId], xAxis[xAxisKey ?? defaultXAxisId], yAxis[yAxisKey ?? defaultYAxisId], zAxis[zAxisKey ?? defaultZAxisId]);
|
|
60
|
-
const xScale = xAxis[xAxisKey ?? defaultXAxisId].scale;
|
|
61
|
-
const yScale = yAxis[yAxisKey ?? defaultYAxisId].scale;
|
|
62
|
+
const colorGetter = getColor(series[seriesId], xAxis[xAxisId ?? xAxisKey ?? defaultXAxisId], yAxis[yAxisId ?? yAxisKey ?? defaultYAxisId], zAxis[zAxisId ?? zAxisKey ?? defaultZAxisId]);
|
|
63
|
+
const xScale = xAxis[xAxisId ?? xAxisKey ?? defaultXAxisId].scale;
|
|
64
|
+
const yScale = yAxis[yAxisId ?? yAxisKey ?? defaultYAxisId].scale;
|
|
62
65
|
return /*#__PURE__*/_jsx(ScatterItems, _extends({
|
|
63
66
|
xScale: xScale,
|
|
64
67
|
yScale: yScale,
|
|
@@ -13,7 +13,10 @@ export const getExtremumX = params => {
|
|
|
13
13
|
axis,
|
|
14
14
|
isDefaultAxis
|
|
15
15
|
} = params;
|
|
16
|
-
return Object.keys(series).filter(seriesId =>
|
|
16
|
+
return Object.keys(series).filter(seriesId => {
|
|
17
|
+
const axisId = series[seriesId].xAxisId ?? series[seriesId].xAxisKey;
|
|
18
|
+
return axisId === axis.id || axisId === undefined && isDefaultAxis;
|
|
19
|
+
}).reduce((acc, seriesId) => {
|
|
17
20
|
const seriesMinMax = series[seriesId].data.reduce((accSeries, {
|
|
18
21
|
x
|
|
19
22
|
}) => {
|
|
@@ -29,7 +32,10 @@ export const getExtremumY = params => {
|
|
|
29
32
|
axis,
|
|
30
33
|
isDefaultAxis
|
|
31
34
|
} = params;
|
|
32
|
-
return Object.keys(series).filter(seriesId =>
|
|
35
|
+
return Object.keys(series).filter(seriesId => {
|
|
36
|
+
const axisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
|
|
37
|
+
return axisId === axis.id || axisId === undefined && isDefaultAxis;
|
|
38
|
+
}).reduce((acc, seriesId) => {
|
|
33
39
|
const seriesMinMax = series[seriesId].data.reduce((accSeries, {
|
|
34
40
|
y
|
|
35
41
|
}) => {
|
|
@@ -6,7 +6,7 @@ export const normalizeAxis = (axis, dataset, axisName) => {
|
|
|
6
6
|
return axisConfig;
|
|
7
7
|
}
|
|
8
8
|
if (dataset === undefined) {
|
|
9
|
-
throw Error(`MUI X
|
|
9
|
+
throw Error(`MUI X: ${axisName}-axis uses \`dataKey\` but no \`dataset\` is provided.`);
|
|
10
10
|
}
|
|
11
11
|
return _extends({}, axisConfig, {
|
|
12
12
|
data: dataset.map(d => d[dataKey])
|
|
@@ -42,7 +42,13 @@ export function DrawingProvider(props) {
|
|
|
42
42
|
const isPointInside = React.useCallback(({
|
|
43
43
|
x,
|
|
44
44
|
y
|
|
45
|
-
}) =>
|
|
45
|
+
}, targetElement) => {
|
|
46
|
+
// For element allowed to overflow, wrapping them in <g data-drawing-container /> make them fully part of the drawing area.
|
|
47
|
+
if (targetElement && targetElement.closest('[data-drawing-container]')) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
return x >= drawingArea.left && x <= drawingArea.left + drawingArea.width && y >= drawingArea.top && y <= drawingArea.top + drawingArea.height;
|
|
51
|
+
}, [drawingArea]);
|
|
46
52
|
const value = React.useMemo(() => _extends({
|
|
47
53
|
chartId: chartId ?? ''
|
|
48
54
|
}, drawingArea, {
|
|
@@ -34,7 +34,7 @@ const preprocessSeries = (series, colors, seriesFormatters, dataset) => {
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
if (seriesGroups[type]?.series[id] !== undefined) {
|
|
37
|
-
throw new Error(`MUI X
|
|
37
|
+
throw new Error(`MUI X: series' id "${id}" is not unique.`);
|
|
38
38
|
}
|
|
39
39
|
seriesGroups[type].series[id] = _extends({
|
|
40
40
|
id
|
|
@@ -22,7 +22,7 @@ function ZAxisContextProvider(props) {
|
|
|
22
22
|
return axisConfig;
|
|
23
23
|
}
|
|
24
24
|
if (dataset === undefined) {
|
|
25
|
-
throw Error('MUI X
|
|
25
|
+
throw Error('MUI X: z-axis uses `dataKey` but no `dataset` is provided.');
|
|
26
26
|
}
|
|
27
27
|
return _extends({}, axisConfig, {
|
|
28
28
|
data: dataset.map(d => d[dataKey])
|
|
@@ -25,6 +25,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
25
25
|
|
|
26
26
|
// Use a ref to avoid rerendering on every mousemove event.
|
|
27
27
|
const mousePosition = React.useRef({
|
|
28
|
+
isInChart: false,
|
|
28
29
|
x: -1,
|
|
29
30
|
y: -1
|
|
30
31
|
});
|
|
@@ -84,6 +85,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
84
85
|
}
|
|
85
86
|
const handleOut = () => {
|
|
86
87
|
mousePosition.current = {
|
|
88
|
+
isInChart: false,
|
|
87
89
|
x: -1,
|
|
88
90
|
y: -1
|
|
89
91
|
};
|
|
@@ -94,16 +96,18 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
94
96
|
const handleMove = event => {
|
|
95
97
|
const target = 'targetTouches' in event ? event.targetTouches[0] : event;
|
|
96
98
|
const svgPoint = getSVGPoint(element, target);
|
|
97
|
-
mousePosition.current =
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
99
|
+
mousePosition.current.x = svgPoint.x;
|
|
100
|
+
mousePosition.current.y = svgPoint.y;
|
|
101
|
+
if (!drawingArea.isPointInside(svgPoint, event.target)) {
|
|
102
|
+
if (mousePosition.current.isInChart) {
|
|
103
|
+
dispatch({
|
|
104
|
+
type: 'exitChart'
|
|
105
|
+
});
|
|
106
|
+
mousePosition.current.isInChart = false;
|
|
107
|
+
}
|
|
105
108
|
return;
|
|
106
109
|
}
|
|
110
|
+
mousePosition.current.isInChart = true;
|
|
107
111
|
const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
|
|
108
112
|
const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
|
|
109
113
|
dispatch({
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -14,7 +14,7 @@ export function getMinXTranslation(width, height, angle = 0) {
|
|
|
14
14
|
if (process.env.NODE_ENV !== 'production') {
|
|
15
15
|
if (!warnedOnce && angle > 90 && angle < -90) {
|
|
16
16
|
warnedOnce = true;
|
|
17
|
-
console.warn([`MUI X
|
|
17
|
+
console.warn([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
const standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
|
|
@@ -24,5 +24,5 @@ export function getPercentageValue(value, refValue) {
|
|
|
24
24
|
return val;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
throw Error(`MUI X
|
|
27
|
+
throw Error(`MUI X: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
|
|
28
28
|
}
|
package/esm/internals/warning.js
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
const warnedOnceCache = new Set();
|
|
2
|
+
|
|
3
|
+
// TODO move to @mui/x-internals
|
|
4
|
+
// TODO eventually move to @base_ui/internals. Base UI, etc. too need this helper.
|
|
5
|
+
export function warnOnce(message, gravity = 'warning') {
|
|
6
|
+
if (process.env.NODE_ENV === 'production') {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const cleanMessage = Array.isArray(message) ? message.join('\n') : message;
|
|
10
|
+
if (!warnedOnceCache.has(cleanMessage)) {
|
|
11
|
+
warnedOnceCache.add(cleanMessage);
|
|
12
|
+
if (gravity === 'error') {
|
|
13
|
+
console.error(cleanMessage);
|
|
14
|
+
} else {
|
|
15
|
+
console.warn(cleanMessage);
|
|
11
16
|
}
|
|
12
|
-
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function clearWarningsCache() {
|
|
20
|
+
warnedOnceCache.clear();
|
|
13
21
|
}
|
package/hooks/useAxisEvents.js
CHANGED
|
@@ -33,6 +33,7 @@ const useAxisEvents = disableAxisListener => {
|
|
|
33
33
|
|
|
34
34
|
// Use a ref to avoid rerendering on every mousemove event.
|
|
35
35
|
const mousePosition = React.useRef({
|
|
36
|
+
isInChart: false,
|
|
36
37
|
x: -1,
|
|
37
38
|
y: -1
|
|
38
39
|
});
|
|
@@ -92,6 +93,7 @@ const useAxisEvents = disableAxisListener => {
|
|
|
92
93
|
}
|
|
93
94
|
const handleOut = () => {
|
|
94
95
|
mousePosition.current = {
|
|
96
|
+
isInChart: false,
|
|
95
97
|
x: -1,
|
|
96
98
|
y: -1
|
|
97
99
|
};
|
|
@@ -102,16 +104,18 @@ const useAxisEvents = disableAxisListener => {
|
|
|
102
104
|
const handleMove = event => {
|
|
103
105
|
const target = 'targetTouches' in event ? event.targetTouches[0] : event;
|
|
104
106
|
const svgPoint = (0, _getSVGPoint.getSVGPoint)(element, target);
|
|
105
|
-
mousePosition.current =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
mousePosition.current.x = svgPoint.x;
|
|
108
|
+
mousePosition.current.y = svgPoint.y;
|
|
109
|
+
if (!drawingArea.isPointInside(svgPoint, event.target)) {
|
|
110
|
+
if (mousePosition.current.isInChart) {
|
|
111
|
+
dispatch({
|
|
112
|
+
type: 'exitChart'
|
|
113
|
+
});
|
|
114
|
+
mousePosition.current.isInChart = false;
|
|
115
|
+
}
|
|
113
116
|
return;
|
|
114
117
|
}
|
|
118
|
+
mousePosition.current.isInChart = true;
|
|
115
119
|
const newStateX = getNewAxisState(xAxis[usedXAxis], svgPoint.x);
|
|
116
120
|
const newStateY = getNewAxisState(yAxis[usedYAxis], svgPoint.y);
|
|
117
121
|
dispatch({
|
package/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type SlotComponentPropsFromProps<TProps extends {}, TOverrides extends {}, TOwnerState extends {}> = (Partial<TProps> & TOverrides) | ((ownerState: TOwnerState) => Partial<TProps> & TOverrides);
|
|
@@ -56,6 +56,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
56
56
|
highlightScope?: Partial<import("..").HighlightScope>;
|
|
57
57
|
xAxisKey?: string;
|
|
58
58
|
yAxisKey?: string;
|
|
59
|
+
xAxisId?: string;
|
|
60
|
+
yAxisId?: string;
|
|
59
61
|
stack?: string;
|
|
60
62
|
stackOrder?: import("..").StackOrderType;
|
|
61
63
|
} | {
|
|
@@ -76,6 +78,8 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
76
78
|
highlightScope?: Partial<import("..").HighlightScope>;
|
|
77
79
|
xAxisKey?: string;
|
|
78
80
|
yAxisKey?: string;
|
|
81
|
+
xAxisId?: string;
|
|
82
|
+
yAxisId?: string;
|
|
79
83
|
stackOrder?: import("..").StackOrderType;
|
|
80
84
|
} | {
|
|
81
85
|
type: "scatter";
|
|
@@ -84,10 +88,13 @@ export declare function defaultizeColor(series: AllSeriesType, seriesIndex: numb
|
|
|
84
88
|
label?: string | ((location: "tooltip" | "legend") => string);
|
|
85
89
|
disableHover?: boolean;
|
|
86
90
|
zAxisKey?: string;
|
|
91
|
+
zAxisId?: string;
|
|
87
92
|
id?: import(".").SeriesId;
|
|
88
93
|
color: string;
|
|
89
94
|
valueFormatter?: import(".").SeriesValueFormatter<import("../models/seriesType").ScatterValueType> | undefined;
|
|
90
95
|
highlightScope?: Partial<import("..").HighlightScope>;
|
|
91
96
|
xAxisKey?: string;
|
|
92
97
|
yAxisKey?: string;
|
|
98
|
+
xAxisId?: string;
|
|
99
|
+
yAxisId?: string;
|
|
93
100
|
};
|
package/internals/geometry.js
CHANGED
|
@@ -20,7 +20,7 @@ function getMinXTranslation(width, height, angle = 0) {
|
|
|
20
20
|
if (process.env.NODE_ENV !== 'production') {
|
|
21
21
|
if (!warnedOnce && angle > 90 && angle < -90) {
|
|
22
22
|
warnedOnce = true;
|
|
23
|
-
console.warn([`MUI X
|
|
23
|
+
console.warn([`MUI X: It seems you applied an angle larger than 90° or smaller than -90° to an axis text.`, `This could cause some text overlapping.`, `If you encounter a use case where it's needed, please open an issue.`].join('\n'));
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
const standardAngle = Math.min(Math.abs(angle) % 180, Math.abs(Math.abs(angle) % 180 - 180) % 180); // Map from R to [0, 90]
|
|
@@ -30,5 +30,5 @@ function getPercentageValue(value, refValue) {
|
|
|
30
30
|
return val;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
throw Error(`MUI X
|
|
33
|
+
throw Error(`MUI X: Received an unknown value "${value}". It should be a number, or a string with a percentage value.`);
|
|
34
34
|
}
|
package/internals/warning.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export declare function
|
|
1
|
+
export declare function warnOnce(message: string | string[], gravity?: 'warning' | 'error'): void;
|
|
2
|
+
export declare function clearWarningsCache(): void;
|
package/internals/warning.js
CHANGED
|
@@ -3,17 +3,26 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
6
|
+
exports.clearWarningsCache = clearWarningsCache;
|
|
7
|
+
exports.warnOnce = warnOnce;
|
|
8
|
+
const warnedOnceCache = new Set();
|
|
9
|
+
|
|
10
|
+
// TODO move to @mui/x-internals
|
|
11
|
+
// TODO eventually move to @base_ui/internals. Base UI, etc. too need this helper.
|
|
12
|
+
function warnOnce(message, gravity = 'warning') {
|
|
13
|
+
if (process.env.NODE_ENV === 'production') {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const cleanMessage = Array.isArray(message) ? message.join('\n') : message;
|
|
17
|
+
if (!warnedOnceCache.has(cleanMessage)) {
|
|
18
|
+
warnedOnceCache.add(cleanMessage);
|
|
19
|
+
if (gravity === 'error') {
|
|
20
|
+
console.error(cleanMessage);
|
|
21
|
+
} else {
|
|
22
|
+
console.warn(cleanMessage);
|
|
17
23
|
}
|
|
18
|
-
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function clearWarningsCache() {
|
|
27
|
+
warnedOnceCache.clear();
|
|
19
28
|
}
|
|
@@ -27,12 +27,22 @@ export type CommonDefaultizedProps = 'id' | 'valueFormatter' | 'data';
|
|
|
27
27
|
export type CartesianSeriesType = {
|
|
28
28
|
/**
|
|
29
29
|
* The id of the x-axis used to render the series.
|
|
30
|
+
* @deprecated Use `xAxisId` instead
|
|
30
31
|
*/
|
|
31
32
|
xAxisKey?: string;
|
|
32
33
|
/**
|
|
33
34
|
* The id of the y-axis used to render the series.
|
|
35
|
+
* @deprecated Use `xAxisId` instead
|
|
34
36
|
*/
|
|
35
37
|
yAxisKey?: string;
|
|
38
|
+
/**
|
|
39
|
+
* The id of the x-axis used to render the series.
|
|
40
|
+
*/
|
|
41
|
+
xAxisId?: string;
|
|
42
|
+
/**
|
|
43
|
+
* The id of the y-axis used to render the series.
|
|
44
|
+
*/
|
|
45
|
+
yAxisId?: string;
|
|
36
46
|
};
|
|
37
47
|
export type StackableSeriesType = {
|
|
38
48
|
/**
|
|
@@ -24,8 +24,13 @@ export interface ScatterSeriesType extends CommonSeriesType<ScatterValueType>, C
|
|
|
24
24
|
disableHover?: boolean;
|
|
25
25
|
/**
|
|
26
26
|
* The id of the z-axis used to render the series.
|
|
27
|
+
* @deprecated Use `zAxisId` instead.
|
|
27
28
|
*/
|
|
28
29
|
zAxisKey?: string;
|
|
30
|
+
/**
|
|
31
|
+
* The id of the z-axis used to render the series.
|
|
32
|
+
*/
|
|
33
|
+
zAxisId?: string;
|
|
29
34
|
}
|
|
30
35
|
/**
|
|
31
36
|
* An object that allows to identify a single scatter item.
|
|
@@ -66,16 +66,16 @@ const useAggregatedData = () => {
|
|
|
66
66
|
ids: groupIds
|
|
67
67
|
}, groupIndex) => {
|
|
68
68
|
return groupIds.flatMap(seriesId => {
|
|
69
|
-
const
|
|
70
|
-
const
|
|
71
|
-
const xAxisConfig = xAxis[
|
|
72
|
-
const yAxisConfig = yAxis[
|
|
69
|
+
const xAxisId = series[seriesId].xAxisId ?? series[seriesId].xAxisKey ?? defaultXAxisId;
|
|
70
|
+
const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey ?? defaultYAxisId;
|
|
71
|
+
const xAxisConfig = xAxis[xAxisId];
|
|
72
|
+
const yAxisConfig = yAxis[yAxisId];
|
|
73
73
|
const verticalLayout = series[seriesId].layout === 'vertical';
|
|
74
|
-
checkScaleErrors(verticalLayout, seriesId,
|
|
74
|
+
checkScaleErrors(verticalLayout, seriesId, xAxisId, xAxis, yAxisId, yAxis);
|
|
75
75
|
const baseScaleConfig = verticalLayout ? xAxisConfig : yAxisConfig;
|
|
76
76
|
const xScale = xAxisConfig.scale;
|
|
77
77
|
const yScale = yAxisConfig.scale;
|
|
78
|
-
const colorGetter = getColor(series[seriesId], xAxis[
|
|
78
|
+
const colorGetter = getColor(series[seriesId], xAxis[xAxisId], yAxis[yAxisId]);
|
|
79
79
|
const bandWidth = baseScaleConfig.scale.bandwidth();
|
|
80
80
|
const {
|
|
81
81
|
barWidth,
|
|
@@ -98,8 +98,8 @@ const useAggregatedData = () => {
|
|
|
98
98
|
seriesId,
|
|
99
99
|
dataIndex,
|
|
100
100
|
layout: series[seriesId].layout,
|
|
101
|
-
x: verticalLayout ? xScale(xAxis[
|
|
102
|
-
y: verticalLayout ? minValueCoord : yScale(yAxis[
|
|
101
|
+
x: verticalLayout ? xScale(xAxis[xAxisId].data?.[dataIndex]) + barOffset : minValueCoord,
|
|
102
|
+
y: verticalLayout ? minValueCoord : yScale(yAxis[yAxisId].data?.[dataIndex]) + barOffset,
|
|
103
103
|
xOrigin: xScale(0),
|
|
104
104
|
yOrigin: yScale(0),
|
|
105
105
|
height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
2
2
|
import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
|
|
3
|
-
const getAxisMessage = (axisDirection,
|
|
3
|
+
const getAxisMessage = (axisDirection, axisId) => {
|
|
4
4
|
const axisName = `${axisDirection}-axis`;
|
|
5
|
-
const
|
|
5
|
+
const axisIdName = `${axisDirection}Axis`;
|
|
6
6
|
const axisDefaultKey = axisDirection === 'x' ? DEFAULT_X_AXIS_KEY : DEFAULT_Y_AXIS_KEY;
|
|
7
|
-
return
|
|
7
|
+
return axisId === axisDefaultKey ? `The first \`${axisIdName}\`` : `The ${axisName} with id "${axisId}"`;
|
|
8
8
|
};
|
|
9
|
-
export function checkScaleErrors(verticalLayout, seriesId,
|
|
10
|
-
const xAxisConfig = xAxis[
|
|
11
|
-
const yAxisConfig = yAxis[
|
|
9
|
+
export function checkScaleErrors(verticalLayout, seriesId, xAxisId, xAxis, yAxisId, yAxis) {
|
|
10
|
+
const xAxisConfig = xAxis[xAxisId];
|
|
11
|
+
const yAxisConfig = yAxis[yAxisId];
|
|
12
12
|
const discreteAxisConfig = verticalLayout ? xAxisConfig : yAxisConfig;
|
|
13
13
|
const continuousAxisConfig = verticalLayout ? yAxisConfig : xAxisConfig;
|
|
14
|
-
const
|
|
15
|
-
const
|
|
14
|
+
const discreteAxisId = verticalLayout ? xAxisId : yAxisId;
|
|
15
|
+
const continuousAxisId = verticalLayout ? yAxisId : xAxisId;
|
|
16
16
|
const discreteAxisDirection = verticalLayout ? 'x' : 'y';
|
|
17
17
|
const continuousAxisDirection = verticalLayout ? 'y' : 'x';
|
|
18
18
|
if (!isBandScaleConfig(discreteAxisConfig)) {
|
|
19
|
-
throw new Error(`MUI X
|
|
19
|
+
throw new Error(`MUI X: ${getAxisMessage(discreteAxisDirection, discreteAxisId)} should be of type "band" to display the bar series of id "${seriesId}".`);
|
|
20
20
|
}
|
|
21
21
|
if (discreteAxisConfig.data === undefined) {
|
|
22
|
-
throw new Error(`MUI X
|
|
22
|
+
throw new Error(`MUI X: ${getAxisMessage(discreteAxisDirection, discreteAxisId)} should have data property.`);
|
|
23
23
|
}
|
|
24
24
|
if (isBandScaleConfig(continuousAxisConfig) || isPointScaleConfig(continuousAxisConfig)) {
|
|
25
|
-
throw new Error(`MUI X
|
|
25
|
+
throw new Error(`MUI X: ${getAxisMessage(continuousAxisDirection, continuousAxisId)} should be a continuous type to display the bar series of id "${seriesId}".`);
|
|
26
26
|
}
|
|
27
27
|
}
|
|
@@ -12,7 +12,10 @@ const getValueExtremum = params => {
|
|
|
12
12
|
axis,
|
|
13
13
|
isDefaultAxis
|
|
14
14
|
} = params;
|
|
15
|
-
return Object.keys(series).filter(seriesId =>
|
|
15
|
+
return Object.keys(series).filter(seriesId => {
|
|
16
|
+
const yAxisId = series[seriesId].yAxisId ?? series[seriesId].yAxisKey;
|
|
17
|
+
return yAxisId === axis.id || isDefaultAxis && yAxisId === undefined;
|
|
18
|
+
}).reduce((acc, seriesId) => {
|
|
16
19
|
const [seriesMin, seriesMax] = series[seriesId].stackedData?.reduce((seriesAcc, values) => [Math.min(...values, ...(seriesAcc[0] === null ? [] : [seriesAcc[0]])), Math.max(...values, ...(seriesAcc[1] === null ? [] : [seriesAcc[1]]))], series[seriesId].stackedData[0]) ?? [null, null];
|
|
17
20
|
return [acc[0] === null ? seriesMin : Math.min(seriesMin, acc[0]), acc[1] === null ? seriesMax : Math.max(seriesMax, acc[1])];
|
|
18
21
|
}, [null, null]);
|
|
@@ -25,7 +25,7 @@ const formatter = (params, dataset) => {
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
} else if (dataset === undefined) {
|
|
28
|
-
throw new Error([`MUI X
|
|
28
|
+
throw new Error([`MUI X: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
const completedSeries = {};
|
|
@@ -52,7 +52,7 @@ const formatter = (params, dataset) => {
|
|
|
52
52
|
if (typeof value !== 'number') {
|
|
53
53
|
if (process.env.NODE_ENV !== 'production' && !warnOnce && value !== null) {
|
|
54
54
|
warnOnce = true;
|
|
55
|
-
console.error([`MUI X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.']);
|
|
55
|
+
console.error([`MUI X charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.'].join('\n'));
|
|
56
56
|
}
|
|
57
57
|
return 0;
|
|
58
58
|
}
|
|
@@ -57,16 +57,16 @@ function ChartsAxis(props) {
|
|
|
57
57
|
const topId = getAxisId(topAxis, xAxisIds[0]);
|
|
58
58
|
const rightId = getAxisId(rightAxis, yAxisIds[0]);
|
|
59
59
|
if (topId !== null && !xAxis[topId]) {
|
|
60
|
-
throw Error([`MUI X
|
|
60
|
+
throw Error([`MUI X: id used for top axis "${topId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
|
|
61
61
|
}
|
|
62
62
|
if (leftId !== null && !yAxis[leftId]) {
|
|
63
|
-
throw Error([`MUI X
|
|
63
|
+
throw Error([`MUI X: id used for left axis "${leftId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
|
|
64
64
|
}
|
|
65
65
|
if (rightId !== null && !yAxis[rightId]) {
|
|
66
|
-
throw Error([`MUI X
|
|
66
|
+
throw Error([`MUI X: id used for right axis "${rightId}" is not defined.`, `Available ids are: ${yAxisIds.join(', ')}.`].join('\n'));
|
|
67
67
|
}
|
|
68
68
|
if (bottomId !== null && !xAxis[bottomId]) {
|
|
69
|
-
throw Error([`MUI X
|
|
69
|
+
throw Error([`MUI X: id used for bottom axis "${bottomId}" is not defined.`, `Available ids are: ${xAxisIds.join(', ')}.`].join('\n'));
|
|
70
70
|
}
|
|
71
71
|
const topAxisProps = mergeProps(topAxis, slots, slotProps);
|
|
72
72
|
const bottomAxisProps = mergeProps(bottomAxis, slots, slotProps);
|
|
@@ -74,7 +74,7 @@ function ChartsAxisHighlight(props) {
|
|
|
74
74
|
const isXError = isBandScaleX && xScale(axisX.value) === undefined;
|
|
75
75
|
const isYError = isBandScaleY && yScale(axisY.value) === undefined;
|
|
76
76
|
if (isXError || isYError) {
|
|
77
|
-
console.error([`MUI X
|
|
77
|
+
console.error([`MUI X: The position value provided for the axis is not valid for the current scale.`, `This probably means something is wrong with the data passed to the chart.`, `The ChartsAxisHighlight component will not be displayed.`].join('\n'));
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
@@ -37,7 +37,9 @@ function ChartsOnAxisClickHandler(props) {
|
|
|
37
37
|
Object.keys(series).filter(seriesType => ['bar', 'line'].includes(seriesType)).forEach(seriesType => {
|
|
38
38
|
series[seriesType]?.seriesOrder.forEach(seriesId => {
|
|
39
39
|
const seriesItem = series[seriesType].series[seriesId];
|
|
40
|
-
const
|
|
40
|
+
const providedXAxisId = seriesItem.xAxisId ?? seriesItem.xAxisKey;
|
|
41
|
+
const providedYAxisId = seriesItem.yAxisId ?? seriesItem.yAxisKey;
|
|
42
|
+
const axisKey = isXaxis ? providedXAxisId : providedYAxisId;
|
|
41
43
|
if (axisKey === undefined || axisKey === USED_AXIS_ID) {
|
|
42
44
|
seriesValues[seriesId] = seriesItem.data[dataIndex];
|
|
43
45
|
}
|
|
@@ -10,10 +10,10 @@ function ChartsReferenceLine(props) {
|
|
|
10
10
|
y
|
|
11
11
|
} = props;
|
|
12
12
|
if (x !== undefined && y !== undefined) {
|
|
13
|
-
throw new Error('MUI X
|
|
13
|
+
throw new Error('MUI X: The ChartsReferenceLine cannot have both `x` and `y` props set.');
|
|
14
14
|
}
|
|
15
15
|
if (x === undefined && y === undefined) {
|
|
16
|
-
throw new Error('MUI X
|
|
16
|
+
throw new Error('MUI X: The ChartsReferenceLine should have a value in `x` or `y` prop.');
|
|
17
17
|
}
|
|
18
18
|
if (x !== undefined) {
|
|
19
19
|
return /*#__PURE__*/_jsx(ChartsXReferenceLine, _extends({}, props));
|