@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
@@ -16,62 +16,48 @@ function Scatter(props) {
16
16
  const {
17
17
  item
18
18
  } = React.useContext(InteractionContext);
19
- const getXPosition = getValueToPositionMapper(xScale);
20
- const getYPosition = getValueToPositionMapper(yScale);
21
19
  const getInteractionItemProps = useInteractionItemProps(series.highlightScope);
22
- const xRange = xScale.range();
23
- const yRange = yScale.range();
24
- const isInRange = ({
25
- x,
26
- y
27
- }) => {
28
- if (x < Math.min(...xRange) || x > Math.max(...xRange)) {
29
- return false;
30
- }
31
- if (y < Math.min(...yRange) || y > Math.max(...yRange)) {
32
- return false;
33
- }
34
- return true;
35
- };
36
- return /*#__PURE__*/_jsx("g", {
37
- children: series.data.map(({
38
- x,
39
- y,
40
- id
41
- }, index) => ({
42
- x: getXPosition(x),
43
- y: getYPosition(y),
44
- id,
45
- dataIndex: index
46
- })).filter(isInRange).map(({
47
- x,
48
- y,
49
- id,
50
- dataIndex
51
- }) => {
52
- const isHighlighted = getIsHighlighted(item, {
53
- type: 'scatter',
54
- seriesId: series.id,
55
- dataIndex
56
- }, series.highlightScope);
57
- const isFaded = !isHighlighted && getIsFaded(item, {
20
+ const cleanData = React.useMemo(() => {
21
+ const getXPosition = getValueToPositionMapper(xScale);
22
+ const getYPosition = getValueToPositionMapper(yScale);
23
+ const xRange = xScale.range();
24
+ const yRange = yScale.range();
25
+ const minXRange = Math.min(...xRange);
26
+ const maxXRange = Math.max(...xRange);
27
+ const minYRange = Math.min(...yRange);
28
+ const maxYRange = Math.max(...yRange);
29
+ const temp = [];
30
+ for (let i = 0; i < series.data.length; i += 1) {
31
+ const scatterPoint = series.data[i];
32
+ const x = getXPosition(scatterPoint.x);
33
+ const y = getYPosition(scatterPoint.y);
34
+ const isInRange = x >= minXRange && x <= maxXRange && y >= minYRange && y <= maxYRange;
35
+ const pointCtx = {
58
36
  type: 'scatter',
59
37
  seriesId: series.id,
60
- dataIndex
61
- }, series.highlightScope);
62
- return /*#__PURE__*/_jsx("circle", _extends({
63
- cx: 0,
64
- cy: 0,
65
- r: markerSize,
66
- transform: `translate(${x}, ${y})`,
67
- fill: color,
68
- opacity: isFaded && 0.3 || 1
69
- }, getInteractionItemProps({
70
- type: 'scatter',
71
- seriesId: series.id,
72
- dataIndex
73
- })), id);
74
- })
38
+ dataIndex: i
39
+ };
40
+ if (isInRange) {
41
+ temp.push({
42
+ x,
43
+ y,
44
+ isFaded: !getIsHighlighted(item, pointCtx, series.highlightScope) && getIsFaded(item, pointCtx, series.highlightScope),
45
+ interactionProps: getInteractionItemProps(pointCtx),
46
+ id: scatterPoint.id
47
+ });
48
+ }
49
+ }
50
+ return temp;
51
+ }, [yScale, xScale, getInteractionItemProps, item, series.data, series.highlightScope, series.id]);
52
+ return /*#__PURE__*/_jsx("g", {
53
+ children: cleanData.map(dataPoint => /*#__PURE__*/_jsx("circle", _extends({
54
+ cx: 0,
55
+ cy: 0,
56
+ r: markerSize,
57
+ transform: `translate(${dataPoint.x}, ${dataPoint.y})`,
58
+ fill: color,
59
+ opacity: dataPoint.isFaded && 0.3 || 1
60
+ }, dataPoint.interactionProps), dataPoint.id))
75
61
  });
76
62
  }
77
63
  process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
@@ -64,7 +64,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
64
64
  }),
65
65
  /**
66
66
  * Indicate which axis to display the bottom of the charts.
67
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
67
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
68
68
  * @default xAxisIds[0] The id of the first provided axis
69
69
  */
70
70
  bottomAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -86,12 +86,13 @@ 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,
92
93
  /**
93
94
  * Indicate which axis to display the left of the charts.
94
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
95
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
95
96
  * @default yAxisIds[0] The id of the first provided axis
96
97
  */
97
98
  leftAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -131,7 +132,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
131
132
  }),
132
133
  /**
133
134
  * Indicate which axis to display the right of the charts.
134
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
135
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
135
136
  * @default null
136
137
  */
137
138
  rightAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -176,7 +177,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
176
177
  }),
177
178
  /**
178
179
  * Indicate which axis to display the top of the charts.
179
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
180
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
180
181
  * @default null
181
182
  */
182
183
  topAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -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']),
@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
3
3
  import useChartDimensions from '../hooks/useChartDimensions';
4
4
 
5
5
  /**
6
- * Defines the area in which it is possible to draw the charts
6
+ * Defines the area in which it is possible to draw the charts.
7
7
  */
8
8
  import { jsx as _jsx } from "react/jsx-runtime";
9
9
  export const DrawingContext = /*#__PURE__*/React.createContext({
@@ -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.4
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.4",
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
  }