@mui/x-charts 7.0.0-alpha.8 → 7.0.0-beta.0

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 (103) hide show
  1. package/BarChart/BarChart.js +1 -19
  2. package/BarChart/formatter.js +1 -1
  3. package/CHANGELOG.md +508 -30
  4. package/ChartContainer/ChartContainer.d.ts +12 -0
  5. package/ChartContainer/ChartContainer.js +197 -0
  6. package/ChartContainer/index.d.ts +1 -11
  7. package/ChartContainer/index.js +9 -63
  8. package/ChartsTooltip/ChartsAxisTooltipContent.js +2 -54
  9. package/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  10. package/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -54
  11. package/ChartsTooltip/DefaultChartsItemTooltipContent.js +3 -15
  12. package/LineChart/LineChart.js +1 -23
  13. package/LineChart/formatter.js +6 -2
  14. package/PieChart/PieArcLabel.js +1 -1
  15. package/PieChart/PieChart.js +1 -46
  16. package/README.md +3 -3
  17. package/ResponsiveChartContainer/ResponsiveChartContainer.d.ts +16 -0
  18. package/ResponsiveChartContainer/ResponsiveChartContainer.js +250 -0
  19. package/ResponsiveChartContainer/index.d.ts +1 -15
  20. package/ResponsiveChartContainer/index.js +8 -113
  21. package/ScatterChart/Scatter.js +1 -20
  22. package/ScatterChart/ScatterChart.js +1 -20
  23. package/SparkLineChart/SparkLineChart.d.ts +2 -2
  24. package/SparkLineChart/SparkLineChart.js +2 -2
  25. package/esm/BarChart/BarChart.js +1 -19
  26. package/esm/BarChart/formatter.js +1 -1
  27. package/esm/ChartContainer/ChartContainer.js +189 -0
  28. package/esm/ChartContainer/index.js +1 -61
  29. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +2 -54
  30. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  31. package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -54
  32. package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +4 -15
  33. package/esm/LineChart/LineChart.js +1 -23
  34. package/esm/LineChart/formatter.js +6 -2
  35. package/esm/PieChart/PieArcLabel.js +1 -1
  36. package/esm/PieChart/PieChart.js +1 -46
  37. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +245 -0
  38. package/esm/ResponsiveChartContainer/index.js +1 -115
  39. package/esm/ScatterChart/Scatter.js +1 -20
  40. package/esm/ScatterChart/ScatterChart.js +1 -20
  41. package/esm/SparkLineChart/SparkLineChart.js +2 -2
  42. package/esm/hooks/useAxisEvents.js +1 -3
  43. package/esm/internals/stackSeries.js +5 -3
  44. package/esm/models/index.js +1 -0
  45. package/esm/models/stacking.js +1 -0
  46. package/hooks/useAxisEvents.js +1 -3
  47. package/index.js +1 -1
  48. package/internals/defaultizeColor.d.ts +9 -9
  49. package/internals/stackSeries.d.ts +8 -3
  50. package/internals/stackSeries.js +4 -3
  51. package/legacy/BarChart/BarChart.js +1 -19
  52. package/legacy/BarChart/formatter.js +1 -1
  53. package/legacy/ChartContainer/ChartContainer.js +187 -0
  54. package/legacy/ChartContainer/index.js +1 -59
  55. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +2 -54
  56. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  57. package/legacy/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -54
  58. package/legacy/ChartsTooltip/DefaultChartsItemTooltipContent.js +4 -15
  59. package/legacy/LineChart/LineChart.js +1 -23
  60. package/legacy/LineChart/formatter.js +7 -3
  61. package/legacy/PieChart/PieArcLabel.js +3 -1
  62. package/legacy/PieChart/PieChart.js +1 -46
  63. package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +253 -0
  64. package/legacy/ResponsiveChartContainer/index.js +1 -123
  65. package/legacy/ScatterChart/Scatter.js +1 -20
  66. package/legacy/ScatterChart/ScatterChart.js +1 -20
  67. package/legacy/SparkLineChart/SparkLineChart.js +2 -2
  68. package/legacy/hooks/useAxisEvents.js +1 -3
  69. package/legacy/index.js +1 -1
  70. package/legacy/internals/stackSeries.js +5 -3
  71. package/legacy/models/index.js +1 -0
  72. package/legacy/models/stacking.js +1 -0
  73. package/models/index.d.ts +1 -0
  74. package/models/index.js +11 -0
  75. package/models/seriesType/bar.d.ts +8 -2
  76. package/models/seriesType/common.d.ts +3 -4
  77. package/models/seriesType/index.d.ts +0 -1
  78. package/models/seriesType/line.d.ts +7 -1
  79. package/models/stacking.d.ts +2 -0
  80. package/models/stacking.js +5 -0
  81. package/modern/BarChart/BarChart.js +1 -19
  82. package/modern/BarChart/formatter.js +1 -1
  83. package/modern/ChartContainer/ChartContainer.js +189 -0
  84. package/modern/ChartContainer/index.js +1 -61
  85. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +2 -54
  86. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +1 -11
  87. package/modern/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -54
  88. package/modern/ChartsTooltip/DefaultChartsItemTooltipContent.js +3 -15
  89. package/modern/LineChart/LineChart.js +1 -23
  90. package/modern/LineChart/formatter.js +6 -2
  91. package/modern/PieChart/PieArcLabel.js +1 -1
  92. package/modern/PieChart/PieChart.js +1 -46
  93. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +242 -0
  94. package/modern/ResponsiveChartContainer/index.js +1 -112
  95. package/modern/ScatterChart/Scatter.js +1 -20
  96. package/modern/ScatterChart/ScatterChart.js +1 -20
  97. package/modern/SparkLineChart/SparkLineChart.js +2 -2
  98. package/modern/hooks/useAxisEvents.js +1 -3
  99. package/modern/index.js +1 -1
  100. package/modern/internals/stackSeries.js +4 -3
  101. package/modern/models/index.js +1 -0
  102. package/modern/models/stacking.js +1 -0
  103. package/package.json +7 -7
