@@ -37,80 +37,63 @@ 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,
42
43
// FIXME: Define the default value in the correct place
43
44
minTickLabelGap = 8 ,
44
45
reverse,
45
46
isMounted,
46
- isPointInside,
47
47
} : Pick < ChartsXAxisProps , 'tickLabelInterval' | 'tickLabelStyle' > &
48
48
Pick < AxisDefaultized < ScaleName , any , ChartsXAxisProps > , 'reverse' | 'minTickLabelGap' > & {
49
+ tickLabelClassName ?: string ;
49
50
isMounted : boolean ;
50
- isPointInside : ( position : number ) => boolean ;
51
51
} ,
52
52
) : ( TickItemType & LabelExtraData ) [ ] {
53
- const getTickLabelSize = ( tick : TickItemType ) => {
53
+ const withDimension = xTicks . map ( ( tick ) => {
54
54
if ( ! isMounted || tick . formattedValue === undefined ) {
55
- return { width : 0 , height : 0 } ;
55
+ return { ... tick , width : 0 , height : 0 } ;
56
56
}
57
-
58
- const tickSizes = getWordsByLines ( { style, needsComputation : true , text : tick . formattedValue } ) ;
59
-
57
+ const tickSizes = getWordsByLines ( {
58
+ className,
59
+ style,
60
+ needsComputation : true ,
61
+ text : tick . formattedValue ,
62
+ } ) ;
60
63
return {
64
+ ...tick ,
61
65
width : Math . max ( ...tickSizes . map ( ( size ) => size . width ) ) ,
62
66
height : Math . max ( tickSizes . length * tickSizes [ 0 ] . height ) ,
63
67
} ;
64
- } ;
68
+ } ) ;
65
69
66
70
if ( typeof tickLabelInterval === 'function' ) {
67
- return xTicks . map ( ( item , index ) => {
68
- const skipLabel = ! tickLabelInterval ( item . value , index ) ;
69
- const size = skipLabel ? { width : 0 , height : 0 } : getTickLabelSize ( item ) ;
70
-
71
- return {
72
- ...item ,
73
- ...size ,
74
- skipLabel,
75
- } ;
76
- } ) ;
71
+ return withDimension . map ( ( item , index ) => ( {
72
+ ...item ,
73
+ skipLabel : ! tickLabelInterval ( item . value , index ) ,
74
+ } ) ) ;
77
75
}
78
76
79
77
// Filter label to avoid overlap
80
78
let previousTextLimit = 0 ;
81
79
const direction = reverse ? - 1 : 1 ;
82
-
83
- return xTicks . map ( ( item , labelIndex ) => {
84
- const { offset, labelOffset } = item ;
85
- const textPosition = offset + labelOffset ;
86
-
87
- if (
88
- labelIndex > 0 &&
89
- direction * ( textPosition - minTickLabelGap ) < direction * previousTextLimit
90
- ) {
91
- return { ...item , width : 0 , height : 0 , skipLabel : true } ;
92
- }
93
-
94
- if ( ! isPointInside ( textPosition ) ) {
95
- return { ...item , width : 0 , height : 0 , skipLabel : true } ;
96
- }
97
-
98
- const { width, height } = getTickLabelSize ( item ) ;
80
+ return withDimension . map ( ( item , labelIndex ) => {
81
+ const { width, offset, labelOffset, height } = item ;
99
82
100
83
const distance = getMinXTranslation ( width , height , style ?. angle ) ;
84
+ const textPosition = offset + labelOffset ;
101
85
102
86
const currentTextLimit = textPosition - ( direction * distance ) / 2 ;
103
87
if (
104
88
labelIndex > 0 &&
105
- direction * ( currentTextLimit - minTickLabelGap ) < direction * previousTextLimit
89
+ direction * currentTextLimit < direction * ( previousTextLimit + minTickLabelGap )
106
90
) {
107
91
// Except for the first label, we skip all label that overlap with the last accepted.
108
92
// Notice that the early return prevents `previousTextLimit` from being updated.
109
- return { ...item , width , height , skipLabel : true } ;
93
+ return { ...item , skipLabel : true } ;
110
94
}
111
-
112
95
previousTextLimit = textPosition + ( direction * distance ) / 2 ;
113
- return { ... item , width , height } ;
96
+ return item ;
114
97
} ) ;
115
98
}
116
99
@@ -186,6 +169,11 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
186
169
externalSlotProps : slotProps ?. axisTickLabel ,
187
170
additionalProps : {
188
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)' ,
189
177
fontSize : 12 ,
190
178
textAnchor : 'middle' ,
191
179
dominantBaseline : position === 'bottom' ? 'hanging' : 'auto' ,
@@ -206,12 +194,11 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
206
194
} ) ;
207
195
208
196
const xTicksWithDimension = addLabelDimension ( xTicks , {
197
+ tickLabelClassName : axisTickLabelProps . className ,
209
198
tickLabelStyle : axisTickLabelProps . style ,
210
199
tickLabelInterval,
211
200
reverse,
212
201
isMounted,
213
- isPointInside : ( offset : number ) =>
214
- instance . isPointInside ( { x : offset , y : - 1 } , { direction : 'x' } ) ,
215
202
} ) ;
216
203
217
204
const labelRefPoint = {
0 commit comments