@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
@@ -2,9 +2,8 @@ import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import { stack as d3Stack } from 'd3-shape';
3
3
  import { getStackingGroups } from '../internals/stackSeries';
4
4
  import defaultizeValueFormatter from '../internals/defaultizeValueFormatter';
5
-
6
5
  // For now it's a copy past of bar charts formatter, but maybe will diverge later
7
- const formatter = params => {
6
+ const formatter = (params, dataset) => {
8
7
  const {
9
8
  seriesOrder,
10
9
  series
@@ -12,17 +11,22 @@ const formatter = params => {
12
11
  const stackingGroups = getStackingGroups(params);
13
12
 
14
13
  // Create a data set with format adapted to d3
15
- const d3Dataset = [];
14
+ const d3Dataset = dataset != null ? dataset : [];
16
15
  seriesOrder.forEach(id => {
17
- series[id].data.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
  });
@@ -82,7 +82,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
82
82
  }),
83
83
  /**
84
84
  * Indicate which axis to display the bottom of the charts.
85
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
85
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
86
86
  * @default xAxisIds[0] The id of the first provided axis
87
87
  */
88
88
  bottomAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -104,12 +104,13 @@ 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,
110
111
  /**
111
112
  * Indicate which axis to display the left of the charts.
112
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
113
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
113
114
  * @default yAxisIds[0] The id of the first provided axis
114
115
  */
115
116
  leftAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -149,7 +150,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
149
150
  }),
150
151
  /**
151
152
  * Indicate which axis to display the right of the charts.
152
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
153
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
153
154
  * @default null
154
155
  */
155
156
  rightAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -214,7 +215,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
214
215
  }),
215
216
  /**
216
217
  * Indicate which axis to display the top of the charts.
217
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
218
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
218
219
  * @default null
219
220
  */
