@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
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.MarkPlot = MarkPlot;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
7
9
  var React = _interopRequireWildcard(require("react"));
8
10
  var _SeriesContextProvider = require("../context/SeriesContextProvider");
9
11
  var _CartesianContextProvider = require("../context/CartesianContextProvider");
@@ -12,7 +14,7 @@ var _useScale = require("../hooks/useScale");
12
14
  var _jsxRuntime = require("react/jsx-runtime");
13
15
  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); }
14
16
  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; }
15
- function MarkPlot() {
17
+ function MarkPlot(props) {
16
18
  const seriesData = React.useContext(_SeriesContextProvider.SeriesContext).line;
17
19
  const axisData = React.useContext(_CartesianContextProvider.CartesianContext);
18
20
  if (seriesData === undefined) {
@@ -30,7 +32,7 @@ function MarkPlot() {
30
32
  } = axisData;
31
33
  const defaultXAxisId = xAxisIds[0];
32
34
  const defaultYAxisId = yAxisIds[0];
33
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
35
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", (0, _extends2.default)({}, props, {
34
36
  children: stackingGroups.flatMap(({
35
37
  ids: groupIds
36
38
  }) => {
@@ -82,5 +84,5 @@ function MarkPlot() {
82
84
  }, `${seriesId}-${index}`));
83
85
  });
84
86
  })
85
- });
87
+ }));
86
88
  }
@@ -10,7 +10,7 @@ var _d3Shape = require("d3-shape");
10
10
  var _stackSeries = require("../internals/stackSeries");
11
11
  var _defaultizeValueFormatter = _interopRequireDefault(require("../internals/defaultizeValueFormatter"));
12
12
  // For now it's a copy past of bar charts formatter, but maybe will diverge later
13
- const formatter = params => {
13
+ const formatter = (params, dataset) => {
14
14
  const {
15
15
  seriesOrder,
16
16
  series
@@ -18,17 +18,22 @@ const formatter = params => {
18
18
  const stackingGroups = (0, _stackSeries.getStackingGroups)(params);
19
19
 
20
20
  // Create a data set with format adapted to d3
21
- const d3Dataset = [];
21
+ const d3Dataset = dataset ?? [];
22
22
  seriesOrder.forEach(id => {
23
- series[id].data.forEach((value, index) => {
24
- if (d3Dataset.length <= index) {
25
- d3Dataset.push({
26
- [id]: value
27
- });
28
- } else {
29
- d3Dataset[index][id] = value;
30
- }
31
- });
23
+ const data = series[id].data;
24
+ if (data !== undefined) {
25
+ data.forEach((value, index) => {
26
+ if (d3Dataset.length <= index) {
27
+ d3Dataset.push({
28
+ [id]: value
29
+ });
30
+ } else {
31
+ d3Dataset[index][id] = value;
32
+ }
33
+ });
34
+ } else if (dataset === undefined) {
35
+ 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'));
36
+ }
32
37
  });
33
38
  const completedSeries = {};
34
39
  stackingGroups.forEach(stackingGroup => {
@@ -38,9 +43,15 @@ const formatter = params => {
38
43
  stackingOrder,
39
44
  stackingOffset
40
45
  } = stackingGroup;
41
- const stackedSeries = (0, _d3Shape.stack)().keys(ids).order(stackingOrder).offset(stackingOffset)(d3Dataset);
46
+ const stackedSeries = (0, _d3Shape.stack)().keys(ids.map(id => {
47
+ // Use dataKey if needed and available
48
+ const dataKey = series[id].dataKey;
49
+ return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
50
+ })).order(stackingOrder).offset(stackingOffset)(d3Dataset);
42
51
  ids.forEach((id, index) => {
52
+ const dataKey = series[id].dataKey;
43
53
  completedSeries[id] = (0, _extends2.default)({}, series[id], {
54
+ data: dataKey ? dataset.map(d => d[dataKey]) : series[id].data,
44
55
  stackedData: stackedSeries[index].map(([a, b]) => [a, b])
45
56
  });
46
57
  });
@@ -90,7 +90,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
90
90
  }),
91
91
  /**
92
92
  * Indicate which axis to display the bottom of the charts.
93
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
93
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
94
94
  * @default xAxisIds[0] The id of the first provided axis
95
95
  */
96
96
  bottomAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -112,12 +112,13 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
112
112
  * Color palette used to colorize multiple series.
113
113
  */
114
114
  colors: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.func]),
115
+ dataset: _propTypes.default.arrayOf(_propTypes.default.object),
115
116
  desc: _propTypes.default.string,
116
117
  disableAxisListener: _propTypes.default.bool,
117
118
  height: _propTypes.default.number,
118
119
  /**
119
120
  * Indicate which axis to display the left of the charts.
120
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
121
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
121
122
  * @default yAxisIds[0] The id of the first provided axis
122
123
  */
123
124
  leftAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -157,7 +158,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
157
158
  }),
