diff --git a/src/core/core.interaction.js b/src/core/core.interaction.js index 8a716023651..d84318b34d5 100644 --- a/src/core/core.interaction.js +++ b/src/core/core.interaction.js @@ -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); diff --git a/test/specs/core.interaction.tests.js b/test/specs/core.interaction.tests.js index 9d693f1488c..ab6377dc94d 100644 --- a/test/specs/core.interaction.tests.js +++ b/test/specs/core.interaction.tests.js @@ -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) => {