UNPKG

vue-data-ui

Version:

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

56 lines (55 loc) 1.55 kB
import { f as k } from "./lib-2iaAPQ_c.js"; function v({ svgRef: x, fontSize: A, minFontSize: S, sizeRef: z, labelClass: g, labelTypes: a = [] }) { let l = null; function F(i, t, o = 1) { const { x: n, y: c, width: u, height: r } = i.getBBox(), e = n >= t.x + o, s = n + u <= t.x + t.width - o, f = c >= t.y + o, h = c + r <= t.y + t.height - o; return e && s && f && h; } function b(i, t, o, n, c = 120, u = 1) { let r = o, e = 0; for (; e < c && (i.setAttribute("font-size", r), !(F(i, t, u) || r <= n)); ) r -= 0.5, e += 1; return r < n ? n : r; } function B() { const i = x.value; if (!i) return; const [t, o, n, c] = i.getAttribute("viewBox").split(" ").map(Number), u = { x: t, y: o, width: n, height: c }; a.length || (a = [ { selector: g, baseSize: A, minSize: S, sizeRef: z } ]), a.map((e) => i.querySelectorAll(e.selector).length).reduce((e, s) => e + s, 0) !== 0 && a.forEach(({ selector: e, baseSize: s, minSize: f, sizeRef: h }) => { i.querySelectorAll(e).forEach((m) => { const O = k({ el: m, bounds: u, currentFontSize: s, minFontSize: f, attempts: 200, padding: 1 }), w = b(m, u, O, f, 120, 1); m.setAttribute("font-size", w), h.value = w; }); }); } function K() { l && cancelAnimationFrame(l), l = requestAnimationFrame(() => { l = null, B(); }); } return { autoSizeLabels: K }; } export { v as u };