Skip to content

Commit

Permalink
Bugfix: Binary search wrapper returns non-existing index (#11991)
Browse files Browse the repository at this point in the history
  • Loading branch information
marisst authored Jan 5, 2025
1 parent a77a63b commit 97b564b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/core.interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function binarySearch(metaset, axis, value, intersect) {
result.lo -= Math.max(0, distanceToDefinedLo);

const distanceToDefinedHi = (_parsed
.slice(result.hi - 1)
.slice(result.hi)
.findIndex(
point => !isNullOrUndef(point[vScale.axis])));
result.hi += Math.max(0, distanceToDefinedHi);
Expand Down
20 changes: 20 additions & 0 deletions test/specs/core.interaction.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,26 @@ describe('Core.Interaction', function() {
data: [12, -1, null, null, null, null, -1, 2],
clickPointIndex: 4,
expectedNearestPointIndex: 6
},
{
data: [null, 2],
clickPointIndex: 0,
expectedNearestPointIndex: 1
},
{
data: [2, null],
clickPointIndex: 1,
expectedNearestPointIndex: 0
},
{
data: [null, null, 2],
clickPointIndex: 0,
expectedNearestPointIndex: 2
},
{
data: [2, null, null],
clickPointIndex: 2,
expectedNearestPointIndex: 0
}
];
testCases.forEach(({data, clickPointIndex, expectedNearestPointIndex}, i) => {
Expand Down

0 comments on commit 97b564b

Please sign in to comment.