@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.
Files changed (90) hide show
  1. package/BarChart/BarChart.js +14 -6
  2. package/BarChart/formatter.js +23 -12
  3. package/CHANGELOG.md +92 -0
  4. package/ChartContainer/index.js +3 -0
  5. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  6. package/LineChart/AreaPlot.d.ts +1 -1
  7. package/LineChart/AreaPlot.js +4 -3
  8. package/LineChart/LineChart.js +14 -6
  9. package/LineChart/LinePlot.d.ts +1 -1
  10. package/LineChart/LinePlot.js +4 -3
  11. package/LineChart/MarkElement.js +1 -1
  12. package/LineChart/MarkPlot.d.ts +1 -1
  13. package/LineChart/MarkPlot.js +5 -3
  14. package/LineChart/formatter.js +23 -12
  15. package/PieChart/PieChart.js +9 -4
  16. package/ScatterChart/ScatterChart.js +9 -4
  17. package/SparkLineChart/SparkLineChart.d.ts +55 -0
  18. package/SparkLineChart/SparkLineChart.js +195 -0
  19. package/SparkLineChart/index.d.ts +1 -0
  20. package/SparkLineChart/index.js +12 -0
  21. package/SparkLineChart/package.json +6 -0
  22. package/context/CartesianContextProvider.d.ts +3 -1
  23. package/context/CartesianContextProvider.js +36 -6
  24. package/context/SeriesContextProvider.d.ts +3 -2
  25. package/context/SeriesContextProvider.js +5 -3
  26. package/esm/BarChart/BarChart.js +17 -6
  27. package/esm/BarChart/formatter.js +23 -12
  28. package/esm/ChartContainer/index.js +3 -0
  29. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  30. package/esm/LineChart/AreaPlot.js +4 -3
  31. package/esm/LineChart/LineChart.js +17 -6
  32. package/esm/LineChart/LinePlot.js +4 -3
  33. package/esm/LineChart/MarkElement.js +1 -1
  34. package/esm/LineChart/MarkPlot.js +4 -3
  35. package/esm/LineChart/formatter.js +23 -13
  36. package/esm/PieChart/PieChart.js +9 -4
  37. package/esm/ScatterChart/ScatterChart.js +9 -4
  38. package/esm/SparkLineChart/SparkLineChart.js +187 -0
  39. package/esm/SparkLineChart/index.js +1 -0
  40. package/esm/context/CartesianContextProvider.js +36 -6
  41. package/esm/context/SeriesContextProvider.js +5 -3
  42. package/esm/index.js +1 -0
  43. package/esm/models/index.js +3 -1
  44. package/index.d.ts +1 -0
  45. package/index.js +12 -1
  46. package/internals/defaultizeColor.d.ts +4 -2
  47. package/legacy/BarChart/BarChart.js +15 -6
  48. package/legacy/BarChart/formatter.js +23 -10
  49. package/legacy/ChartContainer/index.js +3 -0
  50. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  51. package/legacy/LineChart/AreaPlot.js +4 -3
  52. package/legacy/LineChart/LineChart.js +15 -6
  53. package/legacy/LineChart/LinePlot.js +4 -3
  54. package/legacy/LineChart/MarkElement.js +1 -1
  55. package/legacy/LineChart/MarkPlot.js +4 -3
  56. package/legacy/LineChart/formatter.js +23 -11
  57. package/legacy/PieChart/PieChart.js +9 -4
  58. package/legacy/ScatterChart/ScatterChart.js +9 -4
  59. package/legacy/SparkLineChart/SparkLineChart.js +191 -0
  60. package/legacy/SparkLineChart/index.js +1 -0
  61. package/legacy/context/CartesianContextProvider.js +45 -7
  62. package/legacy/context/SeriesContextProvider.js +6 -4
  63. package/legacy/index.js +2 -1
  64. package/legacy/models/index.js +3 -1
  65. package/models/axis.d.ts +10 -2
  66. package/models/index.d.ts +2 -0
  67. package/models/index.js +11 -0
  68. package/models/seriesType/bar.d.ts +8 -1
  69. package/models/seriesType/common.d.ts +2 -2
  70. package/models/seriesType/config.d.ts +4 -1
  71. package/models/seriesType/line.d.ts +8 -1
  72. package/modern/BarChart/BarChart.js +14 -6
  73. package/modern/BarChart/formatter.js +23 -12
  74. package/modern/ChartContainer/index.js +3 -0
  75. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  76. package/modern/LineChart/AreaPlot.js +4 -3
  77. package/modern/LineChart/LineChart.js +14 -6
  78. package/modern/LineChart/LinePlot.js +4 -3
  79. package/modern/LineChart/MarkElement.js +1 -1
  80. package/modern/LineChart/MarkPlot.js +4 -3
  81. package/modern/LineChart/formatter.js +23 -13
  82. package/modern/PieChart/PieChart.js +9 -4
  83. package/modern/ScatterChart/ScatterChart.js +9 -4
  84. package/modern/SparkLineChart/SparkLineChart.js +187 -0
  85. package/modern/SparkLineChart/index.js +1 -0
  86. package/modern/context/CartesianContextProvider.js +36 -6
  87. package/modern/context/SeriesContextProvider.js +5 -3
  88. package/modern/index.js +2 -1
  89. package/modern/models/index.js +3 -1
  90. 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,12 @@ 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 => s.data.length))
