@mui/x-charts 7.0.0-beta.2 → 7.0.0-beta.3

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 (124) hide show
  1. package/BarChart/BarChart.d.ts +21 -5
  2. package/BarChart/BarChart.js +27 -5
  3. package/CHANGELOG.md +73 -9
  4. package/ChartsGrid/ChartsGrid.d.ts +30 -0
  5. package/ChartsGrid/ChartsGrid.js +128 -0
  6. package/ChartsGrid/chartsGridClasses.d.ts +13 -0
  7. package/ChartsGrid/chartsGridClasses.js +14 -0
  8. package/ChartsGrid/index.d.ts +2 -0
  9. package/ChartsGrid/index.js +27 -0
  10. package/ChartsGrid/package.json +6 -0
  11. package/ChartsSurface.js +6 -4
  12. package/ChartsXAxis/ChartsXAxis.js +2 -2
  13. package/ChartsYAxis/ChartsYAxis.js +2 -2
  14. package/Gauge/Gauge.d.ts +13 -0
  15. package/Gauge/Gauge.js +156 -0
  16. package/Gauge/GaugeContainer.d.ts +19 -0
  17. package/Gauge/GaugeContainer.js +216 -0
  18. package/Gauge/GaugeProvider.d.ts +117 -0
  19. package/Gauge/GaugeProvider.js +96 -0
  20. package/Gauge/GaugeReferenceArc.d.ts +2 -0
  21. package/Gauge/GaugeReferenceArc.js +44 -0
  22. package/Gauge/GaugeValueArc.d.ts +2 -0
  23. package/Gauge/GaugeValueArc.js +51 -0
  24. package/Gauge/GaugeValueText.d.ts +15 -0
  25. package/Gauge/GaugeValueText.js +77 -0
  26. package/Gauge/gaugeClasses.d.ts +14 -0
  27. package/Gauge/gaugeClasses.js +15 -0
  28. package/Gauge/index.d.ts +7 -0
  29. package/Gauge/index.js +87 -0
  30. package/Gauge/package.json +6 -0
  31. package/Gauge/utils.d.ts +19 -0
  32. package/Gauge/utils.js +75 -0
  33. package/LineChart/LineChart.d.ts +24 -5
  34. package/LineChart/LineChart.js +31 -5
  35. package/PieChart/PieArc.d.ts +4 -4
  36. package/PieChart/PieArc.js +9 -9
  37. package/PieChart/PieArcLabelPlot.js +13 -13
  38. package/PieChart/PieChart.d.ts +22 -0
  39. package/PieChart/PieChart.js +22 -0
  40. package/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -66
  41. package/ResponsiveChartContainer/useChartContainerDimensions.d.ts +2 -0
  42. package/ResponsiveChartContainer/useChartContainerDimensions.js +76 -0
  43. package/ScatterChart/ScatterChart.d.ts +18 -0
  44. package/ScatterChart/ScatterChart.js +25 -0
  45. package/esm/BarChart/BarChart.js +27 -5
  46. package/esm/ChartsGrid/ChartsGrid.js +121 -0
  47. package/esm/ChartsGrid/chartsGridClasses.js +6 -0
  48. package/esm/ChartsGrid/index.js +2 -0
  49. package/esm/ChartsSurface.js +6 -4
  50. package/esm/ChartsXAxis/ChartsXAxis.js +1 -1
  51. package/esm/ChartsYAxis/ChartsYAxis.js +1 -1
  52. package/esm/Gauge/Gauge.js +149 -0
  53. package/esm/Gauge/GaugeContainer.js +211 -0
  54. package/esm/Gauge/GaugeProvider.js +85 -0
  55. package/esm/Gauge/GaugeReferenceArc.js +35 -0
  56. package/esm/Gauge/GaugeValueArc.js +42 -0
  57. package/esm/Gauge/GaugeValueText.js +69 -0
  58. package/esm/Gauge/gaugeClasses.js +7 -0
  59. package/esm/Gauge/index.js +7 -0
  60. package/esm/Gauge/utils.js +68 -0
  61. package/esm/LineChart/LineChart.js +31 -5
  62. package/esm/PieChart/PieArc.js +9 -9
  63. package/esm/PieChart/PieArcLabelPlot.js +13 -13
  64. package/esm/PieChart/PieChart.js +22 -0
  65. package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -66
  66. package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +66 -0
  67. package/esm/ScatterChart/ScatterChart.js +25 -0
  68. package/esm/hooks/useTicks.js +2 -3
  69. package/esm/index.js +2 -0
  70. package/hooks/useTicks.d.ts +1 -2
  71. package/hooks/useTicks.js +2 -3
  72. package/index.d.ts +2 -0
  73. package/index.js +23 -1
  74. package/legacy/BarChart/BarChart.js +27 -5
  75. package/legacy/ChartsGrid/ChartsGrid.js +119 -0
  76. package/legacy/ChartsGrid/chartsGridClasses.js +6 -0
  77. package/legacy/ChartsGrid/index.js +2 -0
  78. package/legacy/ChartsSurface.js +5 -3
  79. package/legacy/ChartsXAxis/ChartsXAxis.js +1 -1
  80. package/legacy/ChartsYAxis/ChartsYAxis.js +1 -1
  81. package/legacy/Gauge/Gauge.js +146 -0
  82. package/legacy/Gauge/GaugeContainer.js +215 -0
  83. package/legacy/Gauge/GaugeProvider.js +87 -0
  84. package/legacy/Gauge/GaugeReferenceArc.js +37 -0
  85. package/legacy/Gauge/GaugeValueArc.js +44 -0
  86. package/legacy/Gauge/GaugeValueText.js +66 -0
  87. package/legacy/Gauge/gaugeClasses.js +7 -0
  88. package/legacy/Gauge/index.js +7 -0
  89. package/legacy/Gauge/utils.js +84 -0
  90. package/legacy/LineChart/LineChart.js +31 -5
  91. package/legacy/PieChart/PieArc.js +10 -10
  92. package/legacy/PieChart/PieArcLabelPlot.js +14 -14
  93. package/legacy/PieChart/PieChart.js +22 -0
  94. package/legacy/ResponsiveChartContainer/ResponsiveChartContainer.js +7 -77
  95. package/legacy/ResponsiveChartContainer/useChartContainerDimensions.js +73 -0
  96. package/legacy/ScatterChart/ScatterChart.js +25 -0
  97. package/legacy/hooks/useTicks.js +2 -3
  98. package/legacy/index.js +3 -1
  99. package/modern/BarChart/BarChart.js +27 -5
  100. package/modern/ChartsGrid/ChartsGrid.js +121 -0
  101. package/modern/ChartsGrid/chartsGridClasses.js +6 -0
  102. package/modern/ChartsGrid/index.js +2 -0
  103. package/modern/ChartsSurface.js +6 -4
  104. package/modern/ChartsXAxis/ChartsXAxis.js +1 -1
  105. package/modern/ChartsYAxis/ChartsYAxis.js +1 -1
  106. package/modern/Gauge/Gauge.js +149 -0
  107. package/modern/Gauge/GaugeContainer.js +208 -0
  108. package/modern/Gauge/GaugeProvider.js +85 -0
  109. package/modern/Gauge/GaugeReferenceArc.js +35 -0
  110. package/modern/Gauge/GaugeValueArc.js +42 -0
  111. package/modern/Gauge/GaugeValueText.js +69 -0
  112. package/modern/Gauge/gaugeClasses.js +7 -0
  113. package/modern/Gauge/index.js +7 -0
  114. package/modern/Gauge/utils.js +68 -0
  115. package/modern/LineChart/LineChart.js +31 -5
  116. package/modern/PieChart/PieArc.js +9 -9
  117. package/modern/PieChart/PieArcLabelPlot.js +13 -13
  118. package/modern/PieChart/PieChart.js +22 -0
  119. package/modern/ResponsiveChartContainer/ResponsiveChartContainer.js +2 -66
  120. package/modern/ResponsiveChartContainer/useChartContainerDimensions.js +66 -0
  121. package/modern/ScatterChart/ScatterChart.js +25 -0
  122. package/modern/hooks/useTicks.js +2 -3
  123. package/modern/index.js +3 -1
  124. package/package.json +4 -4
