@mui/x-charts 8.11.1 → 8.11.3
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/index.d.ts +1 -0
- package/BarChart/useBarChartProps.js +4 -3
- package/CHANGELOG.md +181 -0
- package/ChartsAxisHighlight/ChartsXAxisHighlight.js +4 -4
- package/ChartsAxisHighlight/ChartsYAxisHighlight.js +4 -4
- package/ChartsLegend/ChartsLegend.js +2 -1
- package/ChartsLegend/PiecewiseColorLegend.d.ts +2 -2
- package/ChartsLegend/PiecewiseColorLegend.js +32 -22
- package/ChartsLegend/piecewiseColorLegendClasses.d.ts +4 -0
- package/ChartsLegend/piecewiseColorLegendClasses.js +2 -2
- package/ChartsSurface/ChartsSurface.js +2 -1
- package/ChartsWrapper/ChartsWrapper.d.ts +4 -0
- package/ChartsWrapper/ChartsWrapper.js +73 -25
- package/ChartsXAxis/ChartsGroupedXAxisTicks.d.ts +8 -0
- package/ChartsXAxis/{ChartsGroupedXAxis.js → ChartsGroupedXAxisTicks.js} +11 -54
- package/ChartsXAxis/ChartsSingleXAxisTicks.d.ts +10 -0
- package/ChartsXAxis/{ChartsSingleXAxis.js → ChartsSingleXAxisTicks.js} +15 -51
- package/ChartsXAxis/ChartsXAxis.js +4 -6
- package/ChartsXAxis/ChartsXAxisImpl.d.ts +13 -0
- package/ChartsXAxis/ChartsXAxisImpl.js +117 -0
- package/ChartsXAxis/getVisibleLabels.js +5 -1
- package/ChartsXAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -496
- package/ChartsXAxis/{useAxisProps.js → useAxisTicksProps.js} +4 -31
- package/ChartsXAxis/utilities.d.ts +1 -2
- package/ChartsXAxis/utilities.js +1 -7
- package/{esm/ChartsYAxis/ChartsGroupedYAxis.d.ts → ChartsYAxis/ChartsGroupedYAxisTicks.d.ts} +2 -2
- package/ChartsYAxis/{ChartsGroupedYAxis.js → ChartsGroupedYAxisTicks.js} +11 -54
- package/ChartsYAxis/ChartsSingleYAxisTicks.d.ts +10 -0
- package/ChartsYAxis/{ChartsSingleYAxis.js → ChartsSingleYAxisTicks.js} +15 -50
- package/ChartsYAxis/ChartsYAxis.js +6 -8
- package/ChartsYAxis/ChartsYAxisImpl.d.ts +13 -0
- package/ChartsYAxis/ChartsYAxisImpl.js +133 -0
- package/ChartsYAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -504
- package/ChartsYAxis/{useAxisProps.js → useAxisTicksProps.js} +5 -44
- package/ChartsYAxis/utilities.d.ts +0 -1
- package/ChartsYAxis/utilities.js +1 -7
- package/LineChart/useAreaPlotData.js +2 -2
- package/LineChart/useLineChartProps.js +2 -1
- package/LineChart/useLinePlotData.js +2 -2
- package/PieChart/PieChart.js +1 -0
- package/RadarChart/RadarAxis/useRadarAxis.js +2 -2
- package/RadarChart/useRadarChartProps.js +2 -1
- package/ScatterChart/useScatterChartProps.js +2 -1
- package/Toolbar/Toolbar.js +2 -1
- package/esm/BarChart/index.d.ts +1 -0
- package/esm/BarChart/useBarChartProps.js +4 -3
- package/esm/ChartsAxisHighlight/ChartsXAxisHighlight.js +4 -4
- package/esm/ChartsAxisHighlight/ChartsYAxisHighlight.js +4 -4
- package/esm/ChartsLegend/ChartsLegend.js +2 -1
- package/esm/ChartsLegend/PiecewiseColorLegend.d.ts +2 -2
- package/esm/ChartsLegend/PiecewiseColorLegend.js +32 -22
- package/esm/ChartsLegend/piecewiseColorLegendClasses.d.ts +4 -0
- package/esm/ChartsLegend/piecewiseColorLegendClasses.js +2 -2
- package/esm/ChartsSurface/ChartsSurface.js +2 -1
- package/esm/ChartsWrapper/ChartsWrapper.d.ts +4 -0
- package/esm/ChartsWrapper/ChartsWrapper.js +73 -25
- package/esm/ChartsXAxis/ChartsGroupedXAxisTicks.d.ts +8 -0
- package/esm/ChartsXAxis/{ChartsGroupedXAxis.js → ChartsGroupedXAxisTicks.js} +12 -55
- package/esm/ChartsXAxis/ChartsSingleXAxisTicks.d.ts +10 -0
- package/esm/ChartsXAxis/{ChartsSingleXAxis.js → ChartsSingleXAxisTicks.js} +16 -54
- package/esm/ChartsXAxis/ChartsXAxis.js +4 -6
- package/esm/ChartsXAxis/ChartsXAxisImpl.d.ts +13 -0
- package/esm/ChartsXAxis/ChartsXAxisImpl.js +110 -0
- package/esm/ChartsXAxis/getVisibleLabels.js +5 -1
- package/esm/ChartsXAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -496
- package/esm/ChartsXAxis/{useAxisProps.js → useAxisTicksProps.js} +3 -29
- package/esm/ChartsXAxis/utilities.d.ts +1 -2
- package/esm/ChartsXAxis/utilities.js +0 -6
- package/{ChartsYAxis/ChartsGroupedYAxis.d.ts → esm/ChartsYAxis/ChartsGroupedYAxisTicks.d.ts} +2 -2
- package/esm/ChartsYAxis/{ChartsGroupedYAxis.js → ChartsGroupedYAxisTicks.js} +12 -55
- package/esm/ChartsYAxis/ChartsSingleYAxisTicks.d.ts +10 -0
- package/esm/ChartsYAxis/{ChartsSingleYAxis.js → ChartsSingleYAxisTicks.js} +16 -53
- package/esm/ChartsYAxis/ChartsYAxis.js +5 -7
- package/esm/ChartsYAxis/ChartsYAxisImpl.d.ts +13 -0
- package/esm/ChartsYAxis/ChartsYAxisImpl.js +126 -0
- package/esm/ChartsYAxis/{useAxisProps.d.ts → useAxisTicksProps.d.ts} +1 -504
- package/esm/ChartsYAxis/{useAxisProps.js → useAxisTicksProps.js} +4 -42
- package/esm/ChartsYAxis/utilities.d.ts +0 -1
- package/esm/ChartsYAxis/utilities.js +0 -6
- package/esm/LineChart/useAreaPlotData.js +2 -2
- package/esm/LineChart/useLineChartProps.js +2 -1
- package/esm/LineChart/useLinePlotData.js +2 -2
- package/esm/PieChart/PieChart.js +1 -0
- package/esm/RadarChart/RadarAxis/useRadarAxis.js +2 -2
- package/esm/RadarChart/useRadarChartProps.js +2 -1
- package/esm/ScatterChart/useScatterChartProps.js +2 -1
- package/esm/Toolbar/Toolbar.js +2 -1
- package/esm/hooks/useInteractionItemProps.js +5 -4
- package/esm/hooks/useScale.js +2 -2
- package/esm/hooks/useTicks.js +10 -3
- package/esm/hooks/useTicksGrouped.js +2 -2
- package/esm/index.js +1 -1
- package/esm/internals/dateHelpers.d.ts +4 -2
- package/esm/internals/dateHelpers.js +5 -4
- package/esm/internals/defaultValueFormatters.js +5 -0
- package/esm/internals/index.d.ts +1 -1
- package/esm/internals/index.js +1 -1
- package/esm/internals/invertScale.js +2 -2
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +5 -5
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -3
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
- package/esm/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js +2 -2
- package/esm/internals/scaleGuards.d.ts +4 -0
- package/esm/internals/scaleGuards.js +3 -0
- package/esm/locales/index.d.ts +2 -1
- package/esm/locales/index.js +1 -0
- package/esm/locales/svSE.d.ts +19 -0
- package/esm/locales/svSE.js +15 -0
- package/esm/models/axis.d.ts +3 -0
- package/hooks/useInteractionItemProps.js +6 -4
- package/hooks/useScale.js +2 -2
- package/hooks/useTicks.js +10 -3
- package/hooks/useTicksGrouped.js +2 -2
- package/index.js +1 -1
- package/internals/dateHelpers.d.ts +4 -2
- package/internals/dateHelpers.js +5 -4
- package/internals/defaultValueFormatters.js +5 -0
- package/internals/index.d.ts +1 -1
- package/internals/index.js +4 -4
- package/internals/invertScale.js +2 -2
- package/internals/plugins/featurePlugins/useChartCartesianAxis/computeAxisValue.js +5 -5
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisValue.js +3 -3
- package/internals/plugins/featurePlugins/useChartPolarAxis/computeAxisValue.js +2 -2
- package/internals/plugins/featurePlugins/useChartPolarAxis/getAxisIndex.js +2 -2
- package/internals/scaleGuards.d.ts +4 -0
- package/internals/{isBandScale.js → scaleGuards.js} +2 -2
- package/locales/index.d.ts +2 -1
- package/locales/index.js +11 -0
- package/locales/svSE.d.ts +19 -0
- package/locales/svSE.js +21 -0
- package/models/axis.d.ts +3 -0
- package/package.json +5 -5
- package/ChartsXAxis/ChartsGroupedXAxis.d.ts +0 -7
- package/ChartsXAxis/ChartsSingleXAxis.d.ts +0 -7
- package/ChartsYAxis/ChartsSingleYAxis.d.ts +0 -7
- package/esm/ChartsXAxis/ChartsGroupedXAxis.d.ts +0 -7
- package/esm/ChartsXAxis/ChartsSingleXAxis.d.ts +0 -7
- package/esm/ChartsYAxis/ChartsSingleYAxis.d.ts +0 -7
- package/esm/internals/isBandScale.d.ts +0 -5
- package/esm/internals/isBandScale.js +0 -3
- package/internals/isBandScale.d.ts +0 -5
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import {
|
|
6
|
-
import { isBandScale } from "../internals/isBandScale.js";
|
|
5
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
7
6
|
import { useChartContext } from "../context/ChartProvider/useChartContext.js";
|
|
8
|
-
import { TICK_LABEL_GAP
|
|
7
|
+
import { TICK_LABEL_GAP } from "./utilities.js";
|
|
9
8
|
import { useTicksGrouped } from "../hooks/useTicksGrouped.js";
|
|
10
|
-
import {
|
|
9
|
+
import { useAxisTicksProps } from "./useAxisTicksProps.js";
|
|
11
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
11
|
const DEFAULT_GROUPING_CONFIG = {
|
|
13
12
|
tickSize: 6
|
|
@@ -20,58 +19,36 @@ const getGroupingConfig = (groups, groupIndex, tickSize) => {
|
|
|
20
19
|
tickSize: config.tickSize ?? calculatedTickSize
|
|
21
20
|
});
|
|
22
21
|
};
|
|
23
|
-
|
|
24
22
|
/**
|
|
25
23
|
* @ignore - internal component.
|
|
26
24
|
*/
|
|
27
|
-
function
|
|
25
|
+
function ChartsGroupedXAxisTicks(inProps) {
|
|
28
26
|
const {
|
|
29
27
|
xScale,
|
|
30
28
|
defaultizedProps,
|
|
31
29
|
tickNumber,
|
|
32
30
|
positionSign,
|
|
33
|
-
skipAxisRendering,
|
|
34
31
|
classes,
|
|
35
|
-
Line,
|
|
36
32
|
Tick,
|
|
37
33
|
TickLabel,
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
} = useAxisProps(inProps);
|
|
42
|
-
if (!isBandScale(xScale)) {
|
|
34
|
+
axisTickLabelProps
|
|
35
|
+
} = useAxisTicksProps(inProps);
|
|
36
|
+
if (!isOrdinalScale(xScale)) {
|
|
43
37
|
throw new Error('MUI X Charts: ChartsGroupedXAxis only supports the `band` and `point` scale types.');
|
|
44
38
|
}
|
|
45
39
|
const {
|
|
46
|
-
position,
|
|
47
|
-
disableLine,
|
|
48
40
|
disableTicks,
|
|
49
|
-
label,
|
|
50
41
|
tickSize,
|
|
51
42
|
valueFormatter,
|
|
52
43
|
slotProps,
|
|
53
44
|
tickInterval,
|
|
54
45
|
tickPlacement,
|
|
55
|
-
tickLabelPlacement
|
|
56
|
-
sx,
|
|
57
|
-
offset,
|
|
58
|
-
height: axisHeight
|
|
46
|
+
tickLabelPlacement
|
|
59
47
|
} = defaultizedProps;
|
|
60
48
|
const groups = defaultizedProps.groups;
|
|
61
|
-
const drawingArea = useDrawingArea();
|
|
62
|
-
const {
|
|
63
|
-
left,
|
|
64
|
-
top,
|
|
65
|
-
width,
|
|
66
|
-
height
|
|
67
|
-
} = drawingArea;
|
|
68
49
|
const {
|
|
69
50
|
instance
|
|
70
51
|
} = useChartContext();
|
|
71
|
-
const labelRefPoint = {
|
|
72
|
-
x: left + width / 2,
|
|
73
|
-
y: positionSign * axisHeight
|
|
74
|
-
};
|
|
75
52
|
const xTicks = useTicksGrouped({
|
|
76
53
|
scale: xScale,
|
|
77
54
|
tickNumber,
|
|
@@ -82,23 +59,8 @@ function ChartsGroupedXAxis(inProps) {
|
|
|
82
59
|
direction: 'x',
|
|
83
60
|
groups
|
|
84
61
|
});
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
// - The domain is an empty array for band/point scales.
|
|
88
|
-
// - The domains contains Infinity for continuous scales.
|
|
89
|
-
// - The position is set to 'none'.
|
|
90
|
-
if (skipAxisRendering) {
|
|
91
|
-
return null;
|
|
92
|
-
}
|
|
93
|
-
return /*#__PURE__*/_jsxs(XAxisRoot, {
|
|
94
|
-
transform: `translate(0, ${position === 'bottom' ? top + height + offset : top - offset})`,
|
|
95
|
-
className: classes.root,
|
|
96
|
-
sx: sx,
|
|
97
|
-
children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
|
|
98
|
-
x1: left,
|
|
99
|
-
x2: left + width,
|
|
100
|
-
className: classes.line
|
|
101
|
-
}, slotProps?.axisLine)), xTicks.map((item, index) => {
|
|
62
|
+
return /*#__PURE__*/_jsx(React.Fragment, {
|
|
63
|
+
children: xTicks.map((item, index) => {
|
|
102
64
|
const {
|
|
103
65
|
offset: tickOffset,
|
|
104
66
|
labelOffset
|
|
@@ -126,12 +88,7 @@ function ChartsGroupedXAxis(inProps) {
|
|
|
126
88
|
text: tickLabel
|
|
127
89
|
}))]
|
|
128
90
|
}, index);
|
|
129
|
-
})
|
|
130
|
-
className: classes.label,
|
|
131
|
-
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
132
|
-
text: label
|
|
133
|
-
}))
|
|
134
|
-
})]
|
|
91
|
+
})
|
|
135
92
|
});
|
|
136
93
|
}
|
|
137
|
-
export {
|
|
94
|
+
export { ChartsGroupedXAxisTicks };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ChartsXAxisProps } from "../models/axis.js";
|
|
3
|
+
interface ChartsSingleXAxisProps extends ChartsXAxisProps {
|
|
4
|
+
axisLabelHeight: number;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @ignore - internal component.
|
|
8
|
+
*/
|
|
9
|
+
declare function ChartsSingleXAxisTicks(inProps: ChartsSingleXAxisProps): React.JSX.Element;
|
|
10
|
+
export { ChartsSingleXAxisTicks };
|
|
@@ -2,44 +2,39 @@
|
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
4
|
import * as React from 'react';
|
|
5
|
+
import { useRtl } from '@mui/system/RtlProvider';
|
|
5
6
|
import { useIsHydrated } from "../hooks/useIsHydrated.js";
|
|
6
|
-
import { getStringSize } from "../internals/domUtils.js";
|
|
7
7
|
import { useTicks } from "../hooks/useTicks.js";
|
|
8
8
|
import { useMounted } from "../hooks/useMounted.js";
|
|
9
9
|
import { useDrawingArea } from "../hooks/useDrawingArea.js";
|
|
10
10
|
import { useChartContext } from "../context/ChartProvider/useChartContext.js";
|
|
11
11
|
import { shortenLabels } from "./shortenLabels.js";
|
|
12
12
|
import { getVisibleLabels } from "./getVisibleLabels.js";
|
|
13
|
-
import { AXIS_LABEL_TICK_LABEL_GAP, TICK_LABEL_GAP
|
|
14
|
-
import {
|
|
15
|
-
|
|
13
|
+
import { AXIS_LABEL_TICK_LABEL_GAP, TICK_LABEL_GAP } from "./utilities.js";
|
|
14
|
+
import { useAxisTicksProps } from "./useAxisTicksProps.js";
|
|
15
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
16
|
/**
|
|
17
17
|
* @ignore - internal component.
|
|
18
18
|
*/
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
function ChartsSingleXAxisTicks(inProps) {
|
|
20
|
+
const {
|
|
21
|
+
axisLabelHeight
|
|
22
|
+
} = inProps;
|
|
21
23
|
const {
|
|
22
24
|
xScale,
|
|
23
25
|
defaultizedProps,
|
|
24
26
|
tickNumber,
|
|
25
27
|
positionSign,
|
|
26
|
-
skipAxisRendering,
|
|
27
28
|
classes,
|
|
28
|
-
Line,
|
|
29
29
|
Tick,
|
|
30
30
|
TickLabel,
|
|
31
|
-
Label,
|
|
32
31
|
axisTickLabelProps,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
} = useAxisProps(inProps);
|
|
32
|
+
reverse
|
|
33
|
+
} = useAxisTicksProps(inProps);
|
|
34
|
+
const isRtl = useRtl();
|
|
37
35
|
const isMounted = useMounted();
|
|
38
36
|
const {
|
|
39
|
-
position,
|
|
40
|
-
disableLine,
|
|
41
37
|
disableTicks,
|
|
42
|
-
label,
|
|
43
38
|
tickSize: tickSizeProp,
|
|
44
39
|
valueFormatter,
|
|
45
40
|
slotProps,
|
|
@@ -48,17 +43,9 @@ function ChartsSingleXAxis(inProps) {
|
|
|
48
43
|
tickPlacement,
|
|
49
44
|
tickLabelPlacement,
|
|
50
45
|
tickLabelMinGap,
|
|
51
|
-
sx,
|
|
52
|
-
offset,
|
|
53
46
|
height: axisHeight
|
|
54
47
|
} = defaultizedProps;
|
|
55
48
|
const drawingArea = useDrawingArea();
|
|
56
|
-
const {
|
|
57
|
-
left,
|
|
58
|
-
top,
|
|
59
|
-
width,
|
|
60
|
-
height
|
|
61
|
-
} = drawingArea;
|
|
62
49
|
const {
|
|
63
50
|
instance
|
|
64
51
|
} = useChartContext();
|
|
@@ -82,31 +69,11 @@ function ChartsSingleXAxis(inProps) {
|
|
|
82
69
|
isXInside: instance.isXInside
|
|
83
70
|
});
|
|
84
71
|
|
|
85
|
-
// Skip axis rendering if no data is available
|
|
86
|
-
// - The domain is an empty array for band/point scales.
|
|
87
|
-
// - The domains contains Infinity for continuous scales.
|
|
88
|
-
// - The position is set to 'none'.
|
|
89
|
-
if (skipAxisRendering) {
|
|
90
|
-
return null;
|
|
91
|
-
}
|
|
92
|
-
const labelHeight = label ? getStringSize(label, axisLabelProps.style).height : 0;
|
|
93
|
-
const labelRefPoint = {
|
|
94
|
-
x: left + width / 2,
|
|
95
|
-
y: positionSign * axisHeight
|
|
96
|
-
};
|
|
97
|
-
|
|
98
72
|
/* If there's an axis title, the tick labels have less space to render */
|
|
99
|
-
const tickLabelsMaxHeight = Math.max(0, axisHeight - (
|
|
73
|
+
const tickLabelsMaxHeight = Math.max(0, axisHeight - (axisLabelHeight > 0 ? axisLabelHeight + AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - TICK_LABEL_GAP);
|
|
100
74
|
const tickLabels = isHydrated ? shortenLabels(visibleLabels, drawingArea, tickLabelsMaxHeight, isRtl, axisTickLabelProps.style) : new Map(Array.from(visibleLabels).map(item => [item, item.formattedValue]));
|
|
101
|
-
return /*#__PURE__*/
|
|
102
|
-
|
|
103
|
-
className: classes.root,
|
|
104
|
-
sx: sx,
|
|
105
|
-
children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
|
|
106
|
-
x1: left,
|
|
107
|
-
x2: left + width,
|
|
108
|
-
className: classes.line
|
|
109
|
-
}, slotProps?.axisLine)), xTicks.map((item, index) => {
|
|
75
|
+
return /*#__PURE__*/_jsx(React.Fragment, {
|
|
76
|
+
children: xTicks.map((item, index) => {
|
|
110
77
|
const {
|
|
111
78
|
offset: tickOffset,
|
|
112
79
|
labelOffset
|
|
@@ -129,12 +96,7 @@ function ChartsSingleXAxis(inProps) {
|
|
|
129
96
|
text: tickLabel
|
|
130
97
|
}))]
|
|
131
98
|
}, index);
|
|
132
|
-
})
|
|
133
|
-
className: classes.label,
|
|
134
|
-
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
135
|
-
text: label
|
|
136
|
-
}))
|
|
137
|
-
})]
|
|
99
|
+
})
|
|
138
100
|
});
|
|
139
101
|
}
|
|
140
|
-
export {
|
|
102
|
+
export { ChartsSingleXAxisTicks };
|
|
@@ -5,8 +5,7 @@ import * as React from 'react';
|
|
|
5
5
|
import PropTypes from 'prop-types';
|
|
6
6
|
import { warnOnce } from '@mui/x-internals/warning';
|
|
7
7
|
import { useXAxes } from "../hooks/useAxis.js";
|
|
8
|
-
import {
|
|
9
|
-
import { ChartsGroupedXAxis } from "./ChartsGroupedXAxis.js";
|
|
8
|
+
import { ChartsXAxisImpl } from "./ChartsXAxisImpl.js";
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* Demos:
|
|
@@ -28,10 +27,9 @@ function ChartsXAxis(inProps) {
|
|
|
28
27
|
warnOnce(`MUI X Charts: No axis found. The axisId "${inProps.axisId}" is probably invalid.`);
|
|
29
28
|
return null;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
return /*#__PURE__*/_jsx(ChartsSingleXAxis, _extends({}, inProps));
|
|
30
|
+
return /*#__PURE__*/_jsx(ChartsXAxisImpl, _extends({}, inProps, {
|
|
31
|
+
axis: axis
|
|
32
|
+
}));
|
|
35
33
|
}
|
|
36
34
|
process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
37
35
|
// ----------------------------- Warning --------------------------------
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { AxisScaleConfig, ChartsXAxisProps, ComputedAxis } from "../models/axis.js";
|
|
3
|
+
interface ChartsXAxisImplProps extends Omit<ChartsXAxisProps, 'axis'> {
|
|
4
|
+
axis: ComputedAxis<keyof AxisScaleConfig, any, ChartsXAxisProps>;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* @ignore - internal component. Use `ChartsXAxis` instead.
|
|
8
|
+
*/
|
|
9
|
+
export declare function ChartsXAxisImpl({
|
|
10
|
+
axis,
|
|
11
|
+
...inProps
|
|
12
|
+
}: ChartsXAxisImplProps): React.JSX.Element | null;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
+
const _excluded = ["axis"],
|
|
6
|
+
_excluded2 = ["scale", "tickNumber", "reverse"];
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import useSlotProps from '@mui/utils/useSlotProps';
|
|
9
|
+
import { styled, useTheme, useThemeProps } from '@mui/material/styles';
|
|
10
|
+
import { ChartsSingleXAxisTicks } from "./ChartsSingleXAxisTicks.js";
|
|
11
|
+
import { ChartsGroupedXAxisTicks } from "./ChartsGroupedXAxisTicks.js";
|
|
12
|
+
import { ChartsText } from "../ChartsText/index.js";
|
|
13
|
+
import { isOrdinalScale } from "../internals/scaleGuards.js";
|
|
14
|
+
import { isInfinity } from "../internals/isInfinity.js";
|
|
15
|
+
import { defaultProps, useUtilityClasses } from "./utilities.js";
|
|
16
|
+
import { useDrawingArea } from "../hooks/index.js";
|
|
17
|
+
import { getStringSize } from "../internals/domUtils.js";
|
|
18
|
+
import { AxisRoot } from "../internals/components/AxisSharedComponents.js";
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
const XAxisRoot = styled(AxisRoot, {
|
|
21
|
+
name: 'MuiChartsXAxis',
|
|
22
|
+
slot: 'Root'
|
|
23
|
+
})({});
|
|
24
|
+
/**
|
|
25
|
+
* @ignore - internal component. Use `ChartsXAxis` instead.
|
|
26
|
+
*/
|
|
27
|
+
export function ChartsXAxisImpl(_ref) {
|
|
28
|
+
let {
|
|
29
|
+
axis
|
|
30
|
+
} = _ref,
|
|
31
|
+
inProps = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
32
|
+
const {
|
|
33
|
+
scale: xScale
|
|
34
|
+
} = axis,
|
|
35
|
+
settings = _objectWithoutPropertiesLoose(axis, _excluded2);
|
|
36
|
+
|
|
37
|
+
// eslint-disable-next-line material-ui/mui-name-matches-component-name
|
|
38
|
+
const themedProps = useThemeProps({
|
|
39
|
+
props: _extends({}, settings, inProps),
|
|
40
|
+
name: 'MuiChartsXAxis'
|
|
41
|
+
});
|
|
42
|
+
const defaultizedProps = _extends({}, defaultProps, themedProps);
|
|
43
|
+
const {
|
|
44
|
+
position,
|
|
45
|
+
labelStyle,
|
|
46
|
+
offset,
|
|
47
|
+
slots,
|
|
48
|
+
slotProps,
|
|
49
|
+
sx,
|
|
50
|
+
disableLine,
|
|
51
|
+
label,
|
|
52
|
+
height: axisHeight
|
|
53
|
+
} = defaultizedProps;
|
|
54
|
+
const theme = useTheme();
|
|
55
|
+
const classes = useUtilityClasses(defaultizedProps);
|
|
56
|
+
const {
|
|
57
|
+
left,
|
|
58
|
+
top,
|
|
59
|
+
width,
|
|
60
|
+
height
|
|
61
|
+
} = useDrawingArea();
|
|
62
|
+
const positionSign = position === 'bottom' ? 1 : -1;
|
|
63
|
+
const Line = slots?.axisLine ?? 'line';
|
|
64
|
+
const Label = slots?.axisLabel ?? ChartsText;
|
|
65
|
+
const axisLabelProps = useSlotProps({
|
|
66
|
+
elementType: Label,
|
|
67
|
+
externalSlotProps: slotProps?.axisLabel,
|
|
68
|
+
additionalProps: {
|
|
69
|
+
style: _extends({}, theme.typography.body1, {
|
|
70
|
+
lineHeight: 1,
|
|
71
|
+
fontSize: 14,
|
|
72
|
+
textAnchor: 'middle',
|
|
73
|
+
dominantBaseline: position === 'bottom' ? 'text-after-edge' : 'text-before-edge'
|
|
74
|
+
}, labelStyle)
|
|
75
|
+
},
|
|
76
|
+
ownerState: {}
|
|
77
|
+
});
|
|
78
|
+
if (position === 'none') {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const labelHeight = label ? getStringSize(label, axisLabelProps.style).height : 0;
|
|
82
|
+
const domain = xScale.domain();
|
|
83
|
+
const isScaleOrdinal = isOrdinalScale(xScale);
|
|
84
|
+
const skipTickRendering = isScaleOrdinal ? domain.length === 0 : domain.some(isInfinity);
|
|
85
|
+
let children = null;
|
|
86
|
+
if (!skipTickRendering) {
|
|
87
|
+
children = 'groups' in axis && Array.isArray(axis.groups) ? /*#__PURE__*/_jsx(ChartsGroupedXAxisTicks, _extends({}, inProps)) : /*#__PURE__*/_jsx(ChartsSingleXAxisTicks, _extends({}, inProps, {
|
|
88
|
+
axisLabelHeight: labelHeight
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
const labelRefPoint = {
|
|
92
|
+
x: left + width / 2,
|
|
93
|
+
y: positionSign * axisHeight
|
|
94
|
+
};
|
|
95
|
+
return /*#__PURE__*/_jsxs(XAxisRoot, {
|
|
96
|
+
transform: `translate(0, ${position === 'bottom' ? top + height + offset : top - offset})`,
|
|
97
|
+
className: classes.root,
|
|
98
|
+
sx: sx,
|
|
99
|
+
children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
|
|
100
|
+
x1: left,
|
|
101
|
+
x2: left + width,
|
|
102
|
+
className: classes.line
|
|
103
|
+
}, slotProps?.axisLine)), children, label && /*#__PURE__*/_jsx("g", {
|
|
104
|
+
className: classes.label,
|
|
105
|
+
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
106
|
+
text: label
|
|
107
|
+
}))
|
|
108
|
+
})]
|
|
109
|
+
});
|
|
110
|
+
}
|
|
@@ -39,8 +39,12 @@ export function getVisibleLabels(xTicks, {
|
|
|
39
39
|
return new Set(xTicks.filter((item, labelIndex) => {
|
|
40
40
|
const {
|
|
41
41
|
offset,
|
|
42
|
-
labelOffset
|
|
42
|
+
labelOffset,
|
|
43
|
+
formattedValue
|
|
43
44
|
} = item;
|
|
45
|
+
if (formattedValue === '') {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
44
48
|
const textPosition = offset + labelOffset;
|
|
45
49
|
if (labelIndex > 0 && direction * textPosition < direction * (previousTextLimit + tickLabelMinGap)) {
|
|
46
50
|
return false;
|