@mui/x-charts 6.0.0-alpha.5 → 6.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BarChart/BarChart.js +14 -6
- package/BarChart/formatter.js +23 -12
- package/CHANGELOG.md +92 -0
- package/ChartContainer/index.js +3 -0
- package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/LineChart/AreaPlot.d.ts +1 -1
- package/LineChart/AreaPlot.js +4 -3
- package/LineChart/LineChart.js +14 -6
- package/LineChart/LinePlot.d.ts +1 -1
- package/LineChart/LinePlot.js +4 -3
- package/LineChart/MarkElement.js +1 -1
- package/LineChart/MarkPlot.d.ts +1 -1
- package/LineChart/MarkPlot.js +5 -3
- package/LineChart/formatter.js +23 -12
- package/PieChart/PieChart.js +9 -4
- package/ScatterChart/ScatterChart.js +9 -4
- package/SparkLineChart/SparkLineChart.d.ts +55 -0
- package/SparkLineChart/SparkLineChart.js +195 -0
- package/SparkLineChart/index.d.ts +1 -0
- package/SparkLineChart/index.js +12 -0
- package/SparkLineChart/package.json +6 -0
- package/context/CartesianContextProvider.d.ts +3 -1
- package/context/CartesianContextProvider.js +36 -6
- package/context/SeriesContextProvider.d.ts +3 -2
- package/context/SeriesContextProvider.js +5 -3
- package/esm/BarChart/BarChart.js +17 -6
- package/esm/BarChart/formatter.js +23 -12
- package/esm/ChartContainer/index.js +3 -0
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/LineChart/AreaPlot.js +4 -3
- package/esm/LineChart/LineChart.js +17 -6
- package/esm/LineChart/LinePlot.js +4 -3
- package/esm/LineChart/MarkElement.js +1 -1
- package/esm/LineChart/MarkPlot.js +4 -3
- package/esm/LineChart/formatter.js +23 -13
- package/esm/PieChart/PieChart.js +9 -4
- package/esm/ScatterChart/ScatterChart.js +9 -4
- package/esm/SparkLineChart/SparkLineChart.js +187 -0
- package/esm/SparkLineChart/index.js +1 -0
- package/esm/context/CartesianContextProvider.js +36 -6
- package/esm/context/SeriesContextProvider.js +5 -3
- package/esm/index.js +1 -0
- package/esm/models/index.js +3 -1
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/defaultizeColor.d.ts +4 -2
- package/legacy/BarChart/BarChart.js +15 -6
- package/legacy/BarChart/formatter.js +23 -10
- package/legacy/ChartContainer/index.js +3 -0
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/legacy/LineChart/AreaPlot.js +4 -3
- package/legacy/LineChart/LineChart.js +15 -6
- package/legacy/LineChart/LinePlot.js +4 -3
- package/legacy/LineChart/MarkElement.js +1 -1
- package/legacy/LineChart/MarkPlot.js +4 -3
- package/legacy/LineChart/formatter.js +23 -11
- package/legacy/PieChart/PieChart.js +9 -4
- package/legacy/ScatterChart/ScatterChart.js +9 -4
- package/legacy/SparkLineChart/SparkLineChart.js +191 -0
- package/legacy/SparkLineChart/index.js +1 -0
- package/legacy/context/CartesianContextProvider.js +45 -7
- package/legacy/context/SeriesContextProvider.js +6 -4
- package/legacy/index.js +2 -1
- package/legacy/models/index.js +3 -1
- package/models/axis.d.ts +10 -2
- 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 +14 -6
- package/modern/BarChart/formatter.js +23 -12
- package/modern/ChartContainer/index.js +3 -0
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/modern/LineChart/AreaPlot.js +4 -3
- package/modern/LineChart/LineChart.js +14 -6
- package/modern/LineChart/LinePlot.js +4 -3
- package/modern/LineChart/MarkElement.js +1 -1
- package/modern/LineChart/MarkPlot.js +4 -3
- package/modern/LineChart/formatter.js +23 -13
- package/modern/PieChart/PieChart.js +9 -4
- package/modern/ScatterChart/ScatterChart.js +9 -4
- package/modern/SparkLineChart/SparkLineChart.js +187 -0
- package/modern/SparkLineChart/index.js +1 -0
- package/modern/context/CartesianContextProvider.js +36 -6
- package/modern/context/SeriesContextProvider.js +5 -3
- package/modern/index.js +2 -1
- package/modern/models/index.js +3 -1
- package/package.json +3 -1
|
@@ -23,6 +23,7 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
23
23
|
height,
|
|
24
24
|
margin,
|
|
25
25
|
colors,
|
|
26
|
+
dataset,
|
|
26
27
|
sx,
|
|
27
28
|
tooltip,
|
|
28
29
|
axisHighlight = {
|
|
@@ -49,11 +50,15 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
|
|
|
49
50
|
id: DEFAULT_X_AXIS_KEY,
|
|
50
51
|
scaleType: 'point',
|
|
51
52
|
data: Array.from({
|
|
52
|
-
length: Math.max(...series.map(s =>
|
|
53
|
+
length: Math.max(...series.map(s => {
|
|
54
|
+
var _ref, _s$data;
|
|
55
|
+
return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
|
|
56
|
+
}))
|
|
53
57
|
}, (_, index) => index)
|
|
54
58
|
}],
|
|
55
59
|
yAxis: yAxis,
|
|
56
60
|
colors: colors,
|
|
61
|
+
dataset: dataset,
|
|
57
62
|
sx: sx,
|
|
58
63
|
disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
|
|
59
64
|
children: [/*#__PURE__*/_jsxs("g", {
|
|
@@ -102,6 +107,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
102
107
|
* Color palette used to colorize multiple series.
|
|
103
108
|
*/
|
|
104
109
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
110
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
105
111
|
desc: PropTypes.string,
|
|
106
112
|
disableAxisListener: PropTypes.bool,
|
|
107
113
|
height: PropTypes.number,
|
|
@@ -167,7 +173,8 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
167
173
|
area: PropTypes.bool,
|
|
168
174
|
color: PropTypes.string,
|
|
169
175
|
curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
|
|
170
|
-
data: PropTypes.arrayOf(PropTypes.number)
|
|
176
|
+
data: PropTypes.arrayOf(PropTypes.number),
|
|
177
|
+
dataKey: PropTypes.string,
|
|
171
178
|
highlightScope: PropTypes.shape({
|
|
172
179
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
173
180
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
@@ -219,15 +226,17 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
219
226
|
axisId: PropTypes.string,
|
|
220
227
|
classes: PropTypes.object,
|
|
221
228
|
data: PropTypes.array,
|
|
229
|
+
dataKey: PropTypes.string,
|
|
222
230
|
disableLine: PropTypes.bool,
|
|
223
231
|
disableTicks: PropTypes.bool,
|
|
224
232
|
fill: PropTypes.string,
|
|
233
|
+
hideTooltip: PropTypes.bool,
|
|
225
234
|
id: PropTypes.string,
|
|
226
235
|
label: PropTypes.string,
|
|
227
236
|
labelFontSize: PropTypes.number,
|
|
228
|
-
max: PropTypes.number,
|
|
237
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
229
238
|
maxTicks: PropTypes.number,
|
|
230
|
-
min: PropTypes.number,
|
|
239
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
231
240
|
minTicks: PropTypes.number,
|
|
232
241
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
233
242
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -241,15 +250,17 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
241
250
|
axisId: PropTypes.string,
|
|
242
251
|
classes: PropTypes.object,
|
|
243
252
|
data: PropTypes.array,
|
|
253
|
+
dataKey: PropTypes.string,
|
|
244
254
|
disableLine: PropTypes.bool,
|
|
245
255
|
disableTicks: PropTypes.bool,
|
|
246
256
|
fill: PropTypes.string,
|
|
257
|
+
hideTooltip: PropTypes.bool,
|
|
247
258
|
id: PropTypes.string,
|
|
248
259
|
label: PropTypes.string,
|
|
249
260
|
labelFontSize: PropTypes.number,
|
|
250
|
-
max: PropTypes.number,
|
|
261
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
251
262
|
maxTicks: PropTypes.number,
|
|
252
|
-
min: PropTypes.number,
|
|
263
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
253
264
|
minTicks: PropTypes.number,
|
|
254
265
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
255
266
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { line as d3Line } from 'd3-shape';
|
|
3
4
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
@@ -6,7 +7,7 @@ import { LineElement } from './LineElement';
|
|
|
6
7
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
7
8
|
import getCurveFactory from '../internals/getCurve';
|
|
8
9
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
9
|
-
export function LinePlot() {
|
|
10
|
+
export function LinePlot(props) {
|
|
10
11
|
const seriesData = React.useContext(SeriesContext).line;
|
|
11
12
|
const axisData = React.useContext(CartesianContext);
|
|
12
13
|
if (seriesData === undefined) {
|
|
@@ -24,7 +25,7 @@ export function LinePlot() {
|
|
|
24
25
|
} = axisData;
|
|
25
26
|
const defaultXAxisId = xAxisIds[0];
|
|
26
27
|
const defaultYAxisId = yAxisIds[0];
|
|
27
|
-
return /*#__PURE__*/_jsx("g", {
|
|
28
|
+
return /*#__PURE__*/_jsx("g", _extends({}, props, {
|
|
28
29
|
children: stackingGroups.flatMap(({
|
|
29
30
|
ids: groupIds
|
|
30
31
|
}) => {
|
|
@@ -54,5 +55,5 @@ export function LinePlot() {
|
|
|
54
55
|
}, seriesId);
|
|
55
56
|
});
|
|
56
57
|
})
|
|
57
|
-
});
|
|
58
|
+
}));
|
|
58
59
|
}
|
|
@@ -38,7 +38,7 @@ const MarkElementPath = styled('path', {
|
|
|
38
38
|
}) => ({
|
|
39
39
|
transform: `translate(${ownerState.x}px, ${ownerState.y}px)`,
|
|
40
40
|
transformOrigin: `${ownerState.x}px ${ownerState.y}px`,
|
|
41
|
-
fill:
|
|
41
|
+
fill: theme.palette.background.paper,
|
|
42
42
|
stroke: ownerState.color,
|
|
43
43
|
strokeWidth: 2,
|
|
44
44
|
'&.MuiMarkElement-highlighted': {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
3
4
|
import { CartesianContext } from '../context/CartesianContextProvider';
|
|
4
5
|
import { MarkElement } from './MarkElement';
|
|
5
6
|
import { getValueToPositionMapper } from '../hooks/useScale';
|
|
6
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
-
export function MarkPlot() {
|
|
8
|
+
export function MarkPlot(props) {
|
|
8
9
|
const seriesData = React.useContext(SeriesContext).line;
|
|
9
10
|
const axisData = React.useContext(CartesianContext);
|
|
10
11
|
if (seriesData === undefined) {
|
|
@@ -22,7 +23,7 @@ export function MarkPlot() {
|
|
|
22
23
|
} = axisData;
|
|
23
24
|
const defaultXAxisId = xAxisIds[0];
|
|
24
25
|
const defaultYAxisId = yAxisIds[0];
|
|
25
|
-
return /*#__PURE__*/_jsx("g", {
|
|
26
|
+
return /*#__PURE__*/_jsx("g", _extends({}, props, {
|
|
26
27
|
children: stackingGroups.flatMap(({
|
|
27
28
|
ids: groupIds
|
|
28
29
|
}) => {
|
|
@@ -74,5 +75,5 @@ export function MarkPlot() {
|
|
|
74
75
|
}, `${seriesId}-${index}`));
|
|
75
76
|
});
|
|
76
77
|
})
|
|
77
|
-
});
|
|
78
|
+
}));
|
|
78
79
|
}
|
|
@@ -2,9 +2,8 @@ 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
|
-
|
|
6
5
|
// For now it's a copy past of bar charts formatter, but maybe will diverge later
|
|
7
|
-
const formatter = params => {
|
|
6
|
+
const formatter = (params, dataset) => {
|
|
8
7
|
const {
|
|
9
8
|
seriesOrder,
|
|
10
9
|
series
|
|
@@ -12,17 +11,22 @@ const formatter = params => {
|
|
|
12
11
|
const stackingGroups = getStackingGroups(params);
|
|
13
12
|
|
|
14
13
|
// Create a data set with format adapted to d3
|
|
15
|
-
const d3Dataset = [];
|
|
14
|
+
const d3Dataset = dataset != null ? dataset : [];
|
|
16
15
|
seriesOrder.forEach(id => {
|
|
17
|
-
series[id].data
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
const data = series[id].data;
|
|
17
|
+
if (data !== undefined) {
|
|
18
|
+
data.forEach((value, index) => {
|
|
19
|
+
if (d3Dataset.length <= index) {
|
|
20
|
+
d3Dataset.push({
|
|
21
|
+
[id]: value
|
|
22
|
+
});
|
|
23
|
+
} else {
|
|
24
|
+
d3Dataset[index][id] = value;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
} else if (dataset === undefined) {
|
|
28
|
+
throw new Error([`MUI: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
29
|
+
}
|
|
26
30
|
});
|
|
27
31
|
const completedSeries = {};
|
|
28
32
|
stackingGroups.forEach(stackingGroup => {
|
|
@@ -32,9 +36,15 @@ const formatter = params => {
|
|
|
32
36
|
stackingOrder,
|
|
33
37
|
stackingOffset
|
|
34
38
|
} = stackingGroup;
|
|
35
|
-
const stackedSeries = d3Stack().keys(ids
|
|
39
|
+
const stackedSeries = d3Stack().keys(ids.map(id => {
|
|
40
|
+
// Use dataKey if needed and available
|
|
41
|
+
const dataKey = series[id].dataKey;
|
|
42
|
+
return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
|
|
43
|
+
})).order(stackingOrder).offset(stackingOffset)(d3Dataset);
|
|
36
44
|
ids.forEach((id, index) => {
|
|
45
|
+
const dataKey = series[id].dataKey;
|
|
37
46
|
completedSeries[id] = _extends({}, series[id], {
|
|
47
|
+
data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
|
|
38
48
|
stackedData: stackedSeries[index].map(([a, b]) => [a, b])
|
|
39
49
|
});
|
|
40
50
|
});
|
package/esm/PieChart/PieChart.js
CHANGED
|
@@ -104,6 +104,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
104
104
|
* Color palette used to colorize multiple series.
|
|
105
105
|
*/
|
|
106
106
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
107
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
107
108
|
desc: PropTypes.string,
|
|
108
109
|
disableAxisListener: PropTypes.bool,
|
|
109
110
|
height: PropTypes.number,
|
|
@@ -241,15 +242,17 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
241
242
|
axisId: PropTypes.string,
|
|
242
243
|
classes: PropTypes.object,
|
|
243
244
|
data: PropTypes.array,
|
|
245
|
+
dataKey: PropTypes.string,
|
|
244
246
|
disableLine: PropTypes.bool,
|
|
245
247
|
disableTicks: PropTypes.bool,
|
|
246
248
|
fill: PropTypes.string,
|
|
249
|
+
hideTooltip: PropTypes.bool,
|
|
247
250
|
id: PropTypes.string,
|
|
248
251
|
label: PropTypes.string,
|
|
249
252
|
labelFontSize: PropTypes.number,
|
|
250
|
-
max: PropTypes.number,
|
|
253
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
251
254
|
maxTicks: PropTypes.number,
|
|
252
|
-
min: PropTypes.number,
|
|
255
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
253
256
|
minTicks: PropTypes.number,
|
|
254
257
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
255
258
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -263,15 +266,17 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
|
|
|
263
266
|
axisId: PropTypes.string,
|
|
264
267
|
classes: PropTypes.object,
|
|
265
268
|
data: PropTypes.array,
|
|
269
|
+
dataKey: PropTypes.string,
|
|
266
270
|
disableLine: PropTypes.bool,
|
|
267
271
|
disableTicks: PropTypes.bool,
|
|
268
272
|
fill: PropTypes.string,
|
|
273
|
+
hideTooltip: PropTypes.bool,
|
|
269
274
|
id: PropTypes.string,
|
|
270
275
|
label: PropTypes.string,
|
|
271
276
|
labelFontSize: PropTypes.number,
|
|
272
|
-
max: PropTypes.number,
|
|
277
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
273
278
|
maxTicks: PropTypes.number,
|
|
274
|
-
min: PropTypes.number,
|
|
279
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
275
280
|
minTicks: PropTypes.number,
|
|
276
281
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
277
282
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -86,6 +86,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
86
86
|
* Color palette used to colorize multiple series.
|
|
87
87
|
*/
|
|
88
88
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
89
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
89
90
|
desc: PropTypes.string,
|
|
90
91
|
disableAxisListener: PropTypes.bool,
|
|
91
92
|
height: PropTypes.number,
|
|
@@ -203,15 +204,17 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
203
204
|
axisId: PropTypes.string,
|
|
204
205
|
classes: PropTypes.object,
|
|
205
206
|
data: PropTypes.array,
|
|
207
|
+
dataKey: PropTypes.string,
|
|
206
208
|
disableLine: PropTypes.bool,
|
|
207
209
|
disableTicks: PropTypes.bool,
|
|
208
210
|
fill: PropTypes.string,
|
|
211
|
+
hideTooltip: PropTypes.bool,
|
|
209
212
|
id: PropTypes.string,
|
|
210
213
|
label: PropTypes.string,
|
|
211
214
|
labelFontSize: PropTypes.number,
|
|
212
|
-
max: PropTypes.number,
|
|
215
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
213
216
|
maxTicks: PropTypes.number,
|
|
214
|
-
min: PropTypes.number,
|
|
217
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
215
218
|
minTicks: PropTypes.number,
|
|
216
219
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
217
220
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -225,15 +228,17 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
|
|
|
225
228
|
axisId: PropTypes.string,
|
|
226
229
|
classes: PropTypes.object,
|
|
227
230
|
data: PropTypes.array,
|
|
231
|
+
dataKey: PropTypes.string,
|
|
228
232
|
disableLine: PropTypes.bool,
|
|
229
233
|
disableTicks: PropTypes.bool,
|
|
230
234
|
fill: PropTypes.string,
|
|
235
|
+
hideTooltip: PropTypes.bool,
|
|
231
236
|
id: PropTypes.string,
|
|
232
237
|
label: PropTypes.string,
|
|
233
238
|
labelFontSize: PropTypes.number,
|
|
234
|
-
max: PropTypes.number,
|
|
239
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
235
240
|
maxTicks: PropTypes.number,
|
|
236
|
-
min: PropTypes.number,
|
|
241
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
237
242
|
minTicks: PropTypes.number,
|
|
238
243
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
239
244
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { styled } from '@mui/material/styles';
|
|
5
|
+
import { BarPlot } from '../BarChart';
|
|
6
|
+
import { LinePlot, MarkPlot, AreaPlot, markElementClasses } from '../LineChart';
|
|
7
|
+
import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
|
|
8
|
+
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
9
|
+
import { ChartsTooltip } from '../ChartsTooltip';
|
|
10
|
+
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
const SparkLineMarkPlot = styled(MarkPlot)({
|
|
14
|
+
[`& .${markElementClasses.root}`]: {
|
|
15
|
+
display: 'none',
|
|
16
|
+
[`&.${markElementClasses.highlighted}`]: {
|
|
17
|
+
display: 'inherit'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
const SPARKLINE_DEFAULT_MARGIN = {
|
|
22
|
+
top: 5,
|
|
23
|
+
bottom: 5,
|
|
24
|
+
left: 5,
|
|
25
|
+
right: 5
|
|
26
|
+
};
|
|
27
|
+
const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
|
|
28
|
+
const {
|
|
29
|
+
xAxis,
|
|
30
|
+
width,
|
|
31
|
+
height,
|
|
32
|
+
margin = SPARKLINE_DEFAULT_MARGIN,
|
|
33
|
+
colors,
|
|
34
|
+
sx,
|
|
35
|
+
showTooltip,
|
|
36
|
+
tooltip,
|
|
37
|
+
showHighlight,
|
|
38
|
+
axisHighlight: inAxisHighlight,
|
|
39
|
+
children,
|
|
40
|
+
data,
|
|
41
|
+
plotType = 'line',
|
|
42
|
+
valueFormatter = v => v.toString(),
|
|
43
|
+
area,
|
|
44
|
+
curve = 'linear'
|
|
45
|
+
} = props;
|
|
46
|
+
const defaultXHighlight = showHighlight && plotType === 'bar' ? {
|
|
47
|
+
x: 'band'
|
|
48
|
+
} : {
|
|
49
|
+
x: 'none'
|
|
50
|
+
};
|
|
51
|
+
const axisHighlight = _extends({}, defaultXHighlight, inAxisHighlight);
|
|
52
|
+
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
53
|
+
ref: ref,
|
|
54
|
+
series: [_extends({
|
|
55
|
+
type: plotType,
|
|
56
|
+
data,
|
|
57
|
+
valueFormatter
|
|
58
|
+
}, plotType === 'bar' ? {} : {
|
|
59
|
+
area,
|
|
60
|
+
curve
|
|
61
|
+
})],
|
|
62
|
+
width: width,
|
|
63
|
+
height: height,
|
|
64
|
+
margin: margin,
|
|
65
|
+
xAxis: [_extends({
|
|
66
|
+
id: DEFAULT_X_AXIS_KEY,
|
|
67
|
+
scaleType: plotType === 'bar' ? 'band' : 'linear',
|
|
68
|
+
data: Array.from({
|
|
69
|
+
length: data.length
|
|
70
|
+
}, (_, index) => index),
|
|
71
|
+
hideTooltip: xAxis === undefined
|
|
72
|
+
}, xAxis)],
|
|
73
|
+
colors: colors,
|
|
74
|
+
sx: sx,
|
|
75
|
+
disableAxisListener: (!showTooltip || (tooltip == null ? void 0 : tooltip.trigger) !== 'axis') && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
|
|
76
|
+
children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {}), plotType === 'line' && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
77
|
+
children: [/*#__PURE__*/_jsx(AreaPlot, {}), /*#__PURE__*/_jsx(LinePlot, {}), showHighlight && /*#__PURE__*/_jsx(SparkLineMarkPlot, {})]
|
|
78
|
+
}), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), showTooltip && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
82
|
+
// ----------------------------- Warning --------------------------------
|
|
83
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
84
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
85
|
+
// ----------------------------------------------------------------------
|
|
86
|
+
/**
|
|
87
|
+
* Set to `true` to fill spark line area.
|
|
88
|
+
* Has no effect if plotType='bar'.
|
|
89
|
+
* @default false
|
|
90
|
+
*/
|
|
91
|
+
area: PropTypes.bool,
|
|
92
|
+
axisHighlight: PropTypes.shape({
|
|
93
|
+
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
94
|
+
y: PropTypes.oneOf(['line', 'none'])
|
|
95
|
+
}),
|
|
96
|
+
children: PropTypes.node,
|
|
97
|
+
className: PropTypes.string,
|
|
98
|
+
/**
|
|
99
|
+
* Color palette used to colorize multiple series.
|
|
100
|
+
*/
|
|
101
|
+
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
102
|
+
/**
|
|
103
|
+
* @default 'linear'
|
|
104
|
+
*/
|
|
105
|
+
curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
|
|
106
|
+
/**
|
|
107
|
+
* Data to plot.
|
|
108
|
+
*/
|
|
109
|
+
data: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
110
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
111
|
+
desc: PropTypes.string,
|
|
112
|
+
disableAxisListener: PropTypes.bool,
|
|
113
|
+
height: PropTypes.number,
|
|
114
|
+
margin: PropTypes.shape({
|
|
115
|
+
bottom: PropTypes.number,
|
|
116
|
+
left: PropTypes.number,
|
|
117
|
+
right: PropTypes.number,
|
|
118
|
+
top: PropTypes.number
|
|
119
|
+
}),
|
|
120
|
+
/**
|
|
121
|
+
* Type of plot used.
|
|
122
|
+
* @default 'line'
|
|
123
|
+
*/
|
|
124
|
+
plotType: PropTypes.oneOf(['bar', 'line']),
|
|
125
|
+
/**
|
|
126
|
+
* Set to `true` to highlight the value.
|
|
127
|
+
* With line, it shows a point.
|
|
128
|
+
* With bar, it shows a highlight band.
|
|
129
|
+
* @default false
|
|
130
|
+
*/
|
|
131
|
+
showHighlight: PropTypes.bool,
|
|
132
|
+
/**
|
|
133
|
+
* Set to `true` to enable the tooltip in the sparkline.
|
|
134
|
+
* @default false
|
|
135
|
+
*/
|
|
136
|
+
showTooltip: PropTypes.bool,
|
|
137
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
138
|
+
title: PropTypes.string,
|
|
139
|
+
tooltip: PropTypes.shape({
|
|
140
|
+
axisContent: PropTypes.elementType,
|
|
141
|
+
classes: PropTypes.object,
|
|
142
|
+
itemContent: PropTypes.elementType,
|
|
143
|
+
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
144
|
+
}),
|
|
145
|
+
/**
|
|
146
|
+
* Formatter used by the tooltip.
|
|
147
|
+
* @param {number} value The value to format.
|
|
148
|
+
* @returns {string} the formatted value.
|
|
149
|
+
*/
|
|
150
|
+
valueFormatter: PropTypes.func,
|
|
151
|
+
viewBox: PropTypes.shape({
|
|
152
|
+
height: PropTypes.number,
|
|
153
|
+
width: PropTypes.number,
|
|
154
|
+
x: PropTypes.number,
|
|
155
|
+
y: PropTypes.number
|
|
156
|
+
}),
|
|
157
|
+
width: PropTypes.number,
|
|
158
|
+
/**
|
|
159
|
+
* The xAxis configuration.
|
|
160
|
+
* Notice it is a single configuration object, not an array of configuration.
|
|
161
|
+
*/
|
|
162
|
+
xAxis: PropTypes.shape({
|
|
163
|
+
axisId: PropTypes.string,
|
|
164
|
+
classes: PropTypes.object,
|
|
165
|
+
data: PropTypes.array,
|
|
166
|
+
dataKey: PropTypes.string,
|
|
167
|
+
disableLine: PropTypes.bool,
|
|
168
|
+
disableTicks: PropTypes.bool,
|
|
169
|
+
fill: PropTypes.string,
|
|
170
|
+
hideTooltip: PropTypes.bool,
|
|
171
|
+
id: PropTypes.string,
|
|
172
|
+
label: PropTypes.string,
|
|
173
|
+
labelFontSize: PropTypes.number,
|
|
174
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
175
|
+
maxTicks: PropTypes.number,
|
|
176
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
177
|
+
minTicks: PropTypes.number,
|
|
178
|
+
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
179
|
+
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
180
|
+
stroke: PropTypes.string,
|
|
181
|
+
tickFontSize: PropTypes.number,
|
|
182
|
+
tickSize: PropTypes.number,
|
|
183
|
+
tickSpacing: PropTypes.number,
|
|
184
|
+
valueFormatter: PropTypes.func
|
|
185
|
+
})
|
|
186
|
+
} : void 0;
|
|
187
|
+
export { SparkLineChart };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SparkLineChart } from './SparkLineChart';
|
|
@@ -32,12 +32,37 @@ export const CartesianContext = /*#__PURE__*/React.createContext({
|
|
|
32
32
|
yAxisIds: []
|
|
33
33
|
});
|
|
34
34
|
function CartesianContextProvider({
|
|
35
|
-
xAxis,
|
|
36
|
-
yAxis,
|
|
35
|
+
xAxis: inXAxis,
|
|
36
|
+
yAxis: inYAxis,
|
|
37
|
+
dataset,
|
|
37
38
|
children
|
|
38
39
|
}) {
|
|
39
40
|
const formattedSeries = React.useContext(SeriesContext);
|
|
40
41
|
const drawingArea = React.useContext(DrawingContext);
|
|
42
|
+
const xAxis = React.useMemo(() => inXAxis == null ? void 0 : inXAxis.map(axisConfig => {
|
|
43
|
+
const dataKey = axisConfig.dataKey;
|
|
44
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
45
|
+
return axisConfig;
|
|
46
|
+
}
|
|
47
|
+
if (dataset === undefined) {
|
|
48
|
+
throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
49
|
+
}
|
|
50
|
+
return _extends({}, axisConfig, {
|
|
51
|
+
data: dataset.map(d => d[dataKey])
|
|
52
|
+
});
|
|
53
|
+
}), [inXAxis, dataset]);
|
|
54
|
+
const yAxis = React.useMemo(() => inYAxis == null ? void 0 : inYAxis.map(axisConfig => {
|
|
55
|
+
const dataKey = axisConfig.dataKey;
|
|
56
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
57
|
+
return axisConfig;
|
|
58
|
+
}
|
|
59
|
+
if (dataset === undefined) {
|
|
60
|
+
throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
61
|
+
}
|
|
62
|
+
return _extends({}, axisConfig, {
|
|
63
|
+
data: dataset.map(d => d[dataKey])
|
|
64
|
+
});
|
|
65
|
+
}), [inYAxis, dataset]);
|
|
41
66
|
const value = React.useMemo(() => {
|
|
42
67
|
var _xAxis$map, _yAxis$map;
|
|
43
68
|
const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis) => {
|
|
@@ -186,19 +211,22 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
186
211
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
187
212
|
// ----------------------------------------------------------------------
|
|
188
213
|
children: PropTypes.node,
|
|
214
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
189
215
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
190
216
|
axisId: PropTypes.string,
|
|
191
217
|
classes: PropTypes.object,
|
|
192
218
|
data: PropTypes.array,
|
|
219
|
+
dataKey: PropTypes.string,
|
|
193
220
|
disableLine: PropTypes.bool,
|
|
194
221
|
disableTicks: PropTypes.bool,
|
|
195
222
|
fill: PropTypes.string,
|
|
223
|
+
hideTooltip: PropTypes.bool,
|
|
196
224
|
id: PropTypes.string,
|
|
197
225
|
label: PropTypes.string,
|
|
198
226
|
labelFontSize: PropTypes.number,
|
|
199
|
-
max: PropTypes.number,
|
|
227
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
200
228
|
maxTicks: PropTypes.number,
|
|
201
|
-
min: PropTypes.number,
|
|
229
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
202
230
|
minTicks: PropTypes.number,
|
|
203
231
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
204
232
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -212,15 +240,17 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
212
240
|
axisId: PropTypes.string,
|
|
213
241
|
classes: PropTypes.object,
|
|
214
242
|
data: PropTypes.array,
|
|
243
|
+
dataKey: PropTypes.string,
|
|
215
244
|
disableLine: PropTypes.bool,
|
|
216
245
|
disableTicks: PropTypes.bool,
|
|
217
246
|
fill: PropTypes.string,
|
|
247
|
+
hideTooltip: PropTypes.bool,
|
|
218
248
|
id: PropTypes.string,
|
|
219
249
|
label: PropTypes.string,
|
|
220
250
|
labelFontSize: PropTypes.number,
|
|
221
|
-
max: PropTypes.number,
|
|
251
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
222
252
|
maxTicks: PropTypes.number,
|
|
223
|
-
min: PropTypes.number,
|
|
253
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
224
254
|
minTicks: PropTypes.number,
|
|
225
255
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
226
256
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -15,6 +15,7 @@ const seriesTypeFormatter = {
|
|
|
15
15
|
line: lineSeriesFormatter,
|
|
16
16
|
pie: pieSeriesFormatter
|
|
17
17
|
};
|
|
18
|
+
|
|
18
19
|
/**
|
|
19
20
|
* This methods is the interface between what the developer is providing and what components receives
|
|
20
21
|
* To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if some line data are modified
|
|
@@ -23,7 +24,7 @@ const seriesTypeFormatter = {
|
|
|
23
24
|
* @param colors The color palette used to defaultize series colors
|
|
24
25
|
* @returns An object structuring all the series by type.
|
|
25
26
|
*/
|
|
26
|
-
const formatSeries = (series, colors) => {
|
|
27
|
+
const formatSeries = (series, colors, dataset) => {
|
|
27
28
|
// Group series by type
|
|
28
29
|
const seriesGroups = {};
|
|
29
30
|
series.forEach((seriesData, seriesIndex) => {
|
|
@@ -51,18 +52,19 @@ const formatSeries = (series, colors) => {
|
|
|
51
52
|
Object.keys(seriesTypeFormatter).forEach(type => {
|
|
52
53
|
if (seriesGroups[type] !== undefined) {
|
|
53
54
|
var _seriesTypeFormatter$, _seriesTypeFormatter$2;
|
|
54
|
-
formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type])) != null ? _seriesTypeFormatter$ : seriesGroups[type];
|
|
55
|
+
formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type], dataset)) != null ? _seriesTypeFormatter$ : seriesGroups[type];
|
|
55
56
|
}
|
|
56
57
|
});
|
|
57
58
|
return formattedSeries;
|
|
58
59
|
};
|
|
59
60
|
export function SeriesContextProvider({
|
|
60
61
|
series,
|
|
62
|
+
dataset,
|
|
61
63
|
colors = blueberryTwilightPalette,
|
|
62
64
|
children
|
|
63
65
|
}) {
|
|
64
66
|
const theme = useTheme();
|
|
65
|
-
const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors), [series, colors, theme.palette.mode]);
|
|
67
|
+
const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, dataset), [series, colors, theme.palette.mode, dataset]);
|
|
66
68
|
return /*#__PURE__*/_jsx(SeriesContext.Provider, {
|
|
67
69
|
value: formattedSeries,
|
|
68
70
|
children: children
|
package/esm/index.js
CHANGED
package/esm/models/index.js
CHANGED
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @mui/x-charts v6.0.0-alpha.
|
|
2
|
+
* @mui/x-charts v6.0.0-alpha.6
|
|
3
3
|
*
|
|
4
4
|
* @license MIT
|
|
5
5
|
* This source code is licensed under the MIT license found in the
|
|
@@ -175,6 +175,17 @@ Object.keys(_ScatterChart).forEach(function (key) {
|
|
|
175
175
|
}
|
|
176
176
|
});
|
|
177
177
|
});
|
|
178
|
+
var _SparkLineChart = require("./SparkLineChart");
|
|
179
|
+
Object.keys(_SparkLineChart).forEach(function (key) {
|
|
180
|
+
if (key === "default" || key === "__esModule") return;
|
|
181
|
+
if (key in exports && exports[key] === _SparkLineChart[key]) return;
|
|
182
|
+
Object.defineProperty(exports, key, {
|
|
183
|
+
enumerable: true,
|
|
184
|
+
get: function () {
|
|
185
|
+
return _SparkLineChart[key];
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
});
|
|
178
189
|
var _ChartContainer = require("./ChartContainer");
|
|
179
190
|
Object.keys(_ChartContainer).forEach(function (key) {
|
|
180
191
|
if (key === "default" || key === "__esModule") return;
|