158
159
  /**
159
160
  * Indicate which axis to display the right of the charts.
160
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
161
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
161
162
  * @default null
162
163
  */
163
164
  rightAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -222,7 +223,7 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
222
223
  }),
223
224
  /**
224
225
  * Indicate which axis to display the top of the charts.
225
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
226
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
226
227
  * @default null
227
228
  */
228
229
  topAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -249,15 +250,17 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
249
250
  axisId: _propTypes.default.string,
250
251
  classes: _propTypes.default.object,
251
252
  data: _propTypes.default.array,
253
+ dataKey: _propTypes.default.string,
252
254
  disableLine: _propTypes.default.bool,
253
255
  disableTicks: _propTypes.default.bool,
254
256
  fill: _propTypes.default.string,
257
+ hideTooltip: _propTypes.default.bool,
255
258
  id: _propTypes.default.string,
256
259
  label: _propTypes.default.string,
257
260
  labelFontSize: _propTypes.default.number,
258
- max: _propTypes.default.number,
261
+ max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
259
262
  maxTicks: _propTypes.default.number,
260
- min: _propTypes.default.number,
263
+ min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
261
264
  minTicks: _propTypes.default.number,
262
265
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
263
266
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
@@ -271,15 +274,17 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
271
274
  axisId: _propTypes.default.string,
272
275
  classes: _propTypes.default.object,
273
276
  data: _propTypes.default.array,
277
+ dataKey: _propTypes.default.string,
274
278
  disableLine: _propTypes.default.bool,
275
279
  disableTicks: _propTypes.default.bool,
276
280
  fill: _propTypes.default.string,
281
+ hideTooltip: _propTypes.default.bool,
277
282
  id: _propTypes.default.string,
278
283
  label: _propTypes.default.string,
279
284
  labelFontSize: _propTypes.default.number,
280
- max: _propTypes.default.number,
285
+ max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
281
286
  maxTicks: _propTypes.default.number,
282
- min: _propTypes.default.number,
287
+ min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
283
288
  minTicks: _propTypes.default.number,