220
221
  topAxis: PropTypes.oneOfType([PropTypes.shape({
@@ -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']),
@@ -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 == null ? void 0 : tooltip.trigger) !== 'axis') && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none',
76
+ children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {}), plotType === 'line' && /*#__PURE__*/_jsxs(React.Fragment, {
77
+ children: [/*#__PURE__*/_jsx(AreaPlot, {}), /*#__PURE__*/_jsx(LinePlot, {}), showHighlight && /*#__PURE__*/_jsx(SparkLineMarkPlot, {})]
78
+ }), /*#__PURE__*/_jsx(ChartsAxisHighlight, _extends({}, axisHighlight)), showTooltip && /*#__PURE__*/_jsx(ChartsTooltip, _extends({}, tooltip)), children]
79
+ });
80
+ });
81
+ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
82
+ // ----------------------------- Warning --------------------------------
83
+ // | These PropTypes are generated from the TypeScript type definitions |
84
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
85
+ // ----------------------------------------------------------------------
86
+ /**
87
+ * Set to `true` to fill spark line area.
88
+ * Has no effect if plotType='bar'.
89
+ * @default false
90
+ */
91
+ area: PropTypes.bool,
92
+ axisHighlight: PropTypes.shape({
93
+ x: PropTypes.oneOf(['band', 'line', 'none']),
94
+ y: PropTypes.oneOf(['line', 'none'])
95
+ }),
96
+ children: PropTypes.node,
97
+ className: PropTypes.string,
98
+ /**
99
+ * Color palette used to colorize multiple series.
100
+ */
101
+ colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
102
+ /**
103
+ * @default 'linear'
104
+ */
105
+ curve: PropTypes.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
106
+ /**
107
+ * Data to plot.
108
+ */
109
+ data: PropTypes.arrayOf(PropTypes.number).isRequired,
110
+ dataset: PropTypes.arrayOf(PropTypes.object),
111
+ desc: PropTypes.string,
112
+ disableAxisListener: PropTypes.bool,
113
+ height: PropTypes.number,
114
+ margin: PropTypes.shape({
115
+ bottom: PropTypes.number,
116
+ left: PropTypes.number,
117
+ right: PropTypes.number,
118
+ top: PropTypes.number
119
+ }),
120
+ /**
121
+ * Type of plot used.
122
+ * @default 'line'
123
+ */
124
+ plotType: PropTypes.oneOf(['bar', 'line']),
125
+ /**
126
+ * Set to `true` to highlight the value.
127
+ * With line, it shows a point.
128
+ * With bar, it shows a highlight band.
129
+ * @default false
130
+ */
131
+ showHighlight: PropTypes.bool,
132
+ /**
133
+ * Set to `true` to enable the tooltip in the sparkline.
134
+ * @default false
135
+ */
136
+ showTooltip: PropTypes.bool,
137
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
138
+ title: PropTypes.string,
139
+ tooltip: PropTypes.shape({
140
+ axisContent: PropTypes.elementType,
141
+ classes: PropTypes.object,
142
+ itemContent: PropTypes.elementType,
143
+ trigger: PropTypes.oneOf(['axis', 'item', 'none'])
144
+ }),
145
+ /**
146
+ * Formatter used by the tooltip.
147
+ * @param {number} value The value to format.
148
+ * @returns {string} the formatted value.
149
+ */
150
+ valueFormatter: PropTypes.func,
151
+ viewBox: PropTypes.shape({
152
+ height: PropTypes.number,
153
+ width: PropTypes.number,
154
+ x: PropTypes.number,
155
+ y: PropTypes.number
156
+ }),
157
+ width: PropTypes.number,
158
+ /**
159
+ * The xAxis configuration.
160
+ * Notice it is a single configuration object, not an array of configuration.
161
+ */
162
+ xAxis: PropTypes.shape({
163
+ axisId: PropTypes.string,
164
+ classes: PropTypes.object,
165
+ data: PropTypes.array,
166
+ dataKey: PropTypes.string,
167
+ disableLine: PropTypes.bool,
168
+ disableTicks: PropTypes.bool,
169
+ fill: PropTypes.string,
170
+ hideTooltip: PropTypes.bool,
171
+ id: PropTypes.string,
172
+ label: PropTypes.string,
173
+ labelFontSize: PropTypes.number,
174
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
175
+ maxTicks: PropTypes.number,
176
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
177
+ minTicks: PropTypes.number,
178
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
179
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
180
+ stroke: PropTypes.string,
181
+ tickFontSize: PropTypes.number,
182
+ tickSize: PropTypes.number,
183
+ tickSpacing: PropTypes.number,
184
+ valueFormatter: PropTypes.func
185
+ })
186
+ } : void 0;
187
+ export { SparkLineChart };
@@ -0,0 +1 @@
1
+ export { SparkLineChart } from './SparkLineChart';
@@ -32,12 +32,37 @@ export const CartesianContext = /*#__PURE__*/React.createContext({
32
32
  yAxisIds: []
33
33
  });
