@mui/x-charts 6.0.0-alpha.4 → 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 (104) hide show
  1. package/BarChart/BarChart.js +18 -10
  2. package/BarChart/formatter.js +23 -12
  3. package/CHANGELOG.md +156 -0
  4. package/ChartContainer/index.js +3 -0
  5. package/ChartsAxis/ChartsAxis.d.ts +4 -4
  6. package/ChartsAxis/ChartsAxis.js +4 -4
  7. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  8. package/LineChart/AreaPlot.d.ts +1 -1
  9. package/LineChart/AreaPlot.js +4 -3
  10. package/LineChart/LineChart.js +18 -10
  11. package/LineChart/LinePlot.d.ts +1 -1
  12. package/LineChart/LinePlot.js +4 -3
  13. package/LineChart/MarkElement.js +1 -1
  14. package/LineChart/MarkPlot.d.ts +1 -1
  15. package/LineChart/MarkPlot.js +5 -3
  16. package/LineChart/formatter.js +23 -12
  17. package/PieChart/PieChart.js +13 -8
  18. package/ScatterChart/Scatter.js +39 -53
  19. package/ScatterChart/ScatterChart.js +13 -8
  20. package/SparkLineChart/SparkLineChart.d.ts +55 -0
  21. package/SparkLineChart/SparkLineChart.js +195 -0
  22. package/SparkLineChart/index.d.ts +1 -0
  23. package/SparkLineChart/index.js +12 -0
  24. package/SparkLineChart/package.json +6 -0
  25. package/context/CartesianContextProvider.d.ts +3 -1
  26. package/context/CartesianContextProvider.js +36 -6
  27. package/context/DrawingProvider.d.ts +1 -1
  28. package/context/DrawingProvider.js +1 -1
  29. package/context/SeriesContextProvider.d.ts +3 -2
  30. package/context/SeriesContextProvider.js +5 -3
  31. package/esm/BarChart/BarChart.js +21 -10
  32. package/esm/BarChart/formatter.js +23 -12
  33. package/esm/ChartContainer/index.js +3 -0
  34. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  35. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  36. package/esm/LineChart/AreaPlot.js +4 -3
  37. package/esm/LineChart/LineChart.js +21 -10
  38. package/esm/LineChart/LinePlot.js +4 -3
  39. package/esm/LineChart/MarkElement.js +1 -1
  40. package/esm/LineChart/MarkPlot.js +4 -3
  41. package/esm/LineChart/formatter.js +23 -13
  42. package/esm/PieChart/PieChart.js +13 -8
  43. package/esm/ScatterChart/Scatter.js +39 -53
  44. package/esm/ScatterChart/ScatterChart.js +13 -8
  45. package/esm/SparkLineChart/SparkLineChart.js +187 -0
  46. package/esm/SparkLineChart/index.js +1 -0
  47. package/esm/context/CartesianContextProvider.js +36 -6
  48. package/esm/context/DrawingProvider.js +1 -1
  49. package/esm/context/SeriesContextProvider.js +5 -3
  50. package/esm/index.js +1 -0
  51. package/esm/models/index.js +3 -1
  52. package/index.d.ts +1 -0
  53. package/index.js +12 -1
  54. package/internals/defaultizeColor.d.ts +4 -2
  55. package/legacy/BarChart/BarChart.js +19 -10
  56. package/legacy/BarChart/formatter.js +23 -10
  57. package/legacy/ChartContainer/index.js +3 -0
  58. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  59. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  60. package/legacy/LineChart/AreaPlot.js +4 -3
  61. package/legacy/LineChart/LineChart.js +19 -10
  62. package/legacy/LineChart/LinePlot.js +4 -3
  63. package/legacy/LineChart/MarkElement.js +1 -1
  64. package/legacy/LineChart/MarkPlot.js +4 -3
  65. package/legacy/LineChart/formatter.js +23 -11
  66. package/legacy/PieChart/PieChart.js +13 -8
  67. package/legacy/ScatterChart/Scatter.js +35 -46
  68. package/legacy/ScatterChart/ScatterChart.js +13 -8
  69. package/legacy/SparkLineChart/SparkLineChart.js +191 -0
  70. package/legacy/SparkLineChart/index.js +1 -0
  71. package/legacy/context/CartesianContextProvider.js +45 -7
  72. package/legacy/context/DrawingProvider.js +1 -1
  73. package/legacy/context/SeriesContextProvider.js +6 -4
  74. package/legacy/index.js +2 -1
  75. package/legacy/models/index.js +3 -1
  76. package/models/axis.d.ts +10 -2
  77. package/models/index.d.ts +2 -0
  78. package/models/index.js +11 -0
  79. package/models/seriesType/bar.d.ts +8 -1
  80. package/models/seriesType/common.d.ts +2 -2
  81. package/models/seriesType/config.d.ts +4 -1
  82. package/models/seriesType/line.d.ts +8 -1
  83. package/modern/BarChart/BarChart.js +18 -10
  84. package/modern/BarChart/formatter.js +23 -12
  85. package/modern/ChartContainer/index.js +3 -0
  86. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  87. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  88. package/modern/LineChart/AreaPlot.js +4 -3
  89. package/modern/LineChart/LineChart.js +18 -10
  90. package/modern/LineChart/LinePlot.js +4 -3
  91. package/modern/LineChart/MarkElement.js +1 -1
  92. package/modern/LineChart/MarkPlot.js +4 -3
  93. package/modern/LineChart/formatter.js +23 -13
  94. package/modern/PieChart/PieChart.js +13 -8
  95. package/modern/ScatterChart/Scatter.js +39 -53
  96. package/modern/ScatterChart/ScatterChart.js +13 -8
  97. package/modern/SparkLineChart/SparkLineChart.js +187 -0
  98. package/modern/SparkLineChart/index.js +1 -0
  99. package/modern/context/CartesianContextProvider.js +36 -6
  100. package/modern/context/DrawingProvider.js +1 -1
  101. package/modern/context/SeriesContextProvider.js +5 -3
  102. package/modern/index.js +2 -1
  103. package/modern/models/index.js +3 -1
  104. package/package.json +3 -1
