Last active
December 5, 2022 21:19
-
-
Save kagklis/dce7b3d91578c6d3300b8aebc61099d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let mouseMoveEnabled: boolean = false; | |
function mousemove(data: any): void { | |
if (!mouseMoveEnabled) return; | |
const tooltip = chart.tooltip; | |
const mousePoint = { x: data.x, y: data.y }; | |
const nearest1 = getNearestElementByX(chart.getDatasetMeta(0), mousePoint); | |
const nearest2 = getNearestElementByX(chart.getDatasetMeta(1), mousePoint); | |
if (!isTouched(nearest1, mousePoint) && !isTouched(nearest2, mousePoint)) { | |
tooltip.setActiveElements([]); | |
} else { | |
const nearest = getNearestTouched(nearest1, nearest2, mousePoint); | |
tooltip.setActiveElements([nearest]); | |
} | |
chart.update(); | |
} | |
function mouseenter(): void { | |
mouseMoveEnabled = true; | |
} | |
function mouseleave(): void { | |
mouseMoveEnabled = false; | |
const tooltip = chart.tooltip; | |
tooltip.setActiveElements([]); | |
chart.update(); | |
} | |
const handlers = { | |
// ... | |
mousemove, | |
mouseenter, | |
mouseleave, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment