@@ -5,7 +5,7 @@ import useSlotProps from '@mui/utils/useSlotProps';
5
5
import composeClasses from '@mui/utils/composeClasses' ;
6
6
import { useThemeProps , useTheme , Theme , styled } from '@mui/material/styles' ;
7
7
import { useTicks , TickItemType } from '../hooks/useTicks' ;
8
- import { AxisDefaultized , ChartsXAxisProps } from '../models/axis' ;
8
+ import { AxisDefaultized , ChartsXAxisProps , ScaleName } from '../models/axis' ;
9
9
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses' ;
10
10
import { AxisRoot } from '../internals/components/AxisSharedComponents' ;
11
11
import { ChartsText , ChartsTextProps } from '../ChartsText' ;
@@ -37,18 +37,29 @@ type LabelExtraData = { width: number; height: number; skipLabel?: boolean };
37
37
function addLabelDimension (
38
38
xTicks : TickItemType [ ] ,
39
39
{
40
+ tickLabelClassName : className ,
40
41
tickLabelStyle : style ,
41
42
tickLabelInterval,
43
+ // FIXME: Define the default value in the correct place
44
+ minTickLabelGap = 8 ,
42
45
reverse,
43
46
isMounted,
44
47
} : Pick < ChartsXAxisProps , 'tickLabelInterval' | 'tickLabelStyle' > &
45
- Pick < AxisDefaultized , 'reverse' > & { isMounted : boolean } ,
48
+ Pick < AxisDefaultized < ScaleName , any , ChartsXAxisProps > , 'reverse' | 'minTickLabelGap' > & {
49
+ tickLabelClassName ?: string ;
50
+ isMounted : boolean ;
51
+ } ,
46
52
) : ( TickItemType & LabelExtraData ) [ ] {
47
53
const withDimension = xTicks . map ( ( tick ) => {
48
54
if ( ! isMounted || tick . formattedValue === undefined ) {
49
55
return { ...tick , width : 0 , height : 0 } ;
50
56
}
51
- const tickSizes = getWordsByLines ( { style, needsComputation : true , text : tick . formattedValue } ) ;
57
+ const tickSizes = getWordsByLines ( {
58
+ className,
59
+ style,
60
+ needsComputation : true ,
61
+ text : tick . formattedValue ,
62
+ } ) ;
52
63
return {
53
64
...tick ,
54
65
width : Math . max ( ...tickSizes . map ( ( size ) => size . width ) ) ,
@@ -64,23 +75,24 @@ function addLabelDimension(
64
75
}
65
76
66
77
// Filter label to avoid overlap
67
- let currentTextLimit = 0 ;
68
78
let previousTextLimit = 0 ;
69
79
const direction = reverse ? - 1 : 1 ;
70
80
return withDimension . map ( ( item , labelIndex ) => {
71
81
const { width, offset, labelOffset, height } = item ;
72
82
73
83
const distance = getMinXTranslation ( width , height , style ?. angle ) ;
74
84
const textPosition = offset + labelOffset ;
75
- const gapRatio = 1.2 ; // Ratio applied to the minimal distance to add some margin.
76
85
77
- currentTextLimit = textPosition - ( direction * ( gapRatio * distance ) ) / 2 ;
78
- if ( labelIndex > 0 && direction * currentTextLimit < direction * previousTextLimit ) {
86
+ const currentTextLimit = textPosition - ( direction * distance ) / 2 ;
87
+ if (
88
+ labelIndex > 0 &&
89
+ direction * currentTextLimit < direction * ( previousTextLimit + minTickLabelGap )
90
+ ) {
79
91
// Except for the first label, we skip all label that overlap with the last accepted.
80
92
// Notice that the early return prevents `previousTextLimit` from being updated.
81
93
return { ...item , skipLabel : true } ;
82
94
}
83
- previousTextLimit = textPosition + ( direction * ( gapRatio * distance ) ) / 2 ;
95
+ previousTextLimit = textPosition + ( direction * distance ) / 2 ;
84
96
return item ;
85
97
} ) ;
86
98
}
@@ -157,6 +169,11 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
157
169
externalSlotProps : slotProps ?. axisTickLabel ,
158
170
additionalProps : {
159
171
style : {
172
+ fontFamily : '"Roboto", "Helvetica", "Arial", sans-serif' ,
173
+ fontWeight : 400 ,
174
+ lineHeight : 1.66 ,
175
+ letterSpacing : '0.03333em' ,
176
+ fill : 'rgba(0, 0, 0, 0.87)' ,
160
177
fontSize : 12 ,
161
178
textAnchor : 'middle' ,
162
179
dominantBaseline : position === 'bottom' ? 'hanging' : 'auto' ,
@@ -177,6 +194,7 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
177
194
} ) ;
178
195
179
196
const xTicksWithDimension = addLabelDimension ( xTicks , {
197
+ tickLabelClassName : axisTickLabelProps . className ,
180
198
tickLabelStyle : axisTickLabelProps . style ,
181
199
tickLabelInterval,
182
200
reverse,
0 commit comments