UNPKG

vue-data-ui

Version:

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

359 lines (358 loc) • 15.4 kB
import { defineAsyncComponent as S, computed as d, ref as b, watch as te, onMounted as pe, createElementBlock as c, openBlock as r, unref as s, normalizeStyle as G, normalizeClass as L, createBlock as z, createCommentVNode as f, createSlots as ye, withCtx as x, renderSlot as p, normalizeProps as N, guardReactiveProps as M, createVNode as me, Fragment as ae, renderList as oe, toDisplayString as ke } from "vue"; import { u as le } from "./useNestedProp-Bw1KcAmj.js"; import { u as be, c as Ce, a as _e, v as we, o as $e, e as Oe, w as se, X as Pe, i as xe, f as Ae } from "./index-BLtEpj8j.js"; import { u as Ie } from "./usePrinter-DnRwTdvS.js"; import { u as Fe } from "./useUserOptionState-BIvW1Kz7.js"; import { u as Se } from "./useChartAccessibility-9icAAmYg.js"; import ze from "./Title-DkG60EPg.js"; import Ne from "./img-D-vWHxhM.js"; import { _ as Me } from "./_plugin-vue_export-helper-CHgC5LLL.js"; const Te = ["id"], Ue = { key: 2, style: "width:100%;background:transparent;padding-bottom:12px" }, Re = ["xmlns", "viewBox"], Ee = ["width", "height"], Ge = { key: 1 }, Le = ["d", "stroke-width", "stroke"], je = { key: 2 }, Be = ["x1", "y1", "x2", "y2", "stroke-width", "stroke"], Xe = ["x", "y", "font-size", "fill", "font-weight", "text-anchor"], De = { key: 5, class: "vue-data-ui-watermark" }, He = { key: 6, ref: "source", dir: "auto" }, Ve = { __name: "vue-ui-tiremarks", props: { config: { type: Object, default() { return {}; } }, dataset: { type: Object, default() { return {}; } } }, setup(ne, { expose: re }) { const ue = S(() => import("./PenAndPaper-7BWf7zgA.js")), ie = S(() => import("./vue-ui-skeleton-CsMU8DwQ.js")), ce = S(() => import("./UserOptions-DGw0HvSp.js")), ve = S(() => import("./PackageVersion-CnRyWKP-.js")), { vue_ui_tiremarks: he } = be(), g = ne, T = d(() => !!g.dataset && Object.keys(g.dataset).length), U = b(Ce()), w = b(null), de = b(null), j = b(0), B = b(0), e = d({ get: () => V(), set: (t) => t }), { userOptionsVisible: R, setUserOptionsVisibility: X, keepUserOptionState: D } = Fe({ config: e.value }), { svgRef: H } = Se({ config: e.value.style.chart.title }); function V() { const t = le({ userConfig: g.config, defaultConfig: he }); return t.theme ? { ...le({ userConfig: _e.vue_ui_tiremarks[t.theme] || g.config, defaultConfig: t }) } : t; } te(() => g.config, (t) => { e.value = V(), R.value = !e.value.userOptions.showOnChartHover, W(), B.value += 1; }, { deep: !0 }); const { isPrinting: Y, isImaging: q, generatePdf: J, generateImage: K } = Ie({ elementId: U.value, fileName: e.value.style.chart.title.text || "vue-ui-tiremarks", options: e.value.userOptions.print }), fe = d(() => e.value.userOptions.show && !e.value.style.chart.title.text), u = b(e.value.style.chart.animation.use ? 0 : we(g.dataset.percentage)); te(() => g.dataset, (t) => { e.value.style.chart.animation.use ? Q(t.percentage) : u.value = t.percentage || 0; }, { deep: !0 }), pe(() => { W(); }); function Q(t) { let n = e.value.style.chart.animation.speed; const a = Math.abs(t - u.value) / (n * 120); function o() { u.value < t ? u.value = Math.min(u.value + a, t) : u.value > t && (u.value = Math.max(u.value - a, t)), u.value !== t && requestAnimationFrame(o); } o(); } function W() { $e(g.dataset) && Oe({ componentName: "VueUiTiremarks", type: "dataset" }), Q(g.dataset.percentage || 0); } const _ = d(() => e.value.style.chart.layout.display === "vertical"), i = d(() => { const t = { top: 48, left: 64, right: 64, bottom: 48 }; return _.value ? { top: e.value.style.chart.percentage.verticalPosition === "top" ? t.top : 3, left: 3, right: 3, bottom: e.value.style.chart.percentage.verticalPosition === "bottom" ? t.bottom : 3 } : { top: 0, bottom: 0, left: e.value.style.chart.percentage.horizontalPosition === "left" ? t.left : 3, right: e.value.style.chart.percentage.horizontalPosition === "right" ? t.right : 10 }; }), A = d(() => Object.values(i.value).reduce((t, n) => t + n, 0)), l = d(() => ({ height: _.value ? 312 : 56, width: _.value ? 56 : 312 })), v = d(() => _.value ? { mark: (l.value.height - A.value) / 100 * 0.5, space: (l.value.height - A.value) / 100 * 0.5 } : { mark: (l.value.width - A.value) / 100 * 0.5, space: (l.value.width - A.value) / 100 * 0.5 }), Z = d(() => { const t = []; for (let a = 0; a < 100; a += 1) { const o = e.value.style.chart.layout.ticks.gradient.show ? se(e.value.style.chart.layout.activeColor, a / 100 * (e.value.style.chart.layout.ticks.gradient.shiftHueIntensity / 100)) : e.value.style.chart.layout.activeColor; if (_.value) { const C = e.value.style.chart.layout.crescendo ? (100 - a) * (l.value.width - i.value.left - i.value.right) / 100 / 3 : 0, h = i.value.left + 4 + C, y = l.value.width - i.value.right - 4 - C, m = l.value.height - i.value.bottom - a * v.value.mark - a * v.value.space - v.value.mark, k = l.value.height - i.value.bottom - a * v.value.mark - a * v.value.space - v.value.mark, O = (y - h) / e.value.style.chart.layout.curveAngleX, P = e.value.style.chart.layout.curveAngleY * ((1 + a) / 100); t.push({ x1: h, x2: y, y1: m, y2: k, curve: `M ${h} ${m} C ${h + O} ${m - P}, ${y - O} ${k - P}, ${y} ${k}`, color: o }); } else { const C = e.value.style.chart.layout.crescendo ? (100 - a) * (l.value.height - i.value.top - i.value.bottom) / 100 / 3 : 0, h = i.value.left + a * v.value.mark + a * v.value.space - v.value.mark, y = h, m = i.value.top + 4 + C, k = l.value.height - i.value.bottom - 4 - C, O = e.value.style.chart.layout.curveAngleY * ((1 + a) / 100), P = (k - m) / e.value.style.chart.layout.curveAngleX; t.push({ x1: h, x2: y, y1: m, y2: k, curve: `M ${h} ${m} C ${h + O} ${m + P}, ${y + O} ${k - P}, ${y} ${k}`, color: o }); } } return t; }), $ = d(() => { let t, n, a; const o = e.value.style.chart.percentage.fontSize / 3; return _.value ? e.value.style.chart.percentage.verticalPosition === "top" ? (t = l.value.width / 2, n = i.value.top / 2, a = "middle") : e.value.style.chart.percentage.verticalPosition === "bottom" && (t = l.value.width / 2, n = l.value.height - i.value.bottom / 2 + o, a = "middle") : e.value.style.chart.percentage.horizontalPosition === "left" ? (t = 4, n = l.value.height / 2 + o, a = "start") : e.value.style.chart.percentage.horizontalPosition === "right" && (t = l.value.width - i.value.right + 8, n = l.value.height / 2 + o, a = "start"), { x: t, y: n, textAnchor: a, bold: e.value.style.chart.percentage.bold, fontSize: e.value.style.chart.percentage.fontSize, fill: e.value.style.chart.percentage.color }; }), I = b(!1); function ee(t) { I.value = t, j.value += 1; } const F = b(!1); function E() { F.value = !F.value; } async function ge({ scale: t = 2 } = {}) { if (!w.value) return; const { width: n, height: a } = w.value.getBoundingClientRect(), o = n / a, { imageUri: C, base64: h } = await Ne({ domElement: w.value, base64: !0, img: !0, scale: t }); return { imageUri: C, base64: h, title: e.value.style.chart.title.text, width: n, height: a, aspectRatio: o }; } return re({ getImage: ge, generatePdf: J, generateImage: K, toggleAnnotator: E, toggleFullscreen: ee }), (t, n) => (r(), c("div", { ref_key: "tiremarksChart", ref: w, class: L(`vue-ui-tiremarks ${e.value.useCssAnimation ? "" : "vue-ui-dna"}`), style: G(`font-family:${e.value.style.fontFamily};width:100%; text-align:center;background:${e.value.style.chart.backgroundColor}`), id: U.value, onMouseenter: n[0] || (n[0] = () => s(X)(!0)), onMouseleave: n[1] || (n[1] = () => s(X)(!1)) }, [ e.value.userOptions.buttons.annotator ? (r(), z(s(ue), { key: 0, svgRef: s(H), backgroundColor: e.value.style.chart.backgroundColor, color: e.value.style.chart.color, active: F.value, onClose: E }, null, 8, ["svgRef", "backgroundColor", "color", "active"])) : f("", !0), fe.value ? (r(), c("div", { key: 1, ref_key: "noTitle", ref: de, class: "vue-data-ui-no-title-space", style: "height:36px; width: 100%;background:transparent" }, null, 512)) : f("", !0), e.value.style.chart.title.text ? (r(), c("div", Ue, [ (r(), z(ze, { key: `title_${B.value}`, config: { title: { cy: "wheel-title", ...e.value.style.chart.title }, subtitle: { cy: "wheel-subtitle", ...e.value.style.chart.title.subtitle } } }, null, 8, ["config"])) ])) : f("", !0), e.value.userOptions.show && T.value && (s(D) || s(R)) ? (r(), z(s(ce), { ref: "details", key: `user_options_${j.value}`, backgroundColor: e.value.style.chart.backgroundColor, color: e.value.style.chart.color, isPrinting: s(Y), isImaging: s(q), uid: U.value, hasPdf: e.value.userOptions.buttons.pdf, hasImg: e.value.userOptions.buttons.img, hasFullscreen: e.value.userOptions.buttons.fullscreen, hasXls: !1, isFullscreen: I.value, titles: { ...e.value.userOptions.buttonTitles }, chartElement: w.value, position: e.value.userOptions.position, hasAnnotator: e.value.userOptions.buttons.annotator, isAnnotation: F.value, callbacks: e.value.userOptions.callbacks, printScale: e.value.userOptions.print.scale, onToggleFullscreen: ee, onGeneratePdf: s(J), onGenerateImage: s(K), onToggleAnnotator: E, style: G({ visibility: s(D) ? s(R) ? "visible" : "hidden" : "visible" }) }, ye({ _: 2 }, [ t.$slots.menuIcon ? { name: "menuIcon", fn: x(({ isOpen: a, color: o }) => [ p(t.$slots, "menuIcon", N(M({ isOpen: a, color: o })), void 0, !0) ]), key: "0" } : void 0, t.$slots.optionPdf ? { name: "optionPdf", fn: x(() => [ p(t.$slots, "optionPdf", {}, void 0, !0) ]), key: "1" } : void 0, t.$slots.optionImg ? { name: "optionImg", fn: x(() => [ p(t.$slots, "optionImg", {}, void 0, !0) ]), key: "2" } : void 0, t.$slots.optionFullscreen ? { name: "optionFullscreen", fn: x(({ toggleFullscreen: a, isFullscreen: o }) => [ p(t.$slots, "optionFullscreen", N(M({ toggleFullscreen: a, isFullscreen: o })), void 0, !0) ]), key: "3" } : void 0, t.$slots.optionAnnotator ? { name: "optionAnnotator", fn: x(({ toggleAnnotator: a, isAnnotator: o }) => [ p(t.$slots, "optionAnnotator", N(M({ toggleAnnotator: a, isAnnotator: o })), void 0, !0) ]), key: "4" } : void 0 ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasImg", "hasFullscreen", "isFullscreen", "titles", "chartElement", "position", "hasAnnotator", "isAnnotation", "callbacks", "printScale", "onGeneratePdf", "onGenerateImage", "style"])) : f("", !0), T.value ? (r(), c("svg", { key: 4, ref_key: "svgRef", ref: H, xmlns: s(Pe), class: L({ "vue-data-ui-fullscreen--on": I.value, "vue-data-ui-fulscreen--off": !I.value }), viewBox: `0 0 ${l.value.width} ${l.value.height}`, style: G(`max-width:100%; overflow: visible; background:transparent;color:${e.value.style.chart.color}`) }, [ me(s(ve)), t.$slots["chart-background"] ? (r(), c("foreignObject", { key: 0, x: 0, y: 0, width: l.value.width, height: l.value.height, style: { pointerEvents: "none" } }, [ p(t.$slots, "chart-background", {}, void 0, !0) ], 8, Ee)) : f("", !0), e.value.style.chart.layout.curved ? (r(), c("g", Ge, [ (r(!0), c(ae, null, oe(Z.value, (a, o) => (r(), c("path", { d: a.curve, "stroke-width": v.value.mark, stroke: u.value >= o ? a.color : e.value.style.chart.layout.inactiveColor, "stroke-linecap": "round", fill: "none", class: L({ "vue-ui-tick-animated": e.value.style.chart.animation.use && o <= u.value }) }, null, 10, Le))), 256)) ])) : (r(), c("g", je, [ (r(!0), c(ae, null, oe(Z.value, (a, o) => (r(), c("line", { x1: a.x1, y1: a.y1, x2: a.x2, y2: a.y2, "stroke-width": v.value.mark, stroke: u.value >= o ? a.color : e.value.style.chart.layout.inactiveColor, "stroke-linecap": "round" }, null, 8, Be))), 256)) ])), e.value.style.chart.percentage.show ? (r(), c("text", { key: 3, x: $.value.x, y: $.value.y, "font-size": $.value.fontSize, fill: e.value.style.chart.layout.ticks.gradient.show && e.value.style.chart.percentage.useGradientColor ? s(se)(e.value.style.chart.layout.activeColor, u.value / 100 * (e.value.style.chart.layout.ticks.gradient.shiftHueIntensity / 100)) : e.value.style.chart.percentage.color, "font-weight": $.value.bold ? "bold" : "normal", "text-anchor": $.value.textAnchor }, ke(s(xe)( e.value.style.chart.percentage.formatter, u.value, s(Ae)({ v: u.value, s: "%", r: e.value.style.chart.percentage.rounding }) )), 9, Xe)) : f("", !0), p(t.$slots, "svg", { svg: l.value }, void 0, !0) ], 14, Re)) : f("", !0), t.$slots.watermark ? (r(), c("div", De, [ p(t.$slots, "watermark", N(M({ isPrinting: s(Y) || s(q) })), void 0, !0) ])) : f("", !0), t.$slots.source ? (r(), c("div", He, [ p(t.$slots, "source", {}, void 0, !0) ], 512)) : f("", !0), T.value ? f("", !0) : (r(), z(s(ie), { key: 7, config: { type: "tiremarks", style: { backgroundColor: e.value.style.chart.backgroundColor, tiremarks: { color: "#CCCCCC" } } } }, null, 8, ["config"])) ], 46, Te)); } }, at = /* @__PURE__ */ Me(Ve, [["__scopeId", "data-v-f25a17b8"]]); export { at as default };