Skip to content

Draw grid lines and labels for inverted axes with INCREMENT_BY_VAL - #137

Merged
halfhp merged 1 commit into
masterfrom
fix-125-inverted-axis-grid
Sep 7, 2026
Merged

Draw grid lines and labels for inverted axes with INCREMENT_BY_VAL#137
halfhp merged 1 commit into
masterfrom
fix-125-inverted-axis-grid

Conversation

@halfhp

@halfhp halfhp commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Fixes #125

Cause

With inverted boundaries, e.g. setDomainBoundaries(10, 0, FIXED), the axis region has min greater than max, so Region.ratio is negative. In XYStepCalculator, the INCREMENT_BY_VAL and INCREMENT_BY_FIT modes derive the pixel step by dividing the value step by that ratio, giving a negative pixel step. XYGraphWidget.drawGrid walks each axis in pixel order and computes its loop bounds from the pixel step, so with a negative step the bounds came out reversed and the loop never ran: no grid lines, no labels. The other modes derive the pixel step from pixel lengths, so they stayed positive and worked, which is why the reporter only saw it with INCREMENT_BY_VAL.

Fix

In XYStepCalculator, when the computed pixel step is negative, negate both it and the value step. The pixel step is then always positive and the value step carries the axis direction, which is exactly what INCREMENT_BY_PIXELS and SUBDIVIDE already produce for inverted bounds. drawGrid needs no changes: it already computes each line's value as origin plus index times the signed value step.

This is a narrower change than the reporter's proposed swap of the loop endpoints inside drawGrid, and it fixes the inconsistency at its source so any other consumer of Step sees the same convention across modes.

Verification

  • StepCalculatorTest: new case with inverted real bounds asserts INCREMENT_BY_VAL yields pixel step +1 and value step -1, and that INCREMENT_BY_PIXELS and SUBDIVIDE produce the same signs. Fails on the old code with pixel step -1.
  • XYGraphWidgetTest: new case sets inverted domain and range bounds with INCREMENT_BY_VAL and captures every grid line drawn. Asserts 101 lines per axis, that the leftmost domain line carries the value 100 and the rightmost 0, and that the top range line carries 0 and the bottom 100. Fails on the old code with zero lines drawn.
  • Full suite: 218 tests, 0 failures. Lint, core release AAR and demoapp debug build pass.
  • Release note added under 1.5.12.

With inverted boundaries (min > max), Region.ratio is negative, so
XYStepCalculator produced a negative pixel step for INCREMENT_BY_VAL
and INCREMENT_BY_FIT. XYGraphWidget.drawGrid walks the axis in pixel
order, so its loop bounds came out reversed and no lines or labels were
drawn. Keep the pixel step positive and let the value step carry the
sign, which is what the other step modes already produce for inverted
bounds.

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 71.02%. Comparing base (c15129b) to head (bfd8592).
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##             master     #137      +/-   ##
============================================
+ Coverage     70.98%   71.02%   +0.03%     
- Complexity     1242     1244       +2     
============================================
  Files           109      109              
  Lines          5191     5194       +3     
  Branches        543      544       +1     
============================================
+ Hits           3685     3689       +4     
+ Misses         1151     1150       -1     
  Partials        355      355              

☔ 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 6e1ad96 into master Sep 7, 2026
1 check passed
@halfhp
halfhp deleted the fix-125-inverted-axis-grid branch September 7, 2026 04:30
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.

Range or Domain lines and labels not showing up with inverted min/max boundaries with INCREMENT_BY_VAL

2 participants