@@ -5,6 +5,7 @@ import useSlotProps from '@mui/utils/useSlotProps';
5
5
import composeClasses from '@mui/utils/composeClasses' ;
6
6
import { useThemeProps , useTheme , styled } from '@mui/material/styles' ;
7
7
import { useRtl } from '@mui/system/RtlProvider' ;
8
+ import { getDefaultBaseline , getDefaultTextAnchor } from '../ChartsText/defaultTextPlacement' ;
8
9
import { clampAngle } from '../internals/clampAngle' ;
9
10
import { useIsClient } from '../hooks/useIsClient' ;
10
11
import { ellipsize } from '../internals/ellipsize' ;
@@ -13,7 +14,7 @@ import { useTicks, TickItemType } from '../hooks/useTicks';
13
14
import { AxisConfig , AxisDefaultized , ChartsXAxisProps , ScaleName } from '../models/axis' ;
14
15
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses' ;
15
16
import { AxisRoot } from '../internals/components/AxisSharedComponents' ;
16
- import { ChartsText , ChartsTextProps , ChartsTextStyle } from '../ChartsText' ;
17
+ import { ChartsText , ChartsTextProps } from '../ChartsText' ;
17
18
import { getMinXTranslation } from '../internals/geometry' ;
18
19
import { useMounted } from '../hooks/useMounted' ;
19
20
import { ChartDrawingArea , useDrawingArea } from '../hooks/useDrawingArea' ;
@@ -118,37 +119,6 @@ function getVisibleLabels(
118
119
) ;
119
120
}
120
121
121
- function getDefaultTextAnchor ( angle : number ) : ChartsTextStyle [ 'textAnchor' ] {
122
- const adjustedAngle = clampAngle ( angle ) ;
123
-
124
- if ( adjustedAngle === 0 || adjustedAngle === 180 ) {
125
- return 'middle' ;
126
- }
127
-
128
- if ( adjustedAngle < 180 ) {
129
- return 'start' ;
130
- }
131
-
132
- return 'end' ;
133
- }
134
-
135
- function getDefaultBaseline (
136
- angle : number ,
137
- position : 'top' | 'bottom' | 'none' | undefined ,
138
- ) : ChartsTextStyle [ 'dominantBaseline' ] {
139
- const adjustedAngle = clampAngle ( angle ) ;
140
-
141
- if ( adjustedAngle === 0 ) {
142
- return position === 'bottom' ? 'hanging' : 'auto' ;
143
- }
144
-
145
- if ( adjustedAngle === 180 ) {
146
- return position === 'bottom' ? 'auto' : 'hanging' ;
147
- }
148
-
149
- return 'central' ;
150
- }
151
-
152
122
function shortenLabels (
153
123
visibleLabels : Set < TickItemType > ,
154
124
drawingArea : Pick < ChartDrawingArea , 'left' | 'width' | 'right' > ,
@@ -277,8 +247,13 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
277
247
const TickLabel = slots ?. axisTickLabel ?? ChartsText ;
278
248
const Label = slots ?. axisLabel ?? ChartsText ;
279
249
280
- const defaultTextAnchor = getDefaultTextAnchor ( tickLabelStyle ?. angle ?? 0 ) ;
281
- const shouldInvertTextAnchor = ( isRtl && position !== 'top' ) || ( ! isRtl && position === 'top' ) ;
250
+ const defaultTextAnchor = getDefaultTextAnchor (
251
+ ( position === 'bottom' ? 0 : 180 ) - ( tickLabelStyle ?. angle ?? 0 ) ,
252
+ ) ;
253
+ const defaultDominantBaseline = getDefaultBaseline (
254
+ ( position === 'bottom' ? 0 : 180 ) - ( tickLabelStyle ?. angle ?? 0 ) ,
255
+ ) ;
256
+
282
257
const axisTickLabelProps = useSlotProps ( {
283
258
elementType : TickLabel ,
284
259
externalSlotProps : slotProps ?. axisTickLabel ,
@@ -287,10 +262,8 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
287
262
...theme . typography . caption ,
288
263
fontSize : 12 ,
289
264
lineHeight : 1.25 ,
290
- textAnchor : shouldInvertTextAnchor
291
- ? invertTextAnchor ( defaultTextAnchor )
292
- : defaultTextAnchor ,
293
- dominantBaseline : getDefaultBaseline ( tickLabelStyle ?. angle ?? 0 , position ) ,
265
+ textAnchor : isRtl ? invertTextAnchor ( defaultTextAnchor ) : defaultTextAnchor ,
266
+ dominantBaseline : defaultDominantBaseline ,
294
267
...tickLabelStyle ,
295
268
} ,
296
269
} as Partial < ChartsTextProps > ,
0 commit comments