@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
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import * as React from 'react';
|
|
3
|
+
import { SeriesContext } from '../context/SeriesContextProvider';
|
|
4
|
+
import PieArc from './PieArc';
|
|
5
|
+
import PieArcLabel from './PieArcLabel';
|
|
6
|
+
import { DrawingContext } from '../context/DrawingProvider';
|
|
7
|
+
import { createElement as _createElement } from "react";
|
|
8
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
9
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
+
const RATIO = 180 / Math.PI;
|
|
11
|
+
function getItemLabel(arcLabel, arcLabelMinAngle, item) {
|
|
12
|
+
if (!arcLabel) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const angle = (item.endAngle - item.startAngle) * RATIO;
|
|
16
|
+
if (angle < arcLabelMinAngle) {
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
if (typeof arcLabel === 'string') {
|
|
20
|
+
var _item$arcLabel;
|
|
21
|
+
return (_item$arcLabel = item[arcLabel]) == null ? void 0 : _item$arcLabel.toString();
|
|
22
|
+
}
|
|
23
|
+
return arcLabel(item);
|
|
24
|
+
}
|
|
25
|
+
export function PiePlot() {
|
|
26
|
+
const seriesData = React.useContext(SeriesContext).pie;
|
|
27
|
+
const {
|
|
28
|
+
left,
|
|
29
|
+
top,
|
|
30
|
+
width,
|
|
31
|
+
height
|
|
32
|
+
} = React.useContext(DrawingContext);
|
|
33
|
+
if (seriesData === undefined) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const availableRadius = Math.min(width, height) / 2;
|
|
37
|
+
const center = {
|
|
38
|
+
x: left + width / 2,
|
|
39
|
+
y: top + height / 2
|
|
40
|
+
};
|
|
41
|
+
const {
|
|
42
|
+
series,
|
|
43
|
+
seriesOrder
|
|
44
|
+
} = seriesData;
|
|
45
|
+
return /*#__PURE__*/_jsx("g", {
|
|
46
|
+
children: seriesOrder.map(seriesId => {
|
|
47
|
+
const {
|
|
48
|
+
innerRadius,
|
|
49
|
+
outerRadius,
|
|
50
|
+
cornerRadius,
|
|
51
|
+
arcLabel,
|
|
52
|
+
arcLabelMinAngle = 0,
|
|
53
|
+
data,
|
|
54
|
+
cx,
|
|
55
|
+
cy,
|
|
56
|
+
highlighted,
|
|
57
|
+
faded
|
|
58
|
+
} = series[seriesId];
|
|
59
|
+
return /*#__PURE__*/_jsx("g", {
|
|
60
|
+
transform: `translate(${cx === undefined ? center.x : left + cx}, ${cy === undefined ? center.y : top + cy})`,
|
|
61
|
+
children: /*#__PURE__*/_jsxs("g", {
|
|
62
|
+
children: [data.map((item, index) => {
|
|
63
|
+
return /*#__PURE__*/_createElement(PieArc, _extends({}, item, {
|
|
64
|
+
key: item.id,
|
|
65
|
+
innerRadius: innerRadius,
|
|
66
|
+
outerRadius: outerRadius != null ? outerRadius : availableRadius,
|
|
67
|
+
cornerRadius: cornerRadius,
|
|
68
|
+
id: seriesId,
|
|
69
|
+
color: item.color,
|
|
70
|
+
dataIndex: index,
|
|
71
|
+
highlightScope: series[seriesId].highlightScope,
|
|
72
|
+
highlighted: highlighted,
|
|
73
|
+
faded: faded
|
|
74
|
+
}));
|
|
75
|
+
}), data.map((item, index) => {
|
|
76
|
+
return /*#__PURE__*/_createElement(PieArcLabel, _extends({}, item, {
|
|
77
|
+
key: item.id,
|
|
78
|
+
innerRadius: innerRadius,
|
|
79
|
+
outerRadius: outerRadius != null ? outerRadius : availableRadius,
|
|
80
|
+
cornerRadius: cornerRadius,
|
|
81
|
+
id: seriesId,
|
|
82
|
+
color: item.color,
|
|
83
|
+
dataIndex: index,
|
|
84
|
+
highlightScope: series[seriesId].highlightScope,
|
|
85
|
+
formattedArcLabel: getItemLabel(arcLabel, arcLabelMinAngle, item)
|
|
86
|
+
}));
|
|
87
|
+
})]
|
|
88
|
+
})
|
|
89
|
+
}, seriesId);
|
|
90
|
+
})
|
|
91
|
+
});
|
|
92
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { pie as d3Pie } from 'd3-shape';
|
|
3
|
+
const getSortingComparator = (comparator = 'none') => {
|
|
4
|
+
if (typeof comparator === 'function') {
|
|
5
|
+
return comparator;
|
|
6
|
+
}
|
|
7
|
+
switch (comparator) {
|
|
8
|
+
case 'none':
|
|
9
|
+
return null;
|
|
10
|
+
case 'desc':
|
|
11
|
+
return (a, b) => b - a;
|
|
12
|
+
case 'asc':
|
|
13
|
+
return (a, b) => a - b;
|
|
14
|
+
default:
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
const formatter = params => {
|
|
19
|
+
const {
|
|
20
|
+
seriesOrder,
|
|
21
|
+
series
|
|
22
|
+
} = params;
|
|
23
|
+
const defaultizedSeries = {};
|
|
24
|
+
seriesOrder.forEach(seriesId => {
|
|
25
|
+
var _series$seriesId$star, _series$seriesId$endA, _series$seriesId$padd, _series$seriesId$sort;
|
|
26
|
+
const arcs = d3Pie().startAngle(2 * Math.PI * ((_series$seriesId$star = series[seriesId].startAngle) != null ? _series$seriesId$star : 0) / 360).endAngle(2 * Math.PI * ((_series$seriesId$endA = series[seriesId].endAngle) != null ? _series$seriesId$endA : 360) / 360).padAngle(2 * Math.PI * ((_series$seriesId$padd = series[seriesId].paddingAngle) != null ? _series$seriesId$padd : 0) / 360).sortValues(getSortingComparator((_series$seriesId$sort = series[seriesId].sortingValues) != null ? _series$seriesId$sort : 'none'))(series[seriesId].data.map(piePoint => piePoint.value));
|
|
27
|
+
defaultizedSeries[seriesId] = _extends({
|
|
28
|
+
valueFormatter: item => item.value.toLocaleString()
|
|
29
|
+
}, series[seriesId], {
|
|
30
|
+
data: series[seriesId].data.map((item, index) => {
|
|
31
|
+
var _item$id;
|
|
32
|
+
return _extends({}, item, {
|
|
33
|
+
id: (_item$id = item.id) != null ? _item$id : `auto-generated-pie-id-${seriesId}-${index}`
|
|
34
|
+
}, arcs[index]);
|
|
35
|
+
}).map(item => {
|
|
36
|
+
var _series$seriesId$valu, _series$seriesId$valu2, _series$seriesId;
|
|
37
|
+
return _extends({}, item, {
|
|
38
|
+
formattedValue: (_series$seriesId$valu = (_series$seriesId$valu2 = (_series$seriesId = series[seriesId]).valueFormatter) == null ? void 0 : _series$seriesId$valu2.call(_series$seriesId, item)) != null ? _series$seriesId$valu : item.value.toLocaleString()
|
|
39
|
+
});
|
|
40
|
+
})
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
return {
|
|
44
|
+
seriesOrder,
|
|
45
|
+
series: defaultizedSeries
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
export default formatter;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const legendGetter = params => {
|
|
2
|
+
const {
|
|
3
|
+
seriesOrder,
|
|
4
|
+
series
|
|
5
|
+
} = params;
|
|
6
|
+
return seriesOrder.flatMap(seriesId => series[seriesId].data.map(item => ({
|
|
7
|
+
color: item.color,
|
|
8
|
+
label: item.label,
|
|
9
|
+
id: item.id
|
|
10
|
+
})).filter(item => item.label !== undefined));
|
|
11
|
+
};
|
|
12
|
+
export default legendGetter;
|
|
@@ -1,44 +1,112 @@
|
|
|
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 == null ? void 0 : 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 != null ? inWidth : width, inHeight != null ? inHeight : height];
|
|
30
72
|
};
|
|
73
|
+
const ResizableContainer = styled('div', {
|
|
74
|
+
name: 'MuiResponsiveChart',
|
|
75
|
+
slot: 'Container'
|
|
76
|
+
})(({
|
|
77
|
+
ownerState
|
|
78
|
+
}) => {
|
|
79
|
+
var _ownerState$width, _ownerState$height;
|
|
80
|
+
return {
|
|
81
|
+
width: (_ownerState$width = ownerState.width) != null ? _ownerState$width : '100%',
|
|
82
|
+
height: (_ownerState$height = ownerState.height) != null ? _ownerState$height : '100%',
|
|
83
|
+
display: 'flex',
|
|
84
|
+
position: 'relative',
|
|
85
|
+
flexGrow: 1,
|
|
86
|
+
flexDirection: 'column',
|
|
87
|
+
alignItems: 'center',
|
|
88
|
+
justifyContent: 'center',
|
|
89
|
+
overflow: 'hidden',
|
|
90
|
+
'&>svg': {
|
|
91
|
+
width: '100%',
|
|
92
|
+
height: '100%'
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
});
|
|
31
96
|
export function ResponsiveChartContainer(props) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
97
|
+
const {
|
|
98
|
+
width: propsWidth,
|
|
99
|
+
height: propsHeight
|
|
100
|
+
} = props,
|
|
101
|
+
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
102
|
+
const [containerRef, width, height] = useChartDimensions(propsWidth, propsHeight);
|
|
103
|
+
return /*#__PURE__*/_jsx(ResizableContainer, {
|
|
35
104
|
ref: containerRef,
|
|
36
|
-
|
|
37
|
-
width:
|
|
38
|
-
height:
|
|
39
|
-
padding: 0
|
|
105
|
+
ownerState: {
|
|
106
|
+
width: props.width,
|
|
107
|
+
height: props.height
|
|
40
108
|
},
|
|
41
|
-
children: /*#__PURE__*/_jsx(ChartContainer, _extends({},
|
|
109
|
+
children: /*#__PURE__*/_jsx(ChartContainer, _extends({}, other, {
|
|
42
110
|
width: width,
|
|
43
111
|
height: height
|
|
44
112
|
}))
|
|
@@ -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/esm/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from './ChartsTooltip';
|
|
|
10
10
|
export * from './ChartsAxisHighlight';
|
|
11
11
|
export * from './BarChart';
|
|
12
12
|
export * from './LineChart';
|
|
13
|
+
export * from './PieChart';
|
|
13
14
|
export * from './ScatterChart';
|
|
14
15
|
export * from './ChartContainer';
|
|
15
16
|
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/index.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export * from './ChartsTooltip';
|
|
|
10
10
|
export * from './ChartsAxisHighlight';
|
|
11
11
|
export * from './BarChart';
|
|
12
12
|
export * from './LineChart';
|
|
13
|
+
export * from './PieChart';
|
|
13
14
|
export * from './ScatterChart';
|
|
14
15
|
export * from './ChartContainer';
|
|
15
16
|
export * from './ResponsiveChartContainer';
|
package/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
|
|
@@ -142,6 +142,17 @@ Object.keys(_LineChart).forEach(function (key) {
|
|
|
142
142
|
}
|
|
143
143
|
});
|
|
144
144
|
});
|
|
145
|
+
var _PieChart = require("./PieChart");
|
|
146
|
+
Object.keys(_PieChart).forEach(function (key) {
|
|
147
|
+
if (key === "default" || key === "__esModule") return;
|
|
148
|
+
if (key in exports && exports[key] === _PieChart[key]) return;
|
|
149
|
+
Object.defineProperty(exports, key, {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
get: function () {
|
|
152
|
+
return _PieChart[key];
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
});
|
|
145
156
|
var _ScatterChart = require("./ScatterChart");
|
|
146
157
|
Object.keys(_ScatterChart).forEach(function (key) {
|
|
147
158
|
if (key === "default" || key === "__esModule") return;
|
|
@@ -1,5 +1,40 @@
|
|
|
1
1
|
import { AllSeriesType } from '../models/seriesType';
|
|
2
2
|
export declare function defaultizeColor(series: AllSeriesType, seriesIndex: number, colors?: string[]): {
|
|
3
|
+
data: {
|
|
4
|
+
color: string;
|
|
5
|
+
label?: string | undefined;
|
|
6
|
+
value: number;
|
|
7
|
+
id?: string | number | undefined;
|
|
8
|
+
}[];
|
|
9
|
+
type: "pie";
|
|
10
|
+
innerRadius?: number | undefined;
|
|
11
|
+
outerRadius?: number | undefined;
|
|
12
|
+
cornerRadius?: number | undefined;
|
|
13
|
+
startAngle?: number | undefined;
|
|
14
|
+
endAngle?: number | undefined;
|
|
15
|
+
paddingAngle?: number | undefined;
|
|
16
|
+
sortingValues?: import("../models/seriesType").ChartsPieSorting | undefined;
|
|
17
|
+
arcLabel?: "label" | "value" | "formattedValue" | ((item: import("../models/seriesType").DefaultizedPieValueType) => string) | undefined;
|
|
18
|
+
arcLabelMinAngle?: number | undefined;
|
|
19
|
+
cx?: number | undefined;
|
|
20
|
+
cy?: number | undefined;
|
|
21
|
+
highlighted?: {
|
|
22
|
+
additionalRadius?: number | undefined;
|
|
23
|
+
innerRadius?: number | undefined;
|
|
24
|
+
outerRadius?: number | undefined;
|
|
25
|
+
cornerRadius?: number | undefined;
|
|
26
|
+
} | undefined;
|
|
27
|
+
faded?: {
|
|
28
|
+
additionalRadius?: number | undefined;
|
|
29
|
+
innerRadius?: number | undefined;
|
|
30
|
+
outerRadius?: number | undefined;
|
|
31
|
+
cornerRadius?: number | undefined;
|
|
32
|
+
} | undefined;
|
|
33
|
+
id?: string | undefined;
|
|
34
|
+
color?: string | undefined;
|
|
35
|
+
valueFormatter?: ((value: import("../models/helpers").MakeOptional<import("../models/seriesType").PieValueType, "id">) => string) | undefined;
|
|
36
|
+
highlightScope?: Partial<import("..").HighlightScope> | undefined;
|
|
37
|
+
} | {
|
|
3
38
|
type: "bar";
|
|
4
39
|
data: number[];
|
|
5
40
|
label?: string | undefined;
|
|
@@ -8,6 +8,13 @@ exports.defaultizeColor = defaultizeColor;
|
|
|
8
8
|
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
9
|
const DEFAULT_COLORS = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2', '#7f7f7f', '#bcbd22', '#17becf'];
|
|
10
10
|
function defaultizeColor(series, seriesIndex, colors = DEFAULT_COLORS) {
|
|
11
|
+
if (series.type === 'pie') {
|
|
12
|
+
return (0, _extends2.default)({}, series, {
|
|
13
|
+
data: series.data.map((d, index) => (0, _extends2.default)({
|
|
14
|
+
color: colors[index % colors.length]
|
|
15
|
+
}, d))
|
|
16
|
+
});
|
|
17
|
+
}
|
|
11
18
|
return (0, _extends2.default)({
|
|
12
19
|
color: colors[seriesIndex % colors.length]
|
|
13
20
|
}, series);
|
|
@@ -44,9 +44,11 @@ function BarChart(props) {
|
|
|
44
44
|
xAxis: xAxis != null ? xAxis : [{
|
|
45
45
|
id: DEFAULT_X_AXIS_KEY,
|
|
46
46
|
scaleType: 'band',
|
|
47
|
-
data:
|
|
48
|
-
|
|
49
|
-
|
|
47
|
+
data: Array.from({
|
|
48
|
+
length: Math.max.apply(Math, _toConsumableArray(series.map(function (s) {
|
|
49
|
+
return s.data.length;
|
|
50
|
+
})))
|
|
51
|
+
}, function (_, index) {
|
|
50
52
|
return index;
|
|
51
53
|
})
|
|
52
54
|
}],
|
|
@@ -79,7 +81,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
79
81
|
y: PropTypes.oneOf(['line', 'none'])
|
|
80
82
|
}),
|
|
81
83
|
/**
|
|
82
|
-
* Indicate which axis to display the
|
|
84
|
+
* Indicate which axis to display the bottom of the charts.
|
|
83
85
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`
|
|
84
86
|
* @default xAxisIds[0] The id of the first provided axis
|
|
85
87
|
*/
|
|
@@ -106,7 +108,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
106
108
|
disableAxisListener: PropTypes.bool,
|
|
107
109
|
height: PropTypes.number,
|
|
108
110
|
/**
|
|
109
|
-
* Indicate which axis to display the
|
|
111
|
+
* Indicate which axis to display the left of the charts.
|
|
110
112
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`
|
|
111
113
|
* @default yAxisIds[0] The id of the first provided axis
|
|
112
114
|
*/
|
|
@@ -126,6 +128,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
126
128
|
legend: PropTypes.shape({
|
|
127
129
|
classes: PropTypes.object,
|
|
128
130
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
131
|
+
hidden: PropTypes.bool,
|
|
129
132
|
itemWidth: PropTypes.number,
|
|
130
133
|
markSize: PropTypes.number,
|
|
131
134
|
offset: PropTypes.shape({
|
|
@@ -145,7 +148,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
145
148
|
top: PropTypes.number
|
|
146
149
|
}),
|
|
147
150
|
/**
|
|
148
|
-
* Indicate which axis to display the
|
|
151
|
+
* Indicate which axis to display the right of the charts.
|
|
149
152
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`
|
|
150
153
|
* @default null
|
|
151
154
|
*/
|
|
@@ -188,7 +191,7 @@ process.env.NODE_ENV !== "production" ? BarChart.propTypes = {
|
|
|
188
191
|
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
189
192
|
}),
|
|
190
193
|
/**
|
|
191
|
-
* Indicate which axis to display the
|
|
194
|
+
* Indicate which axis to display the top of the charts.
|
|
192
195
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`
|
|
193
196
|
* @default null
|
|
194
197
|
*/
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var legendGetter = function legendGetter(params) {
|
|
2
|
+
var seriesOrder = params.seriesOrder,
|
|
3
|
+
series = params.series;
|
|
4
|
+
var data = seriesOrder.map(function (seriesId) {
|
|
5
|
+
return {
|
|
6
|
+
color: series[seriesId].color,
|
|
7
|
+
label: series[seriesId].label,
|
|
8
|
+
id: seriesId
|
|
9
|
+
};
|
|
10
|
+
});
|
|
11
|
+
return data.filter(function (item) {
|
|
12
|
+
return item.label !== undefined;
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export default legendGetter;
|
|
@@ -68,7 +68,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
68
68
|
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
69
69
|
// ----------------------------------------------------------------------
|
|
70
70
|
/**
|
|
71
|
-
* Indicate which axis to display the
|
|
71
|
+
* Indicate which axis to display the bottom of the charts.
|
|
72
72
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`
|
|
73
73
|
* @default xAxisIds[0] The id of the first provided axis
|
|
74
74
|
*/
|
|
@@ -86,7 +86,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
86
86
|
tickSize: PropTypes.number
|
|
87
87
|
}), PropTypes.string]),
|
|
88
88
|
/**
|
|
89
|
-
* Indicate which axis to display the
|
|
89
|
+
* Indicate which axis to display the left of the charts.
|
|
90
90
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`
|
|
91
91
|
* @default yAxisIds[0] The id of the first provided axis
|
|
92
92
|
*/
|
|
@@ -104,7 +104,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
104
104
|
tickSize: PropTypes.number
|
|
105
105
|
}), PropTypes.string]),
|
|
106
106
|
/**
|
|
107
|
-
* Indicate which axis to display the
|
|
107
|
+
* Indicate which axis to display the right of the charts.
|
|
108
108
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`
|
|
109
109
|
* @default null
|
|
110
110
|
*/
|
|
@@ -122,7 +122,7 @@ process.env.NODE_ENV !== "production" ? ChartsAxis.propTypes = {
|
|
|
122
122
|
tickSize: PropTypes.number
|
|
123
123
|
}), PropTypes.string]),
|
|
124
124
|
/**
|
|
125
|
-
* Indicate which axis to display the
|
|
125
|
+
* Indicate which axis to display the top of the charts.
|
|
126
126
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`
|
|
127
127
|
* @default null
|
|
128
128
|
*/
|
|
@@ -143,13 +143,17 @@ export function ChartsLegend(inProps) {
|
|
|
143
143
|
});
|
|
144
144
|
var position = props.position,
|
|
145
145
|
direction = props.direction,
|
|
146
|
-
offset = props.offset
|
|
146
|
+
offset = props.offset,
|
|
147
|
+
hidden = props.hidden;
|
|
147
148
|
var theme = useTheme();
|
|
148
149
|
var classes = useUtilityClasses(_extends({}, props, {
|
|
149
150
|
theme: theme
|
|
150
151
|
}));
|
|
151
152
|
var drawingArea = React.useContext(DrawingContext);
|
|
152
153
|
var series = React.useContext(SeriesContext);
|
|
154
|
+
if (hidden) {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
153
157
|
var seriesToDisplay = getSeriesToDisplay(series);
|
|
154
158
|
return /*#__PURE__*/_jsx(ChartsLegendRoot, {
|
|
155
159
|
ownerState: {
|