@@ -4,6 +4,7 @@ import PropTypes from 'prop-types';
4
4
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
+ import { ChartInstance } from '@mui/x-charts/internals' ;
7
8
import { useTicks , TickItemType } from '../hooks/useTicks' ;
8
9
import { AxisDefaultized , ChartsXAxisProps } from '../models/axis' ;
9
10
import { getAxisUtilityClass } from '../ChartsAxis/axisClasses' ;
@@ -41,8 +42,12 @@ function addLabelDimension(
41
42
tickLabelInterval,
42
43
reverse,
43
44
isMounted,
45
+ isPointInside,
44
46
} : Pick < ChartsXAxisProps , 'tickLabelInterval' | 'tickLabelStyle' > &
45
- Pick < AxisDefaultized , 'reverse' > & { isMounted : boolean } ,
47
+ Pick < AxisDefaultized , 'reverse' > & {
48
+ isMounted : boolean ;
49
+ isPointInside : ChartInstance < unknown > [ 'isPointInside' ] ;
50
+ } ,
46
51
) : ( TickItemType & LabelExtraData ) [ ] {
47
52
const getTickSize = ( tick : TickItemType ) => {
48
53
if ( ! isMounted || tick . formattedValue === undefined ) {
@@ -78,6 +83,10 @@ function addLabelDimension(
78
83
return { ...item , width : 0 , height : 0 , skipLabel : true } ;
79
84
}
80
85
86
+ if ( ! isPointInside ( { x : textPosition , y : - 1 } , { direction : 'x' } ) ) {
87
+ return { ...item , width : 0 , height : 0 , skipLabel : true } ;
88
+ }
89
+
81
90
const { width, height } = getTickSize ( item ) ;
82
91
83
92
const distance = getMinXTranslation ( width , height , style ?. angle ) ;
@@ -190,6 +199,12 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
190
199
tickLabelInterval,
191
200
reverse,
192
201
isMounted,
202
+ isPointInside : instance . isPointInside ,
203
+ } ) ;
204
+
205
+ console . log ( {
206
+ xTicksWithDimension,
207
+ measuredTicks : xTicksWithDimension . filter ( ( { width } ) => width > 0 ) ,
193
208
} ) ;
194
209
195
210
const labelRefPoint = {
0 commit comments