@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.
- package/BarChart/BarChart.js +8 -5
- package/BarChart/legend.d.ts +3 -0
- package/BarChart/legend.js +20 -0
- package/CHANGELOG.md +136 -8
- package/ChartsAxis/ChartsAxis.d.ts +4 -4
- package/ChartsAxis/ChartsAxis.js +4 -4
- package/ChartsLegend/ChartsLegend.d.ts +5 -1
- package/ChartsLegend/ChartsLegend.js +5 -1
- package/ChartsLegend/utils.d.ts +1 -1
- package/ChartsLegend/utils.js +12 -1
- package/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
- package/ChartsTooltip/ChartsTooltipTable.js +8 -8
- package/LineChart/LineChart.js +8 -5
- package/LineChart/legend.d.ts +3 -0
- package/LineChart/legend.js +20 -0
- package/PieChart/PieArc.d.ts +36 -0
- package/PieChart/PieArc.js +128 -0
- package/PieChart/PieArcLabel.d.ts +36 -0
- package/PieChart/PieArcLabel.js +113 -0
- package/PieChart/PieChart.d.ts +20 -0
- package/PieChart/PieChart.js +292 -0
- package/PieChart/PiePlot.d.ts +2 -0
- package/PieChart/PiePlot.js +98 -0
- package/PieChart/formatter.d.ts +3 -0
- package/PieChart/formatter.js +49 -0
- package/PieChart/index.d.ts +4 -0
- package/PieChart/index.js +47 -0
- package/PieChart/legend.d.ts +3 -0
- package/PieChart/legend.js +19 -0
- package/PieChart/package.json +6 -0
- package/README.md +30 -2
- package/ResponsiveChartContainer/index.js +91 -25
- package/ScatterChart/Scatter.js +1 -1
- package/ScatterChart/ScatterChart.js +5 -4
- package/ScatterChart/legend.d.ts +3 -0
- package/ScatterChart/legend.js +20 -0
- package/context/SeriesContextProvider.js +11 -1
- package/esm/BarChart/BarChart.js +8 -5
- package/esm/BarChart/legend.js +13 -0
- package/esm/ChartsAxis/ChartsAxis.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +5 -1
- package/esm/ChartsLegend/utils.js +11 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +11 -3
- package/esm/ChartsTooltip/ChartsTooltipTable.js +8 -8
- package/esm/LineChart/LineChart.js +8 -5
- package/esm/LineChart/legend.js +13 -0
- package/esm/PieChart/PieArc.js +117 -0
- package/esm/PieChart/PieArcLabel.js +101 -0
- package/esm/PieChart/PieChart.js +285 -0
- package/esm/PieChart/PiePlot.js +92 -0
- package/esm/PieChart/formatter.js +48 -0
- package/esm/PieChart/index.js +4 -0
- package/esm/PieChart/legend.js +12 -0
- package/esm/ResponsiveChartContainer/index.js +94 -26
- package/esm/ScatterChart/Scatter.js +1 -1
- package/esm/ScatterChart/ScatterChart.js +5 -4
- package/esm/ScatterChart/legend.js +13 -0
- package/esm/context/SeriesContextProvider.js +11 -1
- package/esm/index.js +1 -0
- package/esm/internals/defaultizeColor.js +7 -0
- package/esm/models/seriesType/index.js +1 -8
- package/index.d.ts +1 -0
- package/index.js +12 -1
- package/internals/defaultizeColor.d.ts +35 -0
- package/internals/defaultizeColor.js +7 -0
- package/legacy/BarChart/BarChart.js +10 -7
- package/legacy/BarChart/legend.js +15 -0
- package/legacy/ChartsAxis/ChartsAxis.js +4 -4
- package/legacy/ChartsLegend/ChartsLegend.js +5 -1
- package/legacy/ChartsLegend/utils.js +12 -6
- package/legacy/ChartsTooltip/ChartsAxisTooltipContent.js +3 -1
- package/legacy/ChartsTooltip/ChartsItemTooltipContent.js +10 -3
- package/legacy/ChartsTooltip/ChartsTooltipTable.js +7 -9
- package/legacy/LineChart/LineChart.js +10 -7
- package/legacy/LineChart/legend.js +15 -0
- package/legacy/PieChart/PieArc.js +118 -0
- package/legacy/PieChart/PieArcLabel.js +101 -0
- package/legacy/PieChart/PieChart.js +297 -0
- package/legacy/PieChart/PiePlot.js +89 -0
- package/legacy/PieChart/formatter.js +55 -0
- package/legacy/PieChart/index.js +4 -0
- package/legacy/PieChart/legend.js +16 -0
- package/legacy/ResponsiveChartContainer/index.js +89 -26
- package/legacy/ScatterChart/Scatter.js +1 -1
- package/legacy/ScatterChart/ScatterChart.js +5 -4
- package/legacy/ScatterChart/legend.js +15 -0
- package/legacy/context/SeriesContextProvider.js +11 -1
- package/legacy/index.js +2 -1
- package/legacy/internals/defaultizeColor.js +9 -0
- package/legacy/models/seriesType/index.js +1 -8
- package/models/seriesType/bar.d.ts +1 -1
- package/models/seriesType/common.d.ts +1 -1
- package/models/seriesType/config.d.ts +29 -2
- package/models/seriesType/index.d.ts +7 -3
- package/models/seriesType/index.js +11 -0
- package/models/seriesType/line.d.ts +1 -1
- package/models/seriesType/pie.d.ts +103 -3
- package/models/seriesType/scatter.d.ts +1 -1
- package/modern/BarChart/BarChart.js +8 -5
- package/modern/BarChart/legend.js +13 -0
- package/modern/ChartsAxis/ChartsAxis.js +4 -4
- package/modern/ChartsLegend/ChartsLegend.js +5 -1
- package/modern/ChartsLegend/utils.js +11 -1
- package/modern/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/modern/ChartsTooltip/ChartsItemTooltipContent.js +11 -2
- package/modern/ChartsTooltip/ChartsTooltipTable.js +8 -8
- package/modern/LineChart/LineChart.js +8 -5
- package/modern/LineChart/legend.js +13 -0
- package/modern/PieChart/PieArc.js +116 -0
- package/modern/PieChart/PieArcLabel.js +101 -0
- package/modern/PieChart/PieChart.js +285 -0
- package/modern/PieChart/PiePlot.js +91 -0
- package/modern/PieChart/formatter.js +41 -0
- package/modern/PieChart/index.js +4 -0
- package/modern/PieChart/legend.js +12 -0
- package/modern/ResponsiveChartContainer/index.js +91 -25
- package/modern/ScatterChart/Scatter.js +1 -1
- package/modern/ScatterChart/ScatterChart.js +5 -4
- package/modern/ScatterChart/legend.js +13 -0
- package/modern/context/SeriesContextProvider.js +11 -1
- package/modern/index.js +2 -1
- package/modern/internals/defaultizeColor.js +7 -0
- package/modern/models/seriesType/index.js +1 -8
- 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
|
|
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
|
|
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
|
-
|
|
12
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
|
33
|
-
|
|
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
|
-
|
|
36
|
-
width: props.width
|
|
37
|
-
height: props.height
|
|
38
|
-
padding: 0
|
|
102
|
+
ownerState: {
|
|
103
|
+
width: props.width,
|
|
104
|
+
height: props.height
|
|
39
105
|
},
|
|
40
|
-
children: /*#__PURE__*/_jsx(ChartContainer, _extends({},
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mui/x-charts",
|
|
3
|
-
"version": "6.0.0-alpha.
|
|
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",
|