import { reactive } from "vue"; // One floating tooltip per chart. The first line is the value, shown strongest. export interface TipRow { text: string; color?: string } export function useTip() { const tip = reactive({ show: false, x: 0, y: 0, rows: [] as TipRow[] }); function show(e: MouseEvent | FocusEvent, rows: TipRow[]) { if (e instanceof MouseEvent) { tip.x = e.clientX; tip.y = e.clientY; } else { const r = (e.target as Element).getBoundingClientRect(); tip.x = r.left + r.width / 2; tip.y = r.top; } tip.rows = rows; tip.show = true; } const hide = () => { tip.show = false; }; return { tip, show, hide }; }