@mui/x-charts 6.0.0-alpha.5 → 6.0.0-alpha.7
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 +18 -2
- package/BarChart/BarChart.js +74 -17
- package/BarChart/BarElement.d.ts +22 -0
- package/BarChart/BarElement.js +21 -10
- package/BarChart/BarPlot.d.ts +14 -1
- package/BarChart/BarPlot.js +23 -4
- package/BarChart/formatter.js +23 -12
- package/CHANGELOG.md +154 -0
- package/ChartContainer/index.js +3 -0
- package/ChartsAxis/ChartsAxis.d.ts +11 -1
- package/ChartsAxis/ChartsAxis.js +51 -6
- package/ChartsLegend/ChartsLegend.d.ts +25 -2
- package/ChartsLegend/ChartsLegend.js +49 -17
- package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/ChartsTooltip/ChartsTooltipTable.d.ts +2 -9
- package/ChartsXAxis/ChartsXAxis.js +44 -9
- package/ChartsYAxis/ChartsYAxis.js +44 -9
- package/LineChart/AreaElement.d.ts +22 -0
- package/LineChart/AreaElement.js +31 -11
- package/LineChart/AreaPlot.d.ts +14 -1
- package/LineChart/AreaPlot.js +32 -5
- package/LineChart/LineChart.d.ts +20 -2
- package/LineChart/LineChart.js +76 -16
- package/LineChart/LineElement.d.ts +22 -0
- package/LineChart/LineElement.js +31 -10
- package/LineChart/LinePlot.d.ts +14 -1
- package/LineChart/LinePlot.js +38 -6
- package/LineChart/MarkElement.js +1 -1
- package/LineChart/MarkPlot.d.ts +24 -1
- package/LineChart/MarkPlot.js +30 -6
- package/LineChart/formatter.js +23 -12
- package/PieChart/PieArcLabel.js +0 -1
- package/PieChart/PieChart.d.ts +14 -2
- package/PieChart/PieChart.js +60 -13
- package/PieChart/PiePlot.d.ts +27 -1
- package/PieChart/PiePlot.js +29 -6
- package/ScatterChart/ScatterChart.d.ts +18 -2
- package/ScatterChart/ScatterChart.js +64 -13
- package/ScatterChart/ScatterPlot.d.ts +24 -1
- package/ScatterChart/ScatterPlot.js +28 -4
- package/SparkLineChart/SparkLineChart.d.ts +73 -0
- package/SparkLineChart/SparkLineChart.js +218 -0
- package/SparkLineChart/index.d.ts +1 -0
- package/SparkLineChart/index.js +12 -0
- package/SparkLineChart/package.json +6 -0
- package/colorPalettes/colorPalettes.js +2 -2
- package/context/CartesianContextProvider.d.ts +3 -1
- package/context/CartesianContextProvider.js +50 -14
- package/context/SeriesContextProvider.d.ts +3 -2
- package/context/SeriesContextProvider.js +5 -3
- package/esm/BarChart/BarChart.js +77 -17
- package/esm/BarChart/BarElement.js +21 -11
- package/esm/BarChart/BarPlot.js +23 -4
- package/esm/BarChart/formatter.js +23 -12
- package/esm/ChartContainer/index.js +3 -0
- package/esm/ChartsAxis/ChartsAxis.js +51 -6
- package/esm/ChartsLegend/ChartsLegend.js +47 -14
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/ChartsXAxis/ChartsXAxis.js +45 -9
- package/esm/ChartsYAxis/ChartsYAxis.js +45 -9
- package/esm/LineChart/AreaElement.js +31 -11
- package/esm/LineChart/AreaPlot.js +33 -5
- package/esm/LineChart/LineChart.js +79 -16
- package/esm/LineChart/LineElement.js +31 -11
- package/esm/LineChart/LinePlot.js +45 -9
- package/esm/LineChart/MarkElement.js +1 -1
- package/esm/LineChart/MarkPlot.js +31 -6
- package/esm/LineChart/formatter.js +23 -13
- package/esm/PieChart/PieArcLabel.js +0 -1
- package/esm/PieChart/PieChart.js +60 -13
- package/esm/PieChart/PiePlot.js +31 -6
- package/esm/ScatterChart/ScatterChart.js +64 -13
- package/esm/ScatterChart/ScatterPlot.js +29 -4
- package/esm/SparkLineChart/SparkLineChart.js +210 -0
- package/esm/SparkLineChart/index.js +1 -0
- package/esm/colorPalettes/colorPalettes.js +2 -2
- package/esm/context/CartesianContextProvider.js +50 -14
- package/esm/context/SeriesContextProvider.js +5 -3
- package/esm/hooks/useTicks.js +9 -6
- package/esm/index.js +1 -0
- package/esm/internals/components/AxisSharedComponents.js +10 -10
- package/esm/models/index.js +3 -1
- package/hooks/useTicks.d.ts +20 -5
- package/hooks/useTicks.js +9 -6
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/components/AxisSharedComponents.d.ts +4 -4
- package/internals/components/AxisSharedComponents.js +15 -15
- package/internals/defaultizeColor.d.ts +4 -2
- package/legacy/BarChart/BarChart.js +75 -17
- package/legacy/BarChart/BarElement.js +20 -10
- package/legacy/BarChart/BarPlot.js +23 -4
- package/legacy/BarChart/formatter.js +23 -10
- package/legacy/ChartContainer/index.js +3 -0
- package/legacy/ChartsAxis/ChartsAxis.js +51 -6
- package/legacy/ChartsLegend/ChartsLegend.js +46 -15
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/legacy/ChartsXAxis/ChartsXAxis.js +45 -9
- package/legacy/ChartsYAxis/ChartsYAxis.js +45 -9
- package/legacy/LineChart/AreaElement.js +30 -10
- package/legacy/LineChart/AreaPlot.js +31 -5
- package/legacy/LineChart/LineChart.js +77 -16
- package/legacy/LineChart/LineElement.js +30 -10
- package/legacy/LineChart/LinePlot.js +38 -6
- package/legacy/LineChart/MarkElement.js +1 -1
- package/legacy/LineChart/MarkPlot.js +29 -6
- package/legacy/LineChart/formatter.js +23 -11
- package/legacy/PieChart/PieArcLabel.js +0 -1
- package/legacy/PieChart/PieChart.js +60 -13
- package/legacy/PieChart/PiePlot.js +29 -6
- package/legacy/ScatterChart/ScatterChart.js +64 -13
- package/legacy/ScatterChart/ScatterPlot.js +27 -4
- package/legacy/SparkLineChart/SparkLineChart.js +214 -0
- package/legacy/SparkLineChart/index.js +1 -0
- package/legacy/colorPalettes/colorPalettes.js +2 -2
- package/legacy/context/CartesianContextProvider.js +59 -15
- package/legacy/context/SeriesContextProvider.js +6 -4
- package/legacy/hooks/useTicks.js +9 -9
- package/legacy/index.js +2 -1
- package/legacy/internals/components/AxisSharedComponents.js +10 -10
- package/legacy/models/index.js +3 -1
- package/models/axis.d.ts +34 -3
- package/models/index.d.ts +2 -0
- package/models/index.js +11 -0
- package/models/seriesType/bar.d.ts +8 -1
- package/models/seriesType/common.d.ts +2 -2
- package/models/seriesType/config.d.ts +4 -1
- package/models/seriesType/line.d.ts +8 -1
- package/modern/BarChart/BarChart.js +74 -17
- package/modern/BarChart/BarElement.js +20 -11
- package/modern/BarChart/BarPlot.js +23 -4
- package/modern/BarChart/formatter.js +23 -12
- package/modern/ChartContainer/index.js +3 -0
- package/modern/ChartsAxis/ChartsAxis.js +51 -6
- package/modern/ChartsLegend/ChartsLegend.js +46 -14
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/modern/ChartsXAxis/ChartsXAxis.js +44 -9
- package/modern/ChartsYAxis/ChartsYAxis.js +44 -9
- package/modern/LineChart/AreaElement.js +30 -11
- package/modern/LineChart/AreaPlot.js +33 -5
- package/modern/LineChart/LineChart.js +76 -16
- package/modern/LineChart/LineElement.js +30 -11
- package/modern/LineChart/LinePlot.js +39 -6
- package/modern/LineChart/MarkElement.js +1 -1
- package/modern/LineChart/MarkPlot.js +30 -6
- package/modern/LineChart/formatter.js +23 -13
- package/modern/PieChart/PieArcLabel.js +0 -1
- package/modern/PieChart/PieChart.js +60 -13
- package/modern/PieChart/PiePlot.js +30 -6
- package/modern/ScatterChart/ScatterChart.js +64 -13
- package/modern/ScatterChart/ScatterPlot.js +28 -4
- package/modern/SparkLineChart/SparkLineChart.js +210 -0
- package/modern/SparkLineChart/index.js +1 -0
- package/modern/colorPalettes/colorPalettes.js +2 -2
- package/modern/context/CartesianContextProvider.js +50 -14
- package/modern/context/SeriesContextProvider.js +5 -3
- package/modern/hooks/useTicks.js +9 -6
- package/modern/index.js +2 -1
- package/modern/internals/components/AxisSharedComponents.js +10 -10
- package/modern/models/index.js +3 -1
- package/package.json +4 -2
- package/themeAugmentation/components.d.ts +0 -10
- package/themeAugmentation/overrides.d.ts +0 -2
|
@@ -43,12 +43,37 @@ const CartesianContext = /*#__PURE__*/React.createContext({
|
|
|
43
43
|
});
|
|
44
44
|
exports.CartesianContext = CartesianContext;
|
|
45
45
|
function CartesianContextProvider({
|
|
46
|
-
xAxis,
|
|
47
|
-
yAxis,
|
|
46
|
+
xAxis: inXAxis,
|
|
47
|
+
yAxis: inYAxis,
|
|
48
|
+
dataset,
|
|
48
49
|
children
|
|
49
50
|
}) {
|
|
50
51
|
const formattedSeries = React.useContext(_SeriesContextProvider.SeriesContext);
|
|
51
52
|
const drawingArea = React.useContext(_DrawingProvider.DrawingContext);
|
|
53
|
+
const xAxis = React.useMemo(() => inXAxis?.map(axisConfig => {
|
|
54
|
+
const dataKey = axisConfig.dataKey;
|
|
55
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
56
|
+
return axisConfig;
|
|
57
|
+
}
|
|
58
|
+
if (dataset === undefined) {
|
|
59
|
+
throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
60
|
+
}
|
|
61
|
+
return (0, _extends2.default)({}, axisConfig, {
|
|
62
|
+
data: dataset.map(d => d[dataKey])
|
|
63
|
+
});
|
|
64
|
+
}), [inXAxis, dataset]);
|
|
65
|
+
const yAxis = React.useMemo(() => inYAxis?.map(axisConfig => {
|
|
66
|
+
const dataKey = axisConfig.dataKey;
|
|
67
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
68
|
+
return axisConfig;
|
|
69
|
+
}
|
|
70
|
+
if (dataset === undefined) {
|
|
71
|
+
throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
72
|
+
}
|
|
73
|
+
return (0, _extends2.default)({}, axisConfig, {
|
|
74
|
+
data: dataset.map(d => d[dataKey])
|
|
75
|
+
});
|
|
76
|
+
}), [inYAxis, dataset]);
|
|
52
77
|
const value = React.useMemo(() => {
|
|
53
78
|
const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis) => {
|
|
54
79
|
const getter = getters[chartType];
|
|
@@ -109,7 +134,8 @@ function CartesianContextProvider({
|
|
|
109
134
|
const scaleType = axis.scaleType ?? 'linear';
|
|
110
135
|
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
111
136
|
const ticksNumber = (0, _useTicks.getTicksNumber)((0, _extends2.default)({}, axis, {
|
|
112
|
-
range
|
|
137
|
+
range,
|
|
138
|
+
domain: extremums
|
|
113
139
|
}));
|
|
114
140
|
const niceScale = (0, _getScale.getScale)(scaleType, extremums, range).nice(ticksNumber);
|
|
115
141
|
const niceDomain = niceScale.domain();
|
|
@@ -156,7 +182,8 @@ function CartesianContextProvider({
|
|
|
156
182
|
const scaleType = axis.scaleType ?? 'linear';
|
|
157
183
|
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
158
184
|
const ticksNumber = (0, _useTicks.getTicksNumber)((0, _extends2.default)({}, axis, {
|
|
159
|
-
range
|
|
185
|
+
range,
|
|
186
|
+
domain: extremums
|
|
160
187
|
}));
|
|
161
188
|
const niceScale = (0, _getScale.getScale)(scaleType, extremums, range).nice(ticksNumber);
|
|
162
189
|
const niceDomain = niceScale.domain();
|
|
@@ -191,48 +218,57 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
191
218
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
192
219
|
// ----------------------------------------------------------------------
|
|
193
220
|
children: _propTypes.default.node,
|
|
221
|
+
dataset: _propTypes.default.arrayOf(_propTypes.default.object),
|
|
194
222
|
xAxis: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
195
223
|
axisId: _propTypes.default.string,
|
|
196
224
|
classes: _propTypes.default.object,
|
|
197
225
|
data: _propTypes.default.array,
|
|
226
|
+
dataKey: _propTypes.default.string,
|
|
198
227
|
disableLine: _propTypes.default.bool,
|
|
199
228
|
disableTicks: _propTypes.default.bool,
|
|
200
229
|
fill: _propTypes.default.string,
|
|
230
|
+
hideTooltip: _propTypes.default.bool,
|
|
201
231
|
id: _propTypes.default.string,
|
|
202
232
|
label: _propTypes.default.string,
|
|
203
233
|
labelFontSize: _propTypes.default.number,
|
|
204
|
-
max: _propTypes.default.number,
|
|
205
|
-
|
|
206
|
-
min: _propTypes.default.number,
|
|
207
|
-
minTicks: _propTypes.default.number,
|
|
234
|
+
max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
235
|
+
min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
208
236
|
position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
|
|
209
237
|
scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
238
|
+
slotProps: _propTypes.default.object,
|
|
239
|
+
slots: _propTypes.default.object,
|
|
210
240
|
stroke: _propTypes.default.string,
|
|
211
241
|
tickFontSize: _propTypes.default.number,
|
|
242
|
+
tickMaxStep: _propTypes.default.number,
|
|
243
|
+
tickMinStep: _propTypes.default.number,
|
|
244
|
+
tickNumber: _propTypes.default.number,
|
|
212
245
|
tickSize: _propTypes.default.number,
|
|
213
|
-
tickSpacing: _propTypes.default.number,
|
|
214
246
|
valueFormatter: _propTypes.default.func
|
|
215
247
|
})),
|
|
216
248
|
yAxis: _propTypes.default.arrayOf(_propTypes.default.shape({
|
|
217
249
|
axisId: _propTypes.default.string,
|
|
218
250
|
classes: _propTypes.default.object,
|
|
219
251
|
data: _propTypes.default.array,
|
|
252
|
+
dataKey: _propTypes.default.string,
|
|
220
253
|
disableLine: _propTypes.default.bool,
|
|
221
254
|
disableTicks: _propTypes.default.bool,
|
|
222
255
|
fill: _propTypes.default.string,
|
|
256
|
+
hideTooltip: _propTypes.default.bool,
|
|
223
257
|
id: _propTypes.default.string,
|
|
224
258
|
label: _propTypes.default.string,
|
|
225
259
|
labelFontSize: _propTypes.default.number,
|
|
226
|
-
max: _propTypes.default.number,
|
|
227
|
-
|
|
228
|
-
min: _propTypes.default.number,
|
|
229
|
-
minTicks: _propTypes.default.number,
|
|
260
|
+
max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
261
|
+
min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
|
|
230
262
|
position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
|
|
231
263
|
scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
264
|
+
slotProps: _propTypes.default.object,
|
|
265
|
+
slots: _propTypes.default.object,
|
|
232
266
|
stroke: _propTypes.default.string,
|
|
233
267
|
tickFontSize: _propTypes.default.number,
|
|
268
|
+
tickMaxStep: _propTypes.default.number,
|
|
269
|
+
tickMinStep: _propTypes.default.number,
|
|
270
|
+
tickNumber: _propTypes.default.number,
|
|
234
271
|
tickSize: _propTypes.default.number,
|
|
235
|
-
tickSpacing: _propTypes.default.number,
|
|
236
272
|
valueFormatter: _propTypes.default.func
|
|
237
273
|
}))
|
|
238
274
|
} : void 0;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { AllSeriesType } from '../models/seriesType';
|
|
3
|
-
import { ChartSeriesType, FormatterResult } from '../models/seriesType/config';
|
|
3
|
+
import { ChartSeriesType, DatasetType, FormatterResult } from '../models/seriesType/config';
|
|
4
4
|
import { ChartsColorPalette } from '../colorPalettes';
|
|
5
5
|
export type SeriesContextProviderProps = {
|
|
6
|
+
dataset?: DatasetType;
|
|
6
7
|
series: AllSeriesType[];
|
|
7
8
|
/**
|
|
8
9
|
* Color palette used to colorize multiple series.
|
|
@@ -14,4 +15,4 @@ export type FormattedSeries = {
|
|
|
14
15
|
[type in ChartSeriesType]?: FormatterResult<type>;
|
|
15
16
|
};
|
|
16
17
|
export declare const SeriesContext: React.Context<FormattedSeries>;
|
|
17
|
-
export declare function SeriesContextProvider({ series, colors, children, }: SeriesContextProviderProps): React.JSX.Element;
|
|
18
|
+
export declare function SeriesContextProvider({ series, dataset, colors, children, }: SeriesContextProviderProps): React.JSX.Element;
|
|
@@ -26,6 +26,7 @@ const seriesTypeFormatter = {
|
|
|
26
26
|
line: _formatter3.default,
|
|
27
27
|
pie: _formatter4.default
|
|
28
28
|
};
|
|
29
|
+
|
|
29
30
|
/**
|
|
30
31
|
* This methods is the interface between what the developer is providing and what components receives
|
|
31
32
|
* To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if some line data are modified
|
|
@@ -34,7 +35,7 @@ const seriesTypeFormatter = {
|
|
|
34
35
|
* @param colors The color palette used to defaultize series colors
|
|
35
36
|
* @returns An object structuring all the series by type.
|
|
36
37
|
*/
|
|
37
|
-
const formatSeries = (series, colors) => {
|
|
38
|
+
const formatSeries = (series, colors, dataset) => {
|
|
38
39
|
// Group series by type
|
|
39
40
|
const seriesGroups = {};
|
|
40
41
|
series.forEach((seriesData, seriesIndex) => {
|
|
@@ -60,18 +61,19 @@ const formatSeries = (series, colors) => {
|
|
|
60
61
|
// Apply formater on a type group
|
|
61
62
|
Object.keys(seriesTypeFormatter).forEach(type => {
|
|
62
63
|
if (seriesGroups[type] !== undefined) {
|
|
63
|
-
formattedSeries[type] = seriesTypeFormatter[type]?.(seriesGroups[type]) ?? seriesGroups[type];
|
|
64
|
+
formattedSeries[type] = seriesTypeFormatter[type]?.(seriesGroups[type], dataset) ?? seriesGroups[type];
|
|
64
65
|
}
|
|
65
66
|
});
|
|
66
67
|
return formattedSeries;
|
|
67
68
|
};
|
|
68
69
|
function SeriesContextProvider({
|
|
69
70
|
series,
|
|
71
|
+
dataset,
|
|
70
72
|
colors = _colorPalettes.blueberryTwilightPalette,
|
|
71
73
|
children
|
|
72
74
|
}) {
|
|
73
75
|
const theme = (0, _styles.useTheme)();
|
|
74
|
-
const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors), [series, colors, theme.palette.mode]);
|
|
76
|
+
const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, dataset), [series, colors, theme.palette.mode, dataset]);
|
|
75
77
|
return /*#__PURE__*/(0, _jsxRuntime.jsx)(SeriesContext.Provider, {
|
|
76
78
|
value: formattedSeries,
|
|
77
79
|
children: children
|
package/esm/BarChart/BarChart.js
CHANGED
|
@@ -21,6 +21,7 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
21
21
|
height,
|
|
22
22
|
margin,
|
|
23
23
|
colors,
|
|
24
|
+
dataset,
|
|
24
25
|
sx,
|
|
25
26
|
tooltip,
|
|
26
27
|
axisHighlight,
|
|
@@ -29,7 +30,9 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
29
30
|
leftAxis,
|
|
30
31
|
rightAxis,
|
|
31
32
|
bottomAxis,
|
|
32
|
-
children
|
|
33
|
+
children,
|
|
34
|
+
slots,
|
|
35
|
+
slotProps
|
|
33
36
|
} = props;
|
|
34
37
|
const id = useId();
|
|
35
38
|
const clipPathId = `${id}-clip-path`;
|
|
@@ -45,24 +48,39 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
45
48
|
id: DEFAULT_X_AXIS_KEY,
|
|
46
49
|
scaleType: 'band',
|
|
47
50
|
data: Array.from({
|
|
48
|
-
length: Math.max(...series.map(s =>
|
|
51
|
+
length: Math.max(...series.map(s => {
|
|
52
|
+
var _ref, _s$data;
|
|
53
|
+
return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
|
|
54
|
+
}))
|
|
49
55
|
}, (_, index) => index)
|
|
50
56
|
}],
|
|
51
57
|
yAxis: yAxis,
|
|
52
58
|
colors: colors,
|
|
59
|
+
dataset: dataset,
|
|
53
60
|
sx: sx,
|
|
54
61
|
disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
|
|
55
62
|
children: [/*#__PURE__*/_jsx("g", {
|
|
56
63
|
clipPath: `url(#${clipPathId})`,
|
|
57
|
-
children: /*#__PURE__*/_jsx(BarPlot, {
|
|
64
|
+
children: /*#__PURE__*/_jsx(BarPlot, {
|
|
65
|
+
slots: slots,
|
|
66
|
+
slotProps: slotProps
|
|
67
|
+
})
|
|
58
68
|
}), /*#__PURE__*/_jsx(ChartsAxis, {
|
|
59
69
|
topAxis: topAxis,
|
|
60
70
|
leftAxis: leftAxis,
|
|
61
71
|
rightAxis: rightAxis,
|
|
62
|
-
bottomAxis: bottomAxis
|
|
63
|
-
|
|
72
|
+
bottomAxis: bottomAxis,
|
|
73
|
+
slots: slots,
|
|
74
|
+
slotProps: slotProps
|
|
75
|
+
}), /*#__PURE__*/_jsx(ChartsLegend, _extends({}, legend, {
|
|
76
|
+
slots: slots,
|
|
77
|
+
slotProps: slotProps
|
|
78
|
+
})), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({
|
|
64
79
|
x: "band"
|
|
65
|
-
}, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip
|
|
80
|
+
}, axisHighlight)), /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip, {
|
|
81
|
+
slots: slots,
|
|
82
|
+
slotProps: slotProps
|
|
83
|
+
})), /*#__PURE__*/_jsx(ChartsClipPath, {
|
|
66
84
|
id: clipPathId
|
|
67
85
|
}), children]
|
|
68
86
|
});
|
|
@@ -90,8 +108,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
90
108
|
label: PropTypes.string,
|
|
91
109
|
labelFontSize: PropTypes.number,
|
|
92
110
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
111
|
+
slotProps: PropTypes.object,
|
|
112
|
+
slots: PropTypes.object,
|
|
93
113
|
stroke: PropTypes.string,
|
|
94
114
|
tickFontSize: PropTypes.number,
|
|
115
|
+
tickMaxStep: PropTypes.number,
|
|
116
|
+
tickMinStep: PropTypes.number,
|
|
117
|
+
tickNumber: PropTypes.number,
|
|
95
118
|
tickSize: PropTypes.number
|
|
96
119
|
}), PropTypes.string]),
|
|
97
120
|
children: PropTypes.node,
|
|
@@ -100,6 +123,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
100
123
|
* Color palette used to colorize multiple series.
|
|
101
124
|
*/
|
|
102
125
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
126
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
103
127
|
desc: PropTypes.string,
|
|
104
128
|
disableAxisListener: PropTypes.bool,
|
|
105
129
|
height: PropTypes.number,
|
|
@@ -117,8 +141,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
117
141
|
label: PropTypes.string,
|
|
118
142
|
labelFontSize: PropTypes.number,
|
|
119
143
|
position: PropTypes.oneOf(['left', 'right']),
|
|
144
|
+
slotProps: PropTypes.object,
|
|
145
|
+
slots: PropTypes.object,
|
|
120
146
|
stroke: PropTypes.string,
|
|
121
147
|
tickFontSize: PropTypes.number,
|
|
148
|
+
tickMaxStep: PropTypes.number,
|
|
149
|
+
tickMinStep: PropTypes.number,
|
|
150
|
+
tickNumber: PropTypes.number,
|
|
122
151
|
tickSize: PropTypes.number
|
|
123
152
|
}), PropTypes.string]),
|
|
124
153
|
legend: PropTypes.shape({
|
|
@@ -135,6 +164,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
135
164
|
horizontal: PropTypes.oneOf(['left', 'middle', 'right']).isRequired,
|
|
136
165
|
vertical: PropTypes.oneOf(['bottom', 'middle', 'top']).isRequired
|
|
137
166
|
}),
|
|
167
|
+
slotProps: PropTypes.object,
|
|
168
|
+
slots: PropTypes.object,
|
|
138
169
|
spacing: PropTypes.number
|
|
139
170
|
}),
|
|
140
171
|
margin: PropTypes.shape({
|
|
@@ -157,13 +188,19 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
157
188
|
label: PropTypes.string,
|
|
158
189
|
labelFontSize: PropTypes.number,
|
|
159
190
|
position: PropTypes.oneOf(['left', 'right']),
|
|
191
|
+
slotProps: PropTypes.object,
|
|
192
|
+
slots: PropTypes.object,
|
|
160
193
|
stroke: PropTypes.string,
|
|
161
194
|
tickFontSize: PropTypes.number,
|
|
195
|
+
tickMaxStep: PropTypes.number,
|
|
196
|
+
tickMinStep: PropTypes.number,
|
|
197
|
+
tickNumber: PropTypes.number,
|
|
162
198
|
tickSize: PropTypes.number
|
|
163
199
|
}), PropTypes.string]),
|
|
164
200
|
series: PropTypes.arrayOf(PropTypes.shape({
|
|
165
201
|
color: PropTypes.string,
|
|
166
|
-
data: PropTypes.arrayOf(PropTypes.number)
|
|
202
|
+
data: PropTypes.arrayOf(PropTypes.number),
|
|
203
|
+
dataKey: PropTypes.string,
|
|
167
204
|
highlightScope: PropTypes.shape({
|
|
168
205
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
169
206
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
@@ -178,6 +215,16 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
178
215
|
xAxisKey: PropTypes.string,
|
|
179
216
|
yAxisKey: PropTypes.string
|
|
180
217
|
})).isRequired,
|
|
218
|
+
/**
|
|
219
|
+
* The props used for each component slot.
|
|
220
|
+
* @default {}
|
|
221
|
+
*/
|
|
222
|
+
slotProps: PropTypes.object,
|
|
223
|
+
/**
|
|
224
|
+
* Overridable component slots.
|
|
225
|
+
* @default {}
|
|
226
|
+
*/
|
|
227
|
+
slots: PropTypes.object,
|
|
181
228
|
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
182
229
|
title: PropTypes.string,
|
|
183
230
|
tooltip: PropTypes.shape({
|
|
@@ -200,8 +247,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
200
247
|
label: PropTypes.string,
|
|
201
248
|
labelFontSize: PropTypes.number,
|
|
202
249
|
position: PropTypes.oneOf(['bottom', 'top']),
|
|
250
|
+
slotProps: PropTypes.object,
|
|
251
|
+
slots: PropTypes.object,
|
|
203
252
|
stroke: PropTypes.string,
|
|
204
253
|
tickFontSize: PropTypes.number,
|
|
254
|
+
tickMaxStep: PropTypes.number,
|
|
255
|
+
tickMinStep: PropTypes.number,
|
|
256
|
+
tickNumber: PropTypes.number,
|
|
205
257
|
tickSize: PropTypes.number
|
|
206
258
|
}), PropTypes.string]),
|
|
207
259
|
viewBox: PropTypes.shape({
|
|
@@ -215,44 +267,52 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
215
267
|
axisId: PropTypes.string,
|
|
216
268
|
classes: PropTypes.object,
|
|
217
269
|
data: PropTypes.array,
|
|
270
|
+
dataKey: PropTypes.string,
|
|
218
271
|
disableLine: PropTypes.bool,
|
|
219
272
|
disableTicks: PropTypes.bool,
|
|
220
273
|
fill: PropTypes.string,
|
|
274
|
+
hideTooltip: PropTypes.bool,
|
|
221
275
|
id: PropTypes.string,
|
|
222
276
|
label: PropTypes.string,
|
|
223
277
|
labelFontSize: PropTypes.number,
|
|
224
|
-
max: PropTypes.number,
|
|
225
|
-
|
|
226
|
-
min: PropTypes.number,
|
|
227
|
-
minTicks: PropTypes.number,
|
|
278
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
279
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
228
280
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
229
281
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
282
|
+
slotProps: PropTypes.object,
|
|
283
|
+
slots: PropTypes.object,
|
|
230
284
|
stroke: PropTypes.string,
|
|
231
285
|
tickFontSize: PropTypes.number,
|
|
286
|
+
tickMaxStep: PropTypes.number,
|
|
287
|
+
tickMinStep: PropTypes.number,
|
|
288
|
+
tickNumber: PropTypes.number,
|
|
232
289
|
tickSize: PropTypes.number,
|
|
233
|
-
tickSpacing: PropTypes.number,
|
|
234
290
|
valueFormatter: PropTypes.func
|
|
235
291
|
})),
|
|
236
292
|
yAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
237
293
|
axisId: PropTypes.string,
|
|
238
294
|
classes: PropTypes.object,
|
|
239
295
|
data: PropTypes.array,
|
|
296
|
+
dataKey: PropTypes.string,
|
|
240
297
|
disableLine: PropTypes.bool,
|
|
241
298
|
disableTicks: PropTypes.bool,
|
|
242
299
|
fill: PropTypes.string,
|
|
300
|
+
hideTooltip: PropTypes.bool,
|
|
243
301
|
id: PropTypes.string,
|
|
244
302
|
label: PropTypes.string,
|
|
245
303
|
labelFontSize: PropTypes.number,
|
|
246
|
-
max: PropTypes.number,
|
|
247
|
-
|
|
248
|
-
min: PropTypes.number,
|
|
249
|
-
minTicks: PropTypes.number,
|
|
304
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
305
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
250
306
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
251
307
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
308
|
+
slotProps: PropTypes.object,
|
|
309
|
+
slots: PropTypes.object,
|
|
252
310
|
stroke: PropTypes.string,
|
|
253
311
|
tickFontSize: PropTypes.number,
|
|
312
|
+
tickMaxStep: PropTypes.number,
|
|
313
|
+
tickMinStep: PropTypes.number,
|
|
314
|
+
tickNumber: PropTypes.number,
|
|
254
315
|
tickSize: PropTypes.number,
|
|
255
|
-
tickSpacing: PropTypes.number,
|
|
256
316
|
valueFormatter: PropTypes.func
|
|
257
317
|
}))
|
|
258
318
|
} : void 0;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope"];
|
|
3
|
+
const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "slots", "slotProps"];
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import composeClasses from '@mui/utils/composeClasses';
|
|
6
|
+
import { useSlotProps } from '@mui/base/utils';
|
|
6
7
|
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
7
8
|
import { styled } from '@mui/material/styles';
|
|
8
9
|
import { color as d3Color } from 'd3-color';
|
|
@@ -24,7 +25,7 @@ const useUtilityClasses = ownerState => {
|
|
|
24
25
|
};
|
|
25
26
|
return composeClasses(slots, getBarElementUtilityClass, classes);
|
|
26
27
|
};
|
|
27
|
-
const BarElementPath = styled('rect', {
|
|
28
|
+
export const BarElementPath = styled('rect', {
|
|
28
29
|
name: 'MuiBarElement',
|
|
29
30
|
slot: 'Root',
|
|
30
31
|
overridesResolver: (_, styles) => styles.root
|
|
@@ -38,12 +39,15 @@ const BarElementPath = styled('rect', {
|
|
|
38
39
|
opacity: ownerState.isFaded && 0.3 || 1
|
|
39
40
|
}));
|
|
40
41
|
export function BarElement(props) {
|
|
42
|
+
var _slots$bar;
|
|
41
43
|
const {
|
|
42
44
|
id,
|
|
43
45
|
dataIndex,
|
|
44
46
|
classes: innerClasses,
|
|
45
47
|
color,
|
|
46
|
-
highlightScope
|
|
48
|
+
highlightScope,
|
|
49
|
+
slots,
|
|
50
|
+
slotProps
|
|
47
51
|
} = props,
|
|
48
52
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
49
53
|
const getInteractionItemProps = useInteractionItemProps(highlightScope);
|
|
@@ -69,12 +73,18 @@ export function BarElement(props) {
|
|
|
69
73
|
isHighlighted
|
|
70
74
|
};
|
|
71
75
|
const classes = useUtilityClasses(ownerState);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
const Bar = (_slots$bar = slots == null ? void 0 : slots.bar) != null ? _slots$bar : BarElementPath;
|
|
77
|
+
const barProps = useSlotProps({
|
|
78
|
+
elementType: Bar,
|
|
79
|
+
externalSlotProps: slotProps == null ? void 0 : slotProps.bar,
|
|
80
|
+
additionalProps: _extends({}, other, getInteractionItemProps({
|
|
81
|
+
type: 'bar',
|
|
82
|
+
seriesId: id,
|
|
83
|
+
dataIndex
|
|
84
|
+
}), {
|
|
85
|
+
className: classes.root
|
|
86
|
+
}),
|
|
87
|
+
ownerState
|
|
88
|
+
});
|
|
89
|
+
return /*#__PURE__*/_jsx(Bar, _extends({}, barProps));
|
|
80
90
|
}
|
package/esm/BarChart/BarPlot.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
2
4
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
3
5
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
4
6
|
import { BarElement } from './BarElement';
|
|
@@ -32,7 +34,7 @@ function getBandSize({
|
|
|
32
34
|
offset
|
|
33
35
|
};
|
|
34
36
|
}
|
|
35
|
-
|
|
37
|
+
function BarPlot(props) {
|
|
36
38
|
const seriesData = React.useContext(SeriesContext).bar;
|
|
37
39
|
const axisData = React.useContext(CartesianContext);
|
|
38
40
|
if (seriesData === undefined) {
|
|
@@ -89,7 +91,7 @@ export function BarPlot() {
|
|
|
89
91
|
var _xAxis$xAxisKey$data;
|
|
90
92
|
const baseline = Math.min(...values);
|
|
91
93
|
const value = Math.max(...values);
|
|
92
|
-
return /*#__PURE__*/_jsx(BarElement, {
|
|
94
|
+
return /*#__PURE__*/_jsx(BarElement, _extends({
|
|
93
95
|
id: seriesId,
|
|
94
96
|
dataIndex: dataIndex,
|
|
95
97
|
x: xScale((_xAxis$xAxisKey$data = xAxis[xAxisKey].data) == null ? void 0 : _xAxis$xAxisKey$data[dataIndex]) + groupIndex * (barWidth + offset),
|
|
@@ -98,9 +100,26 @@ export function BarPlot() {
|
|
|
98
100
|
width: barWidth,
|
|
99
101
|
color: color,
|
|
100
102
|
highlightScope: series[seriesId].highlightScope
|
|
101
|
-
}, `${seriesId}-${dataIndex}`);
|
|
103
|
+
}, props), `${seriesId}-${dataIndex}`);
|
|
102
104
|
});
|
|
103
105
|
});
|
|
104
106
|
})
|
|
105
107
|
});
|
|
106
|
-
}
|
|
108
|
+
}
|
|
109
|
+
process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
|
|
110
|
+
// ----------------------------- Warning --------------------------------
|
|
111
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
112
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
113
|
+
// ----------------------------------------------------------------------
|
|
114
|
+
/**
|
|
115
|
+
* The props used for each component slot.
|
|
116
|
+
* @default {}
|
|
117
|
+
*/
|
|
118
|
+
slotProps: PropTypes.object,
|
|
119
|
+
/**
|
|
120
|
+
* Overridable component slots.
|
|
121
|
+
* @default {}
|
|
122
|
+
*/
|
|
123
|
+
slots: PropTypes.object
|
|
124
|
+
} : void 0;
|
|
125
|
+
export { BarPlot };
|
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/esm/extends";
|
|
|
2
2
|
import { stack as d3Stack } from 'd3-shape';
|
|
3
3
|
import { getStackingGroups } from '../internals/stackSeries';
|
|
4
4
|
import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
|
|
5
|
-
const formatter = params => {
|
|
5
|
+
const formatter = (params, dataset) => {
|
|
6
6
|
const {
|
|
7
7
|
seriesOrder,
|
|
8
8
|
series
|
|
@@ -10,17 +10,22 @@ const formatter = params => {
|
|
|
10
10
|
const stackingGroups = getStackingGroups(params);
|
|
11
11
|
|
|
12
12
|
// Create a data set with format adapted to d3
|
|
13
|
-
const d3Dataset = [];
|
|
13
|
+
const d3Dataset = dataset != null ? dataset : [];
|
|
14
14
|
seriesOrder.forEach(id => {
|
|
15
|
-
series[id].data
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
const data = series[id].data;
|
|
16
|
+
if (data !== undefined) {
|
|
17
|
+
data.forEach((value, index) => {
|
|
18
|
+
if (d3Dataset.length <= index) {
|
|
19
|
+
d3Dataset.push({
|
|
20
|
+
[id]: value
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
d3Dataset[index][id] = value;
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
} else if (dataset === undefined) {
|
|
27
|
+
throw new Error([`MUI: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
28
|
+
}
|
|
24
29
|
});
|
|
25
30
|
const completedSeries = {};
|
|
26
31
|
stackingGroups.forEach(stackingGroup => {
|
|
@@ -30,9 +35,15 @@ const formatter = params => {
|
|
|
30
35
|
stackingOrder
|
|
31
36
|
} = stackingGroup;
|
|
32
37
|
// Get stacked values, and derive the domain
|
|
33
|
-
const stackedSeries = d3Stack().keys(ids
|
|
38
|
+
const stackedSeries = d3Stack().keys(ids.map(id => {
|
|
39
|
+
// Use dataKey if needed and available
|
|
40
|
+
const dataKey = series[id].dataKey;
|
|
41
|
+
return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
|
|
42
|
+
})).order(stackingOrder).offset(stackingOffset)(d3Dataset);
|
|
34
43
|
ids.forEach((id, index) => {
|
|
44
|
+
const dataKey = series[id].dataKey;
|
|
35
45
|
completedSeries[id] = _extends({}, series[id], {
|
|
46
|
+
data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
|
|
36
47
|
stackedData: stackedSeries[index].map(([a, b]) => [a, b])
|
|
37
48
|
});
|
|
38
49
|
});
|
|
@@ -16,6 +16,7 @@ export const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContai
|
|
|
16
16
|
xAxis,
|
|
17
17
|
yAxis,
|
|
18
18
|
colors,
|
|
19
|
+
dataset,
|
|
19
20
|
sx,
|
|
20
21
|
title,
|
|
21
22
|
desc,
|
|
@@ -32,9 +33,11 @@ export const ChartContainer = /*#__PURE__*/React.forwardRef(function ChartContai
|
|
|
32
33
|
children: /*#__PURE__*/_jsx(SeriesContextProvider, {
|
|
33
34
|
series: series,
|
|
34
35
|
colors: colors,
|
|
36
|
+
dataset: dataset,
|
|
35
37
|
children: /*#__PURE__*/_jsx(CartesianContextProvider, {
|
|
36
38
|
xAxis: xAxis,
|
|
37
39
|
yAxis: yAxis,
|
|
40
|
+
dataset: dataset,
|
|
38
41
|
children: /*#__PURE__*/_jsx(InteractionProvider, {
|
|
39
42
|
children: /*#__PURE__*/_jsx(HighlightProvider, {
|
|
40
43
|
children: /*#__PURE__*/_jsx(ChartsSurface, {
|