@@ -0,0 +1,253 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
+ var _excluded = ["width", "height"];
5
+ import * as React from 'react';
6
+ import PropTypes from 'prop-types';
7
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
8
+ import ownerWindow from '@mui/utils/ownerWindow';
9
+ import { styled } from '@mui/material/styles';
10
+ import { ChartContainer } from '../ChartContainer';
11
+ import { jsx as _jsx } from "react/jsx-runtime";
12
+ var useChartDimensions = function useChartDimensions(inWidth, inHeight) {
13
+ var rootRef = React.useRef(null);
14
+ var displayError = React.useRef(false);
15
+ var _React$useState = React.useState(0),
16
+ _React$useState2 = _slicedToArray(_React$useState, 2),
17
+ width = _React$useState2[0],
18
+ setWidth = _React$useState2[1];
19
+ var _React$useState3 = React.useState(0),
20
+ _React$useState4 = _slicedToArray(_React$useState3, 2),
21
+ height = _React$useState4[0],
22
+ setHeight = _React$useState4[1];
23
+
24
+ // Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
25
+ var computeSize = React.useCallback(function () {
26
+ var mainEl = rootRef == null ? void 0 : rootRef.current;
27
+ if (!mainEl) {
28
+ return;
29
+ }
30
+ var win = ownerWindow(mainEl);
31
+ var computedStyle = win.getComputedStyle(mainEl);
32
+ var newHeight = Math.floor(parseFloat(computedStyle.height)) || 0;
33
+ var newWidth = Math.floor(parseFloat(computedStyle.width)) || 0;
34
+ setWidth(newWidth);
35
+ setHeight(newHeight);
36
+ }, []);
37
+ React.useEffect(function () {
38
+ // Ensure the error detection occurs after the first rendering.
39
+ displayError.current = true;
40
+ }, []);
41
+ useEnhancedEffect(function () {
42
+ if (inWidth !== undefined && inHeight !== undefined) {
43
+ return function () {};
44
+ }
45
+ computeSize();
46
+ var elementToObserve = rootRef.current;
47
+ if (typeof ResizeObserver === 'undefined') {
48
+ return function () {};
49
+ }
50
+ var animationFrame;
51
+ var observer = new ResizeObserver(function () {
52
+ // See https://github.com/mui/mui-x/issues/8733
53
+ animationFrame = requestAnimationFrame(function () {
54
+ computeSize();
55
+ });
56
+ });
57
+ if (elementToObserve) {
58
+ observer.observe(elementToObserve);
59
+ }
60
+ return function () {
61
+ if (animationFrame) {
62
+ window.cancelAnimationFrame(animationFrame);
63
+ }
64
+ if (elementToObserve) {
65
+ observer.unobserve(elementToObserve);
66
+ }
67
+ };
68
+ }, [computeSize, inHeight, inWidth]);
69
+ if (process.env.NODE_ENV !== 'production') {
70
+ if (displayError.current && inWidth === undefined && width === 0) {
71
+ console.error("MUI X Charts: ChartContainer does not have `width` prop, and its container has no `width` defined.");
72
+ displayError.current = false;
73
+ }
74
+ if (displayError.current && inHeight === undefined && height === 0) {
75
+ console.error("MUI X Charts: ChartContainer does not have `height` prop, and its container has no `height` defined.");
76
+ displayError.current = false;
77
+ }
78
+ }
79
+ return [rootRef, inWidth != null ? inWidth : width, inHeight != null ? inHeight : height];
80
+ };
81
+ var ResizableContainer = styled('div', {
82
+ name: 'MuiResponsiveChart',
83
+ slot: 'Container'
84
+ })(function (_ref) {
85
+ var _ownerState$width, _ownerState$height;
86
+ var ownerState = _ref.ownerState;
87
+ return {
88
+ width: (_ownerState$width = ownerState.width) != null ? _ownerState$width : '100%',
89
+ height: (_ownerState$height = ownerState.height) != null ? _ownerState$height : '100%',
90
+ display: 'flex',
91
+ position: 'relative',
92
+ flexGrow: 1,
93
+ flexDirection: 'column',
94
+ alignItems: 'center',
95
+ justifyContent: 'center',
96
+ overflow: 'hidden',
97
+ '&>svg': {
98
+ width: '100%',
99
+ height: '100%'
100
+ }
101
+ };
102
+ });
103
+ var ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
104
+ var inWidth = props.width,
105
+ inHeight = props.height,
106
+ other = _objectWithoutProperties(props, _excluded);
107
+ var _useChartDimensions = useChartDimensions(inWidth, inHeight),
108
+ _useChartDimensions2 = _slicedToArray(_useChartDimensions, 3),
109
+ containerRef = _useChartDimensions2[0],
110
+ width = _useChartDimensions2[1],
111
+ height = _useChartDimensions2[2];
112
+ return /*#__PURE__*/_jsx(ResizableContainer, {
113
+ ref: containerRef,
114
+ ownerState: {
115
+ width: inWidth,
116
+ height: inHeight
117
+ },
118
+ children: width && height ? /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
119
+ width: width,
120
+ height: height,
121
+ ref: ref
122
+ })) : null
123
+ });
124
+ });
125
+ process.env.NODE_ENV !== "production" ? ResponsiveChartContainer.propTypes = {
126
+ // ----------------------------- Warning --------------------------------
127
+ // | These PropTypes are generated from the TypeScript type definitions |
128
+ // | To update them edit the TypeScript types and run "yarn proptypes" |
129
+ // ----------------------------------------------------------------------
130
+ children: PropTypes.node,
131
+ className: PropTypes.string,
132
+ /**
133
+ * Color palette used to colorize multiple series.
134
+ * @default blueberryTwilightPalette
135
+ */
136
+ colors: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.string), PropTypes.func]),
137
+ /**
138
+ * An array of objects that can be used to populate series and axes data using their `dataKey` property.
139
+ */
140
+ dataset: PropTypes.arrayOf(PropTypes.object),
141
+ desc: PropTypes.string,
142
+ /**
143
+ * If `true`, the charts will not listen to the mouse move event.
144
+ * It might break interactive features, but will improve performance.
145
+ * @default false
146
+ */
147
+ disableAxisListener: PropTypes.bool,
148
+ /**
149
+ * The height of the chart in px. If not defined, it takes the height of the parent element.
150
+ * @default undefined
151
+ */
152
+ height: PropTypes.number,
153
+ /**
154
+ * The margin between the SVG and the drawing area.
155
+ * It's used for leaving some space for extra information such as the x- and y-axis or legend.
156
+ * Accepts an object with the optional properties: `top`, `bottom`, `left`, and `right`.
157
+ * @default object Depends on the charts type.
158
+ */
159
+ margin: PropTypes.shape({
160
+ bottom: PropTypes.number,
161
+ left: PropTypes.number,
162
+ right: PropTypes.number,
163
+ top: PropTypes.number
164
+ }),
165
+ /**
166
+ * The array of series to display.
167
+ * Each type of series has its own specificity.
168
+ * Please refer to the appropriate docs page to learn more about it.
169
+ */
170
+ series: PropTypes.arrayOf(PropTypes.object).isRequired,
171
+ sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
172
+ title: PropTypes.string,
173
+ viewBox: PropTypes.shape({
174
+ height: PropTypes.number,
175
+ width: PropTypes.number,
176
+ x: PropTypes.number,
177
+ y: PropTypes.number
178
+ }),
179
+ /**
180
+ * The width of the chart in px. If not defined, it takes the width of the parent element.
181
+ * @default undefined
182
+ */
183
+ width: PropTypes.number,
184
+ /**
185
+ * The configuration of the x-axes.
186
+ * If not provided, a default axis config is used with id set to `DEFAULT_X_AXIS_KEY`.
187
+ */
188
+ xAxis: PropTypes.arrayOf(PropTypes.shape({
189
+ axisId: PropTypes.string,
190
+ classes: PropTypes.object,
191
+ data: PropTypes.array,
192
+ dataKey: PropTypes.string,
193
+ disableLine: PropTypes.bool,
194
+ disableTicks: PropTypes.bool,
195
+ fill: PropTypes.string,
196
+ hideTooltip: PropTypes.bool,
197
+ id: PropTypes.string,
198
+ label: PropTypes.string,
199
+ labelFontSize: PropTypes.number,
200
+ labelStyle: PropTypes.object,
201
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
202
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
203
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
204
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
205
+ slotProps: PropTypes.object,
206
+ slots: PropTypes.object,
207
+ stroke: PropTypes.string,
208
+ tickFontSize: PropTypes.number,
209
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
210
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
211
+ tickLabelStyle: PropTypes.object,
212
+ tickMaxStep: PropTypes.number,
213
+ tickMinStep: PropTypes.number,
214
+ tickNumber: PropTypes.number,
215
+ tickSize: PropTypes.number,
216
+ valueFormatter: PropTypes.func
217
+ })),
218
+ /**
219
+ * The configuration of the y-axes.
220
+ * If not provided, a default axis config is used with id set to `DEFAULT_Y_AXIS_KEY`.
221
+ */
222
+ yAxis: PropTypes.arrayOf(PropTypes.shape({
223
+ axisId: PropTypes.string,
224
+ classes: PropTypes.object,
225
+ data: PropTypes.array,
226
+ dataKey: PropTypes.string,
227
+ disableLine: PropTypes.bool,
228
+ disableTicks: PropTypes.bool,
229
+ fill: PropTypes.string,
230
+ hideTooltip: PropTypes.bool,
231
+ id: PropTypes.string,
232
+ label: PropTypes.string,
233
+ labelFontSize: PropTypes.number,
234
+ labelStyle: PropTypes.object,
235
+ max: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
236
+ min: PropTypes.oneOfType([PropTypes.instanceOf(Date), PropTypes.number]),
237
+ position: PropTypes.oneOf(['bottom', 'left', 'right', 'top']),
238
+ scaleType: PropTypes.oneOf(['band', 'linear', 'log', 'point', 'pow', 'sqrt', 'time', 'utc']),
239
+ slotProps: PropTypes.object,
240
+ slots: PropTypes.object,
241
+ stroke: PropTypes.string,
242
+ tickFontSize: PropTypes.number,
243
+ tickInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.array, PropTypes.func]),
244
+ tickLabelInterval: PropTypes.oneOfType([PropTypes.oneOf(['auto']), PropTypes.func]),
245
+ tickLabelStyle: PropTypes.object,
246
+ tickMaxStep: PropTypes.number,
247
+ tickMinStep: PropTypes.number,
248
+ tickNumber: PropTypes.number,
249
+ tickSize: PropTypes.number,
250
+ valueFormatter: PropTypes.func
251
+ }))
252
+ } : void 0;
253
+ export { ResponsiveChartContainer };
@@ -1,123 +1 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
4
- var _excluded = ["width", "height"];
5
- import * as React from 'react';
6
- import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
7
- import ownerWindow from '@mui/utils/ownerWindow';
8
- import { styled } from '@mui/material/styles';
9
- import { ChartContainer } from '../ChartContainer';
10
- import { jsx as _jsx } from "react/jsx-runtime";
11
- var useChartDimensions = function useChartDimensions(inWidth, inHeight) {
12
- var rootRef = React.useRef(null);
13
- var displayError = React.useRef(false);
14
- var _React$useState = React.useState(0),
15
- _React$useState2 = _slicedToArray(_React$useState, 2),
16
- width = _React$useState2[0],
17
- setWidth = _React$useState2[1];
18
- var _React$useState3 = React.useState(0),
19
- _React$useState4 = _slicedToArray(_React$useState3, 2),
20
- height = _React$useState4[0],
21
- setHeight = _React$useState4[1];
22
-
23
- // Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
24
- var computeSize = React.useCallback(function () {
25
- var mainEl = rootRef == null ? void 0 : rootRef.current;
26
- if (!mainEl) {
27
- return;
28
- }
29
- var win = ownerWindow(mainEl);
30
- var computedStyle = win.getComputedStyle(mainEl);
31
- var newHeight = Math.floor(parseFloat(computedStyle.height)) || 0;
32
- var newWidth = Math.floor(parseFloat(computedStyle.width)) || 0;
33
- setWidth(newWidth);
34
- setHeight(newHeight);
35
- }, []);
36
- React.useEffect(function () {
37
- // Ensure the error detection occurs after the first rendering.
38
- displayError.current = true;
39
- }, []);
40
- useEnhancedEffect(function () {
41
- if (inWidth !== undefined && inHeight !== undefined) {
42
- return function () {};
43
- }
44
- computeSize();
45
- var elementToObserve = rootRef.current;
46
- if (typeof ResizeObserver === 'undefined') {
47
- return function () {};
48
- }
49
- var animationFrame;
50
- var observer = new ResizeObserver(function () {
51
- // See https://github.com/mui/mui-x/issues/8733
52
- animationFrame = requestAnimationFrame(function () {
53
- computeSize();
54
- });
55
- });
56
- if (elementToObserve) {
57
- observer.observe(elementToObserve);
58
- }
59
- return function () {
60
- if (animationFrame) {
61
- window.cancelAnimationFrame(animationFrame);
62
- }
63
- if (elementToObserve) {
64
- observer.unobserve(elementToObserve);
65
- }
66
- };
67
- }, [computeSize, inHeight, inWidth]);
68
- if (process.env.NODE_ENV !== 'production') {
69
- if (displayError.current && inWidth === undefined && width === 0) {
70
- console.error("MUI X Charts: ChartContainer does not have `width` prop, and its container has no `width` defined.");
71
- displayError.current = false;
72
- }
73
- if (displayError.current && inHeight === undefined && height === 0) {
74
- console.error("MUI X Charts: ChartContainer does not have `height` prop, and its container has no `height` defined.");
75
- displayError.current = false;
76
- }
77
- }
78
- return [rootRef, inWidth != null ? inWidth : width, inHeight != null ? inHeight : height];
79
- };
80
- var ResizableContainer = styled('div', {
81
- name: 'MuiResponsiveChart',
82
- slot: 'Container'
83
- })(function (_ref) {
84
- var _ownerState$width, _ownerState$height;
85
- var ownerState = _ref.ownerState;
86
- return {
87
- width: (_ownerState$width = ownerState.width) != null ? _ownerState$width : '100%',
88
- height: (_ownerState$height = ownerState.height) != null ? _ownerState$height : '100%',
89
- display: 'flex',
90
- position: 'relative',
91
- flexGrow: 1,
92
- flexDirection: 'column',
93
- alignItems: 'center',
94
- justifyContent: 'center',
95
- overflow: 'hidden',
96
- '&>svg': {
97
- width: '100%',
98
- height: '100%'
99
- }
100
- };
101
- });
102
- export var ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
103
- var inWidth = props.width,
104
- inHeight = props.height,
105
- other = _objectWithoutProperties(props, _excluded);
106
- var _useChartDimensions = useChartDimensions(inWidth, inHeight),
107
- _useChartDimensions2 = _slicedToArray(_useChartDimensions, 3),
108
- containerRef = _useChartDimensions2[0],
109
- width = _useChartDimensions2[1],
110
- height = _useChartDimensions2[2];
111
- return /*#__PURE__*/_jsx(ResizableContainer, {
112
- ref: containerRef,
113
- ownerState: {
114
- width: inWidth,
115
- height: inHeight
116
- },
117
- children: width && height ? /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
118
- width: width,
119
- height: height,
120
- ref: ref
121
- })) : null
122
- });
123
- });
1
+ export * from './ResponsiveChartContainer';
@@ -87,26 +87,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
87
87
  // ----------------------------------------------------------------------
