Repository navigation
fix(hooks): order data-snap points by pixel and skip values the scale cannot place - #8309
Conversation
… cannot place createCategoricalInverse binary-searches pixel positions, which only works when they're in order. The data-snap selector feeds it values from selectSortedDataPoints, which sorts by numeric value and keeps nullish values. On a categorical axis the numeric order isn't the on-screen order, and null was mapped to pixel 0, so the search ran over an unsorted list: years listed newest first snapped to the wrong year, and a Line with a gap snapped to the wrong value or to null. Pair each value with its pixel, drop values the scale can't place, and sort by pixel before searching. Fixes recharts#8308
|
No actionable comments were generated in the recent review. WalkthroughThe categorical inverse scale now sorts valid scale positions before bisecting. It skips values without valid numeric positions and selects or clamps to the closest placed value. Tests cover unordered categories and null-valued data. ChangesCategorical inverse snapping
Estimated code review effort: 2 (Simple) | ~12 minutes Change: Bug fix · Severity of issue fixed: Medium Possibly related PRs
Suggested reviewers: Merge Risk:
|
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. |
Bundle ReportChanges will decrease total bundle size by 2.55kB (-0.03%) ⬇️. This is within the configured threshold ✅ Detailed changes
ℹ️ *Bundle size includes cached data from a previous commit Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-treeshaking-treemapAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-cartesianAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-polarAssets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-sankeyAssets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-sunburstAssets Changed:
view changes for bundle: recharts/bundle-es6Assets Changed:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8309 +/- ##
==========================================
+ Coverage 89.79% 89.81% +0.02%
==========================================
Files 691 691
Lines 17965 17973 +8
Branches 4872 4867 -5
==========================================
+ Hits 16131 16143 +12
+ Misses 1630 1628 -2
+ Partials 204 202 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Conflicts in src/util/scale/createCategoricalInverse.ts and its spec with the band-centre change on main: keep main's half-bandwidth offset and add it to each placed pixel before sorting.
Description
createCategoricalInversenow pairs each value with its pixel position, skips values the scale can't place (null, or a category outside the domain), and sorts by pixel before the binary search. Before, it searched values that were pre-sorted by number, and gave unplaceable values pixel 0.Related Issue
Fixes #8308
Motivation and Context
useXAxisInverseDataSnapScale/useYAxisInverseDataSnapScalereturned the wrong data point when:null): on a YAxis with[10, null, 20, 30], the pixel of 10 snapped to 30, 20 to 10, and 30 tonull;selectSortedDataPointssorts numerically and keeps nullish values, but a categorical axis keeps domain order andnullgot pixel 0, so the bisect saw an unsorted list. The plain inverse hooks on categorical axes use the same helper; their band order was already sorted, so their results don't change.This touches the same lines as #8307 (band centre offset), so whichever lands second will need a small rebase.
How Has This Been Tested?
test/util/scale/createCategoricalInverse.spec.tsand hook tests intest/hooks/useAxisScale.spec.tsx. All 5 fail onmainand pass with the fix.npm run test -- test/util test/hooks test/state: 1885 passed.check-types-lib,check-types-test, eslint and prettier pass on the changed files.Types of changes
Checklist:
Summary by CodeRabbit