284
289
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
285
290
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
@@ -25,62 +25,48 @@ function Scatter(props) {
25
25
  const {
26
26
  item
27
27
  } = React.useContext(_InteractionProvider.InteractionContext);
28
- const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
29
- const getYPosition = (0, _useScale.getValueToPositionMapper)(yScale);
30
28
  const getInteractionItemProps = (0, _useInteractionItemProps.useInteractionItemProps)(series.highlightScope);
31
- const xRange = xScale.range();
32
- const yRange = yScale.range();
33
- const isInRange = ({
34
- x,
35
- y
36
- }) => {
37
- if (x < Math.min(...xRange) || x > Math.max(...xRange)) {
38
- return false;
39
- }
40
- if (y < Math.min(...yRange) || y > Math.max(...yRange)) {
41
- return false;
42
- }
43
- return true;
44
- };
45
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
46
- children: series.data.map(({
47
- x,
48
- y,
49
- id
50
- }, index) => ({
51
- x: getXPosition(x),
52
- y: getYPosition(y),
53
- id,
54
- dataIndex: index
55
- })).filter(isInRange).map(({
56
- x,
57
- y,
58
- id,
59
- dataIndex
60
- }) => {
61
- const isHighlighted = (0, _useInteractionItemProps.getIsHighlighted)(item, {
62
- type: 'scatter',
63
- seriesId: series.id,
64
- dataIndex
65
- }, series.highlightScope);
66
- const isFaded = !isHighlighted && (0, _useInteractionItemProps.getIsFaded)(item, {
29
+ const cleanData = React.useMemo(() => {
30
+ const getXPosition = (0, _useScale.getValueToPositionMapper)(xScale);
31
+ const getYPosition = (0, _useScale.getValueToPositionMapper)(yScale);
32
+ const xRange = xScale.range();
33
+ const yRange = yScale.range();
34
+ const minXRange = Math.min(...xRange);
35
+ const maxXRange = Math.max(...xRange);
36
+ const minYRange = Math.min(...yRange);
37
+ const maxYRange = Math.max(...yRange);
38
+ const temp = [];
39
+ for (let i = 0; i < series.data.length; i += 1) {
40
+ const scatterPoint = series.data[i];
41
+ const x = getXPosition(scatterPoint.x);
42
+ const y = getYPosition(scatterPoint.y);
43
+ const isInRange = x >= minXRange && x <= maxXRange && y >= minYRange && y <= maxYRange;
44
+ const pointCtx = {
67
45
  type: 'scatter',
68
46
  seriesId: series.id,
69
- dataIndex
70
- }, series.highlightScope);
71
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("circle", (0, _extends2.default)({
72
- cx: 0,
73
- cy: 0,
74
- r: markerSize,
75
- transform: `translate(${x}, ${y})`,
76
- fill: color,
77
- opacity: isFaded && 0.3 || 1
78
- }, getInteractionItemProps({
79
- type: 'scatter',
80
- seriesId: series.id,
81
- dataIndex
82
- })), id);
83
- })
47
+ dataIndex: i
48
+ };
49
+ if (isInRange) {
50
+ temp.push({
51
+ x,
52
+ y,
53
+ isFaded: !(0, _useInteractionItemProps.getIsHighlighted)(item, pointCtx, series.highlightScope) && (0, _useInteractionItemProps.getIsFaded)(item, pointCtx, series.highlightScope),
54
+ interactionProps: getInteractionItemProps(pointCtx),
55
+ id: scatterPoint.id
56
+ });
57
+ }
58
+ }
59
+ return temp;
60
+ }, [yScale, xScale, getInteractionItemProps, item, series.data, series.highlightScope, series.id]);
61
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
62
+ children: cleanData.map(dataPoint => /*#__PURE__*/(0, _jsxRuntime.jsx)("circle", (0, _extends2.default)({
63
+ cx: 0,
64
+ cy: 0,
65
+ r: markerSize,
66
+ transform: `translate(${dataPoint.x}, ${dataPoint.y})`,
67
+ fill: color,
68
+ opacity: dataPoint.isFaded && 0.3 || 1
69
+ }, dataPoint.interactionProps), dataPoint.id))
84
70
  });
85
71
  }
86
72
  process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
@@ -73,7 +73,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
73
73
  }),
74
74
  /**
75
75
  * Indicate which axis to display the bottom of the charts.
76
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
76
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
77
77
  * @default xAxisIds[0] The id of the first provided axis
78
78
  */
79
79
  bottomAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -95,12 +95,13 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
95
95
  * Color palette used to colorize multiple series.
96
96
  */
97
97
  colors: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.func]),
