Skip to content

Commit

Permalink
improve datapoint detection on mousehover for correct tooltip position
Browse files Browse the repository at this point in the history
  • Loading branch information
junedchhipa committed Dec 11, 2024
1 parent a49d6c7 commit 731fbed
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/charts/Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
7 changes: 3 additions & 4 deletions src/modules/tooltip/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -191,7 +190,7 @@ export default class Utils {
}

return {
index: currIndex,
j: currIndex,
}
}

Expand Down

0 comments on commit 731fbed

Please sign in to comment.