@mui/x-charts 8.17.0 → 8.19.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/BarChart/BarLabel/BarLabel.d.ts +7 -1
- package/BarChart/BarLabel/BarLabel.js +41 -4
- package/BarChart/BarLabel/BarLabelItem.d.ts +6 -0
- package/BarChart/BarLabel/BarLabelItem.js +4 -2
- package/BarChart/BarLabel/BarLabelPlot.js +2 -3
- package/BarChart/BarPlot.js +5 -0
- package/BarChart/seriesConfig/bar/seriesProcessor.js +15 -9
- package/BarChart/types.d.ts +1 -0
- package/BarChart/useBarPlotData.js +3 -2
- package/CHANGELOG.md +213 -0
- package/ChartsSurface/ChartsSurface.js +5 -2
- package/LineChart/seriesConfig/seriesProcessor.js +15 -10
- package/PieChart/PieArcPlot.js +5 -3
- package/esm/BarChart/BarLabel/BarLabel.d.ts +7 -1
- package/esm/BarChart/BarLabel/BarLabel.js +41 -4
- package/esm/BarChart/BarLabel/BarLabelItem.d.ts +6 -0
- package/esm/BarChart/BarLabel/BarLabelItem.js +4 -2
- package/esm/BarChart/BarLabel/BarLabelPlot.js +2 -2
- package/esm/BarChart/BarPlot.js +5 -0
- package/esm/BarChart/seriesConfig/bar/seriesProcessor.js +15 -9
- package/esm/BarChart/types.d.ts +1 -0
- package/esm/BarChart/useBarPlotData.js +3 -2
- package/esm/ChartsSurface/ChartsSurface.js +5 -2
- package/esm/LineChart/seriesConfig/seriesProcessor.js +15 -10
- package/esm/PieChart/PieArcPlot.js +5 -3
- package/esm/hooks/animation/useAnimateBarLabel.d.ts +1 -1
- package/esm/hooks/animation/useAnimateBarLabel.js +61 -12
- package/esm/hooks/useAxis.d.ts +116 -16
- package/esm/hooks/useAxis.js +122 -18
- package/esm/hooks/useBarSeries.js +3 -5
- package/esm/hooks/useLineSeries.js +3 -5
- package/esm/hooks/usePieSeries.js +3 -5
- package/esm/hooks/useRadarSeries.js +3 -5
- package/esm/hooks/useScale.d.ts +25 -6
- package/esm/hooks/useScale.js +29 -8
- package/esm/hooks/useScatterSeries.js +3 -5
- package/esm/index.d.ts +2 -1
- package/esm/index.js +2 -1
- package/esm/internals/domUtils.js +30 -14
- package/esm/internals/getScale.d.ts +2 -1
- package/esm/internals/index.d.ts +1 -1
- package/esm/internals/index.js +1 -1
- package/esm/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.js +2 -2
- package/esm/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.js +5 -6
- package/esm/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.js +2 -2
- package/esm/internals/plugins/corePlugins/useChartId/useChartId.selectors.js +2 -2
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +4 -1
- package/esm/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +3 -1
- package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +1 -1
- package/esm/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.js +4 -4
- package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.d.ts +1 -1
- package/esm/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.js +15 -15
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +1 -1
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +5 -5
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +3 -0
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +11 -11
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +5 -6
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +7 -8
- package/esm/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +2 -2
- package/esm/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.selectors.js +2 -2
- package/esm/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +11 -12
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.js +8 -8
- package/esm/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.js +4 -4
- package/esm/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +11 -11
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.js +6 -6
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js +7 -8
- package/esm/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.js +2 -2
- package/esm/internals/plugins/utils/selectors.d.ts +1 -14
- package/esm/internals/plugins/utils/selectors.js +1 -5
- package/esm/internals/seriesSelectorOfType.d.ts +20 -0
- package/esm/internals/seriesSelectorOfType.js +38 -0
- package/esm/models/seriesType/bar.d.ts +7 -0
- package/esm/models/seriesType/config.d.ts +2 -2
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.js +5 -0
- package/esm/utils/niceDomain.d.ts +20 -0
- package/esm/utils/niceDomain.js +24 -0
- package/hooks/animation/useAnimateBarLabel.d.ts +1 -1
- package/hooks/animation/useAnimateBarLabel.js +61 -12
- package/hooks/useAxis.d.ts +116 -16
- package/hooks/useAxis.js +122 -18
- package/hooks/useBarSeries.js +3 -6
- package/hooks/useLineSeries.js +3 -6
- package/hooks/usePieSeries.js +3 -6
- package/hooks/useRadarSeries.js +3 -6
- package/hooks/useScale.d.ts +25 -6
- package/hooks/useScale.js +29 -8
- package/hooks/useScatterSeries.js +3 -6
- package/index.d.ts +2 -1
- package/index.js +13 -1
- package/internals/domUtils.js +30 -14
- package/internals/getScale.d.ts +2 -1
- package/internals/index.d.ts +1 -1
- package/internals/index.js +4 -4
- package/internals/plugins/corePlugins/useChartAnimation/useChartAnimation.selectors.js +2 -2
- package/internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.js +4 -5
- package/internals/plugins/corePlugins/useChartExperimentalFeature/useChartExperimentalFeature.selectors.js +2 -2
- package/internals/plugins/corePlugins/useChartId/useChartId.selectors.js +2 -2
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.js +4 -1
- package/internals/plugins/corePlugins/useChartInteractionListener/useChartInteractionListener.types.d.ts +3 -1
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.d.ts +1 -1
- package/internals/plugins/corePlugins/useChartSeries/useChartSeries.selectors.js +4 -4
- package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartBrush/useChartBrush.selectors.js +15 -15
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxis.types.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisPreview.selectors.js +5 -5
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.d.ts +3 -0
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js +11 -11
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianHighlight.selectors.js +4 -5
- package/internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianInteraction.selectors.js +6 -7
- package/internals/plugins/featurePlugins/useChartClosestPoint/findClosestPoints.js +2 -2
- package/internals/plugins/featurePlugins/useChartClosestPoint/useChartClosestPoint.selectors.js +2 -2
- package/internals/plugins/featurePlugins/useChartHighlight/useChartHighlight.selectors.js +10 -11
- package/internals/plugins/featurePlugins/useChartInteraction/useChartInteraction.selectors.js +8 -8
- package/internals/plugins/featurePlugins/useChartInteraction/useChartTooltip.selectors.js +4 -4
- package/internals/plugins/featurePlugins/useChartKeyboardNavigation/useChartKeyboardNavigation.selectors.js +11 -11
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarAxis.selectors.js +6 -6
- package/internals/plugins/featurePlugins/useChartPolarAxis/useChartPolarInteraction.selectors.js +6 -7
- package/internals/plugins/featurePlugins/useChartZAxis/useChartZAxis.selectors.js +2 -2
- package/internals/plugins/utils/selectors.d.ts +1 -14
- package/internals/plugins/utils/selectors.js +1 -8
- package/internals/seriesSelectorOfType.d.ts +20 -0
- package/internals/seriesSelectorOfType.js +46 -0
- package/models/seriesType/bar.d.ts +7 -0
- package/models/seriesType/config.d.ts +2 -2
- package/package.json +5 -5
- package/utils/index.d.ts +4 -0
- package/utils/index.js +16 -0
- package/utils/niceDomain.d.ts +20 -0
- package/utils/niceDomain.js +29 -0
- package/esm/internals/createSeriesSelectorOfType.d.ts +0 -4
- package/esm/internals/createSeriesSelectorOfType.js +0 -45
- package/internals/createSeriesSelectorOfType.d.ts +0 -4
- package/internals/createSeriesSelectorOfType.js +0 -53
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
|
-
const _excluded = ["seriesId", "classes", "color", "dataIndex", "barLabel", "slots", "slotProps", "xOrigin", "yOrigin", "x", "y", "width", "height", "value", "skipAnimation", "layout"],
|
|
3
|
+
const _excluded = ["seriesId", "classes", "color", "dataIndex", "barLabel", "slots", "slotProps", "xOrigin", "yOrigin", "x", "y", "width", "height", "value", "skipAnimation", "layout", "barLabelPlacement"],
|
|
4
4
|
_excluded2 = ["ownerState"];
|
|
5
5
|
import * as React from 'react';
|
|
6
6
|
import useSlotProps from '@mui/utils/useSlotProps';
|
|
@@ -30,7 +30,8 @@ function BarLabelItem(props) {
|
|
|
30
30
|
height,
|
|
31
31
|
value,
|
|
32
32
|
skipAnimation,
|
|
33
|
-
layout
|
|
33
|
+
layout,
|
|
34
|
+
barLabelPlacement
|
|
34
35
|
} = props,
|
|
35
36
|
other = _objectWithoutPropertiesLoose(props, _excluded);
|
|
36
37
|
const {
|
|
@@ -62,6 +63,7 @@ function BarLabelItem(props) {
|
|
|
62
63
|
y,
|
|
63
64
|
width,
|
|
64
65
|
height,
|
|
66
|
+
placement: barLabelPlacement,
|
|
65
67
|
className: classes.root
|
|
66
68
|
}),
|
|
67
69
|
ownerState
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
3
3
|
const _excluded = ["processedSeries", "skipAnimation"];
|
|
4
|
-
import * as React from 'react';
|
|
5
4
|
import { BarLabelItem } from "./BarLabelItem.js";
|
|
6
5
|
import { useUtilityClasses } from "../barClasses.js";
|
|
7
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
@@ -51,7 +50,8 @@ function BarLabelPlot(props) {
|
|
|
51
50
|
skipAnimation: skipAnimation ?? false,
|
|
52
51
|
layout: layout ?? 'vertical'
|
|
53
52
|
}, other, {
|
|
54
|
-
barLabel: barLabel
|
|
53
|
+
barLabel: barLabel,
|
|
54
|
+
barLabelPlacement: processedSeries.barLabelPlacement || 'center'
|
|
55
55
|
}), dataIndex))
|
|
56
56
|
}, seriesId);
|
|
57
57
|
}
|
package/esm/BarChart/BarPlot.js
CHANGED
|
@@ -155,6 +155,11 @@ process.env.NODE_ENV !== "production" ? BarPlot.propTypes = {
|
|
|
155
155
|
* @returns {string} The formatted label.
|
|
156
156
|
*/
|
|
157
157
|
barLabel: PropTypes.oneOfType([PropTypes.oneOf(['value']), PropTypes.func]),
|
|
158
|
+
/**
|
|
159
|
+
* The placement of the bar label.
|
|
160
|
+
* It controls whether the label is rendered inside or outside the bar.
|
|
161
|
+
*/
|
|
162
|
+
barLabelPlacement: PropTypes.oneOf(['outside', 'inside']),
|
|
158
163
|
/**
|
|
159
164
|
* Defines the border radius of the bar element.
|
|
160
165
|
*/
|
|
@@ -27,6 +27,20 @@ const seriesProcessor = (params, dataset) => {
|
|
|
27
27
|
} else if (dataset === undefined) {
|
|
28
28
|
throw new Error([`MUI X Charts: bar series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
29
29
|
}
|
|
30
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
31
|
+
if (!data && dataset) {
|
|
32
|
+
const dataKey = series[id].dataKey;
|
|
33
|
+
if (!dataKey) {
|
|
34
|
+
throw new Error([`MUI X Charts: bar series with id='${id}' has no data and no dataKey.`, 'You must provide a dataKey when using the dataset prop.'].join('\n'));
|
|
35
|
+
}
|
|
36
|
+
dataset.forEach((entry, index) => {
|
|
37
|
+
const value = entry[dataKey];
|
|
38
|
+
if (value != null && typeof value !== 'number') {
|
|
39
|
+
warnOnce([`MUI X Charts: your dataset key "${dataKey}" is used for plotting bars, but the dataset contains the non-null non-numerical element "${value}" at index ${index}.`, 'Bar plots only support numeric and null values.'].join('\n'));
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
}
|
|
30
44
|
});
|
|
31
45
|
const completedSeries = {};
|
|
32
46
|
stackingGroups.forEach(stackingGroup => {
|
|
@@ -52,15 +66,7 @@ const seriesProcessor = (params, dataset) => {
|
|
|
52
66
|
}, series[id], {
|
|
53
67
|
data: dataKey ? dataset.map(data => {
|
|
54
68
|
const value = data[dataKey];
|
|
55
|
-
|
|
56
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
57
|
-
if (value !== null) {
|
|
58
|
-
warnOnce([`MUI X Charts: your dataset key "${dataKey}" is used for plotting bars, but contains nonnumerical elements.`, 'Bar plots only support numbers and null values.']);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
return value;
|
|
69
|
+
return typeof value === 'number' ? value : null;
|
|
64
70
|
}) : series[id].data,
|
|
65
71
|
stackedData: stackedSeries[index].map(([a, b]) => [a, b])
|
|
66
72
|
});
|
package/esm/BarChart/types.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export interface ProcessedBarSeriesData {
|
|
|
13
13
|
seriesId: SeriesId;
|
|
14
14
|
data: ProcessedBarData[];
|
|
15
15
|
barLabel?: BarSeriesType['barLabel'];
|
|
16
|
+
barLabelPlacement?: BarSeriesType['barLabelPlacement'];
|
|
16
17
|
}
|
|
17
18
|
export interface ProcessedBarData extends AnimationData {
|
|
18
19
|
seriesId: SeriesId;
|
|
@@ -55,8 +55,8 @@ export function useBarPlotData(drawingArea, xAxes, yAxes) {
|
|
|
55
55
|
seriesId,
|
|
56
56
|
dataIndex,
|
|
57
57
|
layout: series[seriesId].layout,
|
|
58
|
-
xOrigin: xScale(0) ?? 0,
|
|
59
|
-
yOrigin: yScale(0) ?? 0
|
|
58
|
+
xOrigin: Math.round(xScale(0) ?? 0),
|
|
59
|
+
yOrigin: Math.round(yScale(0) ?? 0)
|
|
60
60
|
}, barDimensions, {
|
|
61
61
|
color: colorGetter(dataIndex),
|
|
62
62
|
value: series[seriesId].data[dataIndex],
|
|
@@ -92,6 +92,7 @@ export function useBarPlotData(drawingArea, xAxes, yAxes) {
|
|
|
92
92
|
return {
|
|
93
93
|
seriesId,
|
|
94
94
|
barLabel: series[seriesId].barLabel,
|
|
95
|
+
barLabelPlacement: series[seriesId].barLabelPlacement,
|
|
95
96
|
data: seriesDataPoints
|
|
96
97
|
};
|
|
97
98
|
});
|
|
@@ -15,6 +15,7 @@ import { useStore } from "../internals/store/useStore.js";
|
|
|
15
15
|
import { selectorChartPropsHeight, selectorChartPropsWidth, selectorChartSvgWidth, selectorChartSvgHeight } from "../internals/plugins/corePlugins/useChartDimensions/useChartDimensions.selectors.js";
|
|
16
16
|
import { selectorChartsHasFocusedItem, selectorChartsIsKeyboardNavigationEnabled } from "../internals/plugins/featurePlugins/useChartKeyboardNavigation/index.js";
|
|
17
17
|
import { useUtilityClasses } from "./chartsSurfaceClasses.js";
|
|
18
|
+
import { selectorChartHasZoom } from "../internals/plugins/featurePlugins/useChartCartesianAxis/useChartCartesianAxisRendering.selectors.js";
|
|
18
19
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
19
20
|
const ChartsSurfaceStyles = styled('svg', {
|
|
20
21
|
name: 'MuiChartsSurface',
|
|
@@ -33,7 +34,7 @@ const ChartsSurfaceStyles = styled('svg', {
|
|
|
33
34
|
overflow: 'hidden',
|
|
34
35
|
// This prevents default touch actions when using the svg on mobile devices.
|
|
35
36
|
// For example, prevent page scroll & zoom.
|
|
36
|
-
touchAction: 'pan-y',
|
|
37
|
+
touchAction: ownerState.hasZoom ? 'pan-y' : undefined,
|
|
37
38
|
userSelect: 'none',
|
|
38
39
|
gridArea: 'chart',
|
|
39
40
|
'&:focus': {
|
|
@@ -74,6 +75,7 @@ const ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurface(inPro
|
|
|
74
75
|
const propsHeight = useSelector(store, selectorChartPropsHeight);
|
|
75
76
|
const isKeyboardNavigationEnabled = useSelector(store, selectorChartsIsKeyboardNavigationEnabled);
|
|
76
77
|
const hasFocusedItem = useSelector(store, selectorChartsHasFocusedItem);
|
|
78
|
+
const hasZoom = useSelector(store, selectorChartHasZoom);
|
|
77
79
|
const svgRef = useSvgRef();
|
|
78
80
|
const handleRef = useForkRef(svgRef, ref);
|
|
79
81
|
const themeProps = useThemeProps({
|
|
@@ -92,7 +94,8 @@ const ChartsSurface = /*#__PURE__*/React.forwardRef(function ChartsSurface(inPro
|
|
|
92
94
|
return /*#__PURE__*/_jsxs(ChartsSurfaceStyles, _extends({
|
|
93
95
|
ownerState: {
|
|
94
96
|
width: propsWidth,
|
|
95
|
-
height: propsHeight
|
|
97
|
+
height: propsHeight,
|
|
98
|
+
hasZoom
|
|
96
99
|
},
|
|
97
100
|
viewBox: `${0} ${0} ${svgWidth} ${svgHeight}`,
|
|
98
101
|
className: clsx(classes.root, className),
|
|
@@ -3,7 +3,6 @@ import { stack as d3Stack } from '@mui/x-charts-vendor/d3-shape';
|
|
|
3
3
|
import { warnOnce } from '@mui/x-internals/warning';
|
|
4
4
|
import { getStackingGroups } from "../../internals/stackSeries.js";
|
|
5
5
|
import { defaultizeValueFormatter } from "../../internals/defaultizeValueFormatter.js";
|
|
6
|
-
// For now it's a copy past of bar charts formatter, but maybe will diverge later
|
|
7
6
|
const seriesProcessor = (params, dataset) => {
|
|
8
7
|
const {
|
|
9
8
|
seriesOrder,
|
|
@@ -32,6 +31,20 @@ const seriesProcessor = (params, dataset) => {
|
|
|
32
31
|
} else if (dataset === undefined && process.env.NODE_ENV !== 'production') {
|
|
33
32
|
throw new Error([`MUI X Charts: line series with id='${id}' has no data.`, 'Either provide a data property to the series or use the dataset prop.'].join('\n'));
|
|
34
33
|
}
|
|
34
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
35
|
+
if (!data && dataset) {
|
|
36
|
+
const dataKey = series[id].dataKey;
|
|
37
|
+
if (!dataKey) {
|
|
38
|
+
throw new Error([`MUI X Charts: line series with id='${id}' has no data and no dataKey.`, 'You must provide a dataKey when using the dataset prop.'].join('\n'));
|
|
39
|
+
}
|
|
40
|
+
dataset.forEach((entry, index) => {
|
|
41
|
+
const value = entry[dataKey];
|
|
42
|
+
if (value != null && typeof value !== 'number') {
|
|
43
|
+
warnOnce([`MUI X Charts: your dataset key "${dataKey}" is used for plotting lines, but the dataset contains the non-null non-numerical element "${value}" at index ${index}.`, 'Line plots only support numeric and null values.'].join('\n'));
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
35
48
|
});
|
|
36
49
|
const completedSeries = {};
|
|
37
50
|
stackingGroups.forEach(stackingGroup => {
|
|
@@ -54,15 +67,7 @@ const seriesProcessor = (params, dataset) => {
|
|
|
54
67
|
}, series[id], {
|
|
55
68
|
data: dataKey ? dataset.map(data => {
|
|
56
69
|
const value = data[dataKey];
|
|
57
|
-
|
|
58
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
59
|
-
if (value !== null) {
|
|
60
|
-
warnOnce([`MUI X Charts: Your dataset key "${dataKey}" is used for plotting line, but contains nonnumerical elements.`, 'Line plots only support numbers and null values.']);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
return null;
|
|
64
|
-
}
|
|
65
|
-
return value;
|
|
70
|
+
return typeof value === 'number' ? value : null;
|
|
66
71
|
}) : series[id].data,
|
|
67
72
|
stackedData: stackedSeries[index].map(([a, b]) => [a, b])
|
|
68
73
|
});
|
|
@@ -40,9 +40,11 @@ function PieArcPlot(props) {
|
|
|
40
40
|
data
|
|
41
41
|
});
|
|
42
42
|
const {
|
|
43
|
-
dataIndex
|
|
43
|
+
dataIndex,
|
|
44
|
+
seriesId,
|
|
45
|
+
seriesType
|
|
44
46
|
} = useFocusedItem() ?? {};
|
|
45
|
-
const focusedItem =
|
|
47
|
+
const focusedItem = dataIndex !== undefined && seriesId === id && seriesType === 'pie' ? transformedData[dataIndex] : null;
|
|
46
48
|
if (data.length === 0) {
|
|
47
49
|
return null;
|
|
48
50
|
}
|
|
@@ -83,7 +85,7 @@ function PieArcPlot(props) {
|
|
|
83
85
|
stroke: (theme.vars ?? theme).palette.text.primary,
|
|
84
86
|
id: id,
|
|
85
87
|
className: pieArcClasses.focusIndicator,
|
|
86
|
-
dataIndex:
|
|
88
|
+
dataIndex: focusedItem.dataIndex,
|
|
87
89
|
isFaded: false,
|
|
88
90
|
isHighlighted: false,
|
|
89
91
|
isFocused: false,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import type { BarLabelProps } from "../../BarChart/index.js";
|
|
3
|
-
type UseAnimateBarLabelParams = Pick<BarLabelProps, 'xOrigin' | 'yOrigin' | 'x' | 'y' | 'width' | 'height' | 'layout' | 'skipAnimation'> & {
|
|
3
|
+
type UseAnimateBarLabelParams = Pick<BarLabelProps, 'xOrigin' | 'yOrigin' | 'x' | 'y' | 'width' | 'height' | 'layout' | 'skipAnimation' | 'placement'> & {
|
|
4
4
|
ref?: React.Ref<SVGTextElement>;
|
|
5
5
|
};
|
|
6
6
|
type UseAnimateBarLabelReturn = {
|
|
@@ -5,14 +5,12 @@ function barLabelPropsInterpolator(from, to) {
|
|
|
5
5
|
const interpolateY = interpolateNumber(from.y, to.y);
|
|
6
6
|
const interpolateWidth = interpolateNumber(from.width, to.width);
|
|
7
7
|
const interpolateHeight = interpolateNumber(from.height, to.height);
|
|
8
|
-
return t => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
};
|
|
15
|
-
};
|
|
8
|
+
return t => ({
|
|
9
|
+
x: interpolateX(t),
|
|
10
|
+
y: interpolateY(t),
|
|
11
|
+
width: interpolateWidth(t),
|
|
12
|
+
height: interpolateHeight(t)
|
|
13
|
+
});
|
|
16
14
|
}
|
|
17
15
|
|
|
18
16
|
/**
|
|
@@ -25,15 +23,21 @@ function barLabelPropsInterpolator(from, to) {
|
|
|
25
23
|
* pass the ref returned by this hook to the `path` element and the `ref` provided as argument will also be called.
|
|
26
24
|
*/
|
|
27
25
|
export function useAnimateBarLabel(props) {
|
|
26
|
+
const {
|
|
27
|
+
initialX,
|
|
28
|
+
currentX,
|
|
29
|
+
initialY,
|
|
30
|
+
currentY
|
|
31
|
+
} = props.placement === 'outside' ? getOutsidePlacement(props) : getCenterPlacement(props);
|
|
28
32
|
const initialProps = {
|
|
29
|
-
x:
|
|
30
|
-
y:
|
|
33
|
+
x: initialX,
|
|
34
|
+
y: initialY,
|
|
31
35
|
width: props.width,
|
|
32
36
|
height: props.height
|
|
33
37
|
};
|
|
34
38
|
const currentProps = {
|
|
35
|
-
x:
|
|
36
|
-
y:
|
|
39
|
+
x: currentX,
|
|
40
|
+
y: currentY,
|
|
37
41
|
width: props.width,
|
|
38
42
|
height: props.height
|
|
39
43
|
};
|
|
@@ -50,4 +54,49 @@ export function useAnimateBarLabel(props) {
|
|
|
50
54
|
skip: props.skipAnimation,
|
|
51
55
|
ref: props.ref
|
|
52
56
|
});
|
|
57
|
+
}
|
|
58
|
+
const LABEL_OFFSET = 4;
|
|
59
|
+
function getCenterPlacement(props) {
|
|
60
|
+
return {
|
|
61
|
+
initialX: props.layout === 'vertical' ? props.x + props.width / 2 : props.xOrigin,
|
|
62
|
+
initialY: props.layout === 'vertical' ? props.yOrigin : props.y + props.height / 2,
|
|
63
|
+
currentX: props.x + props.width / 2,
|
|
64
|
+
currentY: props.y + props.height / 2
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function getOutsidePlacement(props) {
|
|
68
|
+
let initialY = 0;
|
|
69
|
+
let currentY = 0;
|
|
70
|
+
let initialX = 0;
|
|
71
|
+
let currentX = 0;
|
|
72
|
+
if (props.layout === 'vertical') {
|
|
73
|
+
const shouldPlaceAbove = props.y < props.yOrigin;
|
|
74
|
+
if (shouldPlaceAbove) {
|
|
75
|
+
initialY = props.yOrigin - LABEL_OFFSET;
|
|
76
|
+
currentY = props.y - LABEL_OFFSET;
|
|
77
|
+
} else {
|
|
78
|
+
initialY = props.yOrigin + LABEL_OFFSET;
|
|
79
|
+
currentY = props.y + props.height + LABEL_OFFSET;
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
initialX: props.x + props.width / 2,
|
|
83
|
+
currentX: props.x + props.width / 2,
|
|
84
|
+
initialY,
|
|
85
|
+
currentY
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const shouldPlaceToTheLeft = props.x < props.xOrigin;
|
|
89
|
+
if (shouldPlaceToTheLeft) {
|
|
90
|
+
initialX = props.xOrigin;
|
|
91
|
+
currentX = props.x - LABEL_OFFSET;
|
|
92
|
+
} else {
|
|
93
|
+
initialX = props.xOrigin;
|
|
94
|
+
currentX = props.x + props.width + LABEL_OFFSET;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
initialX,
|
|
98
|
+
currentX,
|
|
99
|
+
initialY: props.y + props.height / 2,
|
|
100
|
+
currentY: props.y + props.height / 2
|
|
101
|
+
};
|
|
53
102
|
}
|
package/esm/hooks/useAxis.d.ts
CHANGED
|
@@ -2,12 +2,17 @@ import { AxisId, ChartsRadiusAxisProps, ChartsRotationAxisProps, PolarAxisDefaul
|
|
|
2
2
|
/**
|
|
3
3
|
* Get all the x-axes.
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
5
|
+
* Returns all X axes configured in the chart along with their IDs.
|
|
6
|
+
* This is useful when you need to iterate over multiple axes or access all axis configurations at once.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* @returns An object containing:
|
|
9
|
+
* - `xAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
|
|
10
|
+
* - `xAxisIds`: An array of all X axis IDs in the chart
|
|
9
11
|
*
|
|
10
|
-
* @
|
|
12
|
+
* @example
|
|
13
|
+
* const { xAxis, xAxisIds } = useXAxes();
|
|
14
|
+
*
|
|
15
|
+
* @see `useXAxis` for accessing a single X axis
|
|
11
16
|
*/
|
|
12
17
|
export declare function useXAxes(): {
|
|
13
18
|
xAxis: import("../internals/index.js").ComputedAxisConfig<ChartsXAxisProps>;
|
|
@@ -16,36 +21,131 @@ export declare function useXAxes(): {
|
|
|
16
21
|
/**
|
|
17
22
|
* Get all the y-axes.
|
|
18
23
|
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
24
|
+
* Returns all Y axes configured in the chart along with their IDs.
|
|
25
|
+
* This is useful when you need to iterate over multiple axes or access all axis configurations at once.
|
|
26
|
+
*
|
|
27
|
+
* @returns An object containing:
|
|
28
|
+
* - `yAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
|
|
29
|
+
* - `yAxisIds`: An array of all Y axis IDs in the chart
|
|
21
30
|
*
|
|
22
|
-
*
|
|
31
|
+
* @example
|
|
32
|
+
* const { yAxis, yAxisIds } = useYAxes();
|
|
23
33
|
*
|
|
24
|
-
* @
|
|
34
|
+
* @see `useYAxis` for accessing a single Y axis
|
|
25
35
|
*/
|
|
26
36
|
export declare function useYAxes(): {
|
|
27
37
|
yAxis: import("../internals/index.js").ComputedAxisConfig<ChartsYAxisProps>;
|
|
28
38
|
yAxisIds: AxisId[];
|
|
29
39
|
};
|
|
30
40
|
/**
|
|
31
|
-
* Get the X axis.
|
|
32
|
-
*
|
|
33
|
-
* @
|
|
41
|
+
* Get a specific X axis or the default X axis.
|
|
42
|
+
*
|
|
43
|
+
* @param {AxisId} [axisId] - The axis identifier. Can be:
|
|
44
|
+
* - A string or number matching the axis ID defined in the chart's `xAxis` prop
|
|
45
|
+
* - Undefined to get the default (first) X axis
|
|
46
|
+
* @returns The configuration for a single X axis.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* // Get the default X axis
|
|
50
|
+
* const xAxis = useXAxis();
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* // Get a specific X axis by string ID
|
|
54
|
+
* const xAxis = useXAxis('revenue');
|
|
34
55
|
*/
|
|
35
56
|
export declare function useXAxis<T extends keyof AxisScaleConfig>(axisId?: AxisId): ComputedAxis<T, any, ChartsXAxisProps>;
|
|
36
57
|
/**
|
|
37
|
-
* Get the Y axis.
|
|
38
|
-
*
|
|
39
|
-
* @
|
|
58
|
+
* Get a specific Y axis or the default Y axis.
|
|
59
|
+
*
|
|
60
|
+
* @param {AxisId} [axisId] - The axis identifier. Can be:
|
|
61
|
+
* - A string or number matching the axis ID defined in the chart's `yAxis` prop
|
|
62
|
+
* - Undefined to get the default (first) Y axis
|
|
63
|
+
* @returns The configuration for a single Y axis.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* // Get the default Y axis
|
|
67
|
+
* const yAxis = useYAxis();
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* // Get a specific Y axis by string ID
|
|
71
|
+
* const yAxis = useYAxis('temperature');
|
|
40
72
|
*/
|
|
41
73
|
export declare function useYAxis<T extends keyof AxisScaleConfig>(axisId?: AxisId): ComputedAxis<T, any, ChartsYAxisProps>;
|
|
74
|
+
/**
|
|
75
|
+
* Get all the rotation axes for polar charts.
|
|
76
|
+
*
|
|
77
|
+
* Returns all rotation axes configured in polar charts along with their IDs.
|
|
78
|
+
* Rotation axes are used in charts like `RadarChart` to define angular positioning.
|
|
79
|
+
*
|
|
80
|
+
* @returns An object containing:
|
|
81
|
+
* - `rotationAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
|
|
82
|
+
* - `rotationAxisIds`: An array of all rotation axis IDs in the chart
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* const { rotationAxis, rotationAxisIds } = useRotationAxes();
|
|
86
|
+
*
|
|
87
|
+
* @see `useRotationAxis` for accessing a single rotation axis
|
|
88
|
+
*/
|
|
42
89
|
export declare function useRotationAxes(): {
|
|
43
90
|
rotationAxis: import("../internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js").DefaultizedAxisConfig<ChartsRotationAxisProps>;
|
|
44
91
|
rotationAxisIds: string[];
|
|
45
92
|
};
|
|
93
|
+
/**
|
|
94
|
+
* Get all the radius axes for polar charts.
|
|
95
|
+
*
|
|
96
|
+
* Returns all radial axes configured in polar charts along with their IDs.
|
|
97
|
+
* Radius axes are used in charts like `RadarChart` to define radial positioning and scaling.
|
|
98
|
+
*
|
|
99
|
+
* @returns An object containing:
|
|
100
|
+
* - `radiusAxis`: An object mapping axis IDs to their configurations `{ [axisId]: axis }`
|
|
101
|
+
* - `radiusAxisIds`: An array of all radius axis IDs in the chart
|
|
102
|
+
*
|
|
103
|
+
* @example
|
|
104
|
+
* const { radiusAxis, radiusAxisIds } = useRadiusAxes();
|
|
105
|
+
*
|
|
106
|
+
* @see `useRadiusAxis` for accessing a single radius axis
|
|
107
|
+
*/
|
|
46
108
|
export declare function useRadiusAxes(): {
|
|
47
109
|
radiusAxis: import("../internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js").DefaultizedAxisConfig<ChartsRadiusAxisProps>;
|
|
48
110
|
radiusAxisIds: string[];
|
|
49
111
|
};
|
|
50
|
-
|
|
51
|
-
|
|
112
|
+
/**
|
|
113
|
+
* Get a specific rotation axis or the default rotation axis for polar charts.
|
|
114
|
+
*
|
|
115
|
+
* Returns the configuration and scale for a rotation axis in polar charts.
|
|
116
|
+
* The rotation axis controls the angular positioning of data points around the circle.
|
|
117
|
+
*
|
|
118
|
+
* @param {AxisId} [axisId] - The axis identifier. Can be:
|
|
119
|
+
* - A string or number matching the axis ID defined in the chart's rotation axis configuration
|
|
120
|
+
* - Undefined to get the default (first) rotation axis
|
|
121
|
+
* @returns The rotation axis configuration, or undefined if not found
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* // Get the default rotation axis
|
|
125
|
+
* const rotationAxis = useRotationAxis();
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* // Get a specific rotation axis by string ID
|
|
129
|
+
* const rotationAxis = useRotationAxis('categories');
|
|
130
|
+
*/
|
|
131
|
+
export declare function useRotationAxis(axisId?: AxisId): PolarAxisDefaultized<ScaleName, any, ChartsRotationAxisProps> | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* Get a specific radius axis or the default radius axis for polar charts.
|
|
134
|
+
*
|
|
135
|
+
* Returns the configuration and scale for a radial axis in polar charts.
|
|
136
|
+
* The radius axis controls the radial distance of data points from the center of the circle.
|
|
137
|
+
*
|
|
138
|
+
* @param {AxisId} [axisId] - The axis identifier. Can be:
|
|
139
|
+
* - A string or number matching the axis ID defined in the chart's radius axis configuration
|
|
140
|
+
* - Undefined to get the default (first) radius axis
|
|
141
|
+
* @returns The radius axis configuration, or undefined if not found
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* // Get the default radius axis
|
|
145
|
+
* const radiusAxis = useRadiusAxis();
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* // Get a specific radius axis by string ID
|
|
149
|
+
* const radiusAxis = useRadiusAxis('magnitude');
|
|
150
|
+
*/
|
|
151
|
+
export declare function useRadiusAxis(axisId?: AxisId): PolarAxisDefaultized<ScaleName, any, ChartsRadiusAxisProps> | undefined;
|