53
+ length: Math.max(...series.map(s => (s.data ?? dataset ?? []).length))
53
54
  }, (_, index) => index)
54
55
  }],
55
56
  yAxis: yAxis,
56
57
  colors: colors,
58
+ dataset: dataset,
57
59
  sx: sx,
58
60
  disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
59
61
  children: [/*#__PURE__*/_jsxs("g", {
@@ -102,6 +104,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
102
104
  * Color palette used to colorize multiple series.
103
105
  */
104
106
  colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
107
+ dataset: PropTypes.arrayOf(PropTypes.object),
105
108
  desc: PropTypes.string,
106
109
  disableAxisListener: PropTypes.bool,
107
110
  height: PropTypes.number,
@@ -167,7 +170,8 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
167
170
  area: PropTypes.bool,
168
171
  color: PropTypes.string,
169
172
  curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
170
- data: PropTypes.arrayOf(PropTypes.number).isRequired,
173
+ data: PropTypes.arrayOf(PropTypes.number),
174
+ dataKey: PropTypes.string,
171
175
  highlightScope: PropTypes.shape({
172
176
  faded: PropTypes.oneOf(['global', 'none', 'series']),
173
177
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
@@ -219,15 +223,17 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
219
223
  axisId: PropTypes.string,
220
224
  classes: PropTypes.object,
221
225
  data: PropTypes.array,
226
+ dataKey: PropTypes.string,
222
227
  disableLine: PropTypes.bool,
223
228
  disableTicks: PropTypes.bool,
224
229
  fill: PropTypes.string,
230
+ hideTooltip: PropTypes.bool,
225
231
  id: PropTypes.string,
226
232
  label: PropTypes.string,
227
233
  labelFontSize: PropTypes.number,
228
- max: PropTypes.number,
234
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
229
235
  maxTicks: PropTypes.number,
230
- min: PropTypes.number,
236
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
231
237
  minTicks: PropTypes.number,
232
238
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
233
239
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
@@ -241,15 +247,17 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
241
247
  axisId: PropTypes.string,
242
248
  classes: PropTypes.object,
243
249
  data: PropTypes.array,
250
+ dataKey: PropTypes.string,
244
251
  disableLine: PropTypes.bool,
245
252
  disableTicks: PropTypes.bool,
246
253
  fill: PropTypes.string,
254
+ hideTooltip: PropTypes.bool,
247
255
  id: PropTypes.string,
248
256
  label: PropTypes.string,
249
257
  labelFontSize: PropTypes.number,
250
- max: PropTypes.number,
258
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
251
259
  maxTicks: PropTypes.number,
252
- min: PropTypes.number,
260
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
253
261
  minTicks: PropTypes.number,
254
262
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
255
263
  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: (theme.vars || theme).palette.background.paper,
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 ?? [];
16
15
  seriesOrder.forEach(id => {
17
- series[id].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
- });
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).order(stackingOrder).offset(stackingOffset)(d3Dataset);
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
  });
@@ -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?.trigger !== 'axis') && axisHighlight?.x === 'none' && 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?.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?.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
  const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis) => {
43
68
  const getter = getters[chartType];
@@ -180,19 +205,22 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
180
205
  // | To update them edit the TypeScript types and run "yarn proptypes" |
181
206
  // ----------------------------------------------------------------------
182
207
  children: PropTypes.node,
208
+ dataset: PropTypes.arrayOf(PropTypes.object),
183
209
  xAxis: PropTypes.arrayOf(PropTypes.shape({
184
210
  axisId: PropTypes.string,
185
211
  classes: PropTypes.object,
186
212
  data: PropTypes.array,
213
+ dataKey: PropTypes.string,
187
214
  disableLine: PropTypes.bool,
188
215
  disableTicks: PropTypes.bool,
189
216
  fill: PropTypes.string,
217
+ hideTooltip: PropTypes.bool,
190
218
  id: PropTypes.string,
191
219
  label: PropTypes.string,
192
220
  labelFontSize: PropTypes.number,
193
- max: PropTypes.number,
221
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
194
222
  maxTicks: PropTypes.number,
195
- min: PropTypes.number,
223
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
196
224
  minTicks: PropTypes.number,
197
225
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
198
226
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
@@ -206,15 +234,17 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
206
234
  axisId: PropTypes.string,
207
235
  classes: PropTypes.object,
208
236
  data: PropTypes.array,
237
+ dataKey: PropTypes.string,
209
238
  disableLine: PropTypes.bool,
210
239
  disableTicks: PropTypes.bool,
211
240
  fill: PropTypes.string,
241
+ hideTooltip: PropTypes.bool,
212
242
  id: PropTypes.string,
213
243
  label: PropTypes.string,
214
244
  labelFontSize: PropTypes.number,
215
- max: PropTypes.number,
245
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
216
246
  maxTicks: PropTypes.number,
217
- min: PropTypes.number,
247
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
218
248
  minTicks: PropTypes.number,
219
249
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
220
250
  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) => {
@@ -49,18 +50,19 @@ const formatSeries = (series, colors) => {
49
50
  // Apply formater on a type group
50
51
  Object.keys(seriesTypeFormatter).forEach(type => {
51
52
  if (seriesGroups[type] !== undefined) {
52
- formattedSeries[type] = seriesTypeFormatter[type]?.(seriesGroups[type]) ?? seriesGroups[type];
53
+ formattedSeries[type] = seriesTypeFormatter[type]?.(seriesGroups[type], dataset) ?? seriesGroups[type];
53
54
  }
54
55
  });
55
56
  return formattedSeries;
56
57
  };
57
58
  export function SeriesContextProvider({
58
59
  series,
60
+ dataset,
59
61
  colors = blueberryTwilightPalette,
60
62
  children
61
63
  }) {
62
64
  const theme = useTheme();
63
- const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors), [series, colors, theme.palette.mode]);
65
+ const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, dataset), [series, colors, theme.palette.mode, dataset]);
64
66
  return /*#__PURE__*/_jsx(SeriesContext.Provider, {
65
67
  value: formattedSeries,
66
68
  children: children
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.5
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';
@@ -1 +1,3 @@
1
- export * from './seriesType';
1
+ export * from './seriesType';
2
+ export * from './layout';
3
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "6.0.0-alpha.5",
3
+ "version": "6.0.0-alpha.6",
4
4
  "description": "The community edition of the charts components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./index.js",
@@ -52,10 +52,12 @@
52
52
  },
53
53
  "exports": {
54
54
  ".": {
55
+ "types": "./index.d.ts",
55
56
  "require": "./index.js",
56
57
  "import": "./esm/index.js"
57
58
  },
58
59
  "./*": {
60
+ "types": "./*/index.d.ts",
59
61
  "require": "./*",
60
62
  "import": "./esm/*"
61
63
  }