UNPKG

vue-data-ui-hq

Version:

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

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