@@ -43,12 +43,37 @@ const CartesianContext = /*#__PURE__*/React.createContext({
43
43
  });
44
44
  exports.CartesianContext = CartesianContext;
45
45
  function CartesianContextProvider({
46
- xAxis,
47
- yAxis,
46
+ xAxis: inXAxis,
47
+ yAxis: inYAxis,
48
+ dataset,
48
49
  children
49
50
  }) {
50
51
  const formattedSeries = React.useContext(_SeriesContextProvider.SeriesContext);
51
52
  const drawingArea = React.useContext(_DrawingProvider.DrawingContext);
53
+ const xAxis = React.useMemo(() => inXAxis?.map(axisConfig => {
54
+ const dataKey = axisConfig.dataKey;
55
+ if (dataKey === undefined || axisConfig.data !== undefined) {
56
+ return axisConfig;
57
+ }
58
+ if (dataset === undefined) {
59
+ throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
60
+ }
61
+ return (0, _extends2.default)({}, axisConfig, {
62
+ data: dataset.map(d => d[dataKey])
63
+ });
64
+ }), [inXAxis, dataset]);
65
+ const yAxis = React.useMemo(() => inYAxis?.map(axisConfig => {
66
+ const dataKey = axisConfig.dataKey;
67
+ if (dataKey === undefined || axisConfig.data !== undefined) {
68
+ return axisConfig;
69
+ }
70
+ if (dataset === undefined) {
71
+ throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
72
+ }
73
+ return (0, _extends2.default)({}, axisConfig, {
74
+ data: dataset.map(d => d[dataKey])
75
+ });
76
+ }), [inYAxis, dataset]);
52
77
  const value = React.useMemo(() => {
53
78
  const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis) => {
54
79
  const getter = getters[chartType];
@@ -191,19 +216,22 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
191
216
  // | To update them edit the TypeScript types and run "yarn proptypes" |
192
217
  // ----------------------------------------------------------------------
193
218
  children: _propTypes.default.node,
219
+ dataset: _propTypes.default.arrayOf(_propTypes.default.object),
194
220
  xAxis: _propTypes.default.arrayOf(_propTypes.default.shape({
195
221
  axisId: _propTypes.default.string,
196
222
  classes: _propTypes.default.object,
197
223
  data: _propTypes.default.array,
224
+ dataKey: _propTypes.default.string,
198
225
  disableLine: _propTypes.default.bool,
199
226
  disableTicks: _propTypes.default.bool,
200
227
  fill: _propTypes.default.string,
228
+ hideTooltip: _propTypes.default.bool,
201
229
  id: _propTypes.default.string,
202
230
  label: _propTypes.default.string,
203
231
  labelFontSize: _propTypes.default.number,
204
- max: _propTypes.default.number,
232
+ max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
205
233
  maxTicks: _propTypes.default.number,
206
- min: _propTypes.default.number,
234
+ min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
207
235
  minTicks: _propTypes.default.number,
208
236
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
209
237
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
@@ -217,15 +245,17 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
217
245
  axisId: _propTypes.default.string,
218
246
  classes: _propTypes.default.object,
219
247
  data: _propTypes.default.array,
248
+ dataKey: _propTypes.default.string,
220
249
  disableLine: _propTypes.default.bool,
221
250
  disableTicks: _propTypes.default.bool,
222
251
  fill: _propTypes.default.string,
252
+ hideTooltip: _propTypes.default.bool,
223
253
  id: _propTypes.default.string,
224
254
  label: _propTypes.default.string,
225
255
  labelFontSize: _propTypes.default.number,
226
- max: _propTypes.default.number,
256
+ max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
227
257
  maxTicks: _propTypes.default.number,
228
- min: _propTypes.default.number,
258
+ min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
229
259
  minTicks: _propTypes.default.number,
230
260
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
231
261
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
@@ -5,7 +5,7 @@ export interface DrawingProviderProps extends LayoutConfig {
5
5
  svgRef: React.RefObject<SVGSVGElement>;
6
6
  }
7
7
  /**
8
- * Defines the area in which it is possible to draw the charts
8
+ * Defines the area in which it is possible to draw the charts.
9
9
  */
10
10
  export type DrawingArea = {
11
11
  left: number;
@@ -14,7 +14,7 @@ var _jsxRuntime = require("react/jsx-runtime");
14
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
16
  /**
17
- * Defines the area in which it is possible to draw the charts
17
+ * Defines the area in which it is possible to draw the charts.
18
18
  */
19
19
 
20
20
  const DrawingContext = /*#__PURE__*/React.createContext({
@@ -1,8 +1,9 @@
1
1
  import * as React from 'react';
2
2
  import { AllSeriesType } from '../models/seriesType';
3
- import { ChartSeriesType, FormatterResult } from '../models/seriesType/config';
3
+ import { ChartSeriesType, DatasetType, FormatterResult } from '../models/seriesType/config';
4
4
  import { ChartsColorPalette } from '../colorPalettes';
5
5
  export type SeriesContextProviderProps = {
6
+ dataset?: DatasetType;
6
7
  series: AllSeriesType[];
7
8
  /**
8
9
  * Color palette used to colorize multiple series.
@@ -14,4 +15,4 @@ export type FormattedSeries = {
14
15
  [type in ChartSeriesType]?: FormatterResult<type>;
15
16
  };
16
17
  export declare const SeriesContext: React.Context<FormattedSeries>;
17
- export declare function SeriesContextProvider({ series, colors, children, }: SeriesContextProviderProps): React.JSX.Element;
18
+ export declare function SeriesContextProvider({ series, dataset, colors, children, }: SeriesContextProviderProps): React.JSX.Element;
@@ -26,6 +26,7 @@ const seriesTypeFormatter = {
26
26
  line: _formatter3.default,
27
27
  pie: _formatter4.default
28
28
  };
29
+
29
30
  /**
30
31
  * This methods is the interface between what the developer is providing and what components receives
31
32
  * To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if some line data are modified
@@ -34,7 +35,7 @@ const seriesTypeFormatter = {
34
35
  * @param colors The color palette used to defaultize series colors
35
36
  * @returns An object structuring all the series by type.
36
37
  */
37
- const formatSeries = (series, colors) => {
38
+ const formatSeries = (series, colors, dataset) => {
38
39
  // Group series by type
39
40
  const seriesGroups = {};
40
41
  series.forEach((seriesData, seriesIndex) => {
@@ -60,18 +61,19 @@ const formatSeries = (series, colors) => {
60
61
  // Apply formater on a type group
61
62
  Object.keys(seriesTypeFormatter).forEach(type => {
62
63
  if (seriesGroups[type] !== undefined) {
63
- formattedSeries[type] = seriesTypeFormatter[type]?.(seriesGroups[type]) ?? seriesGroups[type];
64
+ formattedSeries[type] = seriesTypeFormatter[type]?.(seriesGroups[type], dataset) ?? seriesGroups[type];
64
65
  }
65
66
  });
66
67
  return formattedSeries;
67
68
  };
68
69
  function SeriesContextProvider({
69
70
  series,
71
+ dataset,
70
72
  colors = _colorPalettes.blueberryTwilightPalette,
71
73
  children
72
74
  }) {
73
75
  const theme = (0, _styles.useTheme)();
74
- const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors), [series, colors, theme.palette.mode]);
76
+ const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, dataset), [series, colors, theme.palette.mode, dataset]);
75
77
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(SeriesContext.Provider, {
76
78
  value: formattedSeries,
77
79
  children: children
@@ -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,15 @@ 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 => {
50
+ var _ref, _s$data;
51
+ return ((_ref = (_s$data = s.data) != null ? _s$data : dataset) != null ? _ref : []).length;
52
+ }))
49
53
  }, (_, index) => index)
50
54
  }],
51
55
  yAxis: yAxis,
52
56
  colors: colors,
57
+ dataset: dataset,
53
58
  sx: sx,
54
59
  disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
55
60
  children: [/*#__PURE__*/_jsx("g", {
@@ -78,7 +83,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
78
83
  }),
79
84
  /**
80
85
  * Indicate which axis to display the bottom of the charts.
81
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
86
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
82
87
  * @default xAxisIds[0] The id of the first provided axis
83
88
  */
84
89
  bottomAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -100,12 +105,13 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
100
105
  * Color palette used to colorize multiple series.
101
106
  */
102
107
  colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
108
+ dataset: PropTypes.arrayOf(PropTypes.object),
103
109
  desc: PropTypes.string,
104
110
  disableAxisListener: PropTypes.bool,
105
111
  height: PropTypes.number,
106
112
  /**
107
113
  * Indicate which axis to display the left of the charts.
108
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
114
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
109
115
  * @default yAxisIds[0] The id of the first provided axis
110
116
  */
111
117
  leftAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -145,7 +151,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
145
151
  }),
146
152
  /**
147
153
  * Indicate which axis to display the right of the charts.
148
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
154
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
149
155
  * @default null
150
156
  */
151
157
  rightAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -163,7 +169,8 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
163
169
  }), PropTypes.string]),
164
170
  series: PropTypes.arrayOf(PropTypes.shape({
165
171
  color: PropTypes.string,
166
- data: PropTypes.arrayOf(PropTypes.number).isRequired,
172
+ data: PropTypes.arrayOf(PropTypes.number),
173
+ dataKey: PropTypes.string,
167
174
  highlightScope: PropTypes.shape({
168
175
  faded: PropTypes.oneOf(['global', 'none', 'series']),
169
176
  highlighted: PropTypes.oneOf(['item', 'none', 'series'])
@@ -188,7 +195,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
188
195
  }),
189
196
  /**
190
197
  * Indicate which axis to display the top of the charts.
191
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
198
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
192
199
  * @default null
193
200
  */
194
201
  topAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -215,15 +222,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
215
222
  axisId: PropTypes.string,
216
223
  classes: PropTypes.object,
217
224
  data: PropTypes.array,
225
+ dataKey: PropTypes.string,
218
226
  disableLine: PropTypes.bool,
219
227
  disableTicks: PropTypes.bool,
220
228
  fill: PropTypes.string,
229
+ hideTooltip: PropTypes.bool,
221
230
  id: PropTypes.string,
222
231
  label: PropTypes.string,
223
232
  labelFontSize: PropTypes.number,
224
- max: PropTypes.number,
233
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
225
234
  maxTicks: PropTypes.number,
226
- min: PropTypes.number,
235
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
227
236
  minTicks: PropTypes.number,
228
237
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
229
238
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
@@ -237,15 +246,17 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
237
246
  axisId: PropTypes.string,
238
247
  classes: PropTypes.object,
239
248
  data: PropTypes.array,
249
+ dataKey: PropTypes.string,
240
250
  disableLine: PropTypes.bool,
241
251
  disableTicks: PropTypes.bool,
242
252
  fill: PropTypes.string,
253
+ hideTooltip: PropTypes.bool,
243
254
  id: PropTypes.string,
244
255
  label: PropTypes.string,
245
256
  labelFontSize: PropTypes.number,
246
- max: PropTypes.number,
257
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
247
258
  maxTicks: PropTypes.number,
248
- min: PropTypes.number,
259
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
249
260
  minTicks: PropTypes.number,
250
261
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
251
262
  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 != null ? dataset : [];
14
14
  seriesOrder.forEach(id => {
15
- series[id].data.forEach((value, index) => {
16
- if (d3Dataset.length <= index) {
17
- d3Dataset.push({
18
- [id]: value
19
- });
20
- } else {
21
- d3Dataset[index][id] = value;
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).order(stackingOrder).offset(stackingOffset)(d3Dataset);
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, {
@@ -71,7 +71,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
71
71
  // ----------------------------------------------------------------------
72
72
  /**
73
73
  * Indicate which axis to display the bottom of the charts.
74
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
74
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
75
75
  * @default xAxisIds[0] The id of the first provided axis
76
76
  */
77
77
  bottomAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -89,7 +89,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
89
89
  }), PropTypes.string]),
90
90
  /**
91
91
  * Indicate which axis to display the left of the charts.
92
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
92
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
93
93
  * @default yAxisIds[0] The id of the first provided axis
94
94
  */
95
95
  leftAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -107,7 +107,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
107
107
  }), PropTypes.string]),
108
108
  /**
109
109
  * Indicate which axis to display the right of the charts.
110
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
110
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
111
111
  * @default null
112
112
  */
113
113
  rightAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -125,7 +125,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
125
125
  }), PropTypes.string]),
