Skip to content

Commit 37c1fbb

Browse files
Remove redundant isPointInside check
1 parent 0c490da commit 37c1fbb

File tree

1 file changed

+34
-41
lines changed

1 file changed

+34
-41
lines changed

packages/x-charts/src/ChartsXAxis/ChartsXAxis.tsx

+34-41
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
207207
tickLabelMinGap,
208208
reverse,
209209
isMounted,
210-
isPointInside: (offset: number) =>
211-
instance.isPointInside({ x: offset, y: -1 }, { direction: 'x' }),
210+
isPointInside: (x: number) => instance.isPointInside({ x, y: -1 }, { direction: 'x' }),
212211
});
213212

214213
const labelRefPoint = {
@@ -248,45 +247,39 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
248247
<Line x1={left} x2={left + width} className={classes.line} {...slotProps?.axisLine} />
249248
)}
250249

251-
{xTicks.map(
252-
(item, index) => {
253-
const { formattedValue, offset: tickOffset, labelOffset } = item;
254-
const xTickLabel = labelOffset ?? 0;
255-
const yTickLabel = positionSign * (tickSize + 3);
256-
257-
const showTick = instance.isPointInside({ x: tickOffset, y: -1 }, { direction: 'x' });
258-
const showTickLabel = instance.isPointInside(
259-
{ x: tickOffset + xTickLabel, y: -1 },
260-
{ direction: 'x' },
261-
);
262-
const skipLabel = !visibleLabels.has(item);
263-
264-
return (
265-
<g
266-
key={index}
267-
transform={`translate(${tickOffset}, 0)`}
268-
className={classes.tickContainer}
269-
>
270-
{!disableTicks && showTick && (
271-
<Tick
272-
y2={positionSign * tickSize}
273-
className={classes.tick}
274-
{...slotProps?.axisTick}
275-
/>
276-
)}
277-
278-
{formattedValue !== undefined && !skipLabel && showTickLabel && (
279-
<TickLabel
280-
x={xTickLabel}
281-
y={yTickLabel}
282-
{...axisTickLabelProps}
283-
text={formattedValue.toString()}
284-
/>
285-
)}
286-
</g>
287-
);
288-
},
289-
)}
250+
{xTicks.map((item, index) => {
251+
const { formattedValue, offset: tickOffset, labelOffset } = item;
252+
const xTickLabel = labelOffset ?? 0;
253+
const yTickLabel = positionSign * (tickSize + 3);
254+
255+
const showTick = instance.isPointInside({ x: tickOffset, y: -1 }, { direction: 'x' });
256+
const showTickLabel = visibleLabels.has(item);
257+
258+
return (
259+
<g
260+
key={index}
261+
transform={`translate(${tickOffset}, 0)`}
262+
className={classes.tickContainer}
263+
>
264+
{!disableTicks && showTick && (
265+
<Tick
266+
y2={positionSign * tickSize}
267+
className={classes.tick}
268+
{...slotProps?.axisTick}
269+
/>
270+
)}
271+
272+
{formattedValue !== undefined && showTickLabel && (
273+
<TickLabel
274+
x={xTickLabel}
275+
y={yTickLabel}
276+
{...axisTickLabelProps}
277+
text={formattedValue.toString()}
278+
/>
279+
)}
280+
</g>
281+
);
282+
})}
290283

291284
{label && (
292285
<g className={classes.label}>

0 commit comments

Comments
 (0)