@mui/x-charts 7.0.0-beta.6 → 7.0.0
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/CHANGELOG.md +311 -12
- package/ChartsLegend/ChartsLegend.d.ts +3 -0
- package/ChartsLegend/ChartsLegend.js +3 -0
- package/ChartsLegend/DefaultChartsLegend.js +3 -0
- package/ChartsTooltip/ChartsTooltip.d.ts +12 -0
- package/README.md +1 -1
- package/context/CartesianContextProvider.js +2 -2
- package/esm/BarChart/BarChart.js +6 -9
- package/esm/BarChart/BarElement.js +2 -3
- package/esm/BarChart/BarPlot.js +5 -8
- package/esm/BarChart/extremums.js +2 -3
- package/esm/BarChart/formatter.js +2 -6
- package/esm/ChartsAxis/ChartsAxis.js +3 -4
- package/esm/ChartsLegend/ChartsLegend.js +5 -3
- package/esm/ChartsLegend/DefaultChartsLegend.js +3 -0
- package/esm/ChartsOnAxisClickHandler/ChartsOnAxisClickHandler.js +2 -4
- package/esm/ChartsReferenceLine/ChartsXReferenceLine.js +2 -3
- package/esm/ChartsReferenceLine/ChartsYReferenceLine.js +2 -3
- package/esm/ChartsText/ChartsText.js +1 -1
- package/esm/ChartsTooltip/ChartsAxisTooltipContent.js +1 -1
- package/esm/ChartsTooltip/ChartsItemTooltipContent.js +1 -1
- package/esm/ChartsTooltip/ChartsTooltip.js +6 -7
- package/esm/ChartsTooltip/DefaultChartsAxisTooltipContent.js +2 -4
- package/esm/ChartsTooltip/DefaultChartsItemTooltipContent.js +1 -2
- package/esm/ChartsVoronoiHandler/ChartsVoronoiHandler.js +4 -6
- package/esm/ChartsXAxis/ChartsXAxis.js +13 -14
- package/esm/ChartsYAxis/ChartsYAxis.js +9 -10
- package/esm/Gauge/GaugeContainer.js +18 -21
- package/esm/Gauge/GaugeProvider.js +3 -3
- package/esm/LineChart/AreaElement.js +2 -3
- package/esm/LineChart/AreaPlot.js +2 -3
- package/esm/LineChart/LineChart.js +3 -6
- package/esm/LineChart/LineElement.js +2 -3
- package/esm/LineChart/LineHighlightPlot.js +3 -4
- package/esm/LineChart/LinePlot.js +2 -3
- package/esm/LineChart/MarkElement.js +1 -2
- package/esm/LineChart/MarkPlot.js +3 -4
- package/esm/LineChart/extremums.js +2 -3
- package/esm/LineChart/formatter.js +2 -6
- package/esm/PieChart/PieArcLabelPlot.js +3 -5
- package/esm/PieChart/PieArcPlot.js +2 -3
- package/esm/PieChart/PieChart.js +2 -2
- package/esm/PieChart/PiePlot.js +9 -9
- package/esm/PieChart/dataTransform/useTransformData.js +5 -6
- package/esm/PieChart/formatter.js +6 -13
- package/esm/ResponsiveChartContainer/ResponsiveChartContainer.js +15 -18
- package/esm/ResponsiveChartContainer/useChartContainerDimensions.js +2 -2
- package/esm/ScatterChart/ScatterPlot.js +5 -6
- package/esm/SparkLineChart/SparkLineChart.js +1 -1
- package/esm/context/CartesianContextProvider.js +18 -24
- package/esm/context/DrawingProvider.js +1 -1
- package/esm/context/SeriesContextProvider.js +2 -4
- package/esm/hooks/useAxisEvents.js +10 -2
- package/esm/hooks/useInteractionItemProps.js +2 -2
- package/esm/hooks/useScale.js +2 -2
- package/esm/hooks/useTicks.js +23 -32
- package/esm/internals/defaultizeValueFormatter.js +1 -2
- package/esm/internals/stackSeries.js +2 -3
- package/hooks/useAxisEvents.js +9 -1
- package/index.js +1 -1
- package/models/axis.d.ts +16 -0
- package/modern/ChartsLegend/ChartsLegend.js +3 -0
- package/modern/ChartsLegend/DefaultChartsLegend.js +3 -0
- package/modern/context/CartesianContextProvider.js +2 -2
- package/modern/hooks/useAxisEvents.js +9 -1
- package/modern/index.js +1 -1
- package/package.json +5 -5
|
@@ -22,7 +22,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
22
22
|
* - [MarkPlot API](https://mui.com/x/api/charts/mark-plot/)
|
|
23
23
|
*/
|
|
24
24
|
function MarkPlot(props) {
|
|
25
|
-
var _slots$mark;
|
|
26
25
|
const {
|
|
27
26
|
slots,
|
|
28
27
|
slotProps,
|
|
@@ -35,7 +34,7 @@ function MarkPlot(props) {
|
|
|
35
34
|
const {
|
|
36
35
|
chartId
|
|
37
36
|
} = React.useContext(DrawingContext);
|
|
38
|
-
const Mark =
|
|
37
|
+
const Mark = slots?.mark ?? MarkElement;
|
|
39
38
|
if (seriesData === undefined) {
|
|
40
39
|
return null;
|
|
41
40
|
}
|
|
@@ -90,7 +89,7 @@ function MarkPlot(props) {
|
|
|
90
89
|
|
|
91
90
|
return /*#__PURE__*/_jsx("g", {
|
|
92
91
|
clipPath: `url(#${clipId})`,
|
|
93
|
-
children: xData
|
|
92
|
+
children: xData?.map((x, index) => {
|
|
94
93
|
const value = data[index] == null ? null : stackedData[index][1];
|
|
95
94
|
return {
|
|
96
95
|
x: xScale(x),
|
|
@@ -147,7 +146,7 @@ function MarkPlot(props) {
|
|
|
147
146
|
seriesId,
|
|
148
147
|
dataIndex: index
|
|
149
148
|
}))
|
|
150
|
-
}, slotProps
|
|
149
|
+
}, slotProps?.mark), `${seriesId}-${index}`);
|
|
151
150
|
})
|
|
152
151
|
}, seriesId);
|
|
153
152
|
});
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
export const getExtremumX = params => {
|
|
2
|
-
var _axis$data, _axis$data2;
|
|
3
2
|
const {
|
|
4
3
|
axis
|
|
5
4
|
} = params;
|
|
6
|
-
const minX = Math.min(...(
|
|
7
|
-
const maxX = Math.max(...(
|
|
5
|
+
const minX = Math.min(...(axis.data ?? []));
|
|
6
|
+
const maxX = Math.max(...(axis.data ?? []));
|
|
8
7
|
return [minX, maxX];
|
|
9
8
|
};
|
|
10
9
|
function getSeriesExtremums(getValues, stackedData) {
|
|
@@ -6,7 +6,6 @@ let warnedOnce = false;
|
|
|
6
6
|
|
|
7
7
|
// For now it's a copy past of bar charts formatter, but maybe will diverge later
|
|
8
8
|
const formatter = (params, dataset) => {
|
|
9
|
-
var _ref;
|
|
10
9
|
const {
|
|
11
10
|
seriesOrder,
|
|
12
11
|
series
|
|
@@ -18,7 +17,7 @@ const formatter = (params, dataset) => {
|
|
|
18
17
|
}));
|
|
19
18
|
|
|
20
19
|
// Create a data set with format adapted to d3
|
|
21
|
-
const d3Dataset =
|
|
20
|
+
const d3Dataset = dataset ?? [];
|
|
22
21
|
seriesOrder.forEach(id => {
|
|
23
22
|
const data = series[id].data;
|
|
24
23
|
if (data !== undefined) {
|
|
@@ -47,10 +46,7 @@ const formatter = (params, dataset) => {
|
|
|
47
46
|
// Use dataKey if needed and available
|
|
48
47
|
const dataKey = series[id].dataKey;
|
|
49
48
|
return series[id].data === undefined && dataKey !== undefined ? dataKey : id;
|
|
50
|
-
})).value((d, key) =>
|
|
51
|
-
var _d$key;
|
|
52
|
-
return (_d$key = d[key]) != null ? _d$key : 0;
|
|
53
|
-
}) // defaultize null value to 0
|
|
49
|
+
})).value((d, key) => d[key] ?? 0) // defaultize null value to 0
|
|
54
50
|
.order(stackingOrder).offset(stackingOffset)(d3Dataset);
|
|
55
51
|
ids.forEach((id, index) => {
|
|
56
52
|
const dataKey = series[id].dataKey;
|
|
@@ -19,13 +19,11 @@ function getItemLabel(arcLabel, arcLabelMinAngle, item) {
|
|
|
19
19
|
return null;
|
|
20
20
|
}
|
|
21
21
|
if (typeof arcLabel === 'string') {
|
|
22
|
-
|
|
23
|
-
return (_item$arcLabel = item[arcLabel]) == null ? void 0 : _item$arcLabel.toString();
|
|
22
|
+
return item[arcLabel]?.toString();
|
|
24
23
|
}
|
|
25
24
|
return arcLabel(item);
|
|
26
25
|
}
|
|
27
26
|
function PieArcLabelPlot(props) {
|
|
28
|
-
var _slots$pieArcLabel;
|
|
29
27
|
const {
|
|
30
28
|
arcLabel,
|
|
31
29
|
arcLabelMinAngle = 0,
|
|
@@ -64,7 +62,7 @@ function PieArcLabelPlot(props) {
|
|
|
64
62
|
if (data.length === 0) {
|
|
65
63
|
return null;
|
|
66
64
|
}
|
|
67
|
-
const ArcLabel =
|
|
65
|
+
const ArcLabel = slots?.pieArcLabel ?? PieArcLabel;
|
|
68
66
|
return /*#__PURE__*/_jsx("g", _extends({}, other, {
|
|
69
67
|
children: transition((_ref, item) => {
|
|
70
68
|
let {
|
|
@@ -91,7 +89,7 @@ function PieArcLabelPlot(props) {
|
|
|
91
89
|
isFaded: item.isFaded,
|
|
92
90
|
isHighlighted: item.isHighlighted,
|
|
93
91
|
formattedArcLabel: getItemLabel(arcLabel, arcLabelMinAngle, item)
|
|
94
|
-
}, slotProps
|
|
92
|
+
}, slotProps?.pieArcLabel));
|
|
95
93
|
})
|
|
96
94
|
}));
|
|
97
95
|
}
|
|
@@ -10,7 +10,6 @@ import { defaultTransitionConfig } from './dataTransform/transition';
|
|
|
10
10
|
import { useTransformData } from './dataTransform/useTransformData';
|
|
11
11
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
12
|
function PieArcPlot(props) {
|
|
13
|
-
var _slots$pieArc;
|
|
14
13
|
const {
|
|
15
14
|
slots,
|
|
16
15
|
slotProps,
|
|
@@ -46,7 +45,7 @@ function PieArcPlot(props) {
|
|
|
46
45
|
if (data.length === 0) {
|
|
47
46
|
return null;
|
|
48
47
|
}
|
|
49
|
-
const Arc =
|
|
48
|
+
const Arc = slots?.pieArc ?? PieArc;
|
|
50
49
|
return /*#__PURE__*/_jsx("g", _extends({}, other, {
|
|
51
50
|
children: transition((_ref, item, _, index) => {
|
|
52
51
|
let {
|
|
@@ -79,7 +78,7 @@ function PieArcPlot(props) {
|
|
|
79
78
|
dataIndex: index
|
|
80
79
|
}, item);
|
|
81
80
|
})
|
|
82
|
-
}, slotProps
|
|
81
|
+
}, slotProps?.pieArc));
|
|
83
82
|
})
|
|
84
83
|
}));
|
|
85
84
|
}
|
package/esm/PieChart/PieChart.js
CHANGED
|
@@ -78,7 +78,7 @@ function PieChart(props) {
|
|
|
78
78
|
width: width,
|
|
79
79
|
height: height,
|
|
80
80
|
margin: margin,
|
|
81
|
-
xAxis: xAxis
|
|
81
|
+
xAxis: xAxis ?? [{
|
|
82
82
|
id: DEFAULT_X_AXIS_KEY,
|
|
83
83
|
scaleType: 'point',
|
|
84
84
|
data: [...new Array(Math.max(...series.map(s => s.data.length)))].map((_, index) => index)
|
|
@@ -86,7 +86,7 @@ function PieChart(props) {
|
|
|
86
86
|
yAxis: yAxis,
|
|
87
87
|
colors: colors,
|
|
88
88
|
sx: sx,
|
|
89
|
-
disableAxisListener:
|
|
89
|
+
disableAxisListener: tooltip?.trigger !== 'axis' && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
90
90
|
children: [/*#__PURE__*/_jsx(ChartsAxis, {
|
|
91
91
|
topAxis: topAxis,
|
|
92
92
|
leftAxis: leftAxis,
|
package/esm/PieChart/PiePlot.js
CHANGED
|
@@ -53,10 +53,10 @@ function PiePlot(props) {
|
|
|
53
53
|
faded,
|
|
54
54
|
highlightScope
|
|
55
55
|
} = series[seriesId];
|
|
56
|
-
const outerRadius = getPercentageValue(outerRadiusParam
|
|
57
|
-
const innerRadius = getPercentageValue(innerRadiusParam
|
|
58
|
-
const cx = getPercentageValue(cxParam
|
|
59
|
-
const cy = getPercentageValue(cyParam
|
|
56
|
+
const outerRadius = getPercentageValue(outerRadiusParam ?? availableRadius, availableRadius);
|
|
57
|
+
const innerRadius = getPercentageValue(innerRadiusParam ?? 0, availableRadius);
|
|
58
|
+
const cx = getPercentageValue(cxParam ?? '50%', width);
|
|
59
|
+
const cy = getPercentageValue(cyParam ?? '50%', height);
|
|
60
60
|
return /*#__PURE__*/_jsx("g", {
|
|
61
61
|
transform: `translate(${left + cx}, ${top + cy})`,
|
|
62
62
|
children: /*#__PURE__*/_jsx(PieArcPlot, {
|
|
@@ -89,16 +89,16 @@ function PiePlot(props) {
|
|
|
89
89
|
cy: cyParam,
|
|
90
90
|
highlightScope
|
|
91
91
|
} = series[seriesId];
|
|
92
|
-
const outerRadius = getPercentageValue(outerRadiusParam
|
|
93
|
-
const innerRadius = getPercentageValue(innerRadiusParam
|
|
92
|
+
const outerRadius = getPercentageValue(outerRadiusParam ?? availableRadius, availableRadius);
|
|
93
|
+
const innerRadius = getPercentageValue(innerRadiusParam ?? 0, availableRadius);
|
|
94
94
|
const arcLabelRadius = arcLabelRadiusParam === undefined ? (outerRadius + innerRadius) / 2 : getPercentageValue(arcLabelRadiusParam, availableRadius);
|
|
95
|
-
const cx = getPercentageValue(cxParam
|
|
96
|
-
const cy = getPercentageValue(cyParam
|
|
95
|
+
const cx = getPercentageValue(cxParam ?? '50%', width);
|
|
96
|
+
const cy = getPercentageValue(cyParam ?? '50%', height);
|
|
97
97
|
return /*#__PURE__*/_jsx("g", {
|
|
98
98
|
transform: `translate(${left + cx}, ${top + cy})`,
|
|
99
99
|
children: /*#__PURE__*/_jsx(PieArcLabelPlot, {
|
|
100
100
|
innerRadius: innerRadius,
|
|
101
|
-
outerRadius: outerRadius
|
|
101
|
+
outerRadius: outerRadius ?? availableRadius,
|
|
102
102
|
arcLabelRadius: arcLabelRadius,
|
|
103
103
|
cornerRadius: cornerRadius,
|
|
104
104
|
paddingAngle: paddingAngle,
|
|
@@ -35,7 +35,6 @@ export function useTransformData(series) {
|
|
|
35
35
|
};
|
|
36
36
|
}, [highlightScope, highlightedItem, seriesId]);
|
|
37
37
|
const dataWithHighlight = React.useMemo(() => data.map((item, itemIndex) => {
|
|
38
|
-
var _attributesOverride$p, _attributesOverride$i, _attributesOverride$o, _attributesOverride$c, _ref, _attributesOverride$a;
|
|
39
38
|
const {
|
|
40
39
|
isHighlighted,
|
|
41
40
|
isFaded
|
|
@@ -43,11 +42,11 @@ export function useTransformData(series) {
|
|
|
43
42
|
const attributesOverride = _extends({
|
|
44
43
|
additionalRadius: 0
|
|
45
44
|
}, isFaded && faded || isHighlighted && highlighted || {});
|
|
46
|
-
const paddingAngle = Math.max(0, Math.PI * (
|
|
47
|
-
const innerRadius = Math.max(0,
|
|
48
|
-
const outerRadius = Math.max(0,
|
|
49
|
-
const cornerRadius =
|
|
50
|
-
const arcLabelRadius =
|
|
45
|
+
const paddingAngle = Math.max(0, Math.PI * (attributesOverride.paddingAngle ?? basePaddingAngle) / 180);
|
|
46
|
+
const innerRadius = Math.max(0, attributesOverride.innerRadius ?? baseInnerRadius);
|
|
47
|
+
const outerRadius = Math.max(0, attributesOverride.outerRadius ?? baseOuterRadius + attributesOverride.additionalRadius);
|
|
48
|
+
const cornerRadius = attributesOverride.cornerRadius ?? baseCornerRadius;
|
|
49
|
+
const arcLabelRadius = attributesOverride.arcLabelRadius ?? baseArcLabelRadius ?? (innerRadius + outerRadius) / 2;
|
|
51
50
|
return _extends({}, item, attributesOverride, {
|
|
52
51
|
isFaded,
|
|
53
52
|
isHighlighted,
|
|
@@ -22,22 +22,15 @@ const formatter = params => {
|
|
|
22
22
|
} = params;
|
|
23
23
|
const defaultizedSeries = {};
|
|
24
24
|
seriesOrder.forEach(seriesId => {
|
|
25
|
-
|
|
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));
|
|
25
|
+
const arcs = d3Pie().startAngle(2 * Math.PI * (series[seriesId].startAngle ?? 0) / 360).endAngle(2 * Math.PI * (series[seriesId].endAngle ?? 360) / 360).padAngle(2 * Math.PI * (series[seriesId].paddingAngle ?? 0) / 360).sortValues(getSortingComparator(series[seriesId].sortingValues ?? 'none'))(series[seriesId].data.map(piePoint => piePoint.value));
|
|
27
26
|
defaultizedSeries[seriesId] = _extends({
|
|
28
27
|
valueFormatter: item => item.value.toLocaleString()
|
|
29
28
|
}, series[seriesId], {
|
|
30
|
-
data: series[seriesId].data.map((item, index) => {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
})
|
|
29
|
+
data: series[seriesId].data.map((item, index) => _extends({}, item, {
|
|
30
|
+
id: item.id ?? `auto-generated-pie-id-${seriesId}-${index}`
|
|
31
|
+
}, arcs[index])).map(item => _extends({}, item, {
|
|
32
|
+
formattedValue: series[seriesId].valueFormatter?.(item) ?? item.value.toLocaleString()
|
|
33
|
+
}))
|
|
41
34
|
});
|
|
42
35
|
});
|
|
43
36
|
return {
|
|
@@ -12,24 +12,21 @@ const ResizableContainer = styled('div', {
|
|
|
12
12
|
slot: 'Container'
|
|
13
13
|
})(({
|
|
14
14
|
ownerState
|
|
15
|
-
}) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
'
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
});
|
|
15
|
+
}) => ({
|
|
16
|
+
width: ownerState.width ?? '100%',
|
|
17
|
+
height: ownerState.height ?? '100%',
|
|
18
|
+
display: 'flex',
|
|
19
|
+
position: 'relative',
|
|
20
|
+
flexGrow: 1,
|
|
21
|
+
flexDirection: 'column',
|
|
22
|
+
alignItems: 'center',
|
|
23
|
+
justifyContent: 'center',
|
|
24
|
+
overflow: 'hidden',
|
|
25
|
+
'&>svg': {
|
|
26
|
+
width: '100%',
|
|
27
|
+
height: '100%'
|
|
28
|
+
}
|
|
29
|
+
}));
|
|
33
30
|
const ResponsiveChartContainer = /*#__PURE__*/React.forwardRef(function ResponsiveChartContainer(props, ref) {
|
|
34
31
|
const {
|
|
35
32
|
width: inWidth,
|
|
@@ -9,7 +9,7 @@ export const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
|
9
9
|
|
|
10
10
|
// Adaptation of the `computeSizeAndPublishResizeEvent` from the grid.
|
|
11
11
|
const computeSize = React.useCallback(() => {
|
|
12
|
-
const mainEl = rootRef
|
|
12
|
+
const mainEl = rootRef?.current;
|
|
13
13
|
if (!mainEl) {
|
|
14
14
|
return;
|
|
15
15
|
}
|
|
@@ -62,5 +62,5 @@ export const useChartContainerDimensions = (inWidth, inHeight) => {
|
|
|
62
62
|
displayError.current = false;
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
|
-
return [rootRef, inWidth
|
|
65
|
+
return [rootRef, inWidth ?? width, inHeight ?? height];
|
|
66
66
|
};
|
|
@@ -16,7 +16,6 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
16
16
|
* - [ScatterPlot API](https://mui.com/x/api/charts/scatter-plot/)
|
|
17
17
|
*/
|
|
18
18
|
function ScatterPlot(props) {
|
|
19
|
-
var _slots$scatter;
|
|
20
19
|
const {
|
|
21
20
|
slots,
|
|
22
21
|
slotProps,
|
|
@@ -39,7 +38,7 @@ function ScatterPlot(props) {
|
|
|
39
38
|
} = axisData;
|
|
40
39
|
const defaultXAxisId = xAxisIds[0];
|
|
41
40
|
const defaultYAxisId = yAxisIds[0];
|
|
42
|
-
const ScatterItems =
|
|
41
|
+
const ScatterItems = slots?.scatter ?? Scatter;
|
|
43
42
|
return /*#__PURE__*/_jsx(React.Fragment, {
|
|
44
43
|
children: seriesOrder.map(seriesId => {
|
|
45
44
|
const {
|
|
@@ -49,16 +48,16 @@ function ScatterPlot(props) {
|
|
|
49
48
|
markerSize,
|
|
50
49
|
color
|
|
51
50
|
} = series[seriesId];
|
|
52
|
-
const xScale = xAxis[xAxisKey
|
|
53
|
-
const yScale = yAxis[yAxisKey
|
|
51
|
+
const xScale = xAxis[xAxisKey ?? defaultXAxisId].scale;
|
|
52
|
+
const yScale = yAxis[yAxisKey ?? defaultYAxisId].scale;
|
|
54
53
|
return /*#__PURE__*/_jsx(ScatterItems, _extends({
|
|
55
54
|
xScale: xScale,
|
|
56
55
|
yScale: yScale,
|
|
57
56
|
color: color,
|
|
58
|
-
markerSize: markerSize
|
|
57
|
+
markerSize: markerSize ?? 4,
|
|
59
58
|
series: series[seriesId],
|
|
60
59
|
onItemClick: onItemClick
|
|
61
|
-
}, slotProps
|
|
60
|
+
}, slotProps?.scatter), id);
|
|
62
61
|
})
|
|
63
62
|
});
|
|
64
63
|
}
|
|
@@ -76,7 +76,7 @@ const SparkLineChart = /*#__PURE__*/React.forwardRef(function SparkLineChart(pro
|
|
|
76
76
|
}, xAxis)],
|
|
77
77
|
colors: colors,
|
|
78
78
|
sx: sx,
|
|
79
|
-
disableAxisListener: (!showTooltip ||
|
|
79
|
+
disableAxisListener: (!showTooltip || tooltip?.trigger !== 'axis') && axisHighlight?.x === 'none' && axisHighlight?.y === 'none',
|
|
80
80
|
children: [plotType === 'bar' && /*#__PURE__*/_jsx(BarPlot, {
|
|
81
81
|
skipAnimation: true,
|
|
82
82
|
slots: slots,
|
|
@@ -43,7 +43,7 @@ function CartesianContextProvider(props) {
|
|
|
43
43
|
} = props;
|
|
44
44
|
const formattedSeries = React.useContext(SeriesContext);
|
|
45
45
|
const drawingArea = React.useContext(DrawingContext);
|
|
46
|
-
const xAxis = React.useMemo(() => inXAxis
|
|
46
|
+
const xAxis = React.useMemo(() => inXAxis?.map(axisConfig => {
|
|
47
47
|
const dataKey = axisConfig.dataKey;
|
|
48
48
|
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
49
49
|
return axisConfig;
|
|
@@ -55,7 +55,7 @@ function CartesianContextProvider(props) {
|
|
|
55
55
|
data: dataset.map(d => d[dataKey])
|
|
56
56
|
});
|
|
57
57
|
}), [inXAxis, dataset]);
|
|
58
|
-
const yAxis = React.useMemo(() => inYAxis
|
|
58
|
+
const yAxis = React.useMemo(() => inYAxis?.map(axisConfig => {
|
|
59
59
|
const dataKey = axisConfig.dataKey;
|
|
60
60
|
if (dataKey === undefined || axisConfig.data !== undefined) {
|
|
61
61
|
return axisConfig;
|
|
@@ -68,11 +68,9 @@ function CartesianContextProvider(props) {
|
|
|
68
68
|
});
|
|
69
69
|
}), [inYAxis, dataset]);
|
|
70
70
|
const value = React.useMemo(() => {
|
|
71
|
-
var _xAxis$map, _yAxis$map;
|
|
72
71
|
const axisExtremumCallback = (acc, chartType, axis, getters, isDefaultAxis) => {
|
|
73
|
-
var _ref, _formattedSeries$char;
|
|
74
72
|
const getter = getters[chartType];
|
|
75
|
-
const series =
|
|
73
|
+
const series = formattedSeries[chartType]?.series ?? {};
|
|
76
74
|
const [minChartTypeData, maxChartTypeData] = getter({
|
|
77
75
|
series,
|
|
78
76
|
axis,
|
|
@@ -91,9 +89,9 @@ function CartesianContextProvider(props) {
|
|
|
91
89
|
const charTypes = Object.keys(getters);
|
|
92
90
|
return charTypes.reduce((acc, charType) => axisExtremumCallback(acc, charType, axis, getters, isDefaultAxis), [null, null]);
|
|
93
91
|
};
|
|
94
|
-
const allXAxis = [...(
|
|
95
|
-
id: `
|
|
96
|
-
}, axis))
|
|
92
|
+
const allXAxis = [...(xAxis?.map((axis, index) => _extends({
|
|
93
|
+
id: `defaultized-x-axis-${index}`
|
|
94
|
+
}, axis)) ?? []),
|
|
97
95
|
// Allows to specify an axis with id=DEFAULT_X_AXIS_KEY
|
|
98
96
|
...(xAxis === undefined || xAxis.findIndex(({
|
|
99
97
|
id
|
|
@@ -103,14 +101,12 @@ function CartesianContextProvider(props) {
|
|
|
103
101
|
}] : [])];
|
|
104
102
|
const completedXAxis = {};
|
|
105
103
|
allXAxis.forEach((axis, axisIndex) => {
|
|
106
|
-
var _axis$scaleType, _axis$min, _axis$max, _axis$min2, _axis$max2;
|
|
107
104
|
const isDefaultAxis = axisIndex === 0;
|
|
108
105
|
const [minData, maxData] = getAxisExtremum(axis, xExtremumGetters, isDefaultAxis);
|
|
109
106
|
const range = axis.reverse ? [drawingArea.left + drawingArea.width, drawingArea.left] : [drawingArea.left, drawingArea.left + drawingArea.width];
|
|
110
107
|
if (isBandScaleConfig(axis)) {
|
|
111
|
-
|
|
112
|
-
const
|
|
113
|
-
const barGapRatio = (_axis$barGapRatio = axis.barGapRatio) != null ? _axis$barGapRatio : DEFAULT_BAR_GAP_RATIO;
|
|
108
|
+
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
109
|
+
const barGapRatio = axis.barGapRatio ?? DEFAULT_BAR_GAP_RATIO;
|
|
114
110
|
completedXAxis[axis.id] = _extends({
|
|
115
111
|
categoryGapRatio,
|
|
116
112
|
barGapRatio
|
|
@@ -129,24 +125,24 @@ function CartesianContextProvider(props) {
|
|
|
129
125
|
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
130
126
|
return;
|
|
131
127
|
}
|
|
132
|
-
const scaleType =
|
|
133
|
-
const extremums = [
|
|
128
|
+
const scaleType = axis.scaleType ?? 'linear';
|
|
129
|
+
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
134
130
|
const tickNumber = getTickNumber(_extends({}, axis, {
|
|
135
131
|
range,
|
|
136
132
|
domain: extremums
|
|
137
133
|
}));
|
|
138
134
|
const niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
139
135
|
const niceDomain = niceScale.domain();
|
|
140
|
-
const domain = [
|
|
136
|
+
const domain = [axis.min ?? niceDomain[0], axis.max ?? niceDomain[1]];
|
|
141
137
|
completedXAxis[axis.id] = _extends({}, axis, {
|
|
142
138
|
scaleType,
|
|
143
139
|
scale: niceScale.domain(domain),
|
|
144
140
|
tickNumber
|
|
145
141
|
});
|
|
146
142
|
});
|
|
147
|
-
const allYAxis = [...(
|
|
148
|
-
id: `
|
|
149
|
-
}, axis))
|
|
143
|
+
const allYAxis = [...(yAxis?.map((axis, index) => _extends({
|
|
144
|
+
id: `defaultized-y-axis-${index}`
|
|
145
|
+
}, axis)) ?? []), ...(yAxis === undefined || yAxis.findIndex(({
|
|
150
146
|
id
|
|
151
147
|
}) => id === DEFAULT_Y_AXIS_KEY) === -1 ? [{
|
|
152
148
|
id: DEFAULT_Y_AXIS_KEY,
|
|
@@ -154,13 +150,11 @@ function CartesianContextProvider(props) {
|
|
|
154
150
|
}] : [])];
|
|
155
151
|
const completedYAxis = {};
|
|
156
152
|
allYAxis.forEach((axis, axisIndex) => {
|
|
157
|
-
var _axis$scaleType2, _axis$min3, _axis$max3, _axis$min4, _axis$max4;
|
|
158
153
|
const isDefaultAxis = axisIndex === 0;
|
|
159
154
|
const [minData, maxData] = getAxisExtremum(axis, yExtremumGetters, isDefaultAxis);
|
|
160
155
|
const range = axis.reverse ? [drawingArea.top, drawingArea.top + drawingArea.height] : [drawingArea.top + drawingArea.height, drawingArea.top];
|
|
161
156
|
if (isBandScaleConfig(axis)) {
|
|
162
|
-
|
|
163
|
-
const categoryGapRatio = (_axis$categoryGapRati2 = axis.categoryGapRatio) != null ? _axis$categoryGapRati2 : DEFAULT_CATEGORY_GAP_RATIO;
|
|
157
|
+
const categoryGapRatio = axis.categoryGapRatio ?? DEFAULT_CATEGORY_GAP_RATIO;
|
|
164
158
|
completedYAxis[axis.id] = _extends({
|
|
165
159
|
categoryGapRatio,
|
|
166
160
|
barGapRatio: 0
|
|
@@ -179,15 +173,15 @@ function CartesianContextProvider(props) {
|
|
|
179
173
|
// Could be merged with the two previous "if conditions" but then TS does not get that `axis.scaleType` can't be `band` or `point`.
|
|
180
174
|
return;
|
|
181
175
|
}
|
|
182
|
-
const scaleType =
|
|
183
|
-
const extremums = [
|
|
176
|
+
const scaleType = axis.scaleType ?? 'linear';
|
|
177
|
+
const extremums = [axis.min ?? minData, axis.max ?? maxData];
|
|
184
178
|
const tickNumber = getTickNumber(_extends({}, axis, {
|
|
185
179
|
range,
|
|
186
180
|
domain: extremums
|
|
187
181
|
}));
|
|
188
182
|
const niceScale = getScale(scaleType, extremums, range).nice(tickNumber);
|
|
189
183
|
const niceDomain = niceScale.domain();
|
|
190
|
-
const domain = [
|
|
184
|
+
const domain = [axis.min ?? niceDomain[0], axis.max ?? niceDomain[1]];
|
|
191
185
|
completedYAxis[axis.id] = _extends({}, axis, {
|
|
192
186
|
scaleType,
|
|
193
187
|
scale: niceScale.domain(domain),
|
|
@@ -36,7 +36,7 @@ export function DrawingProvider(props) {
|
|
|
36
36
|
const drawingArea = useChartDimensions(width, height, margin);
|
|
37
37
|
const chartId = useId();
|
|
38
38
|
const value = React.useMemo(() => _extends({
|
|
39
|
-
chartId: chartId
|
|
39
|
+
chartId: chartId ?? ''
|
|
40
40
|
}, drawingArea), [chartId, drawingArea]);
|
|
41
41
|
return /*#__PURE__*/_jsx(SvgContext.Provider, {
|
|
42
42
|
value: svgRef,
|
|
@@ -31,7 +31,6 @@ const formatSeries = (series, colors, dataset) => {
|
|
|
31
31
|
// Group series by type
|
|
32
32
|
const seriesGroups = {};
|
|
33
33
|
series.forEach((seriesData, seriesIndex) => {
|
|
34
|
-
var _seriesGroups$type;
|
|
35
34
|
const {
|
|
36
35
|
id = `auto-generated-id-${seriesIndex}`,
|
|
37
36
|
type
|
|
@@ -42,7 +41,7 @@ const formatSeries = (series, colors, dataset) => {
|
|
|
42
41
|
seriesOrder: []
|
|
43
42
|
};
|
|
44
43
|
}
|
|
45
|
-
if (
|
|
44
|
+
if (seriesGroups[type]?.series[id] !== undefined) {
|
|
46
45
|
throw new Error(`MUI X Charts: series' id "${id}" is not unique.`);
|
|
47
46
|
}
|
|
48
47
|
seriesGroups[type].series[id] = _extends({
|
|
@@ -54,8 +53,7 @@ const formatSeries = (series, colors, dataset) => {
|
|
|
54
53
|
// Apply formater on a type group
|
|
55
54
|
Object.keys(seriesTypeFormatter).forEach(type => {
|
|
56
55
|
if (seriesGroups[type] !== undefined) {
|
|
57
|
-
|
|
58
|
-
formattedSeries[type] = (_seriesTypeFormatter$ = (_seriesTypeFormatter$2 = seriesTypeFormatter[type]) == null ? void 0 : _seriesTypeFormatter$2.call(seriesTypeFormatter, seriesGroups[type], dataset)) != null ? _seriesTypeFormatter$ : seriesGroups[type];
|
|
56
|
+
formattedSeries[type] = seriesTypeFormatter[type]?.(seriesGroups[type], dataset) ?? seriesGroups[type];
|
|
59
57
|
}
|
|
60
58
|
});
|
|
61
59
|
return formattedSeries;
|
|
@@ -43,7 +43,8 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
43
43
|
}
|
|
44
44
|
const {
|
|
45
45
|
scale,
|
|
46
|
-
data: axisData
|
|
46
|
+
data: axisData,
|
|
47
|
+
reverse
|
|
47
48
|
} = axisConfig;
|
|
48
49
|
if (!isBandScale(scale)) {
|
|
49
50
|
const value = scale.invert(mouseValue);
|
|
@@ -53,7 +54,7 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
53
54
|
};
|
|
54
55
|
}
|
|
55
56
|
const valueAsNumber = getAsANumber(value);
|
|
56
|
-
const closestIndex = axisData
|
|
57
|
+
const closestIndex = axisData?.findIndex((pointValue, index) => {
|
|
57
58
|
const v = getAsANumber(pointValue);
|
|
58
59
|
if (v > valueAsNumber) {
|
|
59
60
|
if (index === 0 || Math.abs(valueAsNumber - v) <= Math.abs(valueAsNumber - getAsANumber(axisData[index - 1]))) {
|
|
@@ -76,6 +77,13 @@ export const useAxisEvents = disableAxisListener => {
|
|
|
76
77
|
if (dataIndex < 0 || dataIndex >= axisData.length) {
|
|
77
78
|
return null;
|
|
78
79
|
}
|
|
80
|
+
if (reverse) {
|
|
81
|
+
const reverseIndex = axisData.length - 1 - dataIndex;
|
|
82
|
+
return {
|
|
83
|
+
index: reverseIndex,
|
|
84
|
+
value: axisData[reverseIndex]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
79
87
|
return {
|
|
80
88
|
index: dataIndex,
|
|
81
89
|
value: axisData[dataIndex]
|
|
@@ -41,7 +41,7 @@ export const useInteractionItemProps = (scope, skip) => {
|
|
|
41
41
|
return getInteractionItemProps;
|
|
42
42
|
};
|
|
43
43
|
export const getIsHighlighted = (selectedItem, currentItem, highlightScope) => {
|
|
44
|
-
if (!
|
|
44
|
+
if (!highlightScope?.highlighted || highlightScope.highlighted === 'none' || selectedItem === null) {
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
47
|
const isSeriesSelected = selectedItem.type === currentItem.type && selectedItem.seriesId === currentItem.seriesId;
|
|
@@ -54,7 +54,7 @@ export const getIsHighlighted = (selectedItem, currentItem, highlightScope) => {
|
|
|
54
54
|
return selectedItem.dataIndex !== undefined && selectedItem.dataIndex === currentItem.dataIndex;
|
|
55
55
|
};
|
|
56
56
|
export const getIsFaded = (selectedItem, currentItem, highlightScope) => {
|
|
57
|
-
if (!
|
|
57
|
+
if (!highlightScope?.faded || highlightScope.faded === 'none' || selectedItem === null) {
|
|
58
58
|
return false;
|
|
59
59
|
}
|
|
60
60
|
const isSeriesSelected = selectedItem.type === currentItem.type && selectedItem.seriesId === currentItem.seriesId;
|
package/esm/hooks/useScale.js
CHANGED
|
@@ -18,7 +18,7 @@ export function useXScale(identifier) {
|
|
|
18
18
|
xAxis,
|
|
19
19
|
xAxisIds
|
|
20
20
|
} = React.useContext(CartesianContext);
|
|
21
|
-
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier
|
|
21
|
+
const id = typeof identifier === 'string' ? identifier : xAxisIds[identifier ?? 0];
|
|
22
22
|
return xAxis[id].scale;
|
|
23
23
|
}
|
|
24
24
|
export function useYScale(identifier) {
|
|
@@ -26,6 +26,6 @@ export function useYScale(identifier) {
|
|
|
26
26
|
yAxis,
|
|
27
27
|
yAxisIds
|
|
28
28
|
} = React.useContext(CartesianContext);
|
|
29
|
-
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier
|
|
29
|
+
const id = typeof identifier === 'string' ? identifier : yAxisIds[identifier ?? 0];
|
|
30
30
|
return yAxis[id].scale;
|
|
31
31
|
}
|