mirror of
https://github.com/chartjs/Chart.js.git
synced 2025-12-08 20:36:08 +00:00
Bugfix: Binary search wrapper returns non-existing index (#11991)
This commit is contained in:
parent
a77a63b16b
commit
97b564b718
@ -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);
|
||||
|
||||
@ -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) => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user