Minetrack/assets/js/plugins.js

32 lines
688 B
JavaScript
Raw Normal View History

2023-12-30 23:03:54 +00:00
export function uPlotTooltipPlugin(onHover) {
let element;
return {
hooks: {
2023-12-30 23:03:54 +00:00
init: (u) => {
element = u.root.querySelector(".over");
2023-12-30 23:03:54 +00:00
element.onmouseenter = () => onHover();
element.onmouseleave = () => onHover();
},
2023-12-30 23:03:54 +00:00
setCursor: (u) => {
const { left, top, idx } = u.cursor;
if (idx === null) {
2023-12-30 23:03:54 +00:00
onHover();
} else {
2023-12-30 23:03:54 +00:00
const bounds = element.getBoundingClientRect();
2023-12-30 23:03:54 +00:00
onHover(
{
left: bounds.left + left + window.pageXOffset,
top: bounds.top + top + window.pageYOffset,
},
idx
);
}
2023-12-30 23:03:54 +00:00
},
},
};
}