@@ -13,6 +13,7 @@ import { ChartsLegend } from '../ChartsLegend';
13
13
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
14
14
  import { ChartsClipPath } from '../ChartsClipPath';
15
15
  import { LineHighlightPlot } from './LineHighlightPlot';
16
+ import { ChartsGrid } from '../ChartsGrid';
16
17
  import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
17
18
  import { jsx as _jsx } from "react/jsx-runtime";
18
19
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -47,6 +48,7 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
47
48
  },
48
49
  disableLineItemHighlight,
49
50
  legend,
51
+ grid,
50
52
  topAxis,
51
53
  leftAxis,
52
54
  rightAxis,
@@ -84,6 +86,9 @@ const LineChart = /*#__PURE__*/React.forwardRef(function LineChart(props, ref) {
84
86
  disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none' && !onAxisClick,
85
87
  children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
86
88
  onAxisClick: onAxisClick
89
+ }), grid && /*#__PURE__*/_jsx(ChartsGrid, {
90
+ vertical: grid.vertical,
91
+ horizontal: grid.horizontal
87
92
  }), /*#__PURE__*/_jsxs("g", {
88
93
  clipPath: `url(#${clipPathId})`,
89
94
  children: [/*#__PURE__*/_jsx(AreaPlot, {
@@ -129,11 +134,8 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
129
134
  // | To update them edit the TypeScript types and run "yarn proptypes" |
130
135
  // ----------------------------------------------------------------------
131
136
  /**
132
- * Object `{ x, y }` that defines how the charts highlight the mouse position along the x- and y-axes.
133
- * The two properties accept the following values:
134
- * - 'none': display nothing.
135
- * - 'line': display a line at the current mouse position.
136
- * - 'band': display a band at the current mouse position. Only available with band scale.
137
+ * The configuration of axes highlight.
138
+ * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
137
139
  * @default { x: 'line' }
138
140
  */
139
141
  axisHighlight: PropTypes.shape({
@@ -189,6 +191,13 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
189
191
  * If `true`, render the line highlight item.
190
192
  */
191
193
  disableLineItemHighlight: PropTypes.bool,
194
+ /**
195
+ * Option to display a cartesian grid in the background.
196
+ */
197
+ grid: PropTypes.shape({
198
+ horizontal: PropTypes.bool,
199
+ vertical: PropTypes.bool
200
+ }),
192
201
  /**
193
202
  * The height of the chart in px. If not defined, it takes the height of the parent element.
194
203
  * @default undefined
@@ -247,6 +256,9 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
247
256
  right: PropTypes.number,
248
257
  top: PropTypes.number
249
258
  }),
259
+ /**
260
+ * Callback fired when an area element is clicked.
261
+ */
250
262
  onAreaClick: PropTypes.func,
251
263
  /**
252
264
  * The function called for onClick events.
@@ -255,7 +267,13 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
255
267
  * @param {null | AxisData} data The data about the clicked axis and items associated with it.
256
268
  */
257
269
  onAxisClick: PropTypes.func,
270
+ /**
271
+ * Callback fired when a line element is clicked.
272
+ */
258
273
  onLineClick: PropTypes.func,
274
+ /**
275
+ * Callback fired when a mark element is clicked.
276
+ */
259
277
  onMarkClick: PropTypes.func,
260
278
  /**
261
279
  * Indicate which axis to display the right of the charts.
@@ -284,6 +302,9 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
284
302
  tickNumber: PropTypes.number,
285
303
  tickSize: PropTypes.number
286
304
  }), PropTypes.string]),
305
+ /**
306
+ * The series to display in the line chart.
307
+ */
287
308
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
288
309
  /**
289
310
  * If `true`, animations are skipped.
@@ -302,6 +323,11 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
302
323
  slots: PropTypes.object,
303
324
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
304
325
  title: PropTypes.string,
326
+ /**
327
+ * The configuration of the tooltip.
328
+ * @see See {@link https://mui.com/x/react-charts/tooltip/ tooltip docs} for more details.
329
+ * @default { trigger: 'item' }
330
+ */
305
331
  tooltip: PropTypes.shape({
306
332
  axisContent: PropTypes.elementType,
307
333
  classes: PropTypes.object,
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "onClick", "isFaded", "isHighlighted", "startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "cornerRadius"];
3
+ const _excluded = ["classes", "color", "cornerRadius", "dataIndex", "endAngle", "highlightScope", "id", "innerRadius", "isFaded", "isHighlighted", "onClick", "outerRadius", "paddingAngle", "startAngle"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
6
  import { arc as d3Arc } from 'd3-shape';
@@ -40,20 +40,20 @@ const PieArcRoot = styled(animated.path, {
40
40
  }));
41
41
  function PieArc(props) {
42
42
  const {
43
- id,
44
- dataIndex,
45
43
  classes: innerClasses,
46
44
  color,
45
+ cornerRadius,
46
+ dataIndex,
47
+ endAngle,
47
48
  highlightScope,
48
- onClick,
49
+ id,
50
+ innerRadius,
49
51
  isFaded,
50
52
  isHighlighted,
51
- startAngle,
52
- endAngle,
53
- paddingAngle,
54
- innerRadius,
53
+ onClick,
55
54
  outerRadius,
56
- cornerRadius
55
+ paddingAngle,
56
+ startAngle
57
57
  } = props,
58
58
  other = _objectWithoutPropertiesLoose(props, _excluded);
59
59
  const ownerState = {
@@ -1,6 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
- const _excluded = ["slots", "slotProps", "innerRadius", "outerRadius", "arcLabelRadius", "cornerRadius", "paddingAngle", "id", "highlightScope", "highlighted", "faded", "data", "arcLabel", "arcLabelMinAngle", "skipAnimation"],
3
+ const _excluded = ["arcLabel", "arcLabelMinAngle", "arcLabelRadius", "cornerRadius", "data", "faded", "highlighted", "highlightScope", "id", "innerRadius", "outerRadius", "paddingAngle", "skipAnimation", "slotProps", "slots"],
4
4
  _excluded2 = ["startAngle", "endAngle", "paddingAngle", "innerRadius", "outerRadius", "arcLabelRadius", "cornerRadius"];
5
5
  import * as React from 'react';
6
6
  import PropTypes from 'prop-types';
@@ -27,23 +27,23 @@ function getItemLabel(arcLabel, arcLabelMinAngle, item) {
27
27
  function PieArcLabelPlot(props) {
28
28
  var _slots$pieArcLabel;
29
29
  const {
30
- slots,
31
- slotProps,
32
- innerRadius,
33
- outerRadius,
30
+ arcLabel,
31
+ arcLabelMinAngle = 0,
34
32
  arcLabelRadius,
35
33
  cornerRadius = 0,
36
- paddingAngle = 0,
37
- id,
38
- highlightScope,
39
- highlighted,
34
+ data,
40
35
  faded = {
41
36
  additionalRadius: -5
42
37
  },
43
- data,
44
- arcLabel,
45
- arcLabelMinAngle = 0,
46
- skipAnimation
38
+ highlighted,
39
+ highlightScope,
40
+ id,
41
+ innerRadius,
42
+ outerRadius,
43
+ paddingAngle = 0,
44
+ skipAnimation,
45
+ slotProps,
46
+ slots
47
47
  } = props,
48
48
  other = _objectWithoutPropertiesLoose(props, _excluded);
49
49
  const transformedData = useTransformData({
@@ -101,6 +101,11 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
101
101
  // | These PropTypes are generated from the TypeScript type definitions |
102
102
  // | To update them edit the TypeScript types and run "yarn proptypes" |
103
103
  // ----------------------------------------------------------------------
104
+ /**
105
+ * The configuration of axes highlight.
106
+ * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
107
+ * @default { x: 'none', y: 'none' }
108
+ */
104
109
  axisHighlight: PropTypes.shape({
105
110
  x: PropTypes.oneOf(['band', 'line', 'none']),
106
111
  y: PropTypes.oneOf(['band', 'line', 'none'])
@@ -183,6 +188,8 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
183
188
  tickSize: PropTypes.number
184
189
  }), PropTypes.string]),
185
190
  /**
191
+ * The props of the legend.
192
+ * @default { direction: 'column', position: { vertical: 'middle', horizontal: 'right' } }
186
193
  * @deprecated Consider using `slotProps.legend` instead.
187
194
  */
188
195
  legend: PropTypes.shape({
@@ -208,6 +215,9 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
208
215
  right: PropTypes.number,
209
216
  top: PropTypes.number
210
217
  }),
218
+ /**
219
+ * Callback fired when a pie arc is clicked.
220
+ */
211
221
  onItemClick: PropTypes.func,
212
222
  /**
213
223
  * Indicate which axis to display the right of the charts.
@@ -236,6 +246,9 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
236
246
  tickNumber: PropTypes.number,
237
247
  tickSize: PropTypes.number
238
248
  }), PropTypes.string]),
249
+ /**
250
+ * The series to display in the pie chart.
251
+ */
239
252
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
240
253
  /**
241
254
  * If `true`, animations are skipped.
@@ -247,9 +260,18 @@ process.env.NODE_ENV !== "production" ? PieChart.propTypes = {
247
260
  * @default {}
248
261
  */
249
262
  slotProps: PropTypes.object,
263
+ /**
264
+ * Overridable component slots.
265
+ * @default {}
266
+ */
250
267
  slots: PropTypes.object,
251
268
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
252
269
  title: PropTypes.string,
270
+ /**
271
+ * The configuration of the tooltip.
272
+ * @see See {@link https://mui.com/x/react-charts/tooltip/ tooltip docs} for more details.
273
+ * @default { trigger: 'item' }
274
+ */
253
275
  tooltip: PropTypes.shape({
254
276
  axisContent: PropTypes.elementType,
255
277
  classes: PropTypes.object,
@@ -3,74 +3,10 @@ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWith
3
3
  const _excluded = ["width", "height"];
4
4
  import * as React from 'react';
5
5
  import PropTypes from 'prop-types';
6
- import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
7
- import ownerWindow from '@mui/utils/ownerWindow';
8
6
  import { styled } from '@mui/material/styles';
9
7
  import { ChartContainer } from '../ChartContainer';
8
+ import { useChartContainerDimensions } from './useChartContainerDimensions';
10
9
  import { jsx as _jsx } from "react/jsx-runtime";
11
- const useChartDimensions = (inWidth, inHeight) => {
12
- const rootRef = React.useRef(null);
13
- const displayError = React.useRef(false);
14
- const [width, setWidth] = React.useState(0);
15
- const [height, setHeight] = React.useState(0);
16
-
17
- // Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
18
- const computeSize = React.useCallback(() => {
19
- const mainEl = rootRef == null ? void 0 : rootRef.current;
20
- if (!mainEl) {
21
- return;
22
- }
23
- const win = ownerWindow(mainEl);
24
- const computedStyle = win.getComputedStyle(mainEl);
25
- const newHeight = Math.floor(parseFloat(computedStyle.height)) || 0;
26
- const newWidth = Math.floor(parseFloat(computedStyle.width)) || 0;
27
- setWidth(newWidth);
28
- setHeight(newHeight);
29
- }, []);
30
- React.useEffect(() => {
31
- // Ensure the error detection occurs after the first rendering.
32
- displayError.current = true;
33
- }, []);
34
- useEnhancedEffect(() => {
35
- if (inWidth !== undefined && inHeight !== undefined) {
36
- return () => {};
37
- }
38
- computeSize();
39
- const elementToObserve = rootRef.current;
40
- if (typeof ResizeObserver === 'undefined') {
41
- return () => {};
42
- }
43
- let animationFrame;
44
- const observer = new ResizeObserver(() => {
45
- // See https://github.com/mui/mui-x/issues/8733
46
- animationFrame = requestAnimationFrame(() => {
47
- computeSize();
48
- });
49
- });
50
- if (elementToObserve) {
51
- observer.observe(elementToObserve);
52
- }
53
- return () => {
54
- if (animationFrame) {
55
- window.cancelAnimationFrame(animationFrame);
56
- }
57
- if (elementToObserve) {
58
- observer.unobserve(elementToObserve);
59
- }
60
- };
61
- }, [computeSize, inHeight, inWidth]);
62
- if (process.env.NODE_ENV !== 'production') {
63
- if (displayError.current && inWidth === undefined && width === 0) {
64
- console.error(`MUI X Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
65
- displayError.current = false;
66
- }
67
- if (displayError.current && inHeight === undefined && height === 0) {
68
- console.error(`MUI X Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
69
- displayError.current = false;
70
- }
71
- }
72
- return [rootRef, inWidth != null ? inWidth : width, inHeight != null ? inHeight : height];
73
- };
74
10
  const ResizableContainer = styled('div', {
75
11
  name: 'MuiResponsiveChart',
76
12
  slot: 'Container'
@@ -100,7 +36,7 @@ const ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function Responsi
100
36
  height: inHeight
101
37
  } = props,
102
38
  other = _objectWithoutPropertiesLoose(props, _excluded);
103
- const [containerRef, width, height] = useChartDimensions(inWidth, inHeight);
39
+ const [containerRef, width, height] = useChartContainerDimensions(inWidth, inHeight);
104
40
  return /*#__PURE__*/_jsx(ResizableContainer, {
105
41
  ref: containerRef,
106
42
  ownerState: {
@@ -0,0 +1,66 @@
1
+ import * as React from 'react';
2
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
3
+ import ownerWindow from '@mui/utils/ownerWindow';
4
+ export const useChartContainerDimensions = (inWidth, inHeight) => {
5
+ const rootRef = React.useRef(null);
6
+ const displayError = React.useRef(false);
7
+ const [width, setWidth] = React.useState(0);
8
+ const [height, setHeight] = React.useState(0);
9
+
10
+ // Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
11
+ const computeSize = React.useCallback(() => {
12
+ const mainEl = rootRef == null ? void 0 : rootRef.current;
13
+ if (!mainEl) {
14
+ return;
15
+ }
16
+ const win = ownerWindow(mainEl);
17
+ const computedStyle = win.getComputedStyle(mainEl);
18
+ const newHeight = Math.floor(parseFloat(computedStyle.height)) || 0;
19
+ const newWidth = Math.floor(parseFloat(computedStyle.width)) || 0;
20
+ setWidth(newWidth);
21
+ setHeight(newHeight);
22
+ }, []);
23
+ React.useEffect(() => {
24
+ // Ensure the error detection occurs after the first rendering.
25
+ displayError.current = true;
26
+ }, []);
27
+ useEnhancedEffect(() => {
28
+ if (inWidth !== undefined && inHeight !== undefined) {
29
+ return () => {};
30
+ }
31
+ computeSize();
32
+ const elementToObserve = rootRef.current;
33
+ if (typeof ResizeObserver === 'undefined') {
34
+ return () => {};
35
+ }
36
+ let animationFrame;
37
+ const observer = new ResizeObserver(() => {
38
+ // See https://github.com/mui/mui-x/issues/8733
39
+ animationFrame = requestAnimationFrame(() => {
40
+ computeSize();
41
+ });
42
+ });
43
+ if (elementToObserve) {
44
+ observer.observe(elementToObserve);
45
+ }
46
+ return () => {
47
+ if (animationFrame) {
48
+ window.cancelAnimationFrame(animationFrame);
49
+ }
50
+ if (elementToObserve) {
51
+ observer.unobserve(elementToObserve);
52
+ }
53
+ };
54
+ }, [computeSize, inHeight, inWidth]);
55
+ if (process.env.NODE_ENV !== 'production') {
56
+ if (displayError.current && inWidth === undefined && width === 0) {
57
+ console.error(`MUI X Charts: ChartContainer does not have \`width\` prop, and its container has no \`width\` defined.`);
58
+ displayError.current = false;
59
+ }
60
+ if (displayError.current && inHeight === undefined && height === 0) {
61
+ console.error(`MUI X Charts: ChartContainer does not have \`height\` prop, and its container has no \`height\` defined.`);
62
+ displayError.current = false;
63
+ }
64
+ }
65
+ return [rootRef, inWidth != null ? inWidth : width, inHeight != null ? inHeight : height];
66
+ };
@@ -8,6 +8,7 @@ import { ChartsTooltip } from '../ChartsTooltip';
8
8
  import { ChartsLegend } from '../ChartsLegend';
9
9
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
10
10
  import { ChartsVoronoiHandler } from '../ChartsVoronoiHandler/ChartsVoronoiHandler';
11
+ import { ChartsGrid } from '../ChartsGrid';
11
12
  import { jsx as _jsx } from "react/jsx-runtime";
12
13
  import { jsxs as _jsxs } from "react/jsx-runtime";
13
14
  /**
@@ -35,6 +36,7 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
35
36
  margin,
36
37
  colors,
37
38
  sx,
39
+ grid,
38
40
  topAxis,
39
41
  leftAxis,
40
42
  rightAxis,
@@ -66,6 +68,9 @@ const ScatterChart = /*#__PURE__*/React.forwardRef(function ScatterChart(props,
66
68
  bottomAxis: bottomAxis,
67
69
  slots: slots,
68
70
  slotProps: slotProps
71
+ }), grid && /*#__PURE__*/_jsx(ChartsGrid, {
72
+ vertical: grid.vertical,
73
+ horizontal: grid.horizontal
69
74
  }), /*#__PURE__*/_jsx(ScatterPlot, {
70
75
  slots: slots,
71
76
  slotProps: slotProps,
@@ -86,6 +91,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
86
91
  // | These PropTypes are generated from the TypeScript type definitions |
87
92
  // | To update them edit the TypeScript types and run "yarn proptypes" |
88
93
  // ----------------------------------------------------------------------
94
+ /**
95
+ * The configuration of axes highlight.
96
+ * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
97
+ * @default { x: 'none', y: 'none' }
98
+ */
89
99
  axisHighlight: PropTypes.shape({
90
100
  x: PropTypes.oneOf(['band', 'line', 'none']),
91
101
  y: PropTypes.oneOf(['band', 'line', 'none'])
@@ -140,6 +150,13 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
140
150
  * @default false
141
151
  */
142
152
  disableVoronoi: PropTypes.bool,
153
+ /**
154
+ * Option to display a cartesian grid in the background.
155
+ */
156
+ grid: PropTypes.shape({
157
+ horizontal: PropTypes.bool,
158
+ vertical: PropTypes.bool
159
+ }),
143
160
  /**
144
161
  * The height of the chart in px. If not defined, it takes the height of the parent element.
145
162
  * @default undefined
@@ -231,6 +248,9 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
231
248
  tickNumber: PropTypes.number,
232
249
  tickSize: PropTypes.number
233
250
  }), PropTypes.string]),
251
+ /**
252
+ * The series to display in the scatter chart.
253
+ */
234
254
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
235
255
  /**
236
256
  * The props used for each component slot.
@@ -244,6 +264,11 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
244
264
  slots: PropTypes.object,
245
265
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
246
266
  title: PropTypes.string,
267
+ /**
268
+ * The configuration of the tooltip.
269
+ * @see See {@link https://mui.com/x/react-charts/tooltip/ tooltip docs} for more details.
270
+ * @default { trigger: 'item' }
271
+ */
247
272
  tooltip: PropTypes.shape({
248
273
  axisContent: PropTypes.elementType,
249
274
  classes: PropTypes.object,
@@ -13,7 +13,7 @@ export function getTickNumber(params) {
13
13
  const defaultizedTickNumber = tickNumber != null ? tickNumber : Math.floor(Math.abs(range[1] - range[0]) / 50);
14
14
  return Math.min(maxTicks, Math.max(minTicks, defaultizedTickNumber));
15
15
  }
16
- function useTicks(options) {
16
+ export function useTicks(options) {
17
17
  const {
18
18
  scale,
19
19
  tickNumber,
@@ -64,5 +64,4 @@ function useTicks(options) {
64
64
  };
65
65
  });
66
66
  }, [tickNumber, scale, valueFormatter, tickInterval]);
67
- }
68
- export default useTicks;
67
+ }
package/esm/index.js CHANGED
@@ -8,6 +8,7 @@ export * from './ChartsReferenceLine';
8
8
  export * from './ChartsAxis';
9
9
  export * from './ChartsXAxis';
10
10
  export * from './ChartsYAxis';
11
+ export * from './ChartsGrid';
11
12
  export * from './ChartsText';
12
13
  export * from './ChartsTooltip';
13
14
  export * from './ChartsLegend';
@@ -19,6 +20,7 @@ export * from './LineChart';
19
20
  export * from './PieChart';
20
21
  export * from './ScatterChart';
21
22
  export * from './SparkLineChart';
23
+ export * from './Gauge';
22
24
  export * from './ChartContainer';
23
25
  export * from './ChartsSurface';
24
26
  export * from './ResponsiveChartContainer';
@@ -39,8 +39,7 @@ export type TickItemType = {
39
39
  offset: number;
40
40
  labelOffset: number;
41
41
  };
42
- declare function useTicks(options: {
42
+ export declare function useTicks(options: {
43
43
  scale: D3Scale;
44
44
  valueFormatter?: (value: any) => string;
45
45
  } & Pick<TickParams, 'tickNumber' | 'tickInterval'>): TickItemType[];
46
- export default useTicks;
package/hooks/useTicks.js CHANGED
@@ -3,8 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
7
6
  exports.getTickNumber = getTickNumber;
7
+ exports.useTicks = useTicks;
8
8
  var React = _interopRequireWildcard(require("react"));
9
9
  var _isBandScale = require("../internals/isBandScale");
10
10
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
@@ -64,5 +64,4 @@ function useTicks(options) {
64
64
  labelOffset: 0
65
65
  }));
66
66
  }, [tickNumber, scale, valueFormatter, tickInterval]);
67
- }
68
- var _default = exports.default = useTicks;
67
+ }
package/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from './ChartsReferenceLine';
8
8
  export * from './ChartsAxis';
9
9
  export * from './ChartsXAxis';
10
10
  export * from './ChartsYAxis';
11
+ export * from './ChartsGrid';
11
12
  export * from './ChartsText';
12
13
  export * from './ChartsTooltip';
13
14
  export * from './ChartsLegend';
@@ -19,6 +20,7 @@ export * from './LineChart';
19
20
  export * from './PieChart';
20
21
  export * from './ScatterChart';
21
22
  export * from './SparkLineChart';
23
+ export * from './Gauge';
22
24
  export * from './ChartContainer';
23
25
  export * from './ChartsSurface';
24
26
  export * from './ResponsiveChartContainer';
package/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v7.0.0-beta.2
2
+ * @mui/x-charts v7.0.0-beta.3
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -120,6 +120,17 @@ Object.keys(_ChartsYAxis).forEach(function (key) {
120
120
  }
121
121
  });
122
122
  });
123
+ var _ChartsGrid = require("./ChartsGrid");
124
+ Object.keys(_ChartsGrid).forEach(function (key) {
125
+ if (key === "default" || key === "__esModule") return;
126
+ if (key in exports && exports[key] === _ChartsGrid[key]) return;
127
+ Object.defineProperty(exports, key, {
128
+ enumerable: true,
129
+ get: function () {
130
+ return _ChartsGrid[key];
131
+ }
132
+ });
133
+ });
123
134
  var _ChartsText = require("./ChartsText");
124
135
  Object.keys(_ChartsText).forEach(function (key) {
125
136
  if (key === "default" || key === "__esModule") return;
@@ -241,6 +252,17 @@ Object.keys(_SparkLineChart).forEach(function (key) {
241
252
  }
242
253
  });
243
254
  });
255
+ var _Gauge = require("./Gauge");
256
+ Object.keys(_Gauge).forEach(function (key) {
257
+ if (key === "default" || key === "__esModule") return;
258
+ if (key in exports && exports[key] === _Gauge[key]) return;
259
+ Object.defineProperty(exports, key, {
260
+ enumerable: true,
261
+ get: function () {
262
+ return _Gauge[key];
263
+ }
264
+ });
265
+ });
244
266
  var _ChartContainer = require("./ChartContainer");
245
267
  Object.keys(_ChartContainer).forEach(function (key) {
246
268
  if (key === "default" || key === "__esModule") return;
@@ -11,6 +11,7 @@ import { ChartsTooltip } from '../ChartsTooltip';
11
11
  import { ChartsLegend } from '../ChartsLegend';
12
12
  import { ChartsAxisHighlight } from '../ChartsAxisHighlight';
13
13
  import { ChartsClipPath } from '../ChartsClipPath';
14
+ import { ChartsGrid } from '../ChartsGrid';
14
15
  import { ChartsOnAxisClickHandler } from '../ChartsOnAxisClickHandler';
15
16
  import { jsx as _jsx } from "react/jsx-runtime";
16
17
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -39,6 +40,7 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
39
40
  tooltip = props.tooltip,
40
41
  axisHighlight = props.axisHighlight,
41
42
  legend = props.legend,
43
+ grid = props.grid,
42
44
  topAxis = props.topAxis,
43
45
  leftAxis = props.leftAxis,
44
46
  rightAxis = props.rightAxis,
@@ -94,6 +96,9 @@ var BarChart = /*#__PURE__*/React.forwardRef(function BarChart(props, ref) {
94
96
  disableAxisListener: (tooltip == null ? void 0 : tooltip.trigger) !== 'axis' && (axisHighlight == null ? void 0 : axisHighlight.x) === 'none' && (axisHighlight == null ? void 0 : axisHighlight.y) === 'none' && !onAxisClick,
95
97
  children: [onAxisClick && /*#__PURE__*/_jsx(ChartsOnAxisClickHandler, {
96
98
  onAxisClick: onAxisClick
99
+ }), grid && /*#__PURE__*/_jsx(ChartsGrid, {
100
+ vertical: grid.vertical,
101
+ horizontal: grid.horizontal
97
102
  }), /*#__PURE__*/_jsx("g", {
98
103
  clipPath: "url(#".concat(clipPathId, ")"),
99
104
  children: /*#__PURE__*/_jsx(BarPlot, {
@@ -126,11 +131,10 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
126
131
  // | To update them edit the TypeScript types and run "yarn proptypes" |
127
132
  // ----------------------------------------------------------------------
128
133
  /**
129
- * Object `{ x, y }` that defines how the charts highlight the mouse position along the x- and y-axes.
130
- * The two properties accept the following values:
131
- * - 'none': display nothing.
132
- * - 'line': display a line at the current mouse position.
133
- * - 'band': display a band at the current mouse position. Only available with band scale.
134
+ * The configuration of axes highlight.
135
+ * Default is set to 'band' in the bar direction.
136
+ * Depends on `layout` prop.
137
+ * @see See {@link https://mui.com/x/react-charts/tooltip/#highlights highlight docs} for more details.
134
138
  */
135
139
  axisHighlight: PropTypes.shape({
136
140
  x: PropTypes.oneOf(['band', 'line', 'none']),
@@ -181,11 +185,22 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
181
185
  * @default false
182
186
  */
183
187
  disableAxisListener: PropTypes.bool,
188
+ /**
189
+ * Option to display a cartesian grid in the background.
190
+ */
191
+ grid: PropTypes.shape({
192
+ horizontal: PropTypes.bool,
193
+ vertical: PropTypes.bool
194
+ }),
184
195
  /**
185
196
  * The height of the chart in px. If not defined, it takes the height of the parent element.
186
197
  * @default undefined
187
198
  */
188
199
  height: PropTypes.number,
200
+ /**
201
+ * The direction of the bar elements.
202
+ * @default 'vertical'
203
+ */
189
204
  layout: PropTypes.oneOf(['horizontal', 'vertical']),
190
205
  /**
191
206
  * Indicate which axis to display the left of the charts.
@@ -280,6 +295,9 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
280
295
  tickNumber: PropTypes.number,
281
296
  tickSize: PropTypes.number
282
297
  }), PropTypes.string]),
298
+ /**
299
+ * The series to display in the bar chart.
300
+ */
283
301
  series: PropTypes.arrayOf(PropTypes.object).isRequired,
284
302
  /**
285
303
  * If `true`, animations are skipped.
@@ -298,6 +316,10 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
298
316
  slots: PropTypes.object,
299
317
  sx: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.func, PropTypes.object, PropTypes.bool])), PropTypes.func, PropTypes.object]),
300
318
  title: PropTypes.string,
319
+ /**
320
+ * The configuration of the tooltip.
321
+ * @see See {@link https://mui.com/x/react-charts/tooltip/ tooltip docs} for more details.
322
+ */
301
323
  tooltip: PropTypes.shape({
302
324
  axisContent: PropTypes.elementType,
303
325
  classes: PropTypes.object,