@mui/x-charts 8.9.2 → 8.10.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/BarChart.js +16 -0
- package/CHANGELOG.md +121 -6
- package/ChartContainer/ChartContainer.js +24 -0
- package/ChartsAxisHighlight/ChartsXAxisHighlight.js +1 -3
- package/ChartsAxisHighlight/ChartsYAxisHighlight.js +1 -3
- package/ChartsTooltip/ChartsTooltip.d.ts +2 -1
- package/ChartsTooltip/ChartsTooltip.js +3 -3
- package/ChartsTooltip/ChartsTooltipContainer.d.ts +5 -5
- package/ChartsTooltip/ChartsTooltipContainer.js +3 -3
- package/ChartsXAxis/ChartsGroupedXAxis.d.ts +7 -0
- package/ChartsXAxis/ChartsGroupedXAxis.js +142 -0
- package/ChartsXAxis/ChartsSingleXAxis.d.ts +7 -0
- package/ChartsXAxis/ChartsSingleXAxis.js +144 -0
- package/ChartsXAxis/ChartsXAxis.d.ts +1 -1
- package/ChartsXAxis/ChartsXAxis.js +8 -210
- package/ChartsXAxis/getVisibleLabels.d.ts +2 -2
- package/ChartsXAxis/useAxisProps.d.ts +4526 -0
- package/ChartsXAxis/useAxisProps.js +105 -0
- package/ChartsXAxis/utilities.d.ts +11 -0
- package/ChartsXAxis/utilities.js +43 -0
- package/LineChart/LineChart.js +16 -0
- package/RadarChart/index.d.ts +9 -2
- package/RadarChart/index.js +13 -14
- package/ScatterChart/ScatterChart.d.ts +8 -1
- package/ScatterChart/ScatterChart.js +16 -0
- package/SparkLineChart/SparkLineChart.js +16 -0
- package/esm/BarChart/BarChart.js +16 -0
- package/esm/ChartContainer/ChartContainer.js +24 -0
- package/esm/ChartsAxisHighlight/ChartsXAxisHighlight.js +1 -3
- package/esm/ChartsAxisHighlight/ChartsYAxisHighlight.js +1 -3
- package/esm/ChartsTooltip/ChartsTooltip.d.ts +2 -1
- package/esm/ChartsTooltip/ChartsTooltip.js +3 -3
- package/esm/ChartsTooltip/ChartsTooltipContainer.d.ts +5 -5
- package/esm/ChartsTooltip/ChartsTooltipContainer.js +3 -3
- package/esm/ChartsXAxis/ChartsGroupedXAxis.d.ts +7 -0
- package/esm/ChartsXAxis/ChartsGroupedXAxis.js +136 -0
- package/esm/ChartsXAxis/ChartsSingleXAxis.d.ts +7 -0
- package/esm/ChartsXAxis/ChartsSingleXAxis.js +140 -0
- package/esm/ChartsXAxis/ChartsXAxis.d.ts +1 -1
- package/esm/ChartsXAxis/ChartsXAxis.js +7 -207
- package/esm/ChartsXAxis/getVisibleLabels.d.ts +2 -2
- package/esm/ChartsXAxis/useAxisProps.d.ts +4526 -0
- package/esm/ChartsXAxis/useAxisProps.js +98 -0
- package/esm/ChartsXAxis/utilities.d.ts +11 -0
- package/esm/ChartsXAxis/utilities.js +35 -0
- package/esm/LineChart/LineChart.js +16 -0
- package/esm/RadarChart/index.d.ts +9 -2
- package/esm/RadarChart/index.js +12 -2
- package/esm/ScatterChart/ScatterChart.d.ts +8 -1
- package/esm/ScatterChart/ScatterChart.js +16 -0
- package/esm/SparkLineChart/SparkLineChart.js +16 -0
- package/esm/hooks/useTicksGrouped.d.ts +28 -0
- package/esm/hooks/useTicksGrouped.js +98 -0
- package/esm/index.js +1 -1
- package/esm/internals/getScale.d.ts +1 -1
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +3 -1
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +32 -23
- package/esm/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.d.ts +1 -1
- package/esm/models/axis.d.ts +61 -0
- package/hooks/useTicksGrouped.d.ts +28 -0
- package/hooks/useTicksGrouped.js +104 -0
- package/index.js +1 -1
- package/internals/getScale.d.ts +1 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.d.ts +3 -1
- package/internals/plugins/featurePlugins/useChartCartesianAxis/createAxisFilterMapper.js +34 -23
- package/internals/plugins/featurePlugins/useChartCartesianAxis/getAxisExtremum.d.ts +1 -1
- package/models/axis.d.ts +61 -0
- package/package.json +3 -4
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useDrawingArea } from "../hooks/useDrawingArea.js";
|
|
6
|
+
import { isBandScale } from "../internals/isBandScale.js";
|
|
7
|
+
import { useChartContext } from "../context/ChartProvider/useChartContext.js";
|
|
8
|
+
import { TICK_LABEL_GAP, XAxisRoot } from "./utilities.js";
|
|
9
|
+
import { useTicksGrouped } from "../hooks/useTicksGrouped.js";
|
|
10
|
+
import { useAxisProps } from "./useAxisProps.js";
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
const DEFAULT_GROUPING_CONFIG = {
|
|
13
|
+
tickSize: 6
|
|
14
|
+
};
|
|
15
|
+
const getGroupingConfig = (groups, groupIndex, tickSize) => {
|
|
16
|
+
const config = groups[groupIndex] ?? {};
|
|
17
|
+
const defaultTickSize = tickSize ?? DEFAULT_GROUPING_CONFIG.tickSize;
|
|
18
|
+
const calculatedTickSize = defaultTickSize * groupIndex * 2 + defaultTickSize;
|
|
19
|
+
return _extends({}, DEFAULT_GROUPING_CONFIG, config, {
|
|
20
|
+
tickSize: config.tickSize ?? calculatedTickSize
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @ignore - internal component.
|
|
26
|
+
*/
|
|
27
|
+
function ChartsGroupedXAxis(inProps) {
|
|
28
|
+
const {
|
|
29
|
+
xScale,
|
|
30
|
+
defaultizedProps,
|
|
31
|
+
tickNumber,
|
|
32
|
+
positionSign,
|
|
33
|
+
skipAxisRendering,
|
|
34
|
+
classes,
|
|
35
|
+
Line,
|
|
36
|
+
Tick,
|
|
37
|
+
TickLabel,
|
|
38
|
+
Label,
|
|
39
|
+
axisTickLabelProps,
|
|
40
|
+
axisLabelProps
|
|
41
|
+
} = useAxisProps(inProps);
|
|
42
|
+
if (!isBandScale(xScale)) {
|
|
43
|
+
throw new Error('MUI X Charts: ChartsGroupedXAxis only supports the `band` and `point` scale types.');
|
|
44
|
+
}
|
|
45
|
+
const {
|
|
46
|
+
position,
|
|
47
|
+
disableLine,
|
|
48
|
+
disableTicks,
|
|
49
|
+
label,
|
|
50
|
+
tickSize,
|
|
51
|
+
valueFormatter,
|
|
52
|
+
slotProps,
|
|
53
|
+
tickInterval,
|
|
54
|
+
tickPlacement,
|
|
55
|
+
tickLabelPlacement,
|
|
56
|
+
sx,
|
|
57
|
+
offset,
|
|
58
|
+
height: axisHeight
|
|
59
|
+
} = defaultizedProps;
|
|
60
|
+
const groups = defaultizedProps.groups;
|
|
61
|
+
const drawingArea = useDrawingArea();
|
|
62
|
+
const {
|
|
63
|
+
left,
|
|
64
|
+
top,
|
|
65
|
+
width,
|
|
66
|
+
height
|
|
67
|
+
} = drawingArea;
|
|
68
|
+
const {
|
|
69
|
+
instance
|
|
70
|
+
} = useChartContext();
|
|
71
|
+
const labelRefPoint = {
|
|
72
|
+
x: left + width / 2,
|
|
73
|
+
y: positionSign * axisHeight
|
|
74
|
+
};
|
|
75
|
+
const xTicks = useTicksGrouped({
|
|
76
|
+
scale: xScale,
|
|
77
|
+
tickNumber,
|
|
78
|
+
valueFormatter,
|
|
79
|
+
tickInterval,
|
|
80
|
+
tickPlacement,
|
|
81
|
+
tickLabelPlacement,
|
|
82
|
+
direction: 'x',
|
|
83
|
+
groups
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// Skip axis rendering if no data is available
|
|
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) => {
|
|
102
|
+
const {
|
|
103
|
+
offset: tickOffset,
|
|
104
|
+
labelOffset
|
|
105
|
+
} = item;
|
|
106
|
+
const xTickLabel = labelOffset ?? 0;
|
|
107
|
+
const showTick = instance.isXInside(tickOffset);
|
|
108
|
+
const tickLabel = item.formattedValue;
|
|
109
|
+
const ignoreTick = item.ignoreTick ?? false;
|
|
110
|
+
const groupIndex = item.groupIndex ?? 0;
|
|
111
|
+
const groupConfig = getGroupingConfig(groups, groupIndex, tickSize);
|
|
112
|
+
const tickYSize = positionSign * groupConfig.tickSize;
|
|
113
|
+
const labelPositionY = positionSign * (groupConfig.tickSize + TICK_LABEL_GAP);
|
|
114
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
115
|
+
transform: `translate(${tickOffset}, 0)`,
|
|
116
|
+
className: classes.tickContainer,
|
|
117
|
+
"data-group-index": groupIndex,
|
|
118
|
+
children: [!disableTicks && !ignoreTick && showTick && /*#__PURE__*/_jsx(Tick, _extends({
|
|
119
|
+
y2: tickYSize,
|
|
120
|
+
className: classes.tick
|
|
121
|
+
}, slotProps?.axisTick)), tickLabel !== undefined && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
122
|
+
x: xTickLabel,
|
|
123
|
+
y: labelPositionY
|
|
124
|
+
}, axisTickLabelProps, {
|
|
125
|
+
text: tickLabel
|
|
126
|
+
}))]
|
|
127
|
+
}, index);
|
|
128
|
+
}), label && /*#__PURE__*/_jsx("g", {
|
|
129
|
+
className: classes.label,
|
|
130
|
+
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
131
|
+
text: label
|
|
132
|
+
}))
|
|
133
|
+
})]
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
export { ChartsGroupedXAxis };
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { useIsHydrated } from "../hooks/useIsHydrated.js";
|
|
6
|
+
import { getStringSize } from "../internals/domUtils.js";
|
|
7
|
+
import { useTicks } from "../hooks/useTicks.js";
|
|
8
|
+
import { useMounted } from "../hooks/useMounted.js";
|
|
9
|
+
import { useDrawingArea } from "../hooks/useDrawingArea.js";
|
|
10
|
+
import { useChartContext } from "../context/ChartProvider/useChartContext.js";
|
|
11
|
+
import { shortenLabels } from "./shortenLabels.js";
|
|
12
|
+
import { getVisibleLabels } from "./getVisibleLabels.js";
|
|
13
|
+
import { AXIS_LABEL_TICK_LABEL_GAP, TICK_LABEL_GAP, XAxisRoot } from "./utilities.js";
|
|
14
|
+
import { useAxisProps } from "./useAxisProps.js";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @ignore - internal component.
|
|
18
|
+
*/
|
|
19
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
20
|
+
function ChartsSingleXAxis(inProps) {
|
|
21
|
+
const {
|
|
22
|
+
xScale,
|
|
23
|
+
defaultizedProps,
|
|
24
|
+
tickNumber,
|
|
25
|
+
positionSign,
|
|
26
|
+
skipAxisRendering,
|
|
27
|
+
classes,
|
|
28
|
+
Line,
|
|
29
|
+
Tick,
|
|
30
|
+
TickLabel,
|
|
31
|
+
Label,
|
|
32
|
+
axisTickLabelProps,
|
|
33
|
+
axisLabelProps,
|
|
34
|
+
reverse,
|
|
35
|
+
isRtl
|
|
36
|
+
} = useAxisProps(inProps);
|
|
37
|
+
const isMounted = useMounted();
|
|
38
|
+
const {
|
|
39
|
+
position,
|
|
40
|
+
disableLine,
|
|
41
|
+
disableTicks,
|
|
42
|
+
label,
|
|
43
|
+
tickSize: tickSizeProp,
|
|
44
|
+
valueFormatter,
|
|
45
|
+
slotProps,
|
|
46
|
+
tickInterval,
|
|
47
|
+
tickLabelInterval,
|
|
48
|
+
tickPlacement,
|
|
49
|
+
tickLabelPlacement,
|
|
50
|
+
tickLabelMinGap,
|
|
51
|
+
sx,
|
|
52
|
+
offset,
|
|
53
|
+
height: axisHeight
|
|
54
|
+
} = defaultizedProps;
|
|
55
|
+
const drawingArea = useDrawingArea();
|
|
56
|
+
const {
|
|
57
|
+
left,
|
|
58
|
+
top,
|
|
59
|
+
width,
|
|
60
|
+
height
|
|
61
|
+
} = drawingArea;
|
|
62
|
+
const {
|
|
63
|
+
instance
|
|
64
|
+
} = useChartContext();
|
|
65
|
+
const isHydrated = useIsHydrated();
|
|
66
|
+
const tickSize = disableTicks ? 4 : tickSizeProp;
|
|
67
|
+
const xTicks = useTicks({
|
|
68
|
+
scale: xScale,
|
|
69
|
+
tickNumber,
|
|
70
|
+
valueFormatter,
|
|
71
|
+
tickInterval,
|
|
72
|
+
tickPlacement,
|
|
73
|
+
tickLabelPlacement,
|
|
74
|
+
direction: 'x'
|
|
75
|
+
});
|
|
76
|
+
const visibleLabels = getVisibleLabels(xTicks, {
|
|
77
|
+
tickLabelStyle: axisTickLabelProps.style,
|
|
78
|
+
tickLabelInterval,
|
|
79
|
+
tickLabelMinGap,
|
|
80
|
+
reverse,
|
|
81
|
+
isMounted,
|
|
82
|
+
isXInside: instance.isXInside
|
|
83
|
+
});
|
|
84
|
+
|
|
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
|
+
/* If there's an axis title, the tick labels have less space to render */
|
|
99
|
+
const tickLabelsMaxHeight = Math.max(0, axisHeight - (label ? labelHeight + AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - TICK_LABEL_GAP);
|
|
100
|
+
const tickLabels = isHydrated ? shortenLabels(visibleLabels, drawingArea, tickLabelsMaxHeight, isRtl, axisTickLabelProps.style) : new Map(Array.from(visibleLabels).map(item => [item, item.formattedValue]));
|
|
101
|
+
return /*#__PURE__*/_jsxs(XAxisRoot, {
|
|
102
|
+
transform: `translate(0, ${position === 'bottom' ? top + height + offset : top - offset})`,
|
|
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) => {
|
|
110
|
+
const {
|
|
111
|
+
offset: tickOffset,
|
|
112
|
+
labelOffset
|
|
113
|
+
} = item;
|
|
114
|
+
const xTickLabel = labelOffset ?? 0;
|
|
115
|
+
const yTickLabel = positionSign * (tickSize + TICK_LABEL_GAP);
|
|
116
|
+
const showTick = instance.isXInside(tickOffset);
|
|
117
|
+
const tickLabel = tickLabels.get(item);
|
|
118
|
+
const showTickLabel = visibleLabels.has(item);
|
|
119
|
+
return /*#__PURE__*/_jsxs("g", {
|
|
120
|
+
transform: `translate(${tickOffset}, 0)`,
|
|
121
|
+
className: classes.tickContainer,
|
|
122
|
+
children: [!disableTicks && showTick && /*#__PURE__*/_jsx(Tick, _extends({
|
|
123
|
+
y2: positionSign * tickSize,
|
|
124
|
+
className: classes.tick
|
|
125
|
+
}, slotProps?.axisTick)), tickLabel !== undefined && showTickLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
126
|
+
x: xTickLabel,
|
|
127
|
+
y: yTickLabel
|
|
128
|
+
}, axisTickLabelProps, {
|
|
129
|
+
text: tickLabel
|
|
130
|
+
}))]
|
|
131
|
+
}, index);
|
|
132
|
+
}), label && /*#__PURE__*/_jsx("g", {
|
|
133
|
+
className: classes.label,
|
|
134
|
+
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
135
|
+
text: label
|
|
136
|
+
}))
|
|
137
|
+
})]
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
export { ChartsSingleXAxis };
|
|
@@ -9,7 +9,7 @@ import { ChartsXAxisProps } from "../models/axis.js";
|
|
|
9
9
|
*
|
|
10
10
|
* - [ChartsXAxis API](https://mui.com/x/api/charts/charts-x-axis/)
|
|
11
11
|
*/
|
|
12
|
-
declare function ChartsXAxis(inProps: ChartsXAxisProps): React.JSX.Element
|
|
12
|
+
declare function ChartsXAxis(inProps: ChartsXAxisProps): React.JSX.Element;
|
|
13
13
|
declare namespace ChartsXAxis {
|
|
14
14
|
var propTypes: any;
|
|
15
15
|
}
|
|
@@ -1,62 +1,11 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
4
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
5
|
-
const _excluded = ["scale", "tickNumber", "reverse"];
|
|
6
4
|
import * as React from 'react';
|
|
7
5
|
import PropTypes from 'prop-types';
|
|
8
|
-
import useSlotProps from '@mui/utils/useSlotProps';
|
|
9
|
-
import composeClasses from '@mui/utils/composeClasses';
|
|
10
|
-
import { useThemeProps, useTheme, styled } from '@mui/material/styles';
|
|
11
|
-
import { useRtl } from '@mui/system/RtlProvider';
|
|
12
|
-
import { useIsHydrated } from "../hooks/useIsHydrated.js";
|
|
13
|
-
import { getStringSize } from "../internals/domUtils.js";
|
|
14
|
-
import { useTicks } from "../hooks/useTicks.js";
|
|
15
|
-
import { getAxisUtilityClass } from "../ChartsAxis/axisClasses.js";
|
|
16
|
-
import { AxisRoot } from "../internals/components/AxisSharedComponents.js";
|
|
17
|
-
import { ChartsText } from "../ChartsText/index.js";
|
|
18
|
-
import { useMounted } from "../hooks/useMounted.js";
|
|
19
|
-
import { useDrawingArea } from "../hooks/useDrawingArea.js";
|
|
20
|
-
import { isInfinity } from "../internals/isInfinity.js";
|
|
21
|
-
import { isBandScale } from "../internals/isBandScale.js";
|
|
22
|
-
import { useChartContext } from "../context/ChartProvider/useChartContext.js";
|
|
23
6
|
import { useXAxes } from "../hooks/useAxis.js";
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
26
|
-
import { shortenLabels } from "./shortenLabels.js";
|
|
27
|
-
import { getVisibleLabels } from "./getVisibleLabels.js";
|
|
28
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
29
|
-
const useUtilityClasses = ownerState => {
|
|
30
|
-
const {
|
|
31
|
-
classes,
|
|
32
|
-
position,
|
|
33
|
-
id
|
|
34
|
-
} = ownerState;
|
|
35
|
-
const slots = {
|
|
36
|
-
root: ['root', 'directionX', position, `id-${id}`],
|
|
37
|
-
line: ['line'],
|
|
38
|
-
tickContainer: ['tickContainer'],
|
|
39
|
-
tick: ['tick'],
|
|
40
|
-
tickLabel: ['tickLabel'],
|
|
41
|
-
label: ['label']
|
|
42
|
-
};
|
|
43
|
-
return composeClasses(slots, getAxisUtilityClass, classes);
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/* Gap between a tick and its label. */
|
|
47
|
-
const TICK_LABEL_GAP = 3;
|
|
48
|
-
/* Gap between the axis label and tick labels. */
|
|
49
|
-
const AXIS_LABEL_TICK_LABEL_GAP = 4;
|
|
50
|
-
const XAxisRoot = styled(AxisRoot, {
|
|
51
|
-
name: 'MuiChartsXAxis',
|
|
52
|
-
slot: 'Root'
|
|
53
|
-
})({});
|
|
54
|
-
const defaultProps = {
|
|
55
|
-
disableLine: false,
|
|
56
|
-
disableTicks: false,
|
|
57
|
-
tickSize: 6,
|
|
58
|
-
tickLabelMinGap: 4
|
|
59
|
-
};
|
|
7
|
+
import { ChartsSingleXAxis } from "./ChartsSingleXAxis.js";
|
|
8
|
+
import { ChartsGroupedXAxis } from "./ChartsGroupedXAxis.js";
|
|
60
9
|
|
|
61
10
|
/**
|
|
62
11
|
* Demos:
|
|
@@ -67,166 +16,17 @@ const defaultProps = {
|
|
|
67
16
|
*
|
|
68
17
|
* - [ChartsXAxis API](https://mui.com/x/api/charts/charts-x-axis/)
|
|
69
18
|
*/
|
|
19
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
70
20
|
function ChartsXAxis(inProps) {
|
|
71
21
|
const {
|
|
72
22
|
xAxis,
|
|
73
23
|
xAxisIds
|
|
74
24
|
} = useXAxes();
|
|
75
|
-
const
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
tickNumber,
|
|
79
|
-
reverse
|
|
80
|
-
} = _xAxis,
|
|
81
|
-
settings = _objectWithoutPropertiesLoose(_xAxis, _excluded);
|
|
82
|
-
const isMounted = useMounted();
|
|
83
|
-
const themedProps = useThemeProps({
|
|
84
|
-
props: _extends({}, settings, inProps),
|
|
85
|
-
name: 'MuiChartsXAxis'
|
|
86
|
-
});
|
|
87
|
-
const defaultizedProps = _extends({}, defaultProps, themedProps);
|
|
88
|
-
const {
|
|
89
|
-
position,
|
|
90
|
-
disableLine,
|
|
91
|
-
disableTicks,
|
|
92
|
-
tickLabelStyle,
|
|
93
|
-
label,
|
|
94
|
-
labelStyle,
|
|
95
|
-
tickSize: tickSizeProp,
|
|
96
|
-
valueFormatter,
|
|
97
|
-
slots,
|
|
98
|
-
slotProps,
|
|
99
|
-
tickInterval,
|
|
100
|
-
tickLabelInterval,
|
|
101
|
-
tickPlacement,
|
|
102
|
-
tickLabelPlacement,
|
|
103
|
-
tickLabelMinGap,
|
|
104
|
-
sx,
|
|
105
|
-
offset,
|
|
106
|
-
height: axisHeight
|
|
107
|
-
} = defaultizedProps;
|
|
108
|
-
const theme = useTheme();
|
|
109
|
-
const isRtl = useRtl();
|
|
110
|
-
const classes = useUtilityClasses(defaultizedProps);
|
|
111
|
-
const drawingArea = useDrawingArea();
|
|
112
|
-
const {
|
|
113
|
-
left,
|
|
114
|
-
top,
|
|
115
|
-
width,
|
|
116
|
-
height
|
|
117
|
-
} = drawingArea;
|
|
118
|
-
const {
|
|
119
|
-
instance
|
|
120
|
-
} = useChartContext();
|
|
121
|
-
const isHydrated = useIsHydrated();
|
|
122
|
-
const tickSize = disableTicks ? 4 : tickSizeProp;
|
|
123
|
-
const positionSign = position === 'bottom' ? 1 : -1;
|
|
124
|
-
const Line = slots?.axisLine ?? 'line';
|
|
125
|
-
const Tick = slots?.axisTick ?? 'line';
|
|
126
|
-
const TickLabel = slots?.axisTickLabel ?? ChartsText;
|
|
127
|
-
const Label = slots?.axisLabel ?? ChartsText;
|
|
128
|
-
const defaultTextAnchor = getDefaultTextAnchor((position === 'bottom' ? 0 : 180) - (tickLabelStyle?.angle ?? 0));
|
|
129
|
-
const defaultDominantBaseline = getDefaultBaseline((position === 'bottom' ? 0 : 180) - (tickLabelStyle?.angle ?? 0));
|
|
130
|
-
const axisTickLabelProps = useSlotProps({
|
|
131
|
-
elementType: TickLabel,
|
|
132
|
-
externalSlotProps: slotProps?.axisTickLabel,
|
|
133
|
-
additionalProps: {
|
|
134
|
-
style: _extends({}, theme.typography.caption, {
|
|
135
|
-
fontSize: 12,
|
|
136
|
-
lineHeight: 1.25,
|
|
137
|
-
textAnchor: isRtl ? invertTextAnchor(defaultTextAnchor) : defaultTextAnchor,
|
|
138
|
-
dominantBaseline: defaultDominantBaseline
|
|
139
|
-
}, tickLabelStyle)
|
|
140
|
-
},
|
|
141
|
-
className: classes.tickLabel,
|
|
142
|
-
ownerState: {}
|
|
143
|
-
});
|
|
144
|
-
const xTicks = useTicks({
|
|
145
|
-
scale: xScale,
|
|
146
|
-
tickNumber,
|
|
147
|
-
valueFormatter,
|
|
148
|
-
tickInterval,
|
|
149
|
-
tickPlacement,
|
|
150
|
-
tickLabelPlacement,
|
|
151
|
-
direction: 'x'
|
|
152
|
-
});
|
|
153
|
-
const visibleLabels = getVisibleLabels(xTicks, {
|
|
154
|
-
tickLabelStyle: axisTickLabelProps.style,
|
|
155
|
-
tickLabelInterval,
|
|
156
|
-
tickLabelMinGap,
|
|
157
|
-
reverse,
|
|
158
|
-
isMounted,
|
|
159
|
-
isXInside: instance.isXInside
|
|
160
|
-
});
|
|
161
|
-
const axisLabelProps = useSlotProps({
|
|
162
|
-
elementType: Label,
|
|
163
|
-
externalSlotProps: slotProps?.axisLabel,
|
|
164
|
-
additionalProps: {
|
|
165
|
-
style: _extends({}, theme.typography.body1, {
|
|
166
|
-
lineHeight: 1,
|
|
167
|
-
fontSize: 14,
|
|
168
|
-
textAnchor: 'middle',
|
|
169
|
-
dominantBaseline: position === 'bottom' ? 'text-after-edge' : 'text-before-edge'
|
|
170
|
-
}, labelStyle)
|
|
171
|
-
},
|
|
172
|
-
ownerState: {}
|
|
173
|
-
});
|
|
174
|
-
const domain = xScale.domain();
|
|
175
|
-
const ordinalAxis = isBandScale(xScale);
|
|
176
|
-
// Skip axis rendering if no data is available
|
|
177
|
-
// - The domain is an empty array for band/point scales.
|
|
178
|
-
// - The domains contains Infinity for continuous scales.
|
|
179
|
-
// - The position is set to 'none'.
|
|
180
|
-
if (ordinalAxis && domain.length === 0 || !ordinalAxis && domain.some(isInfinity) || position === 'none') {
|
|
181
|
-
return null;
|
|
25
|
+
const axis = xAxis[inProps.axisId ?? xAxisIds[0]];
|
|
26
|
+
if ('groups' in axis && Array.isArray(axis.groups)) {
|
|
27
|
+
return /*#__PURE__*/_jsx(ChartsGroupedXAxis, _extends({}, inProps));
|
|
182
28
|
}
|
|
183
|
-
|
|
184
|
-
const labelRefPoint = {
|
|
185
|
-
x: left + width / 2,
|
|
186
|
-
y: positionSign * axisHeight
|
|
187
|
-
};
|
|
188
|
-
|
|
189
|
-
/* If there's an axis title, the tick labels have less space to render */
|
|
190
|
-
const tickLabelsMaxHeight = Math.max(0, axisHeight - (label ? labelHeight + AXIS_LABEL_TICK_LABEL_GAP : 0) - tickSize - TICK_LABEL_GAP);
|
|
191
|
-
const tickLabels = isHydrated ? shortenLabels(visibleLabels, drawingArea, tickLabelsMaxHeight, isRtl, axisTickLabelProps.style) : new Map(Array.from(visibleLabels).map(item => [item, item.formattedValue]));
|
|
192
|
-
return /*#__PURE__*/_jsxs(XAxisRoot, {
|
|
193
|
-
transform: `translate(0, ${position === 'bottom' ? top + height + offset : top - offset})`,
|
|
194
|
-
className: classes.root,
|
|
195
|
-
sx: sx,
|
|
196
|
-
children: [!disableLine && /*#__PURE__*/_jsx(Line, _extends({
|
|
197
|
-
x1: left,
|
|
198
|
-
x2: left + width,
|
|
199
|
-
className: classes.line
|
|
200
|
-
}, slotProps?.axisLine)), xTicks.map((item, index) => {
|
|
201
|
-
const {
|
|
202
|
-
offset: tickOffset,
|
|
203
|
-
labelOffset
|
|
204
|
-
} = item;
|
|
205
|
-
const xTickLabel = labelOffset ?? 0;
|
|
206
|
-
const yTickLabel = positionSign * (tickSize + TICK_LABEL_GAP);
|
|
207
|
-
const showTick = instance.isXInside(tickOffset);
|
|
208
|
-
const tickLabel = tickLabels.get(item);
|
|
209
|
-
const showTickLabel = visibleLabels.has(item);
|
|
210
|
-
return /*#__PURE__*/_jsxs("g", {
|
|
211
|
-
transform: `translate(${tickOffset}, 0)`,
|
|
212
|
-
className: classes.tickContainer,
|
|
213
|
-
children: [!disableTicks && showTick && /*#__PURE__*/_jsx(Tick, _extends({
|
|
214
|
-
y2: positionSign * tickSize,
|
|
215
|
-
className: classes.tick
|
|
216
|
-
}, slotProps?.axisTick)), tickLabel !== undefined && showTickLabel && /*#__PURE__*/_jsx(TickLabel, _extends({
|
|
217
|
-
x: xTickLabel,
|
|
218
|
-
y: yTickLabel
|
|
219
|
-
}, axisTickLabelProps, {
|
|
220
|
-
text: tickLabel
|
|
221
|
-
}))]
|
|
222
|
-
}, index);
|
|
223
|
-
}), label && /*#__PURE__*/_jsx("g", {
|
|
224
|
-
className: classes.label,
|
|
225
|
-
children: /*#__PURE__*/_jsx(Label, _extends({}, labelRefPoint, axisLabelProps, {
|
|
226
|
-
text: label
|
|
227
|
-
}))
|
|
228
|
-
})]
|
|
229
|
-
});
|
|
29
|
+
return /*#__PURE__*/_jsx(ChartsSingleXAxis, _extends({}, inProps));
|
|
230
30
|
}
|
|
231
31
|
process.env.NODE_ENV !== "production" ? ChartsXAxis.propTypes = {
|
|
232
32
|
// ----------------------------- Warning --------------------------------
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { TickItemType } from "../hooks/useTicks.js";
|
|
2
2
|
import { ChartsXAxisProps, ComputedXAxis } from "../models/axis.js";
|
|
3
|
-
export declare function getVisibleLabels(xTicks:
|
|
3
|
+
export declare function getVisibleLabels<T extends TickItemType>(xTicks: T[], {
|
|
4
4
|
tickLabelStyle: style,
|
|
5
5
|
tickLabelInterval,
|
|
6
6
|
tickLabelMinGap,
|
|
@@ -11,4 +11,4 @@ export declare function getVisibleLabels(xTicks: TickItemType[], {
|
|
|
11
11
|
isMounted: boolean;
|
|
12
12
|
tickLabelMinGap: NonNullable<ChartsXAxisProps['tickLabelMinGap']>;
|
|
13
13
|
isXInside: (x: number) => boolean;
|
|
14
|
-
}): Set<
|
|
14
|
+
}): Set<T>;
|