Skip to content

Commit 97b564b

Browse files
authored
Bugfix: Binary search wrapper returns non-existing index (#11991)
1 parent a77a63b commit 97b564b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/core/core.interaction.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function binarySearch(metaset, axis, value, intersect) {
4040
result.lo -= Math.max(0, distanceToDefinedLo);
4141

4242
const distanceToDefinedHi = (_parsed
43-
.slice(result.hi - 1)
43+
.slice(result.hi)
4444
.findIndex(
4545
point => !isNullOrUndef(point[vScale.axis])));
4646
result.hi += Math.max(0, distanceToDefinedHi);

test/specs/core.interaction.tests.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,26 @@ describe('Core.Interaction', function() {
972972
data: [12, -1, null, null, null, null, -1, 2],
973973
clickPointIndex: 4,
974974
expectedNearestPointIndex: 6
975+
},
976+
{
977+
data: [null, 2],
978+
clickPointIndex: 0,
979+
expectedNearestPointIndex: 1
980+
},
981+
{
982+
data: [2, null],
983+
clickPointIndex: 1,
984+
expectedNearestPointIndex: 0
985+
},
986+
{
987+
data: [null, null, 2],
988+
clickPointIndex: 0,
989+
expectedNearestPointIndex: 2
990+
},
991+
{
992+
data: [2, null, null],
993+
clickPointIndex: 2,
994+
expectedNearestPointIndex: 0
975995
}
976996
];
977997
testCases.forEach(({data, clickPointIndex, expectedNearestPointIndex}, i) => {

0 commit comments

Comments
 (0)