Skip to content

Commit

Permalink
Remove redundant isPointInside check
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardobelchior committed Feb 20, 2025
1 parent 0c490da commit 37c1fbb
Showing 1 changed file with 34 additions and 41 deletions.
75 changes: 34 additions & 41 deletions packages/x-charts/src/ChartsXAxis/ChartsXAxis.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,7 @@ function ChartsXAxis(inProps: ChartsXAxisProps) {
tickLabelMinGap,
reverse,
isMounted,
isPointInside: (offset: number) =>
instance.isPointInside({ x: offset, y: -1 }, { direction: 'x' }),
isPointInside: (x: number) => instance.isPointInside({ x, y: -1 }, { direction: 'x' }),
});

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

{xTicks.map(
(item, index) => {
const { formattedValue, offset: tickOffset, labelOffset } = item;
const xTickLabel = labelOffset ?? 0;
const yTickLabel = positionSign * (tickSize + 3);

const showTick = instance.isPointInside({ x: tickOffset, y: -1 }, { direction: 'x' });
const showTickLabel = instance.isPointInside(
{ x: tickOffset + xTickLabel, y: -1 },
{ direction: 'x' },
);
const skipLabel = !visibleLabels.has(item);

return (
<g
key={index}
transform={`translate(${tickOffset}, 0)`}
className={classes.tickContainer}
>
{!disableTicks && showTick && (
<Tick
y2={positionSign * tickSize}
className={classes.tick}
{...slotProps?.axisTick}
/>
)}

{formattedValue !== undefined && !skipLabel && showTickLabel && (
<TickLabel
x={xTickLabel}
y={yTickLabel}
{...axisTickLabelProps}
text={formattedValue.toString()}
/>
)}
</g>
);
},
)}
{xTicks.map((item, index) => {
const { formattedValue, offset: tickOffset, labelOffset } = item;
const xTickLabel = labelOffset ?? 0;
const yTickLabel = positionSign * (tickSize + 3);

const showTick = instance.isPointInside({ x: tickOffset, y: -1 }, { direction: 'x' });
const showTickLabel = visibleLabels.has(item);

return (
<g
key={index}
transform={`translate(${tickOffset}, 0)`}
className={classes.tickContainer}
>
{!disableTicks && showTick && (
<Tick
y2={positionSign * tickSize}
className={classes.tick}
{...slotProps?.axisTick}
/>
)}

{formattedValue !== undefined && showTickLabel && (
<TickLabel
x={xTickLabel}
y={yTickLabel}
{...axisTickLabelProps}
text={formattedValue.toString()}
/>
)}
</g>
);
})}

{label && (
<g className={classes.label}>
Expand Down

0 comments on commit 37c1fbb

Please # to comment.