126
126
  /**
127
127
  * Indicate which axis to display the top of the charts.
128
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
128
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
129
129
  * @default null
130
130
  */
131
131
  topAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -24,7 +24,7 @@ export function DefaultChartsAxisContent(props) {
24
24
  variant: "outlined",
25
25
  className: classes.root,
26
26
  children: /*#__PURE__*/_jsxs(ChartsTooltipTable, {
27
- children: [axisValue != null && /*#__PURE__*/_jsx("thead", {
27
+ children: [axisValue != null && !axis.hideTooltip && /*#__PURE__*/_jsx("thead", {
28
28
  children: /*#__PURE__*/_jsx(ChartsTooltipRow, {
29
29
  children: /*#__PURE__*/_jsx(ChartsTooltipCell, {
30
30
  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
  }
@@ -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 => s.data.length))
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", {
@@ -80,7 +85,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
80
85
  }),
81
86
  /**
82
87
  * Indicate which axis to display the bottom of the charts.
83
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
88
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
84
89
  * @default xAxisIds[0] The id of the first provided axis
85
90
  */
86
91
  bottomAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -102,12 +107,13 @@ 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,
108
114
  /**
109
115
  * Indicate which axis to display the left of the charts.
110
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
116
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
111
117
  * @default yAxisIds[0] The id of the first provided axis
112
118
  */
113
119
  leftAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -147,7 +153,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
147
153
  }),
148
154
  /**
149
155
  * Indicate which axis to display the right of the charts.
150
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
156
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
151
157
  * @default null
152
158
  */
153
159
  rightAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -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).isRequired,
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'])
@@ -192,7 +199,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
192
199
  }),
193
200
  /**
194
201
  * Indicate which axis to display the top of the charts.
195
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
202
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
196
203
  * @default null
197
204
  */
198
205
  topAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -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: (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
  }