88
88
  color: PropTypes.string.isRequired,
89
89
  markerSize: PropTypes.number.isRequired,
90
- series: PropTypes.shape({
91
- color: PropTypes.string.isRequired,
92
- data: PropTypes.arrayOf(PropTypes.shape({
93
- id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
94
- x: PropTypes.number.isRequired,
95
- y: PropTypes.number.isRequired
96
- })).isRequired,
97
- disableHover: PropTypes.bool,
98
- highlightScope: PropTypes.shape({
99
- faded: PropTypes.oneOf(['global', 'none', 'series']),
100
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
101
- }),
102
- id: PropTypes.string.isRequired,
103
- label: PropTypes.string,
104
- markerSize: PropTypes.number,
105
- type: PropTypes.oneOf(['scatter']).isRequired,
106
- valueFormatter: PropTypes.func.isRequired,
107
- xAxisKey: PropTypes.string,
108
- yAxisKey: PropTypes.string
109
- }).isRequired,
90
+ series: PropTypes.object.isRequired,
110
91
  xScale: PropTypes.func.isRequired,
111
92
  yScale: PropTypes.func.isRequired
112
93
  } : void 0;
@@ -222,26 +222,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
222
222
  tickNumber: PropTypes.number,
223
223
  tickSize: PropTypes.number
