From 731fbed82f63b80b88e52c29038d306d4f58db73 Mon Sep 17 00:00:00 2001 From: Juned Chhipa Date: Thu, 12 Dec 2024 01:03:10 +0530 Subject: [PATCH] improve datapoint detection on mousehover for correct tooltip position --- src/charts/Line.js | 2 +- src/modules/tooltip/Utils.js | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/charts/Line.js b/src/charts/Line.js index aaa038423..874fdf8e4 100644 --- a/src/charts/Line.js +++ b/src/charts/Line.js @@ -643,7 +643,7 @@ class Line { } // push current X - xArrj.push(x) + xArrj.push(series[i][j + 1] === null ? null : x) // push current Y that will be used as next series's bottom position if ( diff --git a/src/modules/tooltip/Utils.js b/src/modules/tooltip/Utils.js index 3acf5063c..798492984 100644 --- a/src/modules/tooltip/Utils.js +++ b/src/modules/tooltip/Utils.js @@ -98,13 +98,13 @@ export default class Utils { capturedSeries = closest.index j = closest.j - if (capturedSeries !== null) { + if (capturedSeries !== null && w.globals.hasNullValues) { // initial push, it should be a little smaller than the 1st val seriesXValArr = w.globals.seriesXvalues[capturedSeries] closest = this.closestInArray(transformedHoverX, seriesXValArr) - j = closest.index + j = closest.j } } @@ -158,7 +158,6 @@ export default class Utils { const xVal = xArr[j] const yVal = yArr[j] - // Compute Euclidean distance from hover point const distX = hoverX - xVal const distY = hoverY - yVal const dist = Math.sqrt(distX * distX + distY * distY) @@ -191,7 +190,7 @@ export default class Utils { } return { - index: currIndex, + j: currIndex, } }