wire uPlot tooltips into the existing tooltip system

This commit is contained in:
Nick Krecklow
2020-05-11 00:37:22 -05:00
parent 8d211434df
commit 1ff9478988
3 changed files with 46 additions and 6 deletions

32
assets/js/tooltip.js Normal file
View File

@ -0,0 +1,32 @@
export function uPlotTooltipPlugin (onHover) {
let element
return {
hooks: {
init: u => {
element = u.root.querySelector('.over')
element.onmouseenter = () => onHover()
element.onmouseleave = () => onHover()
},
setCursor: u => {
const { left, top, idx } = u.cursor
if (idx === null) {
onHover()
} else {
const bounds = element.getBoundingClientRect()
onHover({
left: bounds.left + left + window.pageXOffset,
top: bounds.top + top + window.pageYOffset
}, {
idx,
x: u.data[0][idx],
y: u.data[1][idx]
})
}
}
}
}
}