224
224
  }), PropTypes.string]),
225
- series: PropTypes.arrayOf(PropTypes.shape({
226
- color: PropTypes.string,
227
- data: PropTypes.arrayOf(PropTypes.shape({
228
- id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
229
- x: PropTypes.number.isRequired,
230
- y: PropTypes.number.isRequired
231
- })).isRequired,
232
- disableHover: PropTypes.bool,
233
- highlightScope: PropTypes.shape({
234
- faded: PropTypes.oneOf(['global', 'none', 'series']),
235
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
236
- }),
237
- id: PropTypes.string,
238
- label: PropTypes.string,
239
- markerSize: PropTypes.number,
240
- type: PropTypes.oneOf(['scatter']),
241
- valueFormatter: PropTypes.func,
242
- xAxisKey: PropTypes.string,
243
- yAxisKey: PropTypes.string
244
- })).isRequired,
225
+ series: PropTypes.arrayOf(PropTypes.object).isRequired,
245
226
  /**
246
227
  * The props used for each component slot.
247
228
  * @default {}
@@ -45,7 +45,7 @@ var SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(props
45
45
  plotType = _props$plotType === void 0 ? 'line' : _props$plotType,
46
46
  _props$valueFormatter = props.valueFormatter,
47
47
  valueFormatter = _props$valueFormatter === void 0 ? function (v) {
48
- return v.toString();
48
+ return v === null ? '' : v.toString();
49
49
  } : _props$valueFormatter,
50
50
  area = props.area,
51
51
  _props$curve = props.curve,
@@ -211,7 +211,7 @@ process.env.NODE_ENV !== "production" ? SparkLineChart.propTypes = {
211
211
  * Formatter used by the tooltip.
212
212
  * @param {number} value The value to format.
213
213
  * @returns {string} the formatted value.
214
- * @default (v: number) => v.toString()
214
+ * @default (v: number | null) => (v === null ? '' : v.toString())
215
215
  */
