@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
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import PropTypes from 'prop-types';
|
|
5
|
+
import { styled } from '@mui/material/styles';
|
|
6
|
+
import { BarPlot } from '../BarChart';
|
|
7
|
+
import { LinePlot, MarkPlot, AreaPlot, markElementClasses } from '../LineChart';
|
|
8
|
+
import { ResponsiveChartContainer } from '../ResponsiveChartContainer';
|
|
9
|
+
import { DEFAULT_X_AXIS_KEY } from '../constants';
|
|
10
|
+
import { ChartsTooltip } from '../ChartsTooltip';
|
|
11
|
+
import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
var SparkLineMarkPlot = styled(MarkPlot)(_defineProperty({}, "& .".concat(markElementClasses.root), _defineProperty({
|
|
15
|
+
display: 'none'
|
|
16
|
+
}, "&.".concat(markElementClasses.highlighted), {
|
|
17
|
+
display: 'inherit'
|
|
18
|
+
})));
|
|
19
|
+
var SPARKLINE_DEFAULT_MARGIN = {
|
|
20
|
+
top: 5,
|
|
21
|
+
bottom: 5,
|
|
22
|
+
left: 5,
|
|
23
|
+
right: 5
|
|
24
|
+
};
|
|
25
|
+
var SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
|
|
26
|
+
var xAxis = props.xAxis,
|
|
27
|
+
width = props.width,
|
|
28
|
+
height = props.height,
|
|
29
|
+
_props$margin = props.margin,
|
|
30
|
+
margin = _props$margin === void 0 ? SPARKLINE_DEFAULT_MARGIN : _props$margin,
|
|
31
|
+
colors = props.colors,
|
|
32
|
+
sx = props.sx,
|
|
33
|
+
showTooltip = props.showTooltip,
|
|
34
|
+
tooltip = props.tooltip,
|
|
35
|
+
showHighlight = props.showHighlight,
|
|
36
|
+
inAxisHighlight = props.axisHighlight,
|
|
37
|
+
children = props.children,
|
|
38
|
+
data = props.data,
|
|
39
|
+
_props$plotType = props.plotType,
|
|
40
|
+
plotType = _props$plotType === void 0 ? 'line' : _props$plotType,
|
|
41
|
+
_props$valueFormatter = props.valueFormatter,
|
|
42
|
+
valueFormatter = _props$valueFormatter === void 0 ? function (v) {
|
|
43
|
+
return v.toString();
|
|
44
|
+
} : _props$valueFormatter,
|
|
45
|
+
area = props.area,
|
|
46
|
+
_props$curve = props.curve,
|
|
47
|
+
curve = _props$curve === void 0 ? 'linear' : _props$curve;
|
|
48
|
+
var defaultXHighlight = showHighlight && plotType === 'bar' ? {
|
|
49
|
+
x: 'band'
|
|
50
|
+
} : {
|
|
51
|
+
x: 'none'
|
|
52
|
+
};
|
|
53
|
+
var axisHighlight = _extends({}, defaultXHighlight, inAxisHighlight);
|
|
54
|
+
return /*#__PURE__*/_jsxs(ResponsiveChartContainer, {
|
|
55
|
+
ref: ref,
|
|
56
|
+
series: [_extends({
|
|
57
|
+
type: plotType,
|
|
58
|
+
data: data,
|
|
59
|
+
valueFormatter: valueFormatter
|
|
60
|
+
}, plotType === 'bar' ? {} : {
|
|
61
|
+
area: area,
|
|
62
|
+
curve: curve
|
|
63
|
+
})],
|
|
64
|
+
width: width,
|
|
65
|
+
height: height,
|
|
66
|
+
margin: margin,
|
|
67
|
+
xAxis: [_extends({
|
|
68
|
+
id: DEFAULT_X_AXIS_KEY,
|
|
69
|
+
scaleType: plotType === 'bar' ? 'band' : 'linear',
|
|
70
|
+
data: Array.from({
|
|
71
|
+
length: data.length
|
|
72
|
+
}, function (_, index) {
|
|
73
|
+
return index;
|
|
74
|
+
}),
|
|
75
|
+
hideTooltip: xAxis === undefined
|
|
76
|
+
}, xAxis)],
|
|
77
|
+
colors: colors,
|
|
78
|
+
sx: sx,
|
|
79
|
+
disableAxisListener: (!showTooltip || (tooltip == null ? void 0 : tooltip.trigger) !== 'axis') && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
|
|
80
|
+
children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {}), plotType === 'line' && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
81
|
+
children: [/*#__PURE__*/_jsx(AreaPlot, {}), /*#__PURE__*/_jsx(LinePlot, {}), showHighlight && /*#__PURE__*/_jsx(SparkLineMarkPlot, {})]
|
|
82
|
+
}), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), showTooltip && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
|
|
86
|
+
// ----------------------------- Warning --------------------------------
|
|
87
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
88
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
89
|
+
// ----------------------------------------------------------------------
|
|
90
|
+
/**
|
|
91
|
+
* Set to `true` to fill spark line area.
|
|
92
|
+
* Has no effect if plotType='bar'.
|
|
93
|
+
* @default false
|
|
94
|
+
*/
|
|
95
|
+
area: PropTypes.bool,
|
|
96
|
+
axisHighlight: PropTypes.shape({
|
|
97
|
+
x: PropTypes.oneOf(['band', 'line', 'none']),
|
|
98
|
+
y: PropTypes.oneOf(['line', 'none'])
|
|
99
|
+
}),
|
|
100
|
+
children: PropTypes.node,
|
|
101
|
+
className: PropTypes.string,
|
|
102
|
+
/**
|
|
103
|
+
* Color palette used to colorize multiple series.
|
|
104
|
+
*/
|
|
105
|
+
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
106
|
+
/**
|
|
107
|
+
* @default 'linear'
|
|
108
|
+
*/
|
|
109
|
+
curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
|
|
110
|
+
/**
|
|
111
|
+
* Data to plot.
|
|
112
|
+
*/
|
|
113
|
+
data: PropTypes.arrayOf(PropTypes.number).isRequired,
|
|
114
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
115
|
+
desc: PropTypes.string,
|
|
116
|
+
disableAxisListener: PropTypes.bool,
|
|
117
|
+
height: PropTypes.number,
|
|
118
|
+
margin: PropTypes.shape({
|
|
119
|
+
bottom: PropTypes.number,
|
|
120
|
+
left: PropTypes.number,
|
|
121
|
+
right: PropTypes.number,
|
|
122
|
+
top: PropTypes.number
|
|
123
|
+
}),
|
|
124
|
+
/**
|
|
125
|
+
* Type of plot used.
|
|
126
|
+
* @default 'line'
|
|
127
|
+
*/
|
|
128
|
+
plotType: PropTypes.oneOf(['bar', 'line']),
|
|
129
|
+
/**
|
|
130
|
+
* Set to `true` to highlight the value.
|
|
131
|
+
* With line, it shows a point.
|
|
132
|
+
* With bar, it shows a highlight band.
|
|
133
|
+
* @default false
|
|
134
|
+
*/
|
|
135
|
+
showHighlight: PropTypes.bool,
|
|
136
|
+
/**
|
|
137
|
+
* Set to `true` to enable the tooltip in the sparkline.
|
|
138
|
+
* @default false
|
|
139
|
+
*/
|
|
140
|
+
showTooltip: PropTypes.bool,
|
|
141
|
+
sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
|
|
142
|
+
title: PropTypes.string,
|
|
143
|
+
tooltip: PropTypes.shape({
|
|
144
|
+
axisContent: PropTypes.elementType,
|
|
145
|
+
classes: PropTypes.object,
|
|
146
|
+
itemContent: PropTypes.elementType,
|
|
147
|
+
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
148
|
+
}),
|
|
149
|
+
/**
|
|
150
|
+
* Formatter used by the tooltip.
|
|
151
|
+
* @param {number} value The value to format.
|
|
152
|
+
* @returns {string} the formatted value.
|
|
153
|
+
*/
|
|
154
|
+
valueFormatter: PropTypes.func,
|
|
155
|
+
viewBox: PropTypes.shape({
|
|
156
|
+
height: PropTypes.number,
|
|
157
|
+
width: PropTypes.number,
|
|
158
|
+
x: PropTypes.number,
|
|
159
|
+
y: PropTypes.number
|
|
160
|
+
}),
|
|
161
|
+
width: PropTypes.number,
|
|
162
|
+
/**
|
|
163
|
+
* The xAxis configuration.
|
|
164
|
+
* Notice it is a single configuration object, not an array of configuration.
|
|
165
|
+
*/
|
|
166
|
+
xAxis: PropTypes.shape({
|
|
167
|
+
axisId: PropTypes.string,
|
|
168
|
+
classes: PropTypes.object,
|
|
169
|
+
data: PropTypes.array,
|
|
170
|
+
dataKey: PropTypes.string,
|
|
171
|
+
disableLine: PropTypes.bool,
|
|
172
|
+
disableTicks: PropTypes.bool,
|
|
173
|
+
fill: PropTypes.string,
|
|
174
|
+
hideTooltip: PropTypes.bool,
|
|
175
|
+
id: PropTypes.string,
|
|
176
|
+
label: PropTypes.string,
|
|
177
|
+
labelFontSize: PropTypes.number,
|
|
178
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
179
|
+
maxTicks: PropTypes.number,
|
|
180
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
181
|
+
minTicks: PropTypes.number,
|
|
182
|
+
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
183
|
+
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
184
|
+
stroke: PropTypes.string,
|
|
185
|
+
tickFontSize: PropTypes.number,
|
|
186
|
+
tickSize: PropTypes.number,
|
|
187
|
+
tickSpacing: PropTypes.number,
|
|
188
|
+
valueFormatter: PropTypes.func
|
|
189
|
+
})
|
|
190
|
+
} : void 0;
|
|
191
|
+
export { SparkLineChart };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SparkLineChart } from './SparkLineChart';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
1
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
2
|
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
5
|
import { scaleBand, scalePoint } from 'd3-scale';
|
|
6
6
|
import PropTypes from 'prop-types';
|
|
@@ -34,11 +34,44 @@ export var CartesianContext = /*#__PURE__*/React.createContext({
|
|
|
34
34
|
yAxisIds: []
|
|
35
35
|
});
|
|
36
36
|
function CartesianContextProvider(_ref) {
|
|
37
|
-
var
|
|
38
|
-
|
|
37
|
+
var inXAxis = _ref.xAxis,
|
|
38
|
+
inYAxis = _ref.yAxis,
|
|
39
|
+
dataset = _ref.dataset,
|
|
39
40
|
children = _ref.children;
|
|
40
41
|
var formattedSeries = React.useContext(SeriesContext);
|
|
41
42
|
var drawingArea = React.useContext(DrawingContext);
|
|
43
|
+
var xAxis = React.useMemo(function () {
|
|
44
|
+
return inXAxis == null ? void 0 : inXAxis.map(function (axisConfig) {
|
|
45
|
+
var dataKey = axisConfig.dataKey;
|
|
46
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
47
|
+
return axisConfig;
|
|
48
|
+
}
|
|
49
|
+
if (dataset === undefined) {
|
|
50
|
+
throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
|
|
51
|
+
}
|
|
52
|
+
return _extends({}, axisConfig, {
|
|
53
|
+
data: dataset.map(function (d) {
|
|
54
|
+
return d[dataKey];
|
|
55
|
+
})
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}, [inXAxis, dataset]);
|
|
59
|
+
var yAxis = React.useMemo(function () {
|
|
60
|
+
return inYAxis == null ? void 0 : inYAxis.map(function (axisConfig) {
|
|
61
|
+
var dataKey = axisConfig.dataKey;
|
|
62
|
+
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
63
|
+
return axisConfig;
|
|
64
|
+
}
|
|
65
|
+
if (dataset === undefined) {
|
|
66
|
+
throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
|
|
67
|
+
}
|
|
68
|
+
return _extends({}, axisConfig, {
|
|
69
|
+
data: dataset.map(function (d) {
|
|
70
|
+
return d[dataKey];
|
|
71
|
+
})
|
|
72
|
+
});
|
|
73
|
+
});
|
|
74
|
+
}, [inYAxis, dataset]);
|
|
42
75
|
var value = React.useMemo(function () {
|
|
43
76
|
var _xAxis$map, _yAxis$map;
|
|
44
77
|
var axisExtremumCallback = function axisExtremumCallback(acc, chartType, axis, getters, isDefaultAxis) {
|
|
@@ -206,19 +239,22 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
206
239
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
207
240
|
// ----------------------------------------------------------------------
|
|
208
241
|
children: PropTypes.node,
|
|
242
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
209
243
|
xAxis: PropTypes.arrayOf(PropTypes.shape({
|
|
210
244
|
axisId: PropTypes.string,
|
|
211
245
|
classes: PropTypes.object,
|
|
212
246
|
data: PropTypes.array,
|
|
247
|
+
dataKey: PropTypes.string,
|
|
213
248
|
disableLine: PropTypes.bool,
|
|
214
249
|
disableTicks: PropTypes.bool,
|
|
215
250
|
fill: PropTypes.string,
|
|
251
|
+
hideTooltip: PropTypes.bool,
|
|
216
252
|
id: PropTypes.string,
|
|
217
253
|
label: PropTypes.string,
|
|
218
254
|
labelFontSize: PropTypes.number,
|
|
219
|
-
max: PropTypes.number,
|
|
255
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
220
256
|
maxTicks: PropTypes.number,
|
|
221
|
-
min: PropTypes.number,
|
|
257
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
222
258
|
minTicks: PropTypes.number,
|
|
223
259
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
224
260
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -232,15 +268,17 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
|
|
|
232
268
|
axisId: PropTypes.string,
|
|
233
269
|
classes: PropTypes.object,
|
|
234
270
|
data: PropTypes.array,
|
|
271
|
+
dataKey: PropTypes.string,
|
|
235
272
|
disableLine: PropTypes.bool,
|
|
236
273
|
disableTicks: PropTypes.bool,
|
|
237
274
|
fill: PropTypes.string,
|
|
275
|
+
hideTooltip: PropTypes.bool,
|
|
238
276
|
id: PropTypes.string,
|
|
239
277
|
label: PropTypes.string,
|
|
240
278
|
labelFontSize: PropTypes.number,
|
|
241
|
-
max: PropTypes.number,
|
|
279
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
242
280
|
maxTicks: PropTypes.number,
|
|
243
|
-
min: PropTypes.number,
|
|
281
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
244
282
|
minTicks: PropTypes.number,
|
|
245
283
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
246
284
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -15,6 +15,7 @@ var 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 @@ var 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
|
-
var formatSeries = function formatSeries(series, colors) {
|
|
27
|
+
var formatSeries = function formatSeries(series, colors, dataset) {
|
|
27
28
|
// Group series by type
|
|
28
29
|
var seriesGroups = {};
|
|
29
30
|
series.forEach(function (seriesData, seriesIndex) {
|
|
@@ -50,20 +51,21 @@ var formatSeries = function formatSeries(series, colors) {
|
|
|
50
51
|
Object.keys(seriesTypeFormatter).forEach(function (type) {
|
|
51
52
|
if (seriesGroups[type] !== undefined) {
|
|
52
53
|
var _seriesTypeFormatter$, _seriesTypeFormatter$2;
|
|
53
|
-
formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type])) != null ? _seriesTypeFormatter$ : seriesGroups[type];
|
|
54
|
+
formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type], dataset)) != null ? _seriesTypeFormatter$ : seriesGroups[type];
|
|
54
55
|
}
|
|
55
56
|
});
|
|
56
57
|
return formattedSeries;
|
|
57
58
|
};
|
|
58
59
|
export function SeriesContextProvider(_ref) {
|
|
59
60
|
var series = _ref.series,
|
|
61
|
+
dataset = _ref.dataset,
|
|
60
62
|
_ref$colors = _ref.colors,
|
|
61
63
|
colors = _ref$colors === void 0 ? blueberryTwilightPalette : _ref$colors,
|
|
62
64
|
children = _ref.children;
|
|
63
65
|
var theme = useTheme();
|
|
64
66
|
var formattedSeries = React.useMemo(function () {
|
|
65
|
-
return formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors);
|
|
66
|
-
}, [series, colors, theme.palette.mode]);
|
|
67
|
+
return formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, dataset);
|
|
68
|
+
}, [series, colors, theme.palette.mode, dataset]);
|
|
67
69
|
return /*#__PURE__*/_jsx(SeriesContext.Provider, {
|
|
68
70
|
value: formattedSeries,
|
|
69
71
|
children: children
|
package/legacy/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
|
|
@@ -20,5 +20,6 @@ export * from './BarChart';
|
|
|
20
20
|
export * from './LineChart';
|
|
21
21
|
export * from './PieChart';
|
|
22
22
|
export * from './ScatterChart';
|
|
23
|
+
export * from './SparkLineChart';
|
|
23
24
|
export * from './ChartContainer';
|
|
24
25
|
export * from './ResponsiveChartContainer';
|
package/legacy/models/index.js
CHANGED
package/models/axis.d.ts
CHANGED
|
@@ -114,10 +114,18 @@ interface AxisScaleConfig {
|
|
|
114
114
|
}
|
|
115
115
|
export type AxisConfig<S extends ScaleName = ScaleName, V = any> = {
|
|
116
116
|
id: string;
|
|
117
|
-
min?: number;
|
|
118
|
-
max?: number;
|
|
117
|
+
min?: number | Date;
|
|
118
|
+
max?: number | Date;
|
|
119
119
|
data?: V[];
|
|
120
|
+
/**
|
|
121
|
+
* The key used to retrieve data from the dataset prop.
|
|
122
|
+
*/
|
|
123
|
+
dataKey?: string;
|
|
120
124
|
valueFormatter?: (value: V) => string;
|
|
125
|
+
/**
|
|
126
|
+
* If `true`, hide this value in the tooltip
|
|
127
|
+
*/
|
|
128
|
+
hideTooltip?: boolean;
|
|
121
129
|
} & Partial<ChartsXAxisProps | ChartsYAxisProps> & Partial<Omit<AxisScaleConfig[S], 'scale'>> & TickParams;
|
|
122
130
|
export type AxisDefaultized<S extends ScaleName = ScaleName, V = any> = Omit<AxisConfig<S, V>, 'scaleType'> & AxisScaleConfig[S] & {
|
|
123
131
|
ticksNumber: number;
|
package/models/index.d.ts
CHANGED
package/models/index.js
CHANGED
|
@@ -13,4 +13,15 @@ Object.keys(_seriesType).forEach(function (key) {
|
|
|
13
13
|
return _seriesType[key];
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
+
});
|
|
17
|
+
var _layout = require("./layout");
|
|
18
|
+
Object.keys(_layout).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _layout[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _layout[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
16
27
|
});
|
|
@@ -2,7 +2,14 @@ import { DefaultizedProps } from '../helpers';
|
|
|
2
2
|
import { CartesianSeriesType, CommonSeriesType, CommonDefaultizedProps, StackableSeriesType } from './common';
|
|
3
3
|
export interface BarSeriesType extends CommonSeriesType<number>, CartesianSeriesType, StackableSeriesType {
|
|
4
4
|
type: 'bar';
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Data associated to each bar.
|
|
7
|
+
*/
|
|
8
|
+
data?: number[];
|
|
9
|
+
/**
|
|
10
|
+
* The key used to retrive data from the dataset.
|
|
11
|
+
*/
|
|
12
|
+
dataKey?: string;
|
|
6
13
|
label?: string;
|
|
7
14
|
}
|
|
8
15
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HighlightScope } from '
|
|
1
|
+
import type { HighlightScope } from '../../context/HighlightProvider';
|
|
2
2
|
import type { StackOffset, StackOrder } from '../../internals/stackSeries';
|
|
3
3
|
export type CommonSeriesType<TValue> = {
|
|
4
4
|
id?: string;
|
|
@@ -11,7 +11,7 @@ export type CommonSeriesType<TValue> = {
|
|
|
11
11
|
valueFormatter?: (value: TValue) => string;
|
|
12
12
|
highlightScope?: Partial<HighlightScope>;
|
|
13
13
|
};
|
|
14
|
-
export type CommonDefaultizedProps = 'id' | 'valueFormatter';
|
|
14
|
+
export type CommonDefaultizedProps = 'id' | 'valueFormatter' | 'data';
|
|
15
15
|
export type CartesianSeriesType = {
|
|
16
16
|
xAxisKey?: string;
|
|
17
17
|
yAxisKey?: string;
|
|
@@ -73,7 +73,10 @@ export type FormatterResult<T extends ChartSeriesType> = {
|
|
|
73
73
|
} ? {
|
|
74
74
|
stackingGroups: StackingGroupsType;
|
|
75
75
|
} : {});
|
|
76
|
-
export type
|
|
76
|
+
export type DatasetType<T extends number | string | Date = number | string | Date> = {
|
|
77
|
+
[key: string]: T;
|
|
78
|
+
}[];
|
|
79
|
+
export type Formatter<T extends ChartSeriesType> = (params: FormatterParams<T>, dataset?: DatasetType<number>) => FormatterResult<T>;
|
|
77
80
|
export type LegendParams = {
|
|
78
81
|
/**
|
|
79
82
|
* The color used in the legend
|
|
@@ -3,7 +3,14 @@ import { CartesianSeriesType, CommonDefaultizedProps, CommonSeriesType, Stackabl
|
|
|
3
3
|
export type CurveType = 'catmullRom' | 'linear' | 'monotoneX' | 'monotoneY' | 'natural' | 'step' | 'stepBefore' | 'stepAfter';
|
|
4
4
|
export interface LineSeriesType extends CommonSeriesType<number>, CartesianSeriesType, StackableSeriesType {
|
|
5
5
|
type: 'line';
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* Data associated to the line.
|
|
8
|
+
*/
|
|
9
|
+
data?: number[];
|
|
10
|
+
/**
|
|
11
|
+
* The key used to retrive data from the dataset.
|
|
12
|
+
*/
|
|
13
|
+
dataKey?: string;
|
|
7
14
|
stack?: string;
|
|
8
15
|
area?: boolean;
|
|
9
16
|
label?: string;
|
|
@@ -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,
|
|
@@ -45,11 +46,12 @@ const BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
|
|
|
45
46
|
id: DEFAULT_X_AXIS_KEY,
|
|
46
47
|
scaleType: 'band',
|
|
47
48
|
data: Array.from({
|
|
48
|
-
length: Math.max(...series.map(s => s.data.length))
|
|
49
|
+
length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
|
|
49
50
|
}, (_, index) => index)
|
|
50
51
|
}],
|
|
51
52
|
yAxis: yAxis,
|
|
52
53
|
colors: colors,
|
|
54
|
+
dataset: dataset,
|
|
53
55
|
sx: sx,
|
|
54
56
|
disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
55
57
|
children: [/*#__PURE__*/_jsx("g", {
|
|
@@ -100,6 +102,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
100
102
|
* Color palette used to colorize multiple series.
|
|
101
103
|
*/
|
|
102
104
|
colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
|
|
105
|
+
dataset: PropTypes.arrayOf(PropTypes.object),
|
|
103
106
|
desc: PropTypes.string,
|
|
104
107
|
disableAxisListener: PropTypes.bool,
|
|
105
108
|
height: PropTypes.number,
|
|
@@ -163,7 +166,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
163
166
|
}), PropTypes.string]),
|
|
164
167
|
series: PropTypes.arrayOf(PropTypes.shape({
|
|
165
168
|
color: PropTypes.string,
|
|
166
|
-
data: PropTypes.arrayOf(PropTypes.number)
|
|
169
|
+
data: PropTypes.arrayOf(PropTypes.number),
|
|
170
|
+
dataKey: PropTypes.string,
|
|
167
171
|
highlightScope: PropTypes.shape({
|
|
168
172
|
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
169
173
|
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
@@ -215,15 +219,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
215
219
|
axisId: PropTypes.string,
|
|
216
220
|
classes: PropTypes.object,
|
|
217
221
|
data: PropTypes.array,
|
|
222
|
+
dataKey: PropTypes.string,
|
|
218
223
|
disableLine: PropTypes.bool,
|
|
219
224
|
disableTicks: PropTypes.bool,
|
|
220
225
|
fill: PropTypes.string,
|
|
226
|
+
hideTooltip: PropTypes.bool,
|
|
221
227
|
id: PropTypes.string,
|
|
222
228
|
label: PropTypes.string,
|
|
223
229
|
labelFontSize: PropTypes.number,
|
|
224
|
-
max: PropTypes.number,
|
|
230
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
225
231
|
maxTicks: PropTypes.number,
|
|
226
|
-
min: PropTypes.number,
|
|
232
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
227
233
|
minTicks: PropTypes.number,
|
|
228
234
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
229
235
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -237,15 +243,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
237
243
|
axisId: PropTypes.string,
|
|
238
244
|
classes: PropTypes.object,
|
|
239
245
|
data: PropTypes.array,
|
|
246
|
+
dataKey: PropTypes.string,
|
|
240
247
|
disableLine: PropTypes.bool,
|
|
241
248
|
disableTicks: PropTypes.bool,
|
|
242
249
|
fill: PropTypes.string,
|
|
250
|
+
hideTooltip: PropTypes.bool,
|
|
243
251
|
id: PropTypes.string,
|
|
244
252
|
label: PropTypes.string,
|
|
245
253
|
labelFontSize: PropTypes.number,
|
|
246
|
-
max: PropTypes.number,
|
|
254
|
+
max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
247
255
|
maxTicks: PropTypes.number,
|
|
248
|
-
min: PropTypes.number,
|
|
256
|
+
min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
|
|
249
257
|
minTicks: PropTypes.number,
|
|
250
258
|
position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
|
|
251
259
|
scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
|
|
@@ -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 ?? [];
|
|
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, {
|
|
@@ -23,7 +23,7 @@ export function DefaultChartsAxisContent(props) {
|
|
|
23
23
|
variant: "outlined",
|
|
24
24
|
className: classes.root,
|
|
25
25
|
children: /*#__PURE__*/_jsxs(ChartsTooltipTable, {
|
|
26
|
-
children: [axisValue != null && /*#__PURE__*/_jsx("thead", {
|
|
26
|
+
children: [axisValue != null && !axis.hideTooltip && /*#__PURE__*/_jsx("thead", {
|
|
27
27
|
children: /*#__PURE__*/_jsx(ChartsTooltipRow, {
|
|
28
28
|
children: /*#__PURE__*/_jsx(ChartsTooltipCell, {
|
|
29
29
|
colSpan: 3,
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { area as d3Area } from 'd3-shape';
|
|
3
4
|
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
@@ -6,7 +7,7 @@ import { AreaElement } from './AreaElement';
|
|
|
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 AreaPlot() {
|
|
10
|
+
export function AreaPlot(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 AreaPlot() {
|
|
|
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 AreaPlot() {
|
|
|
54
55
|
}, seriesId);
|
|
55
56
|
});
|
|
56
57
|
})
|
|
57
|
-
});
|
|
58
|
+
}));
|
|
58
59
|
}
|