98
+ dataset: _propTypes.default.arrayOf(_propTypes.default.object),
98
99
  desc: _propTypes.default.string,
99
100
  disableAxisListener: _propTypes.default.bool,
100
101
  height: _propTypes.default.number,
101
102
  /**
102
103
  * Indicate which axis to display the left of the charts.
103
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
104
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
104
105
  * @default yAxisIds[0] The id of the first provided axis
105
106
  */
106
107
  leftAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -140,7 +141,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
140
141
  }),
141
142
  /**
142
143
  * Indicate which axis to display the right of the charts.
143
- * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
144
+ * Can be a string (the id of the axis) or an object `ChartsYAxisProps`.
144
145
  * @default null
145
146
  */
146
147
  rightAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -185,7 +186,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
185
186
  }),
186
187
  /**
187
188
  * Indicate which axis to display the top of the charts.
188
- * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
189
+ * Can be a string (the id of the axis) or an object `ChartsXAxisProps`.
189
190
  * @default null
190
191
  */
191
192
  topAxis: _propTypes.default.oneOfType([_propTypes.default.shape({
@@ -212,15 +213,17 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
212
213
  axisId: _propTypes.default.string,
213
214
  classes: _propTypes.default.object,
214
215
  data: _propTypes.default.array,
216
+ dataKey: _propTypes.default.string,
215
217
  disableLine: _propTypes.default.bool,
216
218
  disableTicks: _propTypes.default.bool,
217
219
  fill: _propTypes.default.string,
220
+ hideTooltip: _propTypes.default.bool,
218
221
  id: _propTypes.default.string,
219
222
  label: _propTypes.default.string,
220
223
  labelFontSize: _propTypes.default.number,
221
- max: _propTypes.default.number,
224
+ max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
222
225
  maxTicks: _propTypes.default.number,
223
- min: _propTypes.default.number,
226
+ min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
224
227
  minTicks: _propTypes.default.number,
225
228
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
226
229
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
@@ -234,15 +237,17 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
234
237
  axisId: _propTypes.default.string,
235
238
  classes: _propTypes.default.object,
236
239
  data: _propTypes.default.array,
240
+ dataKey: _propTypes.default.string,
237
241
  disableLine: _propTypes.default.bool,
238
242
  disableTicks: _propTypes.default.bool,
239
243
  fill: _propTypes.default.string,
244
+ hideTooltip: _propTypes.default.bool,
240
245
  id: _propTypes.default.string,
241
246
  label: _propTypes.default.string,
242
247
  labelFontSize: _propTypes.default.number,
243
- max: _propTypes.default.number,
248
+ max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
244
249
  maxTicks: _propTypes.default.number,
245
- min: _propTypes.default.number,
250
+ min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
246
251
  minTicks: _propTypes.default.number,
247
252
  position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
248
253
  scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
@@ -0,0 +1,55 @@
1
+ import * as React from 'react';
2
+ import { ResponsiveChartContainerProps } from '../ResponsiveChartContainer';
3
+ import { ChartsTooltipProps } from '../ChartsTooltip';
4
+ import { ChartsAxisHighlightProps } from '../ChartsAxisHighlight';
5
+ import { AxisConfig } from '../models/axis';
6
+ import { MakeOptional } from '../models/helpers';
7
+ import { LineSeriesType } from '../models/seriesType/line';
8
+ export interface SparkLineChartProps extends Omit<ResponsiveChartContainerProps, 'series' | 'xAxis' | 'yAxis'> {
9
+ /**
10
+ * The xAxis configuration.
11
+ * Notice it is a single configuration object, not an array of configuration.
12
+ */
13
+ xAxis?: MakeOptional<AxisConfig, 'id'>;
14
+ tooltip?: ChartsTooltipProps;
15
+ axisHighlight?: ChartsAxisHighlightProps;
16
+ /**
17
+ * Type of plot used.
18
+ * @default 'line'
19
+ */
20
+ plotType?: 'line' | 'bar';
21
+ /**
22
+ * Data to plot.
23
+ */
24
+ data: number[];
25
+ /**
26
+ * Formatter used by the tooltip.
27
+ * @param {number} value The value to format.
28
+ * @returns {string} the formatted value.
29
+ */
30
+ valueFormatter?: (value: number) => string;
31
+ /**
32
+ * Set to `true` to enable the tooltip in the sparkline.
33
+ * @default false
34
+ */
35
+ showTooltip?: boolean;
36
+ /**
37
+ * Set to `true` to highlight the value.
38
+ * With line, it shows a point.
39
+ * With bar, it shows a highlight band.
40
+ * @default false
41
+ */
42
+ showHighlight?: boolean;
43
+ /**
44
+ * Set to `true` to fill spark line area.
45
+ * Has no effect if plotType='bar'.
46
+ * @default false
47
+ */
48
+ area?: LineSeriesType['area'];
49
+ /**
50
+ * @default 'linear'
51
+ */
52
+ curve?: LineSeriesType['curve'];
53
+ }
54
+ declare const SparkLineChart: React.ForwardRefExoticComponent<SparkLineChartProps & React.RefAttributes<unknown>>;
55
+ export { SparkLineChart };
@@ -0,0 +1,195 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.SparkLineChart = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _propTypes = _interopRequireDefault(require("prop-types"));
11
+ var _styles = require("@mui/material/styles");
12
+ var _BarChart = require("../BarChart");
13
+ var _LineChart = require("../LineChart");
14
+ var _ResponsiveChartContainer = require("../ResponsiveChartContainer");
15
+ var _constants = require("../constants");
16
+ var _ChartsTooltip = require("../ChartsTooltip");
17
+ var _ChartsAxisHighlight = require("../ChartsAxisHighlight");
18
+ var _jsxRuntime = require("react/jsx-runtime");
19
+ 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); }
20
+ 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; }
21
+ const SparkLineMarkPlot = (0, _styles.styled)(_LineChart.MarkPlot)({
22
+ [`& .${_LineChart.markElementClasses.root}`]: {
23
+ display: 'none',
24
+ [`&.${_LineChart.markElementClasses.highlighted}`]: {
25
+ display: 'inherit'
26
+ }
27
+ }
28
+ });
29
+ const SPARKLINE_DEFAULT_MARGIN = {
30
+ top: 5,
31
+ bottom: 5,
32
+ left: 5,
33
+ right: 5
34
+ };
35
+ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props, ref) {
36
+ const {
37
+ xAxis,
38
+ width,
39
+ height,
40
+ margin = SPARKLINE_DEFAULT_MARGIN,
41
+ colors,
42
+ sx,
43
+ showTooltip,
44
+ tooltip,
45
+ showHighlight,
46
+ axisHighlight: inAxisHighlight,
47
+ children,
48
+ data,
49
+ plotType = 'line',
50
+ valueFormatter = v => v.toString(),
51
+ area,
52
+ curve = 'linear'
53
+ } = props;
54
+ const defaultXHighlight = showHighlight && plotType === 'bar' ? {
55
+ x: 'band'
56
+ } : {
57
+ x: 'none'
58
+ };
59
+ const axisHighlight = (0, _extends2.default)({}, defaultXHighlight, inAxisHighlight);
60
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_ResponsiveChartContainer.ResponsiveChartContainer, {
61
+ ref: ref,
62
+ series: [(0, _extends2.default)({
63
+ type: plotType,
64
+ data,
65
+ valueFormatter
66
+ }, plotType === 'bar' ? {} : {
67
+ area,
68
+ curve
69
+ })],
70
+ width: width,
71
+ height: height,
72
+ margin: margin,
73
+ xAxis: [(0, _extends2.default)({
74
+ id: _constants.DEFAULT_X_AXIS_KEY,
75
+ scaleType: plotType === 'bar' ? 'band' : 'linear',
76
+ data: Array.from({
77
+ length: data.length
78
+ }, (_, index) => index),
79
+ hideTooltip: xAxis === undefined
80
+ }, xAxis)],
81
+ colors: colors,
82
+ sx: sx,
83
+ disableAxisListener: (!showTooltip || tooltip?.trigger !== 'axis') && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
84
+ children: [plotType === 'bar' && /*#__PURE__*/(0, _jsxRuntime.jsx)(_BarChart.BarPlot, {}), plotType === 'line' && /*#__PURE__*/(0, _jsxRuntime.jsxs)(React.Fragment, {
85
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_LineChart.AreaPlot, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_LineChart.LinePlot, {}), showHighlight && /*#__PURE__*/(0, _jsxRuntime.jsx)(SparkLineMarkPlot, {})]
86
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsAxisHighlight.ChartsAxisHighlight, (0, _extends2.default)({}, axisHighlight)), showTooltip && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartsTooltip.ChartsTooltip, (0, _extends2.default)({}, tooltip)), children]
87
+ });
88
+ });
89
+ exports.SparkLineChart = SparkLineChart;
90
+ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
91
+ // ----------------------------- Warning --------------------------------
92
+ // | These PropTypes are generated from the TypeScript type definitions |
93
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
94
+ // ----------------------------------------------------------------------
95
+ /**
96
+ * Set to `true` to fill spark line area.
97
+ * Has no effect if plotType='bar'.
98
+ * @default false
99
+ */
100
+ area: _propTypes.default.bool,
101
+ axisHighlight: _propTypes.default.shape({
102
+ x: _propTypes.default.oneOf(['band', 'line', 'none']),
103
+ y: _propTypes.default.oneOf(['line', 'none'])
104
+ }),
105
+ children: _propTypes.default.node,
106
+ className: _propTypes.default.string,
107
+ /**
108
+ * Color palette used to colorize multiple series.
109
+ */
110
+ colors: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.string), _propTypes.default.func]),
111
+ /**
112
+ * @default 'linear'
113
+ */
114
+ curve: _propTypes.default.oneOf(['catmullRom', 'linear', 'monotoneX', 'monotoneY', 'natural', 'step', 'stepAfter', 'stepBefore']),
115
+ /**
116
+ * Data to plot.
117
+ */
118
+ data: _propTypes.default.arrayOf(_propTypes.default.number).isRequired,
119
+ dataset: _propTypes.default.arrayOf(_propTypes.default.object),
120
+ desc: _propTypes.default.string,
121
+ disableAxisListener: _propTypes.default.bool,
122
+ height: _propTypes.default.number,
123
+ margin: _propTypes.default.shape({
124
+ bottom: _propTypes.default.number,
125
+ left: _propTypes.default.number,
126
+ right: _propTypes.default.number,
127
+ top: _propTypes.default.number
128
+ }),
129
+ /**
130
+ * Type of plot used.
131
+ * @default 'line'
132
+ */
133
+ plotType: _propTypes.default.oneOf(['bar', 'line']),
134
+ /**
135
+ * Set to `true` to highlight the value.
136
+ * With line, it shows a point.
137
+ * With bar, it shows a highlight band.
138
+ * @default false
139
+ */
140
+ showHighlight: _propTypes.default.bool,
141
+ /**
142
+ * Set to `true` to enable the tooltip in the sparkline.
143
+ * @default false
144
+ */
145
+ showTooltip: _propTypes.default.bool,
146
+ sx: _propTypes.default.oneOfType([_propTypes.default.arrayOf(_propTypes.default.oneOfType([_propTypes.default.func, _propTypes.default.object, _propTypes.default.bool])), _propTypes.default.func, _propTypes.default.object]),
147
+ title: _propTypes.default.string,
148
+ tooltip: _propTypes.default.shape({
149
+ axisContent: _propTypes.default.elementType,
150
+ classes: _propTypes.default.object,
151
+ itemContent: _propTypes.default.elementType,
152
+ trigger: _propTypes.default.oneOf(['axis', 'item', 'none'])
153
+ }),
154
+ /**
155
+ * Formatter used by the tooltip.
156
+ * @param {number} value The value to format.
157
+ * @returns {string} the formatted value.
158
+ */
159
+ valueFormatter: _propTypes.default.func,
160
+ viewBox: _propTypes.default.shape({
161
+ height: _propTypes.default.number,
162
+ width: _propTypes.default.number,
163
+ x: _propTypes.default.number,
164
+ y: _propTypes.default.number
165
+ }),
166
+ width: _propTypes.default.number,
167
+ /**
168
+ * The xAxis configuration.
169
+ * Notice it is a single configuration object, not an array of configuration.
170
+ */
171
+ xAxis: _propTypes.default.shape({
172
+ axisId: _propTypes.default.string,
173
+ classes: _propTypes.default.object,
174
+ data: _propTypes.default.array,
175
+ dataKey: _propTypes.default.string,
176
+ disableLine: _propTypes.default.bool,
177
+ disableTicks: _propTypes.default.bool,
178
+ fill: _propTypes.default.string,
179
+ hideTooltip: _propTypes.default.bool,
180
+ id: _propTypes.default.string,
181
+ label: _propTypes.default.string,
182
+ labelFontSize: _propTypes.default.number,
183
+ max: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
184
+ maxTicks: _propTypes.default.number,
185
+ min: _propTypes.default.oneOfType([_propTypes.default.instanceOf(Date), _propTypes.default.number]),
186
+ minTicks: _propTypes.default.number,
187
+ position: _propTypes.default.oneOf(['bottom', 'left', 'right', 'top']),
188
+ scaleType: _propTypes.default.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
189
+ stroke: _propTypes.default.string,
190
+ tickFontSize: _propTypes.default.number,
191
+ tickSize: _propTypes.default.number,
192
+ tickSpacing: _propTypes.default.number,
193
+ valueFormatter: _propTypes.default.func
194
+ })
195
+ } : void 0;
@@ -0,0 +1 @@
1
+ export { SparkLineChart } from './SparkLineChart';
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "SparkLineChart", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _SparkLineChart.SparkLineChart;
10
+ }
11
+ });
12
+ var _SparkLineChart = require("./SparkLineChart");
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "../esm/SparkLineChart/index.js",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts"
6
+ }
@@ -1,10 +1,12 @@
1
1
  import * as React from 'react';
2
2
  import { AxisConfig, AxisDefaultized } from '../models/axis';
3
3
  import { DEFAULT_X_AXIS_KEY } from '../constants';
4
+ import { DatasetType } from '../models/seriesType/config';
4
5
  import { MakeOptional } from '../models/helpers';
5
6
  export type CartesianContextProviderProps = {
6
7
  xAxis?: MakeOptional<AxisConfig, 'id'>[];
7
8
  yAxis?: MakeOptional<AxisConfig, 'id'>[];
9
+ dataset?: DatasetType;
8
10
  children: React.ReactNode;
9
11
  };
10
12
  type DefaultizedAxisConfig = {
@@ -23,7 +25,7 @@ export declare const CartesianContext: React.Context<{
23
25
  xAxisIds: string[];
24
26
  yAxisIds: string[];
25
27
  }>;
26
- declare function CartesianContextProvider({ xAxis, yAxis, children }: CartesianContextProviderProps): React.JSX.Element;
28
+ declare function CartesianContextProvider({ xAxis: inXAxis, yAxis: inYAxis, dataset, children, }: CartesianContextProviderProps): React.JSX.Element;
27
29
  declare namespace CartesianContextProvider {
28
30
  var propTypes: any;
29
31
  }