@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,9 +1,15 @@
|
|
|
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
|
+
var legendGetter = {
|
|
6
|
+
bar: getBarLegend,
|
|
7
|
+
scatter: getScatterLegend,
|
|
8
|
+
line: getLineLegend,
|
|
9
|
+
pie: getPieLegend
|
|
10
|
+
};
|
|
1
11
|
export function getSeriesToDisplay(series) {
|
|
2
|
-
return Object.
|
|
3
|
-
return
|
|
4
|
-
return s.series[seriesId];
|
|
5
|
-
});
|
|
6
|
-
}).filter(function (s) {
|
|
7
|
-
return s.label !== undefined;
|
|
12
|
+
return Object.keys(series).flatMap(function (seriesType) {
|
|
13
|
+
return legendGetter[seriesType](series[seriesType]);
|
|
8
14
|
});
|
|
9
15
|
}
|
|
@@ -80,7 +80,9 @@ export function ChartsAxisTooltipContent(props) {
|
|
|
80
80
|
var USED_X_AXIS_ID = xAxisIds[0];
|
|
81
81
|
var relevantSeries = React.useMemo(function () {
|
|
82
82
|
var rep = [];
|
|
83
|
-
Object.keys(series).
|
|
83
|
+
Object.keys(series).filter(function (seriesType) {
|
|
84
|
+
return ['bar', 'line', 'scatter'].includes(seriesType);
|
|
85
|
+
}).forEach(function (seriesType) {
|
|
84
86
|
series[seriesType].seriesOrder.forEach(function (seriesId) {
|
|
85
87
|
var axisKey = series[seriesType].series[seriesId].xAxisKey;
|
|
86
88
|
if (axisKey === undefined || axisKey === USED_X_AXIS_ID) {
|
|
@@ -4,7 +4,6 @@ import { ChartsTooltipTable, ChartsTooltipCell, ChartsTooltipMark, ChartsTooltip
|
|
|
4
4
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
5
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
6
6
|
export function DefaultChartsItemContent(props) {
|
|
7
|
-
var _series$label;
|
|
8
7
|
var series = props.series,
|
|
9
8
|
itemData = props.itemData,
|
|
10
9
|
sx = props.sx,
|
|
@@ -12,8 +11,16 @@ export function DefaultChartsItemContent(props) {
|
|
|
12
11
|
if (itemData.dataIndex === undefined) {
|
|
13
12
|
return null;
|
|
14
13
|
}
|
|
15
|
-
var
|
|
16
|
-
|
|
14
|
+
var _ref = series.type === 'pie' ? {
|
|
15
|
+
color: series.data[itemData.dataIndex].color,
|
|
16
|
+
displayedLabel: series.data[itemData.dataIndex].label
|
|
17
|
+
} : {
|
|
18
|
+
color: series.color,
|
|
19
|
+
displayedLabel: series.label
|
|
20
|
+
},
|
|
21
|
+
displayedLabel = _ref.displayedLabel,
|
|
22
|
+
color = _ref.color;
|
|
23
|
+
|
|
17
24
|
// TODO: Manage to let TS understand series.data and series.valueFormatter are coherent
|
|
18
25
|
// @ts-ignore
|
|
19
26
|
var formattedValue = series.valueFormatter(series.data[itemData.dataIndex]);
|
|
@@ -25,10 +25,10 @@ export var ChartsTooltipRow = styled('tr', {
|
|
|
25
25
|
})(function (_ref2) {
|
|
26
26
|
var theme = _ref2.theme;
|
|
27
27
|
return {
|
|
28
|
-
'
|
|
28
|
+
'tr:first-of-type& td': {
|
|
29
29
|
paddingTop: theme.spacing(1)
|
|
30
30
|
},
|
|
31
|
-
'
|
|
31
|
+
'tr:last-of-type& td': {
|
|
32
32
|
paddingBottom: theme.spacing(1)
|
|
33
33
|
}
|
|
34
34
|
};
|
|
@@ -41,18 +41,16 @@ export var ChartsTooltipCell = styled('td', {
|
|
|
41
41
|
var theme = _ref3.theme;
|
|
42
42
|
return _ref4 = {
|
|
43
43
|
verticalAlign: 'middle',
|
|
44
|
-
color: theme.palette.text.secondary
|
|
45
|
-
'&:first-child': {
|
|
46
|
-
paddingLeft: theme.spacing(2)
|
|
47
|
-
},
|
|
48
|
-
'&:last-child': {
|
|
49
|
-
paddingRight: theme.spacing(2)
|
|
50
|
-
}
|
|
44
|
+
color: theme.palette.text.secondary
|
|
51
45
|
}, _defineProperty(_ref4, "&.".concat(tooltipClasses.labelCell), {
|
|
52
46
|
paddingLeft: theme.spacing(1)
|
|
53
47
|
}), _defineProperty(_ref4, "&.".concat(tooltipClasses.valueCell), {
|
|
54
48
|
paddingLeft: theme.spacing(4),
|
|
55
49
|
color: theme.palette.text.primary
|
|
50
|
+
}), _defineProperty(_ref4, 'td:first-of-type&', {
|
|
51
|
+
paddingLeft: theme.spacing(2)
|
|
52
|
+
}), _defineProperty(_ref4, 'td:last-of-type&', {
|
|
53
|
+
paddingRight: theme.spacing(2)
|
|
56
54
|
}), _ref4;
|
|
57
55
|
});
|
|
58
56
|
export var ChartsTooltipMark = styled(Box, {
|
|
@@ -49,9 +49,11 @@ function LineChart(props) {
|
|
|
49
49
|
xAxis: xAxis != null ? xAxis : [{
|
|
50
50
|
id: DEFAULT_X_AXIS_KEY,
|
|
51
51
|
scaleType: 'point',
|
|
52
|
-
data:
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
data: Array.from({
|
|
53
|
+
length: Math.max.apply(Math, _toConsumableArray(series.map(function (s) {
|
|
54
|
+
return s.data.length;
|
|
55
|
+
})))
|
|
56
|
+
}, function (_, index) {
|
|
55
57
|
return index;
|
|
56
58
|
})
|
|
57
59
|
}],
|
|
@@ -82,7 +84,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
82
84
|
y: PropTypes.oneOf(['line', 'none'])
|
|
83
85
|
}),
|
|
84
86
|
/**
|
|
85
|
-
* Indicate which axis to display the
|
|
87
|
+
* Indicate which axis to display the bottom of the charts.
|
|
86
88
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`
|
|
87
89
|
* @default xAxisIds[0] The id of the first provided axis
|
|
88
90
|
*/
|
|
@@ -109,7 +111,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
109
111
|
disableAxisListener: PropTypes.bool,
|
|
110
112
|
height: PropTypes.number,
|
|
111
113
|
/**
|
|
112
|
-
* Indicate which axis to display the
|
|
114
|
+
* Indicate which axis to display the left of the charts.
|
|
113
115
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`
|
|
114
116
|
* @default yAxisIds[0] The id of the first provided axis
|
|
115
117
|
*/
|
|
@@ -129,6 +131,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
129
131
|
legend: PropTypes.shape({
|
|
130
132
|
classes: PropTypes.object,
|
|
131
133
|
direction: PropTypes.oneOf(['column', 'row']),
|
|
134
|
+
hidden: PropTypes.bool,
|
|
132
135
|
itemWidth: PropTypes.number,
|
|
133
136
|
markSize: PropTypes.number,
|
|
134
137
|
offset: PropTypes.shape({
|
|
@@ -148,7 +151,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
148
151
|
top: PropTypes.number
|
|
149
152
|
}),
|
|
150
153
|
/**
|
|
151
|
-
* Indicate which axis to display the
|
|
154
|
+
* Indicate which axis to display the right of the charts.
|
|
152
155
|
* Can be a string (the id of the axis) or an object `ChartsYAxisProps`
|
|
153
156
|
* @default null
|
|
154
157
|
*/
|
|
@@ -193,7 +196,7 @@ process.env.NODE_ENV !== "production" ? LineChart.propTypes = {
|
|
|
193
196
|
trigger: PropTypes.oneOf(['axis', 'item', 'none'])
|
|
194
197
|
}),
|
|
195
198
|
/**
|
|
196
|
-
* Indicate which axis to display the
|
|
199
|
+
* Indicate which axis to display the top of the charts.
|
|
197
200
|
* Can be a string (the id of the axis) or an object `ChartsXAxisProps`
|
|
198
201
|
* @default null
|
|
199
202
|
*/
|
|
@@ -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;
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "innerRadius", "outerRadius", "cornerRadius", "highlighted", "faded"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { arc as d3Arc } from 'd3-shape';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
8
|
+
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
9
|
+
import { styled } from '@mui/material/styles';
|
|
10
|
+
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
11
|
+
import { InteractionContext } from '../context/InteractionProvider';
|
|
12
|
+
import { getIsFaded, getIsHighlighted, useInteractionItemProps } from '../hooks/useInteractionItemProps';
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
export function getPieArcUtilityClass(slot) {
|
|
15
|
+
return generateUtilityClass('MuiPieArc', slot);
|
|
16
|
+
}
|
|
17
|
+
export var pieArcClasses = generateUtilityClasses('MuiPieArc', ['root', 'highlighted', 'faded']);
|
|
18
|
+
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
19
|
+
var classes = ownerState.classes,
|
|
20
|
+
id = ownerState.id,
|
|
21
|
+
isFaded = ownerState.isFaded,
|
|
22
|
+
isHighlighted = ownerState.isHighlighted;
|
|
23
|
+
var slots = {
|
|
24
|
+
root: ['root', "series-".concat(id), isHighlighted && 'highlighted', isFaded && 'faded']
|
|
25
|
+
};
|
|
26
|
+
return composeClasses(slots, getPieArcUtilityClass, classes);
|
|
27
|
+
};
|
|
28
|
+
var PieArcRoot = styled('path', {
|
|
29
|
+
name: 'MuiPieArc',
|
|
30
|
+
slot: 'Root',
|
|
31
|
+
overridesResolver: function overridesResolver(_, styles) {
|
|
32
|
+
return styles.arc;
|
|
33
|
+
}
|
|
34
|
+
})(function (_ref) {
|
|
35
|
+
var ownerState = _ref.ownerState,
|
|
36
|
+
theme = _ref.theme;
|
|
37
|
+
return {
|
|
38
|
+
stroke: theme.palette.background.paper,
|
|
39
|
+
strokeWidth: 1,
|
|
40
|
+
strokeLinejoin: 'round',
|
|
41
|
+
fill: ownerState.color,
|
|
42
|
+
opacity: ownerState.isFaded ? 0.3 : 1
|
|
43
|
+
};
|
|
44
|
+
});
|
|
45
|
+
export default function PieArc(props) {
|
|
46
|
+
var _attibuesOverride$inn, _attibuesOverride$out, _attibuesOverride$cor;
|
|
47
|
+
var id = props.id,
|
|
48
|
+
dataIndex = props.dataIndex,
|
|
49
|
+
innerClasses = props.classes,
|
|
50
|
+
color = props.color,
|
|
51
|
+
highlightScope = props.highlightScope,
|
|
52
|
+
_props$innerRadius = props.innerRadius,
|
|
53
|
+
baseInnerRadius = _props$innerRadius === void 0 ? 0 : _props$innerRadius,
|
|
54
|
+
baseOuterRadius = props.outerRadius,
|
|
55
|
+
_props$cornerRadius = props.cornerRadius,
|
|
56
|
+
baseCornerRadius = _props$cornerRadius === void 0 ? 0 : _props$cornerRadius,
|
|
57
|
+
highlighted = props.highlighted,
|
|
58
|
+
_props$faded = props.faded,
|
|
59
|
+
faded = _props$faded === void 0 ? {
|
|
60
|
+
additionalRadius: -5
|
|
61
|
+
} : _props$faded,
|
|
62
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
63
|
+
var getInteractionItemProps = useInteractionItemProps(highlightScope);
|
|
64
|
+
var _React$useContext = React.useContext(InteractionContext),
|
|
65
|
+
item = _React$useContext.item;
|
|
66
|
+
var isHighlighted = getIsHighlighted(item, {
|
|
67
|
+
type: 'pie',
|
|
68
|
+
seriesId: id,
|
|
69
|
+
dataIndex: dataIndex
|
|
70
|
+
}, highlightScope);
|
|
71
|
+
var isFaded = !isHighlighted && getIsFaded(item, {
|
|
72
|
+
type: 'pie',
|
|
73
|
+
seriesId: id,
|
|
74
|
+
dataIndex: dataIndex
|
|
75
|
+
}, highlightScope);
|
|
76
|
+
var ownerState = {
|
|
77
|
+
id: id,
|
|
78
|
+
dataIndex: dataIndex,
|
|
79
|
+
classes: innerClasses,
|
|
80
|
+
color: color,
|
|
81
|
+
isFaded: isFaded,
|
|
82
|
+
isHighlighted: isHighlighted
|
|
83
|
+
};
|
|
84
|
+
var classes = useUtilityClasses(ownerState);
|
|
85
|
+
var attibuesOverride = _extends({
|
|
86
|
+
additionalRadius: 0
|
|
87
|
+
}, isFaded && faded || isHighlighted && highlighted || {});
|
|
88
|
+
var innerRadius = Math.max(0, (_attibuesOverride$inn = attibuesOverride.innerRadius) != null ? _attibuesOverride$inn : baseInnerRadius);
|
|
89
|
+
var outerRadius = Math.max(0, (_attibuesOverride$out = attibuesOverride.outerRadius) != null ? _attibuesOverride$out : baseOuterRadius + attibuesOverride.additionalRadius);
|
|
90
|
+
var cornerRadius = (_attibuesOverride$cor = attibuesOverride.cornerRadius) != null ? _attibuesOverride$cor : baseCornerRadius;
|
|
91
|
+
return /*#__PURE__*/_jsx(PieArcRoot, _extends({
|
|
92
|
+
d: d3Arc().cornerRadius(cornerRadius)(_extends({}, other, {
|
|
93
|
+
innerRadius: innerRadius,
|
|
94
|
+
outerRadius: outerRadius
|
|
95
|
+
})),
|
|
96
|
+
ownerState: ownerState,
|
|
97
|
+
className: classes.root
|
|
98
|
+
}, getInteractionItemProps({
|
|
99
|
+
type: 'pie',
|
|
100
|
+
seriesId: id,
|
|
101
|
+
dataIndex: dataIndex
|
|
102
|
+
})));
|
|
103
|
+
}
|
|
104
|
+
process.env.NODE_ENV !== "production" ? PieArc.propTypes = {
|
|
105
|
+
// ----------------------------- Warning --------------------------------
|
|
106
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
107
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
108
|
+
// ----------------------------------------------------------------------
|
|
109
|
+
classes: PropTypes.object,
|
|
110
|
+
cornerRadius: PropTypes.number,
|
|
111
|
+
dataIndex: PropTypes.number.isRequired,
|
|
112
|
+
highlightScope: PropTypes.shape({
|
|
113
|
+
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
114
|
+
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
115
|
+
}),
|
|
116
|
+
innerRadius: PropTypes.number,
|
|
117
|
+
outerRadius: PropTypes.number.isRequired
|
|
118
|
+
} : void 0;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["id", "dataIndex", "classes", "color", "highlightScope", "innerRadius", "outerRadius", "cornerRadius", "formattedArcLabel"];
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { arc as d3Arc } from 'd3-shape';
|
|
6
|
+
import PropTypes from 'prop-types';
|
|
7
|
+
import composeClasses from '@mui/utils/composeClasses';
|
|
8
|
+
import generateUtilityClass from '@mui/utils/generateUtilityClass';
|
|
9
|
+
import { styled } from '@mui/material/styles';
|
|
10
|
+
import generateUtilityClasses from '@mui/utils/generateUtilityClasses';
|
|
11
|
+
import { InteractionContext } from '../context/InteractionProvider';
|
|
12
|
+
import { getIsFaded, getIsHighlighted } from '../hooks/useInteractionItemProps';
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
export function getPieArcLabelUtilityClass(slot) {
|
|
15
|
+
return generateUtilityClass('MuiPieArcLabel', slot);
|
|
16
|
+
}
|
|
17
|
+
export var pieArcLabelClasses = generateUtilityClasses('MuiPieArcLabel', ['root', 'highlighted', 'faded']);
|
|
18
|
+
var useUtilityClasses = function useUtilityClasses(ownerState) {
|
|
19
|
+
var classes = ownerState.classes,
|
|
20
|
+
id = ownerState.id,
|
|
21
|
+
isFaded = ownerState.isFaded,
|
|
22
|
+
isHighlighted = ownerState.isHighlighted;
|
|
23
|
+
var slots = {
|
|
24
|
+
root: ['root', "series-".concat(id), isHighlighted && 'highlighted', isFaded && 'faded']
|
|
25
|
+
};
|
|
26
|
+
return composeClasses(slots, getPieArcLabelUtilityClass, classes);
|
|
27
|
+
};
|
|
28
|
+
var PieArcLabelRoot = styled('text', {
|
|
29
|
+
name: 'MuiPieArcLabel',
|
|
30
|
+
slot: 'Root',
|
|
31
|
+
overridesResolver: function overridesResolver(_, styles) {
|
|
32
|
+
return styles.root;
|
|
33
|
+
}
|
|
34
|
+
})(function (_ref) {
|
|
35
|
+
var theme = _ref.theme;
|
|
36
|
+
return {
|
|
37
|
+
fill: theme.palette.text.primary,
|
|
38
|
+
alignmentBaseline: 'baseline',
|
|
39
|
+
textAnchor: 'middle'
|
|
40
|
+
};
|
|
41
|
+
});
|
|
42
|
+
export default function PieArcLabel(props) {
|
|
43
|
+
var id = props.id,
|
|
44
|
+
dataIndex = props.dataIndex,
|
|
45
|
+
innerClasses = props.classes,
|
|
46
|
+
color = props.color,
|
|
47
|
+
highlightScope = props.highlightScope,
|
|
48
|
+
_props$innerRadius = props.innerRadius,
|
|
49
|
+
innerRadius = _props$innerRadius === void 0 ? 0 : _props$innerRadius,
|
|
50
|
+
outerRadius = props.outerRadius,
|
|
51
|
+
_props$cornerRadius = props.cornerRadius,
|
|
52
|
+
cornerRadius = _props$cornerRadius === void 0 ? 0 : _props$cornerRadius,
|
|
53
|
+
formattedArcLabel = props.formattedArcLabel,
|
|
54
|
+
other = _objectWithoutProperties(props, _excluded);
|
|
55
|
+
var _React$useContext = React.useContext(InteractionContext),
|
|
56
|
+
item = _React$useContext.item;
|
|
57
|
+
var isHighlighted = getIsHighlighted(item, {
|
|
58
|
+
type: 'pie',
|
|
59
|
+
seriesId: id,
|
|
60
|
+
dataIndex: dataIndex
|
|
61
|
+
}, highlightScope);
|
|
62
|
+
var isFaded = !isHighlighted && getIsFaded(item, {
|
|
63
|
+
type: 'pie',
|
|
64
|
+
seriesId: id,
|
|
65
|
+
dataIndex: dataIndex
|
|
66
|
+
}, highlightScope);
|
|
67
|
+
var ownerState = {
|
|
68
|
+
id: id,
|
|
69
|
+
dataIndex: dataIndex,
|
|
70
|
+
classes: innerClasses,
|
|
71
|
+
color: color,
|
|
72
|
+
isFaded: isFaded,
|
|
73
|
+
isHighlighted: isHighlighted
|
|
74
|
+
};
|
|
75
|
+
var classes = useUtilityClasses(ownerState);
|
|
76
|
+
var arcLabelPosition = formattedArcLabel ? d3Arc().cornerRadius(cornerRadius).centroid(_extends({}, other, {
|
|
77
|
+
innerRadius: innerRadius,
|
|
78
|
+
outerRadius: outerRadius
|
|
79
|
+
})) : [0, 0];
|
|
80
|
+
return /*#__PURE__*/_jsx(PieArcLabelRoot, {
|
|
81
|
+
className: classes.root,
|
|
82
|
+
x: arcLabelPosition[0],
|
|
83
|
+
y: arcLabelPosition[1],
|
|
84
|
+
children: formattedArcLabel
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
process.env.NODE_ENV !== "production" ? PieArcLabel.propTypes = {
|
|
88
|
+
// ----------------------------- Warning --------------------------------
|
|
89
|
+
// | These PropTypes are generated from the TypeScript type definitions |
|
|
90
|
+
// | To update them edit the TypeScript types and run "yarn proptypes" |
|
|
91
|
+
// ----------------------------------------------------------------------
|
|
92
|
+
classes: PropTypes.object,
|
|
93
|
+
cornerRadius: PropTypes.number,
|
|
94
|
+
dataIndex: PropTypes.number.isRequired,
|
|
95
|
+
highlightScope: PropTypes.shape({
|
|
96
|
+
faded: PropTypes.oneOf(['global', 'none', 'series']),
|
|
97
|
+
highlighted: PropTypes.oneOf(['item', 'none', 'series'])
|
|
98
|
+
}),
|
|
99
|
+
innerRadius: PropTypes.number,
|
|
100
|
+
outerRadius: PropTypes.number.isRequired
|
|
101
|
+
} : void 0;
|