UNPKG

vue-data-ui

Version:

A user-empowering data visualization Vue 3 components library for eloquent data storytelling

121 lines (120 loc) 3.6 kB
import { ref as a, onMounted as b, onUnmounted as h, computed as p, createBlock as g, openBlock as v, Teleport as x, createElementBlock as S, createCommentVNode as k, normalizeStyle as $, normalizeClass as C, renderSlot as c, createElementVNode as B } from "vue"; import { s as F } from "./index-BsIlHNy8.js"; function w({ tooltip: e, chart: o, clientPosition: t, positionPreference: r = "center", defaultOffsetY: u = 24, blockShiftY: s = !1 }) { const l = a(0), f = a(u); if (e && o) { const { width: n, height: m } = e.getBoundingClientRect(), { right: i, left: d, bottom: y } = o.getBoundingClientRect(); r === "center" && (t.x + n / 2 > i ? l.value = -n + (i - t.x) : t.x - n / 2 < d ? l.value = -n + (n - (t.x - d)) : l.value = -n / 2), r === "right" && (t.x + n > i ? l.value = -n + (i - t.x) : l.value = 0), r === "left" && (t.x < d + n ? l.value = -n + (n - (t.x - d)) : l.value = -n), t.y + m > y && !s && (f.value = -m - u); } return { top: t.y + f.value, left: t.x + l.value }; } function N(e, o, t) { b(() => e.addEventListener(o, t)), h(() => e.removeEventListener(o, t)); } function Y() { const e = a(0), o = a(0); return N(window, "mousemove", (t) => { e.value = t.clientX, o.value = t.clientY; }), { x: e, y: o }; } const z = ["aria-hidden"], E = ["innerHTML"], M = { __name: "Tooltip", props: { backgroundColor: { type: String, default: "#FFFFFF" }, color: { type: String, default: "#000000" }, content: String, maxWidth: { type: String, default: "300px" }, parent: { type: Object }, show: { type: Boolean, default: !1 }, isCustom: { type: Boolean, default: !1 }, fontSize: { type: [Number, String], default: 14 }, borderRadius: { type: Number, default: 4 }, borderColor: { type: String, default: "#e1e5e8" }, borderWidth: { type: Number, default: 1 }, backgroundOpacity: { type: Number, default: 100 }, position: { type: String, default: "center" }, offsetY: { type: Number, default: 24 }, blockShiftY: { type: Boolean, default: !1 }, isFullscreen: { type: Boolean, default: !1 } }, setup(e) { const o = e, t = a(null), r = a(Y(o.parent)), u = p(() => w({ tooltip: t.value, chart: o.parent, clientPosition: r.value, positionPreference: o.position, defaultOffsetY: o.offsetY, blockShiftY: o.blockShiftY })), s = p(() => F(o.backgroundColor, o.backgroundOpacity)); return (l, f) => (v(), g(x, { to: e.isFullscreen ? e.parent : "body" }, [ e.show ? (v(), S("div", { key: 0, ref_key: "tooltip", ref: t, role: "tooltip", "aria-hidden": !e.show, "aria-live": "polite", class: C({ "vue-data-ui-custom-tooltip": e.isCustom, "vue-data-ui-tooltip": !e.isCustom }), style: $(`pointer-events:none;top:${u.value.top}px;left:${u.value.left}px;${e.isCustom ? "" : `background:${s.value};color:${e.color};max-width:${e.maxWidth};font-size:${e.fontSize}px`};border-radius:${e.borderRadius}px;border:${e.borderWidth}px solid ${e.borderColor};z-index:2147483647;`) }, [ c(l.$slots, "tooltip-before"), c(l.$slots, "default"), B("div", { innerHTML: e.content }, null, 8, E), c(l.$slots, "tooltip-after") ], 14, z)) : k("", !0) ], 8, ["to"])); } }; export { M as _, Y as u };