UNPKG

vue-data-ui

Version:

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

82 lines (81 loc) 2.4 kB
import { a1 as K } from "./index-q-LPw2IT.js"; function q({ svgRef: S, fontSize: p, minFontSize: z, sizeRef: A, labelClass: B, labelTypes: m = [] }) { let y = null; function g(e) { let n = e[0]; for (let t = 1; t < e.length; t += 1) e[t] < n && (n = e[t]); return n; } function w(e) { let n = e[0]; for (let t = 1; t < e.length; t += 1) e[t] > n && (n = e[t]); return n; } function F(e) { const n = e.ownerSVGElement; if (!n) return { x: 0, y: 0, width: 0, height: 0 }; const t = e.getBBox(), i = e.getCTM(), s = [ { x: t.x, y: t.y }, { x: t.x + t.width, y: t.y }, { x: t.x, y: t.y + t.height }, { x: t.x + t.width, y: t.y + t.height } ].map((r) => { const a = n.createSVGPoint(); a.x = r.x, a.y = r.y; const l = i ? a.matrixTransform(i) : a; return { x: l.x, y: l.y }; }), h = s.map((r) => r.x), c = s.map((r) => r.y), o = g(h), u = w(h), f = g(c), x = w(c); return { x: o, y: f, width: u - o, height: x - f }; } function O(e, n, t = 1) { const { x: i, y: s, width: h, height: c } = F(e), o = i >= n.x + t, u = i + h <= n.x + n.width - t, f = s >= n.y + t, x = s + c <= n.y + n.height - t; return o && u && f && x; } function d(e, n, t, i, s = 120, h = 1) { let c = t, o = 0; for (; o < s && (e.style.fontSize = `${c}px`, !(O(e, n, h) || c <= i)); ) c -= 0.5, o += 1; return c < i ? i : c; } function b() { const e = S.value; if (!e) return; const [n, t, i, s] = e.getAttribute("viewBox").split(" ").map(Number), h = { x: n, y: t, width: i, height: s }; m.length || (m = [ { selector: B, baseSize: p, minSize: z, sizeRef: A } ]), m.map((o) => e.querySelectorAll(o.selector).length).reduce((o, u) => o + u, 0) !== 0 && m.forEach(({ selector: o, baseSize: u, minSize: f, sizeRef: x }) => { e.querySelectorAll(o).forEach((r) => { const a = K({ el: r, bounds: h, currentFontSize: u, minFontSize: f, attempts: 200, padding: 1 }), l = d(r, h, a, f, 120, 1); r.style.fontSize = `${l}px`, x.value = l; }); }); } function v() { y && cancelAnimationFrame(y), y = requestAnimationFrame(() => { y = null, b(); }); } return { autoSizeLabels: v }; } export { q as u };