Skip to content

Commit 4b11f10

Browse files
authored
Merge pull request Expensify#81669 from software-mansion-labs/borys3kk-fix-point-cut-off
Fix points clipping
2 parents 21ec003 + f691588 commit 4b11f10

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

src/components/Charts/LineChart/LineChartContent.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ const DOT_RADIUS = 6;
2525
/** Extra hover area beyond the dot radius for easier touch targeting */
2626
const DOT_HOVER_EXTRA_RADIUS = 2;
2727

28+
/** Minimum safe padding to avoid clipping labels/points */
29+
const MIN_SAFE_PADDING = DOT_RADIUS + DOT_HOVER_EXTRA_RADIUS;
30+
2831
/** Base domain padding applied to all sides */
2932
const BASE_DOMAIN_PADDING = {top: 16, bottom: 16, left: 0, right: 0};
3033

@@ -96,13 +99,15 @@ function LineChartContent({data, title, titleIcon, isLoading, yAxisUnit, yAxisUn
9699
// How much space is wasted on each side
97100
const wastedLeft = geometricPadding - firstLabelNeeds;
98101
const wastedRight = geometricPadding - lastLabelNeeds;
99-
const canReduce = Math.min(wastedLeft, wastedRight);
102+
const reclaimablePadding = Math.min(wastedLeft, wastedRight);
100103

101104
// Only reduce if both sides have excess space (labels short enough for 0°)
102-
// If canReduce <= 0, labels are too long and hook will use rotation/truncation
103-
const horizontalPadding = canReduce > 0 ? geometricPadding - canReduce : geometricPadding;
105+
// If reclaimablePadding <= 0, labels are too long and hook will use rotation/truncation
106+
const shouldUseExtraPadding = reclaimablePadding > 0;
107+
const horizontalPadding = Math.max(shouldUseExtraPadding ? geometricPadding - reclaimablePadding : geometricPadding, MIN_SAFE_PADDING);
104108

105-
return {...BASE_DOMAIN_PADDING, left: horizontalPadding, right: horizontalPadding};
109+
// If shouldUseExtraPadding is true then we have to add the extra padding to the right so the label is not clipped
110+
return {...BASE_DOMAIN_PADDING, left: horizontalPadding, right: horizontalPadding + (shouldUseExtraPadding ? MIN_SAFE_PADDING : 0)};
106111
}, [chartWidth, data, font]);
107112

108113
// For centered labels, tick spacing is evenly distributed across the plot area (same as BarChart)

0 commit comments

Comments
 (0)