216
216
  valueFormatter: PropTypes.func,
217
217
  viewBox: PropTypes.shape({
@@ -57,9 +57,7 @@ export var useAxisEvents = function useAxisEvents(disableAxisListener) {
57
57
  }
58
58
  }
59
59
  if (v <= valueAsNumber) {
60
- if (index === axisData.length - 1 ||
61
- // @ts-ignore
62
- Math.abs(value - v) < Math.abs(value - getAsANumber(axisData[index + 1]))) {
60
+ if (index === axisData.length - 1 || Math.abs(getAsANumber(value) - v) < Math.abs(getAsANumber(value) - getAsANumber(axisData[index + 1]))) {
63
61
  return true;
64
62
  }
65
63
  }
package/legacy/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.0.0-alpha.8
2
+ * @mui/x-charts v7.0.0-beta.0
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -55,7 +55,8 @@ export var StackOffset = {
55
55
  */
56
56
  export var getStackingGroups = function getStackingGroups(params) {
57
57
  var series = params.series,
58
- seriesOrder = params.seriesOrder;
58
+ seriesOrder = params.seriesOrder,
59
+ defaultStrategy = params.defaultStrategy;
59
60
  var stackingGroups = [];
60
61
  var stackIndex = {};
61
62
  seriesOrder.forEach(function (id) {
@@ -70,11 +71,12 @@ export var getStackingGroups = function getStackingGroups(params) {
70
71
  stackingOffset: StackOffset.none
71
72
  });
72
73
  } else if (stackIndex[stack] === undefined) {
74
+ var _ref, _ref2;
73
75
  stackIndex[stack] = stackingGroups.length;
74
76
  stackingGroups.push({
75
77
  ids: [id],
76
- stackingOrder: StackOrder[stackOrder != null ? stackOrder : 'none'],
77
- stackingOffset: StackOffset[stackOffset != null ? stackOffset : 'diverging']
78
+ stackingOrder: StackOrder[(_ref = stackOrder != null ? stackOrder : defaultStrategy == null ? void 0 : defaultStrategy.stackOrder) != null ? _ref : 'none'],
79
+ stackingOffset: StackOffset[(_ref2 = stackOffset != null ? stackOffset : defaultStrategy == null ? void 0 : defaultStrategy.stackOffset) != null ? _ref2 : 'diverging']
78
80
  });
79
81
  } else {
80
82
  stackingGroups[stackIndex[stack]].ids.push(id);
@@ -1,3 +1,4 @@
1
1
  export * from './seriesType';
2
2
  export * from './layout';
3
+ export * from './stacking';
3
4
  export {};
@@ -0,0 +1 @@
1
+ export {};
package/models/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './seriesType';
2
2
  export * from './layout';
3
+ export * from './stacking';
3
4
  export type { AxisConfig, ChartsYAxisProps, ChartsXAxisProps, ScaleName, ContinuouseScaleName, } from './axis';
package/models/index.js CHANGED
@@ -24,4 +24,15 @@ Object.keys(_layout).forEach(function (key) {
24
24
  return _layout[key];
25
25
  }
26
26
  });
27
+ });
28
+ var _stacking = require("./stacking");
29
+ Object.keys(_stacking).forEach(function (key) {
30
+ if (key === "default" || key === "__esModule") return;
31
+ if (key in exports && exports[key] === _stacking[key]) return;
32
+ Object.defineProperty(exports, key, {
33
+ enumerable: true,
34
+ get: function () {
35
+ return _stacking[key];
36
+ }
37
+ });
27
38
  });
@@ -1,11 +1,12 @@
1
1
  import { DefaultizedProps } from '../helpers';
2
+ import type { StackOffsetType } from '../stacking';
2
3
  import { CartesianSeriesType, CommonSeriesType, CommonDefaultizedProps, StackableSeriesType } from './common';
3
- export interface BarSeriesType extends CommonSeriesType<number>, CartesianSeriesType, StackableSeriesType {
4
+ export interface BarSeriesType extends CommonSeriesType<number | null>, CartesianSeriesType, StackableSeriesType {
4
5
  type: 'bar';
5
6
  /**
6
7
  * Data associated to each bar.
7
8
  */
8
- data?: number[];
9
+ data?: (number | null)[];
9
10
  /**
10
11
  * The key used to retrive data from the dataset.
11
12
  */
@@ -16,6 +17,11 @@ export interface BarSeriesType extends CommonSeriesType<number>, CartesianSeries
16
17
  * @default 'vertical'
17
18
  */
18
19
  layout?: 'horizontal' | 'vertical';
20
+ /**
21
+ * Defines how stacked series handle negative values.
22
+ * @default 'diverging'
23
+ */
24
+ stackOffset?: StackOffsetType;
19
25
  }
20
26
  /**
21
27
  * An object that allows to identify a single bar.
@@ -1,5 +1,5 @@
1
1
  import type { HighlightScope } from '../../context/HighlightProvider';
2
- import type { StackOffset, StackOrder } from '../../internals/stackSeries';
2
+ import type { StackOffsetType, StackOrderType } from '../stacking';
3
3
  export type CommonSeriesType<TValue> = {
4
4
  id?: string;
5
5
  color?: string;
@@ -8,7 +8,7 @@ export type CommonSeriesType<TValue> = {
8
8
  * @param {TValue} value The series' value to render.
9
9
  * @returns {string} The string to dispaly.
10
10
  */
11
- valueFormatter?: (value: TValue) => string;
11
+ valueFormatter?: <V extends TValue>(value: V) => string;
12
12
  highlightScope?: Partial<HighlightScope>;
13
13
  };
14
14
  export type CommonDefaultizedProps = 'id' | 'valueFormatter' | 'data';
@@ -34,9 +34,8 @@ export type StackableSeriesType = {
34
34
  stackOffset?: StackOffsetType;
35
35
  /**
36
36
  * The order in which series' of the same group are stacked together.
37
+ * @default 'none'
37
38
  */
38
39
  stackOrder?: StackOrderType;
39
40
  };
40
- export type StackOrderType = keyof typeof StackOrder;
41
- export type StackOffsetType = keyof typeof StackOffset;
42
41
  export type DefaultizedCartesianSeriesType = Required<CartesianSeriesType>;
@@ -13,5 +13,4 @@ export * from './line';
13
13
  export * from './bar';
14
14
  export * from './scatter';
15
15
  export * from './pie';
16
- export type { StackOrderType, StackOffsetType } from './common';
17
16
  export type { AllSeriesType, CartesianSeriesType, DefaultizedSeriesType, DefaultizedCartesianSeriesType, StackableSeriesType, };
@@ -1,4 +1,5 @@
1
1
  import { DefaultizedProps } from '../helpers';
2
+ import type { StackOffsetType } from '../stacking';
2
3
  import { CartesianSeriesType, CommonDefaultizedProps, CommonSeriesType, StackableSeriesType } from './common';
3
4
  export type CurveType = 'catmullRom' | 'linear' | 'monotoneX' | 'monotoneY' | 'natural' | 'step' | 'stepBefore' | 'stepAfter';
4
5
  export interface ShowMarkParams<AxisValue = number | Date> {
@@ -23,7 +24,7 @@ export interface ShowMarkParams<AxisValue = number | Date> {
23
24
  */
24
25
  value: number;
25
26
  }
26
- export interface LineSeriesType extends CommonSeriesType<number>, CartesianSeriesType, StackableSeriesType {
27
+ export interface LineSeriesType extends CommonSeriesType<number | null>, CartesianSeriesType, StackableSeriesType {
27
28
  type: 'line';
28
29
  /**
29
30
  * Data associated to the line.
@@ -53,6 +54,11 @@ export interface LineSeriesType extends CommonSeriesType<number>, CartesianSerie
53
54
  * @default false
54
55
  */
55
56
  connectNulls?: boolean;
57
+ /**
58
+ * Defines how stacked series handle negative values.
59
+ * @default 'none'
60
+ */
61
+ stackOffset?: StackOffsetType;
56
62
  }
57
63
  /**
58
64
  * An object that allows to identify a single line.
@@ -0,0 +1,2 @@
1
+ export type StackOrderType = 'appearance' | 'ascending' | 'descending' | 'insideOut' | 'none' | 'reverse';
2
+ export type StackOffsetType = 'expand' | 'diverging' | 'none' | 'silhouette' | 'wiggle';
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -253,25 +253,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
253
253
  tickNumber: PropTypes.number,
254
254
  tickSize: PropTypes.number
255
255
  }), PropTypes.string]),
256
- series: PropTypes.arrayOf(PropTypes.shape({
257
- color: PropTypes.string,
258
- data: PropTypes.arrayOf(PropTypes.number),
259
- dataKey: PropTypes.string,
260
- highlightScope: PropTypes.shape({
261
- faded: PropTypes.oneOf(['global', 'none', 'series']),
262
- highlighted: PropTypes.oneOf(['item', 'none', 'series'])
263
- }),
264
- id: PropTypes.string,
265
- label: PropTypes.string,
266
- layout: PropTypes.oneOf(['horizontal', 'vertical']),
267
- stack: PropTypes.string,
268
- stackOffset: PropTypes.oneOf(['diverging', 'expand', 'none', 'silhouette', 'wiggle']),
269
- stackOrder: PropTypes.oneOf(['appearance', 'ascending', 'descending', 'insideOut', 'none', 'reverse']),
270
- type: PropTypes.oneOf(['bar']),
271
- valueFormatter: PropTypes.func,
272
- xAxisKey: PropTypes.string,
273
- yAxisKey: PropTypes.string
274
- })).isRequired,
256
+ series: PropTypes.arrayOf(PropTypes.object).isRequired,
275
257
  /**
276
258
  * If `true`, animations are skiped.
277
259
  * @default false
@@ -65,7 +65,7 @@ const formatter = (params, dataset) => {
65
65
  return {
66
66
  seriesOrder,
67
67
  stackingGroups,
68
- series: defaultizeValueFormatter(completedSeries, v => v?.toLocaleString())
68
+ series: defaultizeValueFormatter(completedSeries, v => v === null ? '' : v.toLocaleString())
69
69
  };
70
70
  };
71
71
  export default formatter;