34
34
  function CartesianContextProvider({
35
- xAxis,
36
- yAxis,
35
+ xAxis: inXAxis,
36
+ yAxis: inYAxis,
37
+ dataset,
37
38
  children
38
39
  }) {
39
40
  const formattedSeries = React.useContext(SeriesContext);
40
41
  const drawingArea = React.useContext(DrawingContext);
42
+ const xAxis = React.useMemo(() => inXAxis == null ? void 0 : inXAxis.map(axisConfig => {
43
+ const dataKey = axisConfig.dataKey;
44
+ if (dataKey === undefined || axisConfig.data !== undefined) {
45
+ return axisConfig;
46
+ }
47
+ if (dataset === undefined) {
48
+ throw Error('MUI: x-axis uses `dataKey` but no `dataset` is provided.');
49
+ }
50
+ return _extends({}, axisConfig, {
51
+ data: dataset.map(d => d[dataKey])
52
+ });
53
+ }), [inXAxis, dataset]);
54
+ const yAxis = React.useMemo(() => inYAxis == null ? void 0 : inYAxis.map(axisConfig => {
55
+ const dataKey = axisConfig.dataKey;
56
+ if (dataKey === undefined || axisConfig.data !== undefined) {
57
+ return axisConfig;
58
+ }
59
+ if (dataset === undefined) {
60
+ throw Error('MUI: y-axis uses `dataKey` but no `dataset` is provided.');
61
+ }
62
+ return _extends({}, axisConfig, {
63
+ data: dataset.map(d => d[dataKey])
64
+ });
65
+ }), [inYAxis, dataset]);
41
66
  const value = React.useMemo(() => {
42
67
  var _xAxis$map, _yAxis$map;
43
68
  const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis) => {
@@ -186,19 +211,22 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
186
211
  // | To update them edit the TypeScript types and run "yarn proptypes" |
187
212
  // ----------------------------------------------------------------------
188
213
  children: PropTypes.node,
214
+ dataset: PropTypes.arrayOf(PropTypes.object),
189
215
  xAxis: PropTypes.arrayOf(PropTypes.shape({
190
216
  axisId: PropTypes.string,
191
217
  classes: PropTypes.object,
192
218
  data: PropTypes.array,
219
+ dataKey: PropTypes.string,
193
220
  disableLine: PropTypes.bool,
194
221
  disableTicks: PropTypes.bool,
195
222
  fill: PropTypes.string,
223
+ hideTooltip: PropTypes.bool,
196
224
  id: PropTypes.string,
197
225
  label: PropTypes.string,
198
226
  labelFontSize: PropTypes.number,
199
- max: PropTypes.number,
227
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
200
228
  maxTicks: PropTypes.number,
201
- min: PropTypes.number,
229
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
202
230
  minTicks: PropTypes.number,
203
231
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
204
232
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
@@ -212,15 +240,17 @@ process.env.NODE_ENV !== "production" ? CartesianContextProvider.propTypes = {
212
240
  axisId: PropTypes.string,
213
241
  classes: PropTypes.object,
214
242
  data: PropTypes.array,
243
+ dataKey: PropTypes.string,
215
244
  disableLine: PropTypes.bool,
216
245
  disableTicks: PropTypes.bool,
217
246
  fill: PropTypes.string,
247
+ hideTooltip: PropTypes.bool,
218
248
  id: PropTypes.string,
219
249
  label: PropTypes.string,
220
250
  labelFontSize: PropTypes.number,
221
- max: PropTypes.number,
251
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
222
252
  maxTicks: PropTypes.number,
223
- min: PropTypes.number,
253
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
224
254
  minTicks: PropTypes.number,
225
255
  position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
226
256
  scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
@@ -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) => {
@@ -51,18 +52,19 @@ const formatSeries = (series, colors) => {
51
52
  Object.keys(seriesTypeFormatter).forEach(type => {
52
53
  if (seriesGroups[type] !== undefined) {
53
54
  var _seriesTypeFormatter$, _seriesTypeFormatter$2;
54
- formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type])) != null ? _seriesTypeFormatter$ : seriesGroups[type];
55
+ formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type], dataset)) != null ? _seriesTypeFormatter$ : seriesGroups[type];
55
56
  }
56
57
  });
57
58
  return formattedSeries;
58
59
  };
59
60
  export function SeriesContextProvider({
60
61
  series,
62
+ dataset,
61
63
  colors = blueberryTwilightPalette,
62
64
  children
63
65
  }) {
64
66
  const theme = useTheme();
65
- const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors), [series, colors, theme.palette.mode]);
67
+ const formattedSeries = React.useMemo(() => formatSeries(series, typeof colors === 'function' ? colors(theme.palette.mode) : colors, dataset), [series, colors, theme.palette.mode, dataset]);
66
68
  return /*#__PURE__*/_jsx(SeriesContext.Provider, {
67
69
  value: formattedSeries,
68
70
  children: children
package/esm/index.js CHANGED
@@ -13,5 +13,6 @@ export * from './BarChart';
13
13
  export * from './LineChart';
14
14
  export * from './PieChart';
15
15
  export * from './ScatterChart';
16
+ export * from './SparkLineChart';
16
17
  export * from './ChartContainer';
17
18
  export * from './ResponsiveChartContainer';
@@ -1 +1,3 @@
1
- export * from './seriesType';
1
+ export * from './seriesType';
2
+ export * from './layout';
3
+ export {};
package/index.d.ts CHANGED
@@ -13,5 +13,6 @@ export * from './BarChart';
13
13
  export * from './LineChart';
14
14
  export * from './PieChart';
15
15
  export * from './ScatterChart';
16
+ export * from './SparkLineChart';
16
17
  export * from './ChartContainer';
17
18
  export * from './ResponsiveChartContainer';