@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
@@ -1,43 +1,109 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
3
+ const _excluded = ["width", "height"];
2
4
  import * as React from 'react';
3
- import { ResizeObserver } from '@juggle/resize-observer';
5
+ import useEnhancedEffect from '@mui/utils/useEnhancedEffect';
6
+ import ownerWindow from '@mui/utils/ownerWindow';
7
+ import { styled } from '@mui/material/styles';
4
8
  import { ChartContainer } from '../ChartContainer';
5
9
  import { jsx as _jsx } from "react/jsx-runtime";
6
10
  const useChartDimensions = (inWidth, inHeight) => {
7
- const ref = React.useRef(null);
11
+ const rootRef = React.useRef(null);
12
+ const displayError = React.useRef(false);
8
13
  const [width, setWidth] = React.useState(0);
9
14
  const [height, setHeight] = React.useState(0);
15
+
16
+ // Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
17
+ const computeSize = React.useCallback(() => {
18
+ const mainEl = rootRef?.current;
19
+ if (!mainEl) {
20
+ return;
21
+ }
22
+ const win = ownerWindow(mainEl);
23
+ const computedStyle = win.getComputedStyle(mainEl);
24
+ const newHeight = parseFloat(computedStyle.height) || 0;
25
+ const newWidth = parseFloat(computedStyle.width) || 0;
26
+ setWidth(newWidth);
27
+ setHeight(newHeight);
28
+ }, []);
10
29
  React.useEffect(() => {
11
- const element = ref.current;
12
- if (element === null || inHeight !== undefined && inWidth !== undefined) {
30
+ // Ensure the error detection occurs after the first rendering.
31
+ displayError.current = true;
32
+ }, []);
33
+ useEnhancedEffect(() => {
34
+ if (inWidth !== undefined && inHeight !== undefined) {
13
35
  return () => {};
14
36
  }
15
- const resizeObserver = new ResizeObserver(entries => {
16
- if (Array.isArray(entries) && entries.length) {
17
- const entry = entries[0];
18
- if (inWidth === undefined) {
19
- setWidth(entry.contentRect.width);
20
- }
21
- if (inHeight === undefined) {
22
- setHeight(entry.contentRect.height);
23
- }
24
- }
37
+ computeSize();
38
+ const elementToObserve = rootRef.current;
39
+ if (typeof ResizeObserver === 'undefined') {
40
+ return () => {};
41
+ }
42
+ let animationFrame;
43
+ const observer = new ResizeObserver(() => {
44
+ // See https://github.com/mui/mui-x/issues/8733
45
+ animationFrame = window.requestAnimationFrame(() => {
46
+ computeSize();
47
+ });
25
48
  });
26
- resizeObserver.observe(element);
27
- return () => resizeObserver.disconnect();
28
- }, [height, inHeight, inWidth, width]);
29
- return [ref, inWidth ?? width, inHeight ?? height];
49
+ if (elementToObserve) {
50
+ observer.observe(elementToObserve);
51
+ }
52
+ return () => {
53
+ if (animationFrame) {
54
+ window.cancelAnimationFrame(animationFrame);
55
+ }
56
+ if (elementToObserve) {
57
+ observer.unobserve(elementToObserve);
58
+ }
59
+ };
60
+ }, [computeSize, inHeight, inWidth]);
61
+ if (process.env.NODE_ENV !== 'production') {
62
+ if (displayError.current && inWidth === undefined && width === 0) {
63
+ console.error(`MUI: Charts does not have \`width\` prop, and its container has no \`width\` defined.`);
64
+ displayError.current = false;
65
+ }
66
+ if (displayError.current && inHeight === undefined && height === 0) {
67
+ console.error(`MUI: Charts does not have \`height\` prop, and its container has no \`height\` defined.`);
68
+ displayError.current = false;
69
+ }
70
+ }
71
+ return [rootRef, inWidth ?? width, inHeight ?? height];
30
72
  };
73
+ const ResizableContainer = styled('div', {
74
+ name: 'MuiResponsiveChart',
75
+ slot: 'Container'
76
+ })(({
77
+ ownerState
78
+ }) => ({
79
+ width: ownerState.width ?? '100%',
80
+ height: ownerState.height ?? '100%',
81
+ display: 'flex',
82
+ position: 'relative',
83
+ flexGrow: 1,
84
+ flexDirection: 'column',
85
+ alignItems: 'center',
86
+ justifyContent: 'center',
87
+ overflow: 'hidden',
88
+ '&>svg': {
89
+ width: '100%',
90
+ height: '100%'
91
+ }
92
+ }));
31
93
  export function ResponsiveChartContainer(props) {
32
- const [containerRef, width, height] = useChartDimensions(props.width, props.height);
33
- return /*#__PURE__*/_jsx("div", {
94
+ const {
95
+ width: propsWidth,
96
+ height: propsHeight
97
+ } = props,
98
+ other = _objectWithoutPropertiesLoose(props, _excluded);
99
+ const [containerRef, width, height] = useChartDimensions(propsWidth, propsHeight);
100
+ return /*#__PURE__*/_jsx(ResizableContainer, {
34
101
  ref: containerRef,
35
- style: {
36
- width: props.width ?? '100%',
37
- height: props.height ?? '100%',
38
- padding: 0
102
+ ownerState: {
103
+ width: props.width,
104
+ height: props.height
39
105
  },
40
- children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, props, {
106
+ children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
41
107
  width: width,
42
108
  height: height
43
109
  }))
@@ -82,7 +82,7 @@ process.env.NODE_ENV !== "production" ? Scatter.propTypes = {
82
82
  color: PropTypes.string.isRequired,
83
83
  markerSize: PropTypes.number.isRequired,
84
84
  series: PropTypes.shape({
85
- color: PropTypes.string.isRequired,
85
+ color: PropTypes.string,
86
86
  data: PropTypes.arrayOf(PropTypes.shape({
87
87
  id: PropTypes.oneOfType([PropTypes.number, PropTypes.string]).isRequired,
88
88
  x: PropTypes.number.isRequired,
@@ -62,7 +62,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
62
62
  y: PropTypes.oneOf(['line', 'none'])
63
63
  }),
64
64
  /**
65
- * Indicate which axis to display the the bottom of the charts.
65
+ * Indicate which axis to display the bottom of the charts.
66
66
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
67
67
  * @default xAxisIds[0] The id of the first provided axis
68
68
  */
@@ -89,7 +89,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
89
89
  disableAxisListener: PropTypes.bool,
90
90
  height: PropTypes.number,
91
91
  /**
92
- * Indicate which axis to display the the left of the charts.
92
+ * Indicate which axis to display the left of the charts.
93
93
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
94
94
  * @default yAxisIds[0] The id of the first provided axis
95
95
  */
@@ -109,6 +109,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
109
109
  legend: PropTypes.shape({
110
110
  classes: PropTypes.object,
111
111
  direction: PropTypes.oneOf(['column', 'row']),
112
+ hidden: PropTypes.bool,
112
113
  itemWidth: PropTypes.number,
113
114
  markSize: PropTypes.number,
114
115
  offset: PropTypes.shape({
@@ -128,7 +129,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
128
129
  top: PropTypes.number
129
130
  }),
130
131
  /**
131
- * Indicate which axis to display the the right of the charts.
132
+ * Indicate which axis to display the right of the charts.
132
133
  * Can be a string (the id of the axis) or an object `ChartsYAxisProps`
133
134
  * @default null
134
135
  */
@@ -173,7 +174,7 @@ process.env.NODE_ENV !== "production" ? ScatterChart.propTypes = {
173
174
  trigger: PropTypes.oneOf(['axis', 'item', 'none'])
174
175
  }),
175
176
  /**
176
- * Indicate which axis to display the the top of the charts.
177
+ * Indicate which axis to display the top of the charts.
177
178
  * Can be a string (the id of the axis) or an object `ChartsXAxisProps`
178
179
  * @default null
179
180
  */
@@ -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;
@@ -4,6 +4,7 @@ import { useTheme } from '@mui/material/styles';
4
4
  import barSeriesFormatter from '../BarChart/formatter';
5
5
  import scatterSeriesFormatter from '../ScatterChart/formatter';
6
6
  import lineSeriesFormatter from '../LineChart/formatter';
7
+ import pieSeriesFormatter from '../PieChart/formatter';
7
8
  import { defaultizeColor } from '../internals/defaultizeColor';
8
9
  import { blueberryTwilightPalette } from '../colorPalettes';
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -11,8 +12,17 @@ export const SeriesContext = /*#__PURE__*/React.createContext({});
11
12
  const seriesTypeFormatter = {
12
13
  bar: barSeriesFormatter,
13
14
  scatter: scatterSeriesFormatter,
14
- line: lineSeriesFormatter
15
+ line: lineSeriesFormatter,
16
+ pie: pieSeriesFormatter
15
17
  };
18
+ /**
19
+ * This methods is the interface between what the developper is providing and what compoenents receives
20
+ * To simplify the components behaviors, it groups series by type, such that LinePlots props are not updated if soe line data are modified
21
+ * It also add defaultized values such as the ids, colors
22
+ * @param series The array of series provided by devs
23
+ * @param colors The color palette used to defaultize series colors
24
+ * @returns An object structuring all the series by type.
25
+ */
16
26
  const formatSeries = (series, colors) => {
17
27
  // Group series by type
18
28
  const seriesGroups = {};
package/modern/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @mui/x-charts v6.0.0-alpha.0
2
+ * @mui/x-charts v6.0.0-alpha.2
3
3
  *
4
4
  * @license MIT
5
5
  * This source code is licensed under the MIT license found in the
@@ -17,6 +17,7 @@ export * from './ChartsTooltip';
17
17
  export * from './ChartsAxisHighlight';
18
18
  export * from './BarChart';
19
19
  export * from './LineChart';
20
+ export * from './PieChart';
20
21
  export * from './ScatterChart';
21
22
  export * from './ChartContainer';
22
23
  export * from './ResponsiveChartContainer';
@@ -1,6 +1,13 @@
1
1
  import _extends from "@babel/runtime/helpers/esm/extends";
2
2
  const DEFAULT_COLORS = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'];
3
3
  export function defaultizeColor(series, seriesIndex, colors = DEFAULT_COLORS) {
4
+ if (series.type === 'pie') {
5
+ return _extends({}, series, {
6
+ data: series.data.map((d, index) => _extends({
7
+ color: colors[index % colors.length]
8
+ }, d))
9
+ });
10
+ }
4
11
  return _extends({
5
12
  color: colors[seriesIndex % colors.length]
6
13
  }, series);
@@ -1,12 +1,5 @@
1
- // import { PieSeriesType } from './pie';
2
-
3
- // | PieSeriesType;
4
-
5
- // | PieSeriesType;
6
-
7
- // | PieSeriesType
8
-
9
1
  export * from './line';
10
2
  export * from './bar';
11
3
  export * from './scatter';
4
+ export * from './pie';
12
5
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mui/x-charts",
3
- "version": "6.0.0-alpha.0",
3
+ "version": "6.0.0-alpha.2",
4
4
  "description": "The community edition of the charts components (MUI X).",
5
5
  "author": "MUI Team",
6
6
  "main": "./index.js",
@@ -28,12 +28,10 @@
28
28
  },
29
29
  "dependencies": {
30
30
  "@babel/runtime": "^7.22.5",
31
- "@juggle/resize-observer": "^3.4.0",
32
31
  "@types/d3-color": "^3.1.0",
33
32
  "@types/d3-scale": "^4.0.3",
34
33
  "@types/d3-shape": "^3.1.1",
35
34
  "clsx": "^1.2.1",
36
- "d3-array": "^3.2.4",
37
35
  "d3-color": "^3.1.0",
38
36
  "d3-scale": "^4.0.2",
39
37
  "d3-shape": "^3.2.0",