@mui/x-charts 6.0.0-alpha.0 → 6.0.0-alpha.2

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 (126) hide show
  1. package/BarChart/BarChart.js +8 -5
  2. package/BarChart/legend.d.ts +3 -0
  3. package/BarChart/legend.js +20 -0
  4. package/CHANGELOG.md +136 -8
  5. package/ChartsAxis/ChartsAxis.d.ts +4 -4
  6. package/ChartsAxis/ChartsAxis.js +4 -4
  7. package/ChartsLegend/ChartsLegend.d.ts +5 -1
  8. package/ChartsLegend/ChartsLegend.js +5 -1
  9. package/ChartsLegend/utils.d.ts +1 -1
  10. package/ChartsLegend/utils.js +12 -1
  11. package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  12. package/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  13. package/ChartsTooltip/ChartsTooltipTable.js +8 -8
  14. package/LineChart/LineChart.js +8 -5
  15. package/LineChart/legend.d.ts +3 -0
  16. package/LineChart/legend.js +20 -0
  17. package/PieChart/PieArc.d.ts +36 -0
  18. package/PieChart/PieArc.js +128 -0
  19. package/PieChart/PieArcLabel.d.ts +36 -0
  20. package/PieChart/PieArcLabel.js +113 -0
  21. package/PieChart/PieChart.d.ts +20 -0
  22. package/PieChart/PieChart.js +292 -0
  23. package/PieChart/PiePlot.d.ts +2 -0
  24. package/PieChart/PiePlot.js +98 -0
  25. package/PieChart/formatter.d.ts +3 -0
  26. package/PieChart/formatter.js +49 -0
  27. package/PieChart/index.d.ts +4 -0
  28. package/PieChart/index.js +47 -0
  29. package/PieChart/legend.d.ts +3 -0
  30. package/PieChart/legend.js +19 -0
  31. package/PieChart/package.json +6 -0
  32. package/README.md +30 -2
  33. package/ResponsiveChartContainer/index.js +91 -25
  34. package/ScatterChart/Scatter.js +1 -1
  35. package/ScatterChart/ScatterChart.js +5 -4
  36. package/ScatterChart/legend.d.ts +3 -0
  37. package/ScatterChart/legend.js +20 -0
  38. package/context/SeriesContextProvider.js +11 -1
  39. package/esm/BarChart/BarChart.js +8 -5
  40. package/esm/BarChart/legend.js +13 -0
  41. package/esm/ChartsAxis/ChartsAxis.js +4 -4
  42. package/esm/ChartsLegend/ChartsLegend.js +5 -1
  43. package/esm/ChartsLegend/utils.js +11 -1
  44. package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  45. package/esm/ChartsTooltip/ChartsItemTooltipContent.js +11 -3
  46. package/esm/ChartsTooltip/ChartsTooltipTable.js +8 -8
  47. package/esm/LineChart/LineChart.js +8 -5
  48. package/esm/LineChart/legend.js +13 -0
  49. package/esm/PieChart/PieArc.js +117 -0
  50. package/esm/PieChart/PieArcLabel.js +101 -0
  51. package/esm/PieChart/PieChart.js +285 -0
  52. package/esm/PieChart/PiePlot.js +92 -0
  53. package/esm/PieChart/formatter.js +48 -0
  54. package/esm/PieChart/index.js +4 -0
  55. package/esm/PieChart/legend.js +12 -0
  56. package/esm/ResponsiveChartContainer/index.js +94 -26
  57. package/esm/ScatterChart/Scatter.js +1 -1
  58. package/esm/ScatterChart/ScatterChart.js +5 -4
  59. package/esm/ScatterChart/legend.js +13 -0
  60. package/esm/context/SeriesContextProvider.js +11 -1
  61. package/esm/index.js +1 -0
  62. package/esm/internals/defaultizeColor.js +7 -0
  63. package/esm/models/seriesType/index.js +1 -8
  64. package/index.d.ts +1 -0
  65. package/index.js +12 -1
  66. package/internals/defaultizeColor.d.ts +35 -0
  67. package/internals/defaultizeColor.js +7 -0
  68. package/legacy/BarChart/BarChart.js +10 -7
  69. package/legacy/BarChart/legend.js +15 -0
  70. package/legacy/ChartsAxis/ChartsAxis.js +4 -4
  71. package/legacy/ChartsLegend/ChartsLegend.js +5 -1
  72. package/legacy/ChartsLegend/utils.js +12 -6
  73. package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +3 -1
  74. package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +10 -3
  75. package/legacy/ChartsTooltip/ChartsTooltipTable.js +7 -9
  76. package/legacy/LineChart/LineChart.js +10 -7
  77. package/legacy/LineChart/legend.js +15 -0
  78. package/legacy/PieChart/PieArc.js +118 -0
  79. package/legacy/PieChart/PieArcLabel.js +101 -0
  80. package/legacy/PieChart/PieChart.js +297 -0
  81. package/legacy/PieChart/PiePlot.js +89 -0
  82. package/legacy/PieChart/formatter.js +55 -0
  83. package/legacy/PieChart/index.js +4 -0
  84. package/legacy/PieChart/legend.js +16 -0
  85. package/legacy/ResponsiveChartContainer/index.js +89 -26
  86. package/legacy/ScatterChart/Scatter.js +1 -1
  87. package/legacy/ScatterChart/ScatterChart.js +5 -4
  88. package/legacy/ScatterChart/legend.js +15 -0
  89. package/legacy/context/SeriesContextProvider.js +11 -1
  90. package/legacy/index.js +2 -1
  91. package/legacy/internals/defaultizeColor.js +9 -0
  92. package/legacy/models/seriesType/index.js +1 -8
  93. package/models/seriesType/bar.d.ts +1 -1
  94. package/models/seriesType/common.d.ts +1 -1
  95. package/models/seriesType/config.d.ts +29 -2
  96. package/models/seriesType/index.d.ts +7 -3
  97. package/models/seriesType/index.js +11 -0
  98. package/models/seriesType/line.d.ts +1 -1
  99. package/models/seriesType/pie.d.ts +103 -3
  100. package/models/seriesType/scatter.d.ts +1 -1
  101. package/modern/BarChart/BarChart.js +8 -5
  102. package/modern/BarChart/legend.js +13 -0
  103. package/modern/ChartsAxis/ChartsAxis.js +4 -4
  104. package/modern/ChartsLegend/ChartsLegend.js +5 -1
  105. package/modern/ChartsLegend/utils.js +11 -1
  106. package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
  107. package/modern/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
  108. package/modern/ChartsTooltip/ChartsTooltipTable.js +8 -8
  109. package/modern/LineChart/LineChart.js +8 -5
  110. package/modern/LineChart/legend.js +13 -0
  111. package/modern/PieChart/PieArc.js +116 -0
  112. package/modern/PieChart/PieArcLabel.js +101 -0
  113. package/modern/PieChart/PieChart.js +285 -0
  114. package/modern/PieChart/PiePlot.js +91 -0
  115. package/modern/PieChart/formatter.js +41 -0
  116. package/modern/PieChart/index.js +4 -0
  117. package/modern/PieChart/legend.js +12 -0
  118. package/modern/ResponsiveChartContainer/index.js +91 -25
  119. package/modern/ScatterChart/Scatter.js +1 -1
  120. package/modern/ScatterChart/ScatterChart.js +5 -4
  121. package/modern/ScatterChart/legend.js +13 -0
  122. package/modern/context/SeriesContextProvider.js +11 -1
  123. package/modern/index.js +2 -1
  124. package/modern/internals/defaultizeColor.js +7 -0
  125. package/modern/models/seriesType/index.js +1 -8
  126. package/package.json +1 -3
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.PiePlot = PiePlot;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var React = _interopRequireWildcard(require("react"));
10
+ var _SeriesContextProvider = require("../context/SeriesContextProvider");
11
+ var _PieArc = _interopRequireDefault(require("./PieArc"));
12
+ var _PieArcLabel = _interopRequireDefault(require("./PieArcLabel"));
13
+ var _DrawingProvider = require("../context/DrawingProvider");
14
+ var _jsxRuntime = require("react/jsx-runtime");
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); }
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; }
17
+ const RATIO = 180 / Math.PI;
18
+ function getItemLabel(arcLabel, arcLabelMinAngle, item) {
19
+ if (!arcLabel) {
20
+ return null;
21
+ }
22
+ const angle = (item.endAngle - item.startAngle) * RATIO;
23
+ if (angle < arcLabelMinAngle) {
24
+ return null;
25
+ }
26
+ if (typeof arcLabel === 'string') {
27
+ return item[arcLabel]?.toString();
28
+ }
29
+ return arcLabel(item);
30
+ }
31
+ function PiePlot() {
32
+ const seriesData = React.useContext(_SeriesContextProvider.SeriesContext).pie;
33
+ const {
34
+ left,
35
+ top,
36
+ width,
37
+ height
38
+ } = React.useContext(_DrawingProvider.DrawingContext);
39
+ if (seriesData === undefined) {
40
+ return null;
41
+ }
42
+ const availableRadius = Math.min(width, height) / 2;
43
+ const center = {
44
+ x: left + width / 2,
45
+ y: top + height / 2
46
+ };
47
+ const {
48
+ series,
49
+ seriesOrder
50
+ } = seriesData;
51
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
52
+ children: seriesOrder.map(seriesId => {
53
+ const {
54
+ innerRadius,
55
+ outerRadius,
56
+ cornerRadius,
57
+ arcLabel,
58
+ arcLabelMinAngle = 0,
59
+ data,
60
+ cx,
61
+ cy,
62
+ highlighted,
63
+ faded
64
+ } = series[seriesId];
65
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("g", {
66
+ transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
67
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("g", {
68
+ children: [data.map((item, index) => {
69
+ return /*#__PURE__*/(0, React.createElement)(_PieArc.default, (0, _extends2.default)({}, item, {
70
+ key: item.id,
71
+ innerRadius: innerRadius,
72
+ outerRadius: outerRadius ?? availableRadius,
73
+ cornerRadius: cornerRadius,
74
+ id: seriesId,
75
+ color: item.color,
76
+ dataIndex: index,
77
+ highlightScope: series[seriesId].highlightScope,
78
+ highlighted: highlighted,
79
+ faded: faded
80
+ }));
81
+ }), data.map((item, index) => {
82
+ return /*#__PURE__*/(0, React.createElement)(_PieArcLabel.default, (0, _extends2.default)({}, item, {
83
+ key: item.id,
84
+ innerRadius: innerRadius,
85
+ outerRadius: outerRadius ?? availableRadius,
86
+ cornerRadius: cornerRadius,
87
+ id: seriesId,
88
+ color: item.color,
89
+ dataIndex: index,
90
+ highlightScope: series[seriesId].highlightScope,
91
+ formattedArcLabel: getItemLabel(arcLabel, arcLabelMinAngle, item)
92
+ }));
93
+ })]
94
+ })
95
+ }, seriesId);
96
+ })
97
+ });
98
+ }
@@ -0,0 +1,3 @@
1
+ import { Formatter } from '../models/seriesType/config';
2
+ declare const formatter: Formatter<'pie'>;
3
+ export default formatter;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _d3Shape = require("d3-shape");
10
+ const getSortingComparator = (comparator = 'none') => {
11
+ if (typeof comparator === 'function') {
12
+ return comparator;
13
+ }
14
+ switch (comparator) {
15
+ case 'none':
16
+ return null;
17
+ case 'desc':
18
+ return (a, b) => b - a;
19
+ case 'asc':
20
+ return (a, b) => a - b;
21
+ default:
22
+ return null;
23
+ }
24
+ };
25
+ const formatter = params => {
26
+ const {
27
+ seriesOrder,
28
+ series
29
+ } = params;
30
+ const defaultizedSeries = {};
31
+ seriesOrder.forEach(seriesId => {
32
+ const arcs = (0, _d3Shape.pie)().startAngle(2 * Math.PI * (series[seriesId].startAngle ?? 0) / 360).endAngle(2 * Math.PI * (series[seriesId].endAngle ?? 360) / 360).padAngle(2 * Math.PI * (series[seriesId].paddingAngle ?? 0) / 360).sortValues(getSortingComparator(series[seriesId].sortingValues ?? 'none'))(series[seriesId].data.map(piePoint => piePoint.value));
33
+ defaultizedSeries[seriesId] = (0, _extends2.default)({
34
+ valueFormatter: item => item.value.toLocaleString()
35
+ }, series[seriesId], {
36
+ data: series[seriesId].data.map((item, index) => (0, _extends2.default)({}, item, {
37
+ id: item.id ?? `auto-generated-pie-id-${seriesId}-${index}`
38
+ }, arcs[index])).map(item => (0, _extends2.default)({}, item, {
39
+ formattedValue: series[seriesId].valueFormatter?.(item) ?? item.value.toLocaleString()
40
+ }))
41
+ });
42
+ });
43
+ return {
44
+ seriesOrder,
45
+ series: defaultizedSeries
46
+ };
47
+ };
48
+ var _default = formatter;
49
+ exports.default = _default;
@@ -0,0 +1,4 @@
1
+ export { PiePlot } from './PiePlot';
2
+ export { PieChart } from './PieChart';
3
+ export * from './PieArc';
4
+ export * from './PieArcLabel';
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _exportNames = {
7
+ PiePlot: true,
8
+ PieChart: true
9
+ };
10
+ Object.defineProperty(exports, "PieChart", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _PieChart.PieChart;
14
+ }
15
+ });
16
+ Object.defineProperty(exports, "PiePlot", {
17
+ enumerable: true,
18
+ get: function () {
19
+ return _PiePlot.PiePlot;
20
+ }
21
+ });
22
+ var _PiePlot = require("./PiePlot");
23
+ var _PieChart = require("./PieChart");
24
+ var _PieArc = require("./PieArc");
25
+ Object.keys(_PieArc).forEach(function (key) {
26
+ if (key === "default" || key === "__esModule") return;
27
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
28
+ if (key in exports && exports[key] === _PieArc[key]) return;
29
+ Object.defineProperty(exports, key, {
30
+ enumerable: true,
31
+ get: function () {
32
+ return _PieArc[key];
33
+ }
34
+ });
35
+ });
36
+ var _PieArcLabel = require("./PieArcLabel");
37
+ Object.keys(_PieArcLabel).forEach(function (key) {
38
+ if (key === "default" || key === "__esModule") return;
39
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
40
+ if (key in exports && exports[key] === _PieArcLabel[key]) return;
41
+ Object.defineProperty(exports, key, {
42
+ enumerable: true,
43
+ get: function () {
44
+ return _PieArcLabel[key];
45
+ }
46
+ });
47
+ });
@@ -0,0 +1,3 @@
1
+ import { LegendGetter } from '../models/seriesType/config';
2
+ declare const legendGetter: LegendGetter<'pie'>;
3
+ export default legendGetter;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const legendGetter = params => {
8
+ const {
9
+ seriesOrder,
10
+ series
11
+ } = params;
12
+ return seriesOrder.flatMap(seriesId => series[seriesId].data.map(item => ({
13
+ color: item.color,
14
+ label: item.label,
15
+ id: item.id
16
+ })).filter(item => item.label !== undefined));
17
+ };
18
+ var _default = legendGetter;
19
+ exports.default = _default;
@@ -0,0 +1,6 @@
1
+ {
2
+ "sideEffects": false,
3
+ "module": "../esm/PieChart/index.js",
4
+ "main": "./index.js",
5
+ "types": "./index.d.ts"
6
+ }
package/README.md CHANGED
@@ -1,5 +1,33 @@
1
1
  # @mui/x-charts
2
2
 
3
- Package under development.
3
+ This package is the community edition of the charts components.
4
+ It's part of MUI X, an open-core extension of MUI, with advanced components.
4
5
 
5
- The alpha phase will start in the coming months, stay tuned!
6
+ ## Installation
7
+
8
+ Install the package in your project directory with:
9
+
10
+ ```bash
11
+ npm install @mui/x-charts
12
+ ```
13
+
14
+ or
15
+
16
+ ```bash
17
+ yarn add @mui/x-charts
18
+ ```
19
+
20
+ This component has the following peer dependencies that you will need to install as well.
21
+
22
+ ```json
23
+ "peerDependencies": {
24
+ "@mui/material": "^5.4.1",
25
+ "@mui/system": "^5.4.1",
26
+ "react": "^17.0.0 || ^18.0.0",
27
+ "react-dom": "^17.0.0 || ^18.0.0"
28
+ },
29
+ ```
30
+
31
+ ## Documentation
32
+
33
+ [The documentation](https://mui.com/x/react-charts/)
@@ -6,47 +6,113 @@ Object.defineProperty(exports, "__esModule", {
6
6
  });
7
7
  exports.ResponsiveChartContainer = ResponsiveChartContainer;
8
8
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
+ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
9
10
  var React = _interopRequireWildcard(require("react"));
10
- var _resizeObserver = require("@juggle/resize-observer");
11
+ var _useEnhancedEffect = _interopRequireDefault(require("@mui/utils/useEnhancedEffect"));
12
+ var _ownerWindow = _interopRequireDefault(require("@mui/utils/ownerWindow"));
13
+ var _styles = require("@mui/material/styles");
11
14
  var _ChartContainer = require("../ChartContainer");
12
15
  var _jsxRuntime = require("react/jsx-runtime");
16
+ const _excluded = ["width", "height"];
13
17
  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
18
  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
19
  const useChartDimensions = (inWidth, inHeight) => {
16
- const ref = React.useRef(null);
20
+ const rootRef = React.useRef(null);
21
+ const displayError = React.useRef(false);
17
22
  const [width, setWidth] = React.useState(0);
18
23
  const [height, setHeight] = React.useState(0);
24
+
25
+ // Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
26
+ const computeSize = React.useCallback(() => {
27
+ const mainEl = rootRef?.current;
28
+ if (!mainEl) {
29
+ return;
30
+ }
31
+ const win = (0, _ownerWindow.default)(mainEl);
32
+ const computedStyle = win.getComputedStyle(mainEl);
33
+ const newHeight = parseFloat(computedStyle.height) || 0;
34
+ const newWidth = parseFloat(computedStyle.width) || 0;
35
+ setWidth(newWidth);
36
+ setHeight(newHeight);
37
+ }, []);
19
38
  React.useEffect(() => {
20
- const element = ref.current;
21
- if (element === null || inHeight !== undefined && inWidth !== undefined) {
39
+ // Ensure the error detection occurs after the first rendering.
40
+ displayError.current = true;
41
+ }, []);
42
+ (0, _useEnhancedEffect.default)(() => {
43
+ if (inWidth !== undefined && inHeight !== undefined) {
22
44
  return () => {};
23
45
  }
24
- const resizeObserver = new _resizeObserver.ResizeObserver(entries => {
25
- if (Array.isArray(entries) && entries.length) {
26
- const entry = entries[0];
27
- if (inWidth === undefined) {
28
- setWidth(entry.contentRect.width);
29
- }
30
- if (inHeight === undefined) {
31
- setHeight(entry.contentRect.height);
32
- }
33
- }
46
+ computeSize();
47
+ const elementToObserve = rootRef.current;
48
+ if (typeof ResizeObserver === 'undefined') {
49
+ return () => {};
50
+ }
51
+ let animationFrame;
52
+ const observer = new ResizeObserver(() => {
53
+ // See https://github.com/mui/mui-x/issues/8733
54
+ animationFrame = window.requestAnimationFrame(() => {
55
+ computeSize();
56
+ });
34
57
  });
35
- resizeObserver.observe(element);
36
- return () => resizeObserver.disconnect();
37
- }, [height, inHeight, inWidth, width]);
38
- return [ref, inWidth ?? width, inHeight ?? height];
58
+ if (elementToObserve) {
59
+ observer.observe(elementToObserve);
60
+ }
61
+ return () => {
62
+ if (animationFrame) {
63
+ window.cancelAnimationFrame(animationFrame);
64
+ }
65
+ if (elementToObserve) {
66
+ observer.unobserve(elementToObserve);
67
+ }
68
+ };
69
+ }, [computeSize, inHeight, inWidth]);
70
+ if (process.env.NODE_ENV !== 'production') {
71
+ if (displayError.current && inWidth === undefined && width === 0) {
72
+ console.error(`MUI: Charts does not have \`width\` prop, and its container has no \`width\` defined.`);
73
+ displayError.current = false;
74
+ }
75
+ if (displayError.current && inHeight === undefined && height === 0) {
76
+ console.error(`MUI: Charts does not have \`height\` prop, and its container has no \`height\` defined.`);
77
+ displayError.current = false;
78
+ }
79
+ }
80
+ return [rootRef, inWidth ?? width, inHeight ?? height];
39
81
  };
82
+ const ResizableContainer = (0, _styles.styled)('div', {
83
+ name: 'MuiResponsiveChart',
84
+ slot: 'Container'
85
+ })(({
86
+ ownerState
87
+ }) => ({
88
+ width: ownerState.width ?? '100%',
89
+ height: 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
+ }));
40
102
  function ResponsiveChartContainer(props) {
41
- const [containerRef, width, height] = useChartDimensions(props.width, props.height);
42
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
103
+ const {
104
+ width: propsWidth,
105
+ height: propsHeight
106
+ } = props,
107
+ other = (0, _objectWithoutPropertiesLoose2.default)(props, _excluded);
108
+ const [containerRef, width, height] = useChartDimensions(propsWidth, propsHeight);
109
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(ResizableContainer, {
43
110
  ref: containerRef,
44
- style: {
45
- width: props.width ?? '100%',
46
- height: props.height ?? '100%',
47
- padding: 0
111
+ ownerState: {
112
+ width: props.width,
113
+ height: props.height
48
114
  },
49
- children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartContainer.ChartContainer, (0, _extends2.default)({}, props, {
115
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_ChartContainer.ChartContainer, (0, _extends2.default)({}, other, {
50
116
  width: width,
51
117
  height: height
52
118
  }))
@@ -91,7 +91,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
91
91
  color: _propTypes.default.string.isRequired,
92
92
  markerSize: _propTypes.default.number.isRequired,
93
93
  series: _propTypes.default.shape({
94
- color: _propTypes.default.string.isRequired,
94
+ color: _propTypes.default.string,
95
95
  data: _propTypes.default.arrayOf(_propTypes.default.shape({
96
96
  id: _propTypes.default.oneOfType([_propTypes.default.number, _propTypes.default.string]).isRequired,
97
97
  x: _propTypes.default.number.isRequired,
@@ -70,7 +70,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
70
70
  y: _propTypes.default.oneOf(['line', 'none'])
71
71
  }),
72
72
  /**
73
- * Indicate which axis to display the the bottom of the charts.
73
+ * Indicate which axis to display the bottom of the charts.
74
74
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
75
75
  * @default xAxisIds[0] The id of the first provided axis
76
76
  */
@@ -97,7 +97,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
97
97
  disableAxisListener: _propTypes.default.bool,
98
98
  height: _propTypes.default.number,
99
99
  /**
100
- * Indicate which axis to display the the left of the charts.
100
+ * Indicate which axis to display the left of the charts.
101
101
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
102
102
  * @default yAxisIds[0] The id of the first provided axis
103
103
  */
@@ -117,6 +117,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
117
117
  legend: _propTypes.default.shape({
118
118
  classes: _propTypes.default.object,
119
119
  direction: _propTypes.default.oneOf(['column', 'row']),
120
+ hidden: _propTypes.default.bool,
120
121
  itemWidth: _propTypes.default.number,
121
122
  markSize: _propTypes.default.number,
122
123
  offset: _propTypes.default.shape({
@@ -136,7 +137,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
136
137
  top: _propTypes.default.number
137
138
  }),
138
139
  /**
139
- * Indicate which axis to display the the right of the charts.
140
+ * Indicate which axis to display the right of the charts.
140
141
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
141
142
  * @default null
142
143
  */
@@ -181,7 +182,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
181
182
  trigger: _propTypes.default.oneOf(['axis', 'item', 'none'])
182
183
  }),
183
184
  /**
184
- * Indicate which axis to display the the top of the charts.
185
+ * Indicate which axis to display the top of the charts.
185
186
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
186
187
  * @default null
187
188
  */
@@ -0,0 +1,3 @@
1
+ import { LegendGetter } from '../models/seriesType/config';
2
+ declare const legendGetter: LegendGetter<'scatter'>;
3
+ export default legendGetter;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ const legendGetter = params => {
8
+ const {
9
+ seriesOrder,
10
+ series
11
+ } = params;
12
+ const data = seriesOrder.map(seriesId => ({
13
+ color: series[seriesId].color,
14
+ label: series[seriesId].label,
15
+ id: seriesId
16
+ }));
17
+ return data.filter(item => item.label !== undefined);
18
+ };
19
+ var _default = legendGetter;
20
+ exports.default = _default;
@@ -12,6 +12,7 @@ var _styles = require("@mui/material/styles");
12
12
  var _formatter = _interopRequireDefault(require("../BarChart/formatter"));
13
13
  var _formatter2 = _interopRequireDefault(require("../ScatterChart/formatter"));
14
14
  var _formatter3 = _interopRequireDefault(require("../LineChart/formatter"));
15
+ var _formatter4 = _interopRequireDefault(require("../PieChart/formatter"));
15
16
  var _defaultizeColor = require("../internals/defaultizeColor");
16
17
  var _colorPalettes = require("../colorPalettes");
17
18
  var _jsxRuntime = require("react/jsx-runtime");
@@ -22,8 +23,17 @@ exports.SeriesContext = SeriesContext;
22
23
  const seriesTypeFormatter = {
23
24
  bar: _formatter.default,
24
25
  scatter: _formatter2.default,
25
- line: _formatter3.default
26
+ line: _formatter3.default,
27
+ pie: _formatter4.default
26
28
  };
29
+ /**
30
+ * This methods is the interface between what the developper is providing and what compoenents receives
31
+ * To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if soe line data are modified
32
+ * It also add defaultized values such as the ids, colors
33
+ * @param series The array of series provided by devs
34
+ * @param colors The color palette used to defaultize series colors
35
+ * @returns An object structuring all the series by type.
36
+ */
27
37
  const formatSeries = (series, colors) => {
28
38
  // Group series by type
29
39
  const seriesGroups = {};
@@ -43,7 +43,9 @@ function BarChart(props) {
43
43
  xAxis: xAxis != null ? xAxis : [{
44
44
  id: DEFAULT_X_AXIS_KEY,
45
45
  scaleType: 'band',
46
- data: [...new Array(Math.max(...series.map(s => s.data.length)))].map((_, index) => index)
46
+ data: Array.from({
47
+ length: Math.max(...series.map(s => s.data.length))
48
+ }, (_, index) => index)
47
49
  }],
48
50
  yAxis: yAxis,
49
51
  colors: colors,
@@ -74,7 +76,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
74
76
  y: PropTypes.oneOf(['line', 'none'])
75
77
  }),
76
78
  /**
77
- * Indicate which axis to display the the bottom of the charts.
79
+ * Indicate which axis to display the bottom of the charts.
78
80
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
79
81
  * @default xAxisIds[0] The id of the first provided axis
80
82
  */
@@ -101,7 +103,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
101
103
  disableAxisListener: PropTypes.bool,
102
104
  height: PropTypes.number,
103
105
  /**
104
- * Indicate which axis to display the the left of the charts.
106
+ * Indicate which axis to display the left of the charts.
105
107
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
106
108
  * @default yAxisIds[0] The id of the first provided axis
107
109
  */
@@ -121,6 +123,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
121
123
  legend: PropTypes.shape({
122
124
  classes: PropTypes.object,
123
125
  direction: PropTypes.oneOf(['column', 'row']),
126
+ hidden: PropTypes.bool,
124
127
  itemWidth: PropTypes.number,
125
128
  markSize: PropTypes.number,
126
129
  offset: PropTypes.shape({
@@ -140,7 +143,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
140
143
  top: PropTypes.number
141
144
  }),
142
145
  /**
143
- * Indicate which axis to display the the right of the charts.
146
+ * Indicate which axis to display the right of the charts.
144
147
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
145
148
  * @default null
146
149
  */
@@ -183,7 +186,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
183
186
  trigger: PropTypes.oneOf(['axis', 'item', 'none'])
184
187
  }),
185
188
  /**
186
- * Indicate which axis to display the the top of the charts.
189
+ * Indicate which axis to display the top of the charts.
187
190
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
188
191
  * @default null
189
192
  */
@@ -0,0 +1,13 @@
1
+ const legendGetter = params => {
2
+ const {
3
+ seriesOrder,
4
+ series
5
+ } = params;
6
+ const data = seriesOrder.map(seriesId => ({
7
+ color: series[seriesId].color,
8
+ label: series[seriesId].label,
9
+ id: seriesId
10
+ }));
11
+ return data.filter(item => item.label !== undefined);
12
+ };
13
+ export default legendGetter;
@@ -70,7 +70,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
70
70
  // | To update them edit the TypeScript types and run "yarn proptypes" |
71
71
  // ----------------------------------------------------------------------
72
72
  /**
73
- * Indicate which axis to display the the bottom of the charts.
73
+ * Indicate which axis to display the bottom of the charts.
74
74
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
75
75
  * @default xAxisIds[0] The id of the first provided axis
76
76
  */
@@ -88,7 +88,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
88
88
  tickSize: PropTypes.number
89
89
  }), PropTypes.string]),
90
90
  /**
91
- * Indicate which axis to display the the left of the charts.
91
+ * Indicate which axis to display the left of the charts.
92
92
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
93
93
  * @default yAxisIds[0] The id of the first provided axis
94
94
  */
@@ -106,7 +106,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
106
106
  tickSize: PropTypes.number
107
107
  }), PropTypes.string]),
108
108
  /**
109
- * Indicate which axis to display the the right of the charts.
109
+ * Indicate which axis to display the right of the charts.
110
110
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
111
111
  * @default null
112
112
  */
@@ -124,7 +124,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
124
124
  tickSize: PropTypes.number
125
125
  }), PropTypes.string]),
126
126
  /**
127
- * Indicate which axis to display the the top of the charts.
127
+ * Indicate which axis to display the top of the charts.
128
128
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
129
129
  * @default null
130
130
  */
@@ -146,7 +146,8 @@ export function ChartsLegend(inProps) {
146
146
  const {
147
147
  position,
148
148
  direction,
149
- offset
149
+ offset,
150
+ hidden
150
151
  } = props;
151
152
  const theme = useTheme();
152
153
  const classes = useUtilityClasses(_extends({}, props, {
@@ -154,6 +155,9 @@ export function ChartsLegend(inProps) {
154
155
  }));
155
156
  const drawingArea = React.useContext(DrawingContext);
156
157
  const series = React.useContext(SeriesContext);
158
+ if (hidden) {
159
+ return null;
160
+ }
157
161
  const seriesToDisplay = getSeriesToDisplay(series);
158
162
  return /*#__PURE__*/_jsx(ChartsLegendRoot, {
159
163
  ownerState: {
@@ -1,3 +1,13 @@
1
+ import getBarLegend from '../BarChart/legend';
2
+ import getScatterLegend from '../ScatterChart/legend';
3
+ import getLineLegend from '../LineChart/legend';
4
+ import getPieLegend from '../PieChart/legend';
5
+ const legendGetter = {
6
+ bar: getBarLegend,
7
+ scatter: getScatterLegend,
8
+ line: getLineLegend,
9
+ pie: getPieLegend
10
+ };
1
11
  export function getSeriesToDisplay(series) {
2
- return Object.values(series).flatMap(s => s.seriesOrder.map(seriesId => s.series[seriesId])).filter(s => s.label !== undefined);
12
+ return Object.keys(series).flatMap(seriesType => legendGetter[seriesType](series[seriesType]));
3
13
  }