Repository navigation
fix(scale): inverse data-snap handles unordered categories and null gaps (#8308) - #8332
samiarif02 wants to merge 1 commit into
Conversation
createCategoricalInverse mapped each sorted data value to its pixel position and fed those pixels to bisect, which assumes a monotonic array. The data order is not the pixel order, so two cases returned the wrong point: - a categorical axis whose numeric values are not ascending (e.g. years newest first): the pixel of one category snapped to its neighbour; - a series with a null gap: null has no real position (NaN, or a coerced pixel on a continuous scale), so it displaced the nearest real point. Pair each value with its pixel, drop values with no finite position (null/undefined gaps), and sort by pixel so the array bisect sees is monotonic. Nearest-neighbour lookup then returns the correct point. Fixes recharts#8308
|
No actionable comments were generated in the recent review. Walkthrough
ChangesCategorical inverse lookup
Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Possibly related issues
Possibly related PRs
Suggested reviewers: Merge Risk:
|
|
Duplicate of #8309 ? |
Bundle ReportChanges will increase total bundle size by 3.68kB (0.05%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-treeshaking-cartesianAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-polarAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8332 +/- ##
=======================================
Coverage 89.79% 89.79%
=======================================
Files 691 691
Lines 17965 17972 +7
Branches 4872 4874 +2
=======================================
+ Hits 16131 16138 +7
Misses 1630 1630
Partials 204 204 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Test Results SummaryThis comment shows the latest test results for this pull request.
ℹ️ About Flakiness.io in GitHubYour team has set up Flakiness.io pull request comments. This comment is updated when
Flakiness.io rewrites the comment in place, so it always reflects the most recently tested commit. |
What is the current behavior?
createCategoricalInverse(used byuseXAxisInverseDataSnapScale/useYAxisInverseDataSnapScale) maps each sorted data value to its pixel position and feeds those pixels tobisect, which assumes a monotonic array. The data order is not the pixel order, so the inverse returns the wrong point in two common cases (#8308):[2024, 2022, 2023, 2021]the pixel of2022returned2023.nullgap.nullhas no real position — its scaled value isNaN, or on a continuous scale a coerced pixel that belongs to no data point — so it displaced the nearest real point (the pixel of10snapped to30, the pixel of30snapped tonull).What is the expected behavior?
The inverse returns the data point whose pixel is nearest the given coordinate, and never a
null/undefinedgap.Fix
Pair each value with its pixel position, drop values that have no finite position (
null/undefinedgaps), and sort the pairs by pixel. The pixel arraybisectsees is then genuinely monotonic, and the nearest-neighbour lookup returns the correct point. This is self-contained increateCategoricalInverse;bisectis unchanged.Tests
Added two cases to
test/util/scale/createCategoricalInverse.spec.ts(non-ascending numeric categories, and anullgap on a categorical axis). Both fail onmain(expected 2023 to be 2022,expected null to be 10) and pass with the fix. The scale/hooks suites (test/util/scale,test/hooks/useAxisInverseBandScale) stay green (137 tests),tscis clean and eslint passes.Summary by CodeRabbit