@@ -5,6 +5,7 @@ import useSlotProps from '@mui/utils/useSlotProps';
5
5
import composeClasses from '@mui/utils/composeClasses' ;
6
6
import { useThemeProps , styled , useTheme } from '@mui/material/styles' ;
7
7
import { useRtl } from '@mui/system/RtlProvider' ;
8
+ import { getDefaultBaseline , getDefaultTextAnchor } from '../ChartsText/defaultTextPlacement' ;
8
9
import { ellipsize } from '../internals/ellipsize' ;
9
10
import { useIsClient } from '../hooks/useIsClient' ;
10
11
import { getStringSize } from '../internals/domUtils' ;
@@ -94,41 +95,6 @@ function shortenLabels(
94
95
return shortenedLabels ;
95
96
}
96
97
97
- function getDefaultTextAnchor ( angle : number ) : ChartsTextStyle [ 'textAnchor' ] {
98
- const adjustedAngle = clampAngle ( angle ) ;
99
-
100
- if ( adjustedAngle === 90 || adjustedAngle === 270 ) {
101
- return 'middle' ;
102
- }
103
-
104
- if ( adjustedAngle < 90 ) {
105
- return 'end' ;
106
- }
107
-
108
- if ( adjustedAngle < 270 ) {
109
- return 'start' ;
110
- }
111
-
112
- return 'end' ;
113
- }
114
-
115
- function getDefaultBaseline (
116
- angle : number ,
117
- position : 'left' | 'right' | 'none' | undefined ,
118
- ) : ChartsTextStyle [ 'dominantBaseline' ] {
119
- const adjustedAngle = clampAngle ( angle ) ;
120
-
121
- if ( adjustedAngle === 90 || adjustedAngle === 270 ) {
122
- return position === 'left' ? 'auto' : 'hanging' ;
123
- }
124
-
125
- if ( adjustedAngle > 270 ) {
126
- return position === 'left' ? 'auto' : 'hanging' ;
127
- }
128
-
129
- return 'central' ;
130
- }
131
-
132
98
function invertTextAnchor (
133
99
textAnchor : ChartsTextStyle [ 'textAnchor' ] ,
134
100
) : ChartsTextStyle [ 'textAnchor' ] {
@@ -224,20 +190,22 @@ function ChartsYAxis(inProps: ChartsYAxisProps) {
224
190
const TickLabel = slots ?. axisTickLabel ?? ChartsText ;
225
191
const Label = slots ?. axisLabel ?? ChartsText ;
226
192
227
- const defaultTextAnchor = getDefaultTextAnchor ( tickLabelStyle ?. angle ?? 0 ) ;
228
- const shouldInvertTextAnchor =
229
- ( isRtl && position !== 'right' ) || ( ! isRtl && position === 'right' ) ;
193
+ const defaultTextAnchor = getDefaultTextAnchor (
194
+ ( position === 'right' ? - 90 : 90 ) - ( tickLabelStyle ?. angle ?? 0 ) ,
195
+ ) ;
196
+ const defaultDominantBaseline = getDefaultBaseline (
197
+ ( position === 'right' ? - 90 : 90 ) - ( tickLabelStyle ?. angle ?? 0 ) ,
198
+ ) ;
199
+
230
200
const axisTickLabelProps = useSlotProps ( {
231
201
elementType : TickLabel ,
232
202
externalSlotProps : slotProps ?. axisTickLabel ,
233
203
additionalProps : {
234
204
style : {
235
205
...theme . typography . caption ,
236
206
fontSize : tickFontSize ,
237
- textAnchor : shouldInvertTextAnchor
238
- ? invertTextAnchor ( defaultTextAnchor )
239
- : defaultTextAnchor ,
240
- dominantBaseline : getDefaultBaseline ( tickLabelStyle ?. angle ?? 0 , position ) ,
207
+ textAnchor : isRtl ? invertTextAnchor ( defaultTextAnchor ) : defaultTextAnchor ,
208
+ dominantBaseline : defaultDominantBaseline ,
241
209
...tickLabelStyle ,
242
210
} ,
243
211
} as Partial < ChartsTextProps > ,
0 commit comments