@mui/x-charts 7.3.1 → 7.4.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.d.ts +4 -3
- package/BarChart/BarChart.js +22 -6
- package/BarChart/BarClipPath.d.ts +14 -0
- package/BarChart/BarClipPath.js +50 -0
- package/BarChart/BarPlot.d.ts +4 -0
- package/BarChart/BarPlot.js +108 -36
- package/BarChart/getRadius.d.ts +15 -0
- package/BarChart/getRadius.js +37 -0
- package/BarChart/types.d.ts +25 -0
- package/BarChart/types.js +5 -0
- package/CHANGELOG.md +141 -5
- package/ChartsAxis/axisClasses.d.ts +1 -1
- package/ChartsGrid/ChartsGrid.js +22 -11
- package/ChartsOverlay/ChartsLoadingOverlay.d.ts +3 -0
- package/ChartsOverlay/ChartsLoadingOverlay.js +43 -0
- package/ChartsOverlay/ChartsNoDataOverlay.d.ts +3 -0
- package/ChartsOverlay/ChartsNoDataOverlay.js +43 -0
- package/ChartsOverlay/ChartsOverlay.d.ts +35 -0
- package/ChartsOverlay/ChartsOverlay.js +41 -0
- package/ChartsOverlay/index.d.ts +3 -0
- package/ChartsOverlay/index.js +26 -0
- package/ChartsOverlay/package.json +6 -0
- package/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
- package/ChartsReferenceLine/common.d.ts +1 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.d.ts +1 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/ChartsTooltip/ChartsTooltip.d.ts +2 -2
- package/ChartsTooltip/ChartsTooltip.js +2 -2
- package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
- package/ChartsXAxis/ChartsXAxis.d.ts +1 -1
- package/ChartsXAxis/ChartsXAxis.js +7 -0
- package/ChartsYAxis/ChartsYAxis.d.ts +1 -1
- package/ChartsYAxis/ChartsYAxis.js +7 -0
- package/Gauge/Gauge.js +1 -1
- package/Gauge/GaugeContainer.js +1 -1
- package/Gauge/GaugeProvider.d.ts +2 -2
- package/Gauge/GaugeProvider.js +1 -1
- package/Gauge/gaugeClasses.d.ts +2 -2
- package/Gauge/utils.d.ts +1 -1
- package/Gauge/utils.js +4 -4
- package/LineChart/AreaElement.d.ts +1 -1
- package/LineChart/LineChart.d.ts +4 -3
- package/LineChart/LineChart.js +12 -2
- package/LineChart/LineElement.d.ts +1 -1
- package/LineChart/MarkElement.d.ts +1 -1
- package/PieChart/PieArc.d.ts +1 -1
- package/PieChart/PieArcLabel.d.ts +1 -1
- package/PieChart/PieArcLabel.js +1 -1
- package/PieChart/PieArcLabelPlot.d.ts +1 -1
- package/PieChart/PieArcLabelPlot.js +3 -3
- package/PieChart/PieArcPlot.d.ts +1 -1
- package/PieChart/PieArcPlot.js +3 -3
- package/PieChart/PieChart.d.ts +4 -3
- package/PieChart/PieChart.js +15 -2
- package/ScatterChart/ScatterChart.d.ts +4 -3
- package/ScatterChart/ScatterChart.js +12 -2
- package/context/SeriesContextProvider.js +1 -1
- package/esm/BarChart/BarChart.js +22 -6
- package/esm/BarChart/BarClipPath.js +42 -0
- package/esm/BarChart/BarPlot.js +109 -37
- package/esm/BarChart/getRadius.js +30 -0
- package/esm/BarChart/types.js +1 -0
- package/esm/ChartsGrid/ChartsGrid.js +23 -12
- package/esm/ChartsOverlay/ChartsLoadingOverlay.js +34 -0
- package/esm/ChartsOverlay/ChartsNoDataOverlay.js +34 -0
- package/esm/ChartsOverlay/ChartsOverlay.js +31 -0
- package/esm/ChartsOverlay/index.js +3 -0
- package/esm/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/ChartsTooltip/ChartsTooltip.js +2 -2
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
- package/esm/ChartsXAxis/ChartsXAxis.js +7 -0
- package/esm/ChartsYAxis/ChartsYAxis.js +7 -0
- package/esm/Gauge/Gauge.js +1 -1
- package/esm/Gauge/GaugeContainer.js +1 -1
- package/esm/Gauge/GaugeProvider.js +1 -1
- package/esm/Gauge/utils.js +4 -4
- package/esm/LineChart/LineChart.js +12 -2
- package/esm/PieChart/PieArcLabel.js +1 -1
- package/esm/PieChart/PieArcLabelPlot.js +3 -3
- package/esm/PieChart/PieArcPlot.js +3 -3
- package/esm/PieChart/PieChart.js +15 -2
- package/esm/ScatterChart/ScatterChart.js +12 -2
- package/esm/context/SeriesContextProvider.js +1 -1
- package/esm/hooks/useReducedMotion.js +1 -1
- package/esm/hooks/useScale.js +1 -1
- package/esm/hooks/useTicks.js +4 -0
- package/esm/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
- package/esm/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
- package/esm/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
- package/esm/internals/utils.js +1 -1
- package/hooks/useReducedMotion.d.ts +1 -1
- package/hooks/useReducedMotion.js +1 -1
- package/hooks/useScale.d.ts +4 -4
- package/hooks/useScale.js +1 -1
- package/hooks/useTicks.js +4 -0
- package/index.js +1 -1
- package/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.d.ts +1 -1
- package/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
- package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.d.ts +1 -1
- package/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
- package/internals/utils.d.ts +1 -1
- package/internals/utils.js +1 -1
- package/models/axis.d.ts +1 -1
- package/models/seriesType/bar.d.ts +1 -1
- package/models/seriesType/line.d.ts +1 -1
- package/models/seriesType/pie.d.ts +4 -4
- package/modern/BarChart/BarChart.js +22 -6
- package/modern/BarChart/BarClipPath.js +42 -0
- package/modern/BarChart/BarPlot.js +109 -37
- package/modern/BarChart/getRadius.js +30 -0
- package/modern/BarChart/types.js +1 -0
- package/modern/ChartsGrid/ChartsGrid.js +23 -12
- package/modern/ChartsOverlay/ChartsLoadingOverlay.js +34 -0
- package/modern/ChartsOverlay/ChartsNoDataOverlay.js +34 -0
- package/modern/ChartsOverlay/ChartsOverlay.js +31 -0
- package/modern/ChartsOverlay/index.js +3 -0
- package/modern/ChartsReferenceLine/ChartsReferenceLine.js +1 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/modern/ChartsTooltip/ChartsTooltip.js +2 -2
- package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +1 -1
- package/modern/ChartsXAxis/ChartsXAxis.js +7 -0
- package/modern/ChartsYAxis/ChartsYAxis.js +7 -0
- package/modern/Gauge/Gauge.js +1 -1
- package/modern/Gauge/GaugeContainer.js +1 -1
- package/modern/Gauge/GaugeProvider.js +1 -1
- package/modern/Gauge/utils.js +4 -4
- package/modern/LineChart/LineChart.js +12 -2
- package/modern/PieChart/PieArcLabel.js +1 -1
- package/modern/PieChart/PieArcLabelPlot.js +3 -3
- package/modern/PieChart/PieArcPlot.js +3 -3
- package/modern/PieChart/PieChart.js +15 -2
- package/modern/ScatterChart/ScatterChart.js +12 -2
- package/modern/context/SeriesContextProvider.js +1 -1
- package/modern/hooks/useReducedMotion.js +1 -1
- package/modern/hooks/useScale.js +1 -1
- package/modern/hooks/useTicks.js +4 -0
- package/modern/index.js +1 -1
- package/modern/internals/components/ChartsAxesGradients/ChartsAxesGradients.js +5 -5
- package/modern/internals/components/ChartsAxesGradients/ChartsContinuousGradient.js +3 -3
- package/modern/internals/components/ChartsAxesGradients/ChartsPiecewiseGradient.js +3 -3
- package/modern/internals/utils.js +1 -1
- package/package.json +2 -2
- package/themeAugmentation/components.d.ts +4 -0
- package/themeAugmentation/overrides.d.ts +2 -0
- package/themeAugmentation/props.d.ts +2 -0
package/esm/BarChart/BarPlot.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
2
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["skipAnimation", "onItemClick"];
|
|
3
|
+
const _excluded = ["skipAnimation", "onItemClick", "borderRadius"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { useTransition } from '@react-spring/web';
|
|
@@ -10,6 +10,8 @@ import { BarElement } from './BarElement';
|
|
|
10
10
|
import { isBandScaleConfig, isPointScaleConfig } from '../models/axis';
|
|
11
11
|
import { DEFAULT_X_AXIS_KEY, DEFAULT_Y_AXIS_KEY } from '../constants';
|
|
12
12
|
import getColor from './getColor';
|
|
13
|
+
import { useChartId } from '../hooks';
|
|
14
|
+
import { BarClipPath } from './BarClipPath';
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Solution of the equations
|
|
@@ -20,7 +22,7 @@ import getColor from './getColor';
|
|
|
20
22
|
* @param gapRatio The ratio of the gap between bars over the bar width.
|
|
21
23
|
* @returns The bar width and the offset between bars.
|
|
22
24
|
*/
|
|
23
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
25
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
26
|
function getBandSize({
|
|
25
27
|
bandWidth: W,
|
|
26
28
|
numberOfGroups: N,
|
|
@@ -46,6 +48,7 @@ const useAggregatedData = () => {
|
|
|
46
48
|
seriesOrder: []
|
|
47
49
|
};
|
|
48
50
|
const axisData = React.useContext(CartesianContext);
|
|
51
|
+
const chartId = useChartId();
|
|
49
52
|
const {
|
|
50
53
|
series,
|
|
51
54
|
stackingGroups
|
|
@@ -58,6 +61,7 @@ const useAggregatedData = () => {
|
|
|
58
61
|
} = axisData;
|
|
59
62
|
const defaultXAxisId = xAxisIds[0];
|
|
60
63
|
const defaultYAxisId = yAxisIds[0];
|
|
64
|
+
const masks = {};
|
|
61
65
|
const data = stackingGroups.flatMap(({
|
|
62
66
|
ids: groupIds
|
|
63
67
|
}, groupIndex) => {
|
|
@@ -70,25 +74,25 @@ const useAggregatedData = () => {
|
|
|
70
74
|
let baseScaleConfig;
|
|
71
75
|
if (verticalLayout) {
|
|
72
76
|
if (!isBandScaleConfig(xAxisConfig)) {
|
|
73
|
-
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`}
|
|
77
|
+
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should be of type "band" to display the bar series of id "${seriesId}".`);
|
|
74
78
|
}
|
|
75
79
|
if (xAxis[xAxisKey].data === undefined) {
|
|
76
|
-
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`}
|
|
80
|
+
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should have data property.`);
|
|
77
81
|
}
|
|
78
82
|
baseScaleConfig = xAxisConfig;
|
|
79
83
|
if (isBandScaleConfig(yAxisConfig) || isPointScaleConfig(yAxisConfig)) {
|
|
80
|
-
throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`}
|
|
84
|
+
throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} should be a continuous type to display the bar series of id "${seriesId}".`);
|
|
81
85
|
}
|
|
82
86
|
} else {
|
|
83
87
|
if (!isBandScaleConfig(yAxisConfig)) {
|
|
84
|
-
throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`}
|
|
88
|
+
throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} should be of type "band" to display the bar series of id "${seriesId}".`);
|
|
85
89
|
}
|
|
86
90
|
if (yAxis[yAxisKey].data === undefined) {
|
|
87
|
-
throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`}
|
|
91
|
+
throw new Error(`MUI X Charts: ${yAxisKey === DEFAULT_Y_AXIS_KEY ? 'The first `yAxis`' : `The y-axis with id "${yAxisKey}"`} should have data property.`);
|
|
88
92
|
}
|
|
89
93
|
baseScaleConfig = yAxisConfig;
|
|
90
94
|
if (isBandScaleConfig(xAxisConfig) || isPointScaleConfig(xAxisConfig)) {
|
|
91
|
-
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`}
|
|
95
|
+
throw new Error(`MUI X Charts: ${xAxisKey === DEFAULT_X_AXIS_KEY ? 'The first `xAxis`' : `The x-axis with id "${xAxisKey}"`} should be a continuous type to display the bar series of id "${seriesId}".`);
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
const xScale = xAxisConfig.scale;
|
|
@@ -111,7 +115,8 @@ const useAggregatedData = () => {
|
|
|
111
115
|
const valueCoordinates = values.map(v => verticalLayout ? yScale(v) : xScale(v));
|
|
112
116
|
const minValueCoord = Math.round(Math.min(...valueCoordinates));
|
|
113
117
|
const maxValueCoord = Math.round(Math.max(...valueCoordinates));
|
|
114
|
-
|
|
118
|
+
const stackId = series[seriesId].stack;
|
|
119
|
+
const result = {
|
|
115
120
|
seriesId,
|
|
116
121
|
dataIndex,
|
|
117
122
|
layout: series[seriesId].layout,
|
|
@@ -122,14 +127,41 @@ const useAggregatedData = () => {
|
|
|
122
127
|
height: verticalLayout ? maxValueCoord - minValueCoord : barWidth,
|
|
123
128
|
width: verticalLayout ? barWidth : maxValueCoord - minValueCoord,
|
|
124
129
|
color: colorGetter(dataIndex),
|
|
125
|
-
highlightScope: series[seriesId].highlightScope
|
|
130
|
+
highlightScope: series[seriesId].highlightScope,
|
|
131
|
+
value: series[seriesId].data[dataIndex],
|
|
132
|
+
maskId: `${chartId}_${stackId || seriesId}_${groupIndex}_${dataIndex}`
|
|
126
133
|
};
|
|
134
|
+
if (!masks[result.maskId]) {
|
|
135
|
+
masks[result.maskId] = {
|
|
136
|
+
id: result.maskId,
|
|
137
|
+
width: 0,
|
|
138
|
+
height: 0,
|
|
139
|
+
hasNegative: false,
|
|
140
|
+
hasPositive: false,
|
|
141
|
+
layout: result.layout,
|
|
142
|
+
xOrigin: xScale(0),
|
|
143
|
+
yOrigin: yScale(0),
|
|
144
|
+
x: 0,
|
|
145
|
+
y: 0
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
const mask = masks[result.maskId];
|
|
149
|
+
mask.width = result.layout === 'vertical' ? result.width : mask.width + result.width;
|
|
150
|
+
mask.height = result.layout === 'vertical' ? mask.height + result.height : result.height;
|
|
151
|
+
mask.x = Math.min(mask.x === 0 ? Infinity : mask.x, result.x);
|
|
152
|
+
mask.y = Math.min(mask.y === 0 ? Infinity : mask.y, result.y);
|
|
153
|
+
mask.hasNegative = mask.hasNegative || (result.value ?? 0) < 0;
|
|
154
|
+
mask.hasPositive = mask.hasPositive || (result.value ?? 0) > 0;
|
|
155
|
+
return result;
|
|
127
156
|
});
|
|
128
157
|
});
|
|
129
158
|
});
|
|
130
|
-
return
|
|
159
|
+
return {
|
|
160
|
+
completedData: data,
|
|
161
|
+
masksData: Object.values(masks)
|
|
162
|
+
};
|
|
131
163
|
};
|
|
132
|
-
const
|
|
164
|
+
const leaveStyle = ({
|
|
133
165
|
layout,
|
|
134
166
|
yOrigin,
|
|
135
167
|
x,
|
|
@@ -148,7 +180,7 @@ const getOutStyle = ({
|
|
|
148
180
|
height,
|
|
149
181
|
width: 0
|
|
150
182
|
});
|
|
151
|
-
const
|
|
183
|
+
const enterStyle = ({
|
|
152
184
|
x,
|
|
153
185
|
width,
|
|
154
186
|
y,
|
|
@@ -172,41 +204,77 @@ const getInStyle = ({
|
|
|
172
204
|
* - [BarPlot API](https://mui.com/x/api/charts/bar-plot/)
|
|
173
205
|
*/
|
|
174
206
|
function BarPlot(props) {
|
|
175
|
-
const
|
|
207
|
+
const {
|
|
208
|
+
completedData,
|
|
209
|
+
masksData
|
|
210
|
+
} = useAggregatedData();
|
|
176
211
|
const {
|
|
177
212
|
skipAnimation,
|
|
178
|
-
onItemClick
|
|
213
|
+
onItemClick,
|
|
214
|
+
borderRadius
|
|
179
215
|
} = props,
|
|
180
216
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
181
217
|
const transition = useTransition(completedData, {
|
|
182
218
|
keys: bar => `${bar.seriesId}-${bar.dataIndex}`,
|
|
183
|
-
from:
|
|
184
|
-
leave:
|
|
185
|
-
enter:
|
|
186
|
-
update:
|
|
219
|
+
from: leaveStyle,
|
|
220
|
+
leave: leaveStyle,
|
|
221
|
+
enter: enterStyle,
|
|
222
|
+
update: enterStyle,
|
|
223
|
+
immediate: skipAnimation
|
|
224
|
+
});
|
|
225
|
+
const maskTransition = useTransition(masksData, {
|
|
226
|
+
keys: v => v.id,
|
|
227
|
+
from: leaveStyle,
|
|
228
|
+
leave: leaveStyle,
|
|
229
|
+
enter: enterStyle,
|
|
230
|
+
update: enterStyle,
|
|
187
231
|
immediate: skipAnimation
|
|
188
232
|
});
|
|
189
|
-
return /*#__PURE__*/
|
|
190
|
-
children:
|
|
233
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
234
|
+
children: [maskTransition((style, {
|
|
235
|
+
id,
|
|
236
|
+
hasPositive,
|
|
237
|
+
hasNegative,
|
|
238
|
+
layout
|
|
239
|
+
}) => {
|
|
240
|
+
return /*#__PURE__*/_jsx(BarClipPath, {
|
|
241
|
+
maskId: id,
|
|
242
|
+
borderRadius: borderRadius,
|
|
243
|
+
hasNegative: hasNegative,
|
|
244
|
+
hasPositive: hasPositive,
|
|
245
|
+
layout: layout,
|
|
246
|
+
style: style
|
|
247
|
+
});
|
|
248
|
+
}), transition((style, {
|
|
191
249
|
seriesId,
|
|
192
250
|
dataIndex,
|
|
193
251
|
color,
|
|
194
|
-
highlightScope
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
252
|
+
highlightScope,
|
|
253
|
+
maskId
|
|
254
|
+
}) => {
|
|
255
|
+
const barElement = /*#__PURE__*/_jsx(BarElement, _extends({
|
|
256
|
+
id: seriesId,
|
|
257
|
+
dataIndex: dataIndex,
|
|
258
|
+
color: color,
|
|
259
|
+
highlightScope: highlightScope
|
|
260
|
+
}, other, {
|
|
261
|
+
onClick: onItemClick && (event => {
|
|
262
|
+
onItemClick(event, {
|
|
263
|
+
type: 'bar',
|
|
264
|
+
seriesId,
|
|
265
|
+
dataIndex
|
|
266
|
+
});
|
|
267
|
+
}),
|
|
268
|
+
style: style
|
|
269
|
+
}));
|
|
270
|
+
if (!borderRadius || borderRadius <= 0) {
|
|
271
|
+
return barElement;
|
|
272
|
+
}
|
|
273
|
+
return /*#__PURE__*/_jsx("g", {
|
|
274
|
+
clipPath: `url(#${maskId})`,
|
|
275
|
+
children: barElement
|
|
276
|
+
});
|
|
277
|
+
})]
|
|
210
278
|
});
|
|
211
279
|
}
|
|
212
280
|
process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
|
|
@@ -214,6 +282,10 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
|
|
|
214
282
|
// | These PropTypes are generated from the TypeScript type definitions |
|
|
215
283
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
216
284
|
// ----------------------------------------------------------------------
|
|
285
|
+
/**
|
|
286
|
+
* Defines the border radius of the bar element.
|
|
287
|
+
*/
|
|
288
|
+
borderRadius: PropTypes.number,
|
|
217
289
|
/**
|
|
218
290
|
* Callback fired when a bar item is clicked.
|
|
219
291
|
* @param {React.MouseEvent<SVGElement, MouseEvent>} event The event source of the callback.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns if the corner should have a radius or not based on the layout and the data.
|
|
3
|
+
* @param {GetRadiusCorner} corner The corner to check.
|
|
4
|
+
* @param {GetRadiusData} cornerData The data for the corner.
|
|
5
|
+
* @returns {number} The radius for the corner.
|
|
6
|
+
*/
|
|
7
|
+
export const getRadius = (corner, {
|
|
8
|
+
hasNegative,
|
|
9
|
+
hasPositive,
|
|
10
|
+
borderRadius,
|
|
11
|
+
layout
|
|
12
|
+
}) => {
|
|
13
|
+
if (!borderRadius) {
|
|
14
|
+
return 0;
|
|
15
|
+
}
|
|
16
|
+
const isVertical = layout === 'vertical';
|
|
17
|
+
if (corner === 'top-left' && (isVertical && hasPositive || !isVertical && hasNegative)) {
|
|
18
|
+
return borderRadius;
|
|
19
|
+
}
|
|
20
|
+
if (corner === 'top-right' && (isVertical && hasPositive || !isVertical && hasPositive)) {
|
|
21
|
+
return borderRadius;
|
|
22
|
+
}
|
|
23
|
+
if (corner === 'bottom-right' && (isVertical && hasNegative || !isVertical && hasPositive)) {
|
|
24
|
+
return borderRadius;
|
|
25
|
+
}
|
|
26
|
+
if (corner === 'bottom-left' && (isVertical && hasNegative || !isVertical && hasNegative)) {
|
|
27
|
+
return borderRadius;
|
|
28
|
+
}
|
|
29
|
+
return 0;
|
|
30
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -4,7 +4,7 @@ const _excluded = ["vertical", "horizontal"];
|
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import composeClasses from '@mui/utils/composeClasses';
|
|
7
|
-
import { styled } from '@mui/material/styles';
|
|
7
|
+
import { styled, useThemeProps } from '@mui/material/styles';
|
|
8
8
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
9
9
|
import { useTicks } from '../hooks/useTicks';
|
|
10
10
|
import { getChartsGridUtilityClass, chartsGridClasses } from './chartsGridClasses';
|
|
@@ -12,15 +12,22 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
12
12
|
const GridRoot = styled('g', {
|
|
13
13
|
name: 'MuiChartsGrid',
|
|
14
14
|
slot: 'Root',
|
|
15
|
-
overridesResolver: (props, styles) =>
|
|
15
|
+
overridesResolver: (props, styles) => [{
|
|
16
|
+
[`&.${chartsGridClasses.verticalLine}`]: styles.verticalLine
|
|
17
|
+
}, {
|
|
18
|
+
[`&.${chartsGridClasses.horizontalLine}`]: styles.horizontalLine
|
|
19
|
+
}, styles.root]
|
|
20
|
+
})({});
|
|
21
|
+
const GridLine = styled('line', {
|
|
22
|
+
name: 'MuiChartsGrid',
|
|
23
|
+
slot: 'Line',
|
|
24
|
+
overridesResolver: (props, styles) => styles.line
|
|
16
25
|
})(({
|
|
17
26
|
theme
|
|
18
27
|
}) => ({
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
strokeWidth: 1
|
|
23
|
-
}
|
|
28
|
+
stroke: (theme.vars || theme).palette.divider,
|
|
29
|
+
shapeRendering: 'crispEdges',
|
|
30
|
+
strokeWidth: 1
|
|
24
31
|
}));
|
|
25
32
|
const useUtilityClasses = ({
|
|
26
33
|
classes
|
|
@@ -42,18 +49,22 @@ const useUtilityClasses = ({
|
|
|
42
49
|
* - [ChartsGrid API](https://mui.com/x/api/charts/charts-axis/)
|
|
43
50
|
*/
|
|
44
51
|
function ChartsGrid(props) {
|
|
52
|
+
const themeProps = useThemeProps({
|
|
53
|
+
props,
|
|
54
|
+
name: 'MuiChartsGrid'
|
|
55
|
+
});
|
|
45
56
|
const {
|
|
46
57
|
vertical,
|
|
47
58
|
horizontal
|
|
48
|
-
} =
|
|
49
|
-
other = _objectWithoutPropertiesLoose(
|
|
59
|
+
} = themeProps,
|
|
60
|
+
other = _objectWithoutPropertiesLoose(themeProps, _excluded);
|
|
50
61
|
const {
|
|
51
62
|
xAxis,
|
|
52
63
|
xAxisIds,
|
|
53
64
|
yAxis,
|
|
54
65
|
yAxisIds
|
|
55
66
|
} = React.useContext(CartesianContext);
|
|
56
|
-
const classes = useUtilityClasses(
|
|
67
|
+
const classes = useUtilityClasses(themeProps);
|
|
57
68
|
const horizontalAxisId = yAxisIds[0];
|
|
58
69
|
const verticalAxisId = xAxisIds[0];
|
|
59
70
|
const {
|
|
@@ -81,7 +92,7 @@ function ChartsGrid(props) {
|
|
|
81
92
|
children: [vertical && xTicks.map(({
|
|
82
93
|
formattedValue,
|
|
83
94
|
offset
|
|
84
|
-
}) => /*#__PURE__*/_jsx(
|
|
95
|
+
}) => /*#__PURE__*/_jsx(GridLine, {
|
|
85
96
|
y1: yScale.range()[0],
|
|
86
97
|
y2: yScale.range()[1],
|
|
87
98
|
x1: offset,
|
|
@@ -90,7 +101,7 @@ function ChartsGrid(props) {
|
|
|
90
101
|
}, `vertical-${formattedValue}`)), horizontal && yTicks.map(({
|
|
91
102
|
formattedValue,
|
|
92
103
|
offset
|
|
93
|
-
}) => /*#__PURE__*/_jsx(
|
|
104
|
+
}) => /*#__PURE__*/_jsx(GridLine, {
|
|
94
105
|
y1: offset,
|
|
95
106
|
y2: offset,
|
|
96
107
|
x1: xScale.range()[0],
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["message"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
|
+
import { useDrawingArea } from '../hooks/useDrawingArea';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const StyledText = styled('text')(({
|
|
9
|
+
theme
|
|
10
|
+
}) => ({
|
|
11
|
+
stroke: 'none',
|
|
12
|
+
fill: theme.palette.text.primary,
|
|
13
|
+
shapeRendering: 'crispEdges',
|
|
14
|
+
textAnchor: 'middle',
|
|
15
|
+
dominantBaseline: 'middle'
|
|
16
|
+
}));
|
|
17
|
+
export function ChartsLoadingOverlay(props) {
|
|
18
|
+
const {
|
|
19
|
+
message
|
|
20
|
+
} = props,
|
|
21
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
22
|
+
const {
|
|
23
|
+
top,
|
|
24
|
+
left,
|
|
25
|
+
height,
|
|
26
|
+
width
|
|
27
|
+
} = useDrawingArea();
|
|
28
|
+
return /*#__PURE__*/_jsx(StyledText, _extends({
|
|
29
|
+
x: left + width / 2,
|
|
30
|
+
y: top + height / 2
|
|
31
|
+
}, other, {
|
|
32
|
+
children: message ?? 'Loading data ...'
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
+
const _excluded = ["message"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
|
+
import { useDrawingArea } from '../hooks/useDrawingArea';
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
const StyledText = styled('text')(({
|
|
9
|
+
theme
|
|
10
|
+
}) => ({
|
|
11
|
+
stroke: 'none',
|
|
12
|
+
fill: theme.palette.text.primary,
|
|
13
|
+
shapeRendering: 'crispEdges',
|
|
14
|
+
textAnchor: 'middle',
|
|
15
|
+
dominantBaseline: 'middle'
|
|
16
|
+
}));
|
|
17
|
+
export function ChartsNoDataOverlay(props) {
|
|
18
|
+
const {
|
|
19
|
+
message
|
|
20
|
+
} = props,
|
|
21
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
22
|
+
const {
|
|
23
|
+
top,
|
|
24
|
+
left,
|
|
25
|
+
height,
|
|
26
|
+
width
|
|
27
|
+
} = useDrawingArea();
|
|
28
|
+
return /*#__PURE__*/_jsx(StyledText, _extends({
|
|
29
|
+
x: left + width / 2,
|
|
30
|
+
y: top + height / 2
|
|
31
|
+
}, other, {
|
|
32
|
+
children: message ?? 'No data to display'
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { ChartsLoadingOverlay } from './ChartsLoadingOverlay';
|
|
4
|
+
import { useSeries } from '../hooks/useSeries';
|
|
5
|
+
import { ChartsNoDataOverlay } from './ChartsNoDataOverlay';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
export function useNoData() {
|
|
8
|
+
const seriesPerType = useSeries();
|
|
9
|
+
return Object.values(seriesPerType).every(seriesOfGivenType => {
|
|
10
|
+
if (!seriesOfGivenType) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
const {
|
|
14
|
+
series,
|
|
15
|
+
seriesOrder
|
|
16
|
+
} = seriesOfGivenType;
|
|
17
|
+
return seriesOrder.every(seriesId => series[seriesId].data.length === 0);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
export function ChartsOverlay(props) {
|
|
21
|
+
const noData = useNoData();
|
|
22
|
+
if (props.loading) {
|
|
23
|
+
const LoadingOverlay = props.slots?.loadingOverlay ?? ChartsLoadingOverlay;
|
|
24
|
+
return /*#__PURE__*/_jsx(LoadingOverlay, _extends({}, props.slotProps?.loadingOverlay));
|
|
25
|
+
}
|
|
26
|
+
if (noData) {
|
|
27
|
+
const NoDataOverlay = props.slots?.noDataOverlay ?? ChartsNoDataOverlay;
|
|
28
|
+
return /*#__PURE__*/_jsx(NoDataOverlay, _extends({}, props.slotProps?.noDataOverlay));
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
@@ -52,7 +52,7 @@ process.env.NODE_ENV !== "production" ? ChartsReferenceLine.propTypes = {
|
|
|
52
52
|
*/
|
|
53
53
|
lineStyle: PropTypes.object,
|
|
54
54
|
/**
|
|
55
|
-
* Additional space
|
|
55
|
+
* Additional space around the label in px.
|
|
56
56
|
* Can be a number or an object `{ x, y }` to distinguish space with the reference line and space with axes.
|
|
57
57
|
* @default 5
|
|
58
58
|
*/
|
|
@@ -106,7 +106,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxisTooltipContent.propTypes = {
|
|
|
106
106
|
value: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]).isRequired
|
|
107
107
|
})
|
|
108
108
|
}),
|
|
109
|
-
axisValue: PropTypes.
|
|
109
|
+
axisValue: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]),
|
|
110
110
|
classes: PropTypes.object,
|
|
111
111
|
dataIndex: PropTypes.number,
|
|
112
112
|
series: PropTypes.arrayOf(PropTypes.object),
|
|
@@ -113,7 +113,7 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
|
|
|
113
113
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
114
114
|
// ----------------------------------------------------------------------
|
|
115
115
|
/**
|
|
116
|
-
* Component to override the tooltip content when
|
|
116
|
+
* Component to override the tooltip content when trigger is set to 'axis'.
|
|
117
117
|
* @deprecated Use slots.axisContent instead
|
|
118
118
|
*/
|
|
119
119
|
axisContent: PropTypes.elementType,
|
|
@@ -122,7 +122,7 @@ process.env.NODE_ENV !== "production" ? ChartsTooltip.propTypes = {
|
|
|
122
122
|
*/
|
|
123
123
|
classes: PropTypes.object,
|
|
124
124
|
/**
|
|
125
|
-
* Component to override the tooltip content when
|
|
125
|
+
* Component to override the tooltip content when trigger is set to 'item'.
|
|
126
126
|
* @deprecated Use slots.itemContent instead
|
|
127
127
|
*/
|
|
128
128
|
itemContent: PropTypes.elementType,
|
|
@@ -100,7 +100,7 @@ process.env.NODE_ENV !== "production" ? DefaultChartsAxisTooltipContent.propType
|
|
|
100
100
|
/**
|
|
101
101
|
* The value associated to the current mouse position.
|
|
102
102
|
*/
|
|
103
|
-
axisValue: PropTypes.
|
|
103
|
+
axisValue: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number, PropTypes.string]),
|
|
104
104
|
/**
|
|
105
105
|
* Override or extend the styles applied to the component.
|
|
106
106
|
*/
|
|
@@ -203,6 +203,13 @@ function ChartsXAxis(inProps) {
|
|
|
203
203
|
},
|
|
204
204
|
ownerState: {}
|
|
205
205
|
});
|
|
206
|
+
const domain = xScale.domain();
|
|
207
|
+
if (domain.length === 0 || domain[0] === domain[1]) {
|
|
208
|
+
// Skip axis rendering if
|
|
209
|
+
// - the data is empty (for band and point axis)
|
|
210
|
+
// - No data is associated to the axis (other scale types)
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
206
213
|
return /*#__PURE__*/_jsxs(AxisRoot, {
|
|
207
214
|
transform: `translate(0, ${position === 'bottom' ? top + height : top})`,
|
|
208
215
|
className: classes.root,
|
|
@@ -138,6 +138,13 @@ function ChartsYAxis(inProps) {
|
|
|
138
138
|
},
|
|
139
139
|
ownerState: {}
|
|
140
140
|
});
|
|
141
|
+
const domain = yScale.domain();
|
|
142
|
+
if (domain.length === 0 || domain[0] === domain[1]) {
|
|
143
|
+
// Skip axis rendering if
|
|
144
|
+
// - the data is empty (for band and point axis)
|
|
145
|
+
// - No data is associated to the axis (other scale types)
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
141
148
|
return /*#__PURE__*/_jsxs(AxisRoot, {
|
|
142
149
|
transform: `translate(${position === 'right' ? left + width : left}, 0)`,
|
|
143
150
|
className: classes.root,
|
package/esm/Gauge/Gauge.js
CHANGED
|
@@ -84,7 +84,7 @@ process.env.NODE_ENV !== "production" ? Gauge.propTypes = {
|
|
|
84
84
|
*/
|
|
85
85
|
height: PropTypes.number,
|
|
86
86
|
/**
|
|
87
|
-
* The radius between circle center and the
|
|
87
|
+
* The radius between circle center and the beginning of the arc.
|
|
88
88
|
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
89
89
|
* The '100%' is the maximal radius that fit into the drawing area.
|
|
90
90
|
* @default '80%'
|
|
@@ -145,7 +145,7 @@ process.env.NODE_ENV !== "production" ? GaugeContainer.propTypes = {
|
|
|
145
145
|
*/
|
|
146
146
|
height: PropTypes.number,
|
|
147
147
|
/**
|
|
148
|
-
* The radius between circle center and the
|
|
148
|
+
* The radius between circle center and the beginning of the arc.
|
|
149
149
|
* Can be a number (in px) or a string with a percentage such as '50%'.
|
|
150
150
|
* The '100%' is the maximal radius that fit into the drawing area.
|
|
151
151
|
* @default '80%'
|
|
@@ -48,7 +48,7 @@ export function GaugeProvider(props) {
|
|
|
48
48
|
let cy = top + innerCy;
|
|
49
49
|
const maxRadius = getAvailableRadius(innerCx, innerCy, width, height, ratios);
|
|
50
50
|
|
|
51
|
-
// If the center is not defined, after computation of the available radius,
|
|
51
|
+
// If the center is not defined, after computation of the available radius, update the center to use the remaining space.
|
|
52
52
|
if (cxParam === undefined) {
|
|
53
53
|
const usedWidth = maxRadius * (ratios.maxX - ratios.minX);
|
|
54
54
|
cx = left + (width - usedWidth) / 2 + ratios.cx * usedWidth;
|
package/esm/Gauge/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ function getPoint(angle) {
|
|
|
7
7
|
}
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Returns the ratio of the arc bounding box and its center.
|
|
11
11
|
* @param startAngle The start angle (in deg)
|
|
12
12
|
* @param endAngle The end angle (in deg)
|
|
13
13
|
*/
|
|
@@ -20,9 +20,9 @@ export function getArcRatios(startAngle, endAngle) {
|
|
|
20
20
|
const maxAngle = Math.max(startAngle, endAngle);
|
|
21
21
|
const initialAngle = Math.floor(minAngle / 90) * 90;
|
|
22
22
|
for (let step = 1; step <= 4; step += 1) {
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
points.push(getPoint(
|
|
23
|
+
const cardinalAngle = initialAngle + step * 90;
|
|
24
|
+
if (cardinalAngle < maxAngle) {
|
|
25
|
+
points.push(getPoint(cardinalAngle));
|
|
26
26
|
}
|
|
27
27
|
}
|
|
28
28
|
const minX = Math.min(...points.map(([x]) => x));
|
|
@@ -15,6 +15,7 @@ import { ChartsClipPath } from '../ChartsClipPath';
|
|
|
15
15
|
import { LineHighlightPlot } from './LineHighlightPlot';
|
|
16
16
|
import { ChartsGrid } from '../ChartsGrid';
|
|
17
17
|
import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
|
|
18
|
+
import { ChartsOverlay } from '../ChartsOverlay/ChartsOverlay';
|
|
18
19
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
20
|
/**
|
|
20
21
|
* Demos:
|
|
@@ -55,7 +56,8 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
55
56
|
children,
|
|
56
57
|
slots,
|
|
57
58
|
slotProps,
|
|
58
|
-
skipAnimation
|
|
59
|
+
skipAnimation,
|
|
60
|
+
loading
|
|
59
61
|
} = props;
|
|
60
62
|
const id = useId();
|
|
61
63
|
const clipPathId = `${id}-clip-path`;
|
|
@@ -97,6 +99,10 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
97
99
|
slotProps: slotProps,
|
|
98
100
|
onItemClick: onLineClick,
|
|
99
101
|
skipAnimation: skipAnimation
|
|
102
|
+
}), /*#__PURE__*/_jsx(ChartsOverlay, {
|
|
103
|
+
loading: loading,
|
|
104
|
+
slots: slots,
|
|
105
|
+
slotProps: slotProps
|
|
100
106
|
})]
|
|
101
107
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
102
108
|
topAxis: topAxis,
|
|
@@ -116,7 +122,7 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
116
122
|
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
117
123
|
slots: slots,
|
|
118
124
|
slotProps: slotProps
|
|
119
|
-
})), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
|
|
125
|
+
})), !loading && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
|
|
120
126
|
slots: slots,
|
|
121
127
|
slotProps: slotProps
|
|
122
128
|
})), /*#__PURE__*/_jsx(ChartsClipPath, {
|
|
@@ -197,6 +203,10 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
197
203
|
slotProps: PropTypes.object,
|
|
198
204
|
slots: PropTypes.object
|
|
199
205
|
}),
|
|
206
|
+
/**
|
|
207
|
+
* If `true`, a loading overlay is displayed.
|
|
208
|
+
*/
|
|
209
|
+
loading: PropTypes.bool,
|
|
200
210
|
/**
|
|
201
211
|
* The margin between the SVG and the drawing area.
|
|
202
212
|
* It's used for leaving some space for extra information such as the x- and y-axis or legend.
|
|
@@ -39,7 +39,7 @@ const PieArcLabelRoot = styled(animated.text, {
|
|
|
39
39
|
}));
|
|
40
40
|
/**
|
|
41
41
|
* Helper to compute label position.
|
|
42
|
-
* It's not an inline function because we need it in
|
|
42
|
+
* It's not an inline function because we need it in interpolation.
|
|
43
43
|
*/
|
|
44
44
|
const getLabelPosition = (formattedArcLabel, variable) => (startAngle, endAngle, padAngle, arcLabelRadius, cornerRadius) => {
|
|
45
45
|
if (!formattedArcLabel) {
|