Skip to content

Fix clicks on pie segments larger than half the pie - #135

Merged
halfhp merged 1 commit into
masterfrom
fix-118-pie-hit-test
Sep 7, 2026
Merged

Fix clicks on pie segments larger than half the pie#135
halfhp merged 1 commit into
masterfrom
fix-118-pie-hit-test

Conversation

@halfhp

@halfhp halfhp commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Fixes #118

Cause

PieRenderer.getContainingSegment located the clicked segment using signedDistance, which returns the shortest angular path between two angles and is therefore capped at 180 degrees. For a segment sweeping more than 180 degrees, a click in the part of the segment nearest its start measures as lying "behind" the segment's end and is rejected. With values 8, 1, 1 the first segment sweeps 288 degrees, and clicks in roughly its first 108 degrees returned no segment. The reporter's diagnosis pointed at exactly this calculation.

Fix

Segments are drawn clockwise from their start angle, so a point is inside a segment when its clockwise distance from the segment's start is less than the sweep. A new clockwiseDistance helper computes that in the 0 to 360 range, and the containment check uses it. The old signedDistance is left in place since it's a protected static that subclasses may use, but it is no longer involved in hit-testing.

Verification

  • New PieRendererTest case builds the 8/1/1 pie from the report and probes ten angles across all three segments, including one degree past the big segment's start and one degree either side of each boundary. It fails on the old code at the first probe and passes on the fix.
  • Existing hit-test cases, including the one for a 51 percent segment, still pass.
  • Full suite: 212 tests, 0 failures. Lint, core release AAR and demoapp debug build pass.
  • Release note added under 1.5.12.

getContainingSegment measured the click's position with signedDistance,
which returns the shortest angular path and is therefore capped at 180
degrees. For a segment sweeping more than 180 degrees, clicks in the
part of the segment nearest its start measured as lying "behind" it and
matched nothing. Measure the clockwise distance from the segment's
start instead and compare it with the sweep, which holds for any
segment size up to a full pie.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 69.07%. Comparing base (c16a720) to head (fe795dc).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #135      +/-   ##
============================================
- Coverage     69.16%   69.07%   -0.09%     
+ Complexity     1233     1227       -6     
============================================
  Files           109      109              
  Lines          5160     5158       -2     
  Branches        537      536       -1     
============================================
- Hits           3569     3563       -6     
- Misses         1248     1253       +5     
+ Partials        343      342       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@halfhp
halfhp merged commit f8d00ce into master Sep 7, 2026
1 check passed
@halfhp
halfhp deleted the fix-118-pie-hit-test branch September 7, 2026 04:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Pie chart are not clickable with large segment

2 participants