UNPKG

vue-data-ui-hq

Version:

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

577 lines (576 loc) 21.7 kB
import { ref as k, computed as Q, onMounted as R, onBeforeUnmount as Y, withDirectives as Z, openBlock as o, createElementBlock as s, normalizeStyle as b, unref as e, createElementVNode as j, withModifiers as p, withKeys as _, createVNode as tt, normalizeClass as c, renderSlot as m, Fragment as S, createBlock as g, toDisplayString as $, createCommentVNode as u, normalizeProps as P, mergeProps as X } from "vue"; import r from "./BaseIcon-MqKW8Nkx.js"; import { _ as et } from "./_plugin-vue_export-helper-CHgC5LLL.js"; const ot = { beforeMount(t, A) { t.clickOutsideEvent = function(f) { t === f.target || t.contains(f.target) || A.value(f); }, document.addEventListener("click", t.clickOutsideEvent); }, unmounted(t) { document.removeEventListener("click", t.clickOutsideEvent); } }, nt = ["title"], it = ["data-open"], lt = { __name: "UserOptions", props: { hasPdf: { type: Boolean, default: !0 }, hasXls: { type: Boolean, default: !0 }, hasImg: { type: Boolean, default: !1 }, hasLabel: { type: Boolean, default: !1 }, isLabelActive: { type: Boolean, default: !1 }, hasTable: { type: Boolean, default: !1 }, hasSort: { type: Boolean, default: !1 }, hasStack: { type: Boolean, default: !1 }, hasTooltip: { type: Boolean, default: !1 }, color: { type: String }, backgroundColor: { type: String }, isPrinting: { type: Boolean, default: !1 }, isImaging: { type: Boolean, default: !1 }, title: { type: String }, uid: { type: String }, hasFullscreen: { type: Boolean, default: !1 }, chartElement: { type: HTMLElement, default: null }, isFullscreen: { type: Boolean, default: !1 }, isStacked: { type: Boolean, default: !1 }, isTooltip: { type: Boolean, default: !1 }, hasAnimation: { type: Boolean, default: !1 }, isAnimation: { type: Boolean, default: !1 }, titles: { type: Object, default() { return {}; } }, showTooltips: { type: Boolean, default: !0 }, zIndex: { type: Number, default: 1 }, noOffset: { type: Boolean, default: !0 }, position: { type: String, default: "right" }, offsetX: { type: Number, default: 0 }, hasAnnotator: { type: Boolean, default: !1 }, isAnnotation: { type: Boolean, default: !1 } }, emits: ["generatePdf", "generateCsv", "generateImage", "toggleTable", "toggleLabels", "toggleSort", "toggleFullscreen", "toggleStack", "toggleTooltip", "toggleAnimation", "toggleAnnotator"], setup(t, { emit: A }) { const f = t, d = A; function B() { d("generatePdf"); } function M() { d("generateCsv"); } function F() { d("generateImage"); } const T = k(!1); function h() { T.value = !T.value, d("toggleTable"); } const C = k(!1), K = k(!0); function z() { v.value = window.innerWidth > 600, C.value = !C.value, C.value && (K.value = !1); } function W() { f.isPrinting || f.isImaging || (C.value = !1); } function q() { C.value && W(); } const O = k(f.isLabelActive); function x() { O.value = !O.value, d("toggleLabels"); } const I = k(f.isAnimation); function D() { I.value = !I.value, d("toggleAnimation"); } const E = Q({ get: () => f.isAnnotation, set: (l) => l }); function N() { E.value = !E.value, d("toggleAnnotator"); } function H() { d("toggleSort"); } const L = k(f.isStacked); function G() { L.value = !L.value, d("toggleStack"); } const w = k(f.isTooltip); function J() { w.value = !w.value, d("toggleTooltip"); } const y = k(!1); function U(l) { f.chartElement && (l === "in" ? (y.value = !0, f.chartElement.requestFullscreen(), d("toggleFullscreen", !0)) : (y.value = !1, document && document.exitFullscreen(), d("toggleFullscreen", !1))); } function V(l) { document.fullscreenElement ? y.value = !0 : y.value = !1; } R(() => { document.addEventListener("fullscreenchange", V); }), Y(() => { document.removeEventListener("fullscreenchange", V); }); const v = k(window.innerWidth > 600), i = k({ tooltip: !1, pdf: !1, csv: !1, img: !1, table: !1, labels: !1, sort: !1, stack: !1, fullscreen: !1, animation: !1, annotator: !1 }); return (l, n) => Z((o(), s("div", { "data-html2canvas-ignore": "", class: "vue-ui-user-options", style: b(`z-index: ${t.zIndex}; height: 34px; position: ${e(y) ? "fixed" : "absolute"}; top: 0; ${t.position === "right" ? `right:${e(y) ? "12px" : "0"}` : `left:${e(y) ? "12px" : "0"}`}; padding: 4px; background:transparent;`) }, [ j("div", { tabindex: "0", title: e(C) ? t.titles.close || "" : t.titles.open || "", style: b(`width:32px; position: absolute; top: 0;${t.position === "right" ? `right: ${t.offsetX ? t.offsetX : t.noOffset ? 0 : 4}px` : `left: ${t.noOffset ? 0 : 4}px`}; padding: 0 0px; display: flex; align-items:center;justify-content:center;height: 36px; cursor:pointer; background:transparent`), onClick: p(z, ["stop"]), onKeypress: _(z, ["enter"]) }, [ tt(r, { name: e(C) ? "close" : "menu", stroke: t.color, "stroke-width": 2 }, null, 8, ["name", "stroke"]) ], 44, nt), j("div", { "data-open": e(C), class: c({ "vue-ui-user-options-drawer": !0 }), style: b(`background:${t.backgroundColor}; ${t.position === "right" ? `right: ${t.offsetX ? t.offsetX : t.noOffset ? 0 : 4}px` : `left: ${t.noOffset ? 0 : 4}px`}`) }, [ t.hasTooltip ? (o(), s("button", { key: 0, tabindex: "0", class: "vue-ui-user-options-button", onClick: J, onMouseenter: n[0] || (n[0] = (a) => e(i).tooltip = !0), onMouseout: n[1] || (n[1] = (a) => e(i).tooltip = !1) }, [ l.$slots.optionTooltip ? m(l.$slots, "optionTooltip", { key: 0 }, void 0, !0) : (o(), s(S, { key: 1 }, [ e(w) ? (o(), g(r, { key: 0, name: "tooltip", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) : (o(), g(r, { key: 1, name: "tooltipDisabled", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) ], 64)), e(v) && t.titles.tooltip && !l.$slots.optionTooltip ? (o(), s("div", { key: 2, dir: "auto", class: c({ "button-info-left": t.position === "left", "button-info-right": t.position === "right", "button-info-left-visible": t.position === "left" && e(i).tooltip, "button-info-right-visible": t.position === "right" && e(i).tooltip }), style: b({ background: t.backgroundColor, color: t.color }) }, $(t.titles.tooltip), 7)) : u("", !0) ], 32)) : u("", !0), t.hasPdf ? (o(), s("button", { key: 1, tabindex: "0", class: "vue-ui-user-options-button", onClick: B, onMouseenter: n[2] || (n[2] = (a) => e(i).pdf = !0), onMouseout: n[3] || (n[3] = (a) => e(i).pdf = !1) }, [ l.$slots.optionPdf ? m(l.$slots, "optionPdf", { key: 0 }, void 0, !0) : (o(), s(S, { key: 1 }, [ t.isPrinting ? (o(), g(r, { key: 0, name: "spin", isSpin: "", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) : (o(), g(r, { key: 1, name: "pdf", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) ], 64)), e(v) && t.titles.pdf && !l.$slots.optionPdf ? (o(), s("div", { key: 2, dir: "auto", class: c({ "button-info-left": t.position === "left", "button-info-right": t.position === "right", "button-info-right-visible": t.position === "right" && e(i).pdf, "button-info-left-visible": t.position === "left" && e(i).pdf }), style: b({ background: t.backgroundColor, color: t.color }) }, $(t.titles.pdf), 7)) : u("", !0) ], 32)) : u("", !0), t.hasXls ? (o(), s("button", { key: 2, tabindex: "0", class: "vue-ui-user-options-button", onClick: M, onMouseenter: n[4] || (n[4] = (a) => e(i).csv = !0), onMouseout: n[5] || (n[5] = (a) => e(i).csv = !1) }, [ l.$slots.optionCsv ? m(l.$slots, "optionCsv", { key: 0 }, void 0, !0) : (o(), g(r, { key: 1, name: "excel", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])), e(v) && t.titles.csv && !l.$slots.optionCsv ? (o(), s("div", { key: 2, dir: "auto", class: c({ "button-info-left": t.position === "left", "button-info-right": t.position === "right", "button-info-right-visible": t.position === "right" && e(i).csv, "button-info-left-visible": t.position === "left" && e(i).csv }), style: b({ background: t.backgroundColor, color: t.color }) }, $(t.titles.csv), 7)) : u("", !0) ], 32)) : u("", !0), t.hasImg ? (o(), s("button", { key: 3, tabindex: "0", class: "vue-ui-user-options-button", onClick: F, onMouseenter: n[6] || (n[6] = (a) => e(i).img = !0), onMouseout: n[7] || (n[7] = (a) => e(i).img = !1) }, [ l.$slots.optionImg ? m(l.$slots, "optionImg", { key: 0 }, void 0, !0) : (o(), s(S, { key: 1 }, [ t.isImaging ? (o(), g(r, { key: 0, name: "spin", isSpin: "", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) : (o(), g(r, { key: 1, name: "image", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) ], 64)), e(v) && t.titles.img && !l.$slots.optionImg ? (o(), s("div", { key: 2, dir: "auto", class: c({ "button-info-left": t.position === "left", "button-info-right": t.position === "right", "button-info-right-visible": t.position === "right" && e(i).img, "button-info-left-visible": t.position === "left" && e(i).img }), style: b({ background: t.backgroundColor, color: t.color }) }, $(t.titles.img), 7)) : u("", !0) ], 32)) : u("", !0), t.hasTable ? (o(), s("button", { key: 4, tabindex: "0", class: "vue-ui-user-options-button", onClick: h, onMouseenter: n[8] || (n[8] = (a) => e(i).table = !0), onMouseout: n[9] || (n[9] = (a) => e(i).table = !1) }, [ l.$slots.optionTable ? m(l.$slots, "optionTable", { key: 0 }, void 0, !0) : (o(), g(r, { key: 1, name: e(T) ? "tableClose" : "tableOpen", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["name", "stroke"])), e(v) && t.titles.table && !l.$slots.optionTable ? (o(), s("div", { key: 2, dir: "auto", class: c({ "button-info-left": t.position === "left", "button-info-right": t.position === "right", "button-info-right-visible": t.position === "right" && e(i).table, "button-info-left-visible": t.position === "left" && e(i).table }), style: b({ background: t.backgroundColor, color: t.color }) }, $(t.titles.table), 7)) : u("", !0) ], 32)) : u("", !0), t.hasLabel ? (o(), s("button", { key: 5, tabindex: "0", class: "vue-ui-user-options-button", onClick: x, onMouseenter: n[10] || (n[10] = (a) => e(i).labels = !0), onMouseout: n[11] || (n[11] = (a) => e(i).labels = !1) }, [ l.$slots.optionLabels ? m(l.$slots, "optionLabels", { key: 0 }, void 0, !0) : (o(), g(r, { key: 1, name: e(O) ? "labelClose" : "labelOpen", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["name", "stroke"])), e(v) && t.titles.labels && !l.$slots.optionLabels ? (o(), s("div", { key: 2, dir: "auto", class: c({ "button-info-left": t.position === "left", "button-info-right": t.position === "right", "button-info-right-visible": t.position === "right" && e(i).labels, "button-info-left-visible": t.position === "left" && e(i).labels }), style: b({ background: t.backgroundColor, color: t.color }) }, $(t.titles.labels), 7)) : u("", !0) ], 32)) : u("", !0), t.hasSort ? (o(), s("button", { key: 6, tabindex: "0", class: "vue-ui-user-options-button", onClick: H, onMouseenter: n[12] || (n[12] = (a) => e(i).sort = !0), onMouseout: n[13] || (n[13] = (a) => e(i).sort = !1) }, [ l.$slots.optionSort ? m(l.$slots, "optionSort", { key: 0 }, void 0, !0) : (o(), g(r, { key: 1, name: "sort", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])), e(v) && t.titles.sort && !l.$slots.optionSort ? (o(), s("div", { key: 2, dir: "auto", class: c({ "button-info-left": t.position === "left", "button-info-right": t.position === "right", "button-info-right-visible": t.position === "right" && e(i).sort, "button-info-left-visible": t.position === "left" && e(i).sort }), style: b({ background: t.backgroundColor, color: t.color }) }, $(t.titles.sort), 7)) : u("", !0) ], 32)) : u("", !0), t.hasStack ? (o(), s("button", { key: 7, tabindex: "0", class: "vue-ui-user-options-button", onClick: G, onMouseenter: n[14] || (n[14] = (a) => e(i).stack = !0), onMouseout: n[15] || (n[15] = (a) => e(i).stack = !1) }, [ l.$slots.optionStack ? m(l.$slots, "optionStack", { key: 0 }, void 0, !0) : (o(), s(S, { key: 1 }, [ e(L) ? (o(), g(r, { key: 0, name: "unstack", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) : (o(), g(r, { key: 1, name: "stack", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) ], 64)), e(v) && t.titles.stack && !l.$slots.optionStack ? (o(), s("div", { key: 2, dir: "auto", class: c({ "button-info-left": t.position === "left", "button-info-right": t.position === "right", "button-info-right-visible": t.position === "right" && e(i).stack, "button-info-left-visible": t.position === "left" && e(i).stack }), style: b({ background: t.backgroundColor, color: t.color }) }, $(t.titles.stack), 7)) : u("", !0) ], 32)) : u("", !0), t.hasFullscreen ? (o(), s("button", { key: 8, tabindex: "0", class: "vue-ui-user-options-button", onMouseenter: n[16] || (n[16] = (a) => e(i).fullscreen = !0), onMouseout: n[17] || (n[17] = (a) => e(i).fullscreen = !1), onClick: n[18] || (n[18] = (a) => U(e(y) ? "out" : "in")) }, [ l.$slots.optionFullscreen ? m(l.$slots, "optionFullscreen", P(X({ key: 0 }, { toggleFullscreen: U, isFullscreen: e(y) })), void 0, !0) : (o(), s(S, { key: 1 }, [ e(y) ? (o(), g(r, { key: 0, name: "exitFullscreen", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) : u("", !0), e(y) ? u("", !0) : (o(), g(r, { key: 1, name: "fullscreen", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) ], 64)), e(v) && t.titles.fullscreen && !l.$slots.optionFullscreen ? (o(), s("div", { key: 2, dir: "auto", class: c({ "button-info-left": t.position === "left", "button-info-right": t.position === "right", "button-info-right-visible": t.position === "right" && e(i).fullscreen, "button-info-left-visible": t.position === "left" && e(i).fullscreen }), style: b({ background: t.backgroundColor, color: t.color }) }, $(t.titles.fullscreen), 7)) : u("", !0) ], 32)) : u("", !0), t.hasAnimation ? (o(), s("button", { key: 9, tabindex: "0", class: "vue-ui-user-options-button", onMouseenter: n[19] || (n[19] = (a) => e(i).animation = !0), onMouseout: n[20] || (n[20] = (a) => e(i).animation = !1), onClick: D }, [ l.$slots.optionAnimation ? m(l.$slots, "optionAnimation", P(X({ key: 0 }, { toggleAnimation: D, isAnimated: e(I) })), void 0, !0) : (o(), s(S, { key: 1 }, [ e(I) ? (o(), g(r, { key: 0, name: "play", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) : u("", !0), e(I) ? u("", !0) : (o(), g(r, { key: 1, name: "pause", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) ], 64)), e(v) && t.titles.fullscreen && !l.$slots.optionAnimation ? (o(), s("div", { key: 2, dir: "auto", class: c({ "button-info-left": t.position === "left", "button-info-right": t.position === "right", "button-info-right-visible": t.position === "right" && e(i).animation, "button-info-left-visible": t.position === "left" && e(i).animation }), style: b({ background: t.backgroundColor, color: t.color }) }, $(t.titles.animation), 7)) : u("", !0) ], 32)) : u("", !0), t.hasAnnotator ? (o(), s("button", { key: 10, tabindex: "0", class: "vue-ui-user-options-button", onMouseenter: n[21] || (n[21] = (a) => e(i).annotator = !0), onMouseout: n[22] || (n[22] = (a) => e(i).annotator = !1), onClick: N }, [ l.$slots.optionAnnotator ? m(l.$slots, "optionAnnotator", P(X({ key: 0 }, { toggleAnnotator: N, isAnnotator: e(E) })), void 0, !0) : (o(), s(S, { key: 1 }, [ e(E) ? (o(), g(r, { key: 0, name: "annotatorDisabled", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) : u("", !0), e(E) ? u("", !0) : (o(), g(r, { key: 1, name: "annotator", stroke: t.color, style: { "pointer-events": "none" } }, null, 8, ["stroke"])) ], 64)), e(v) && t.titles.annotator && !l.$slots.optionAnnotator ? (o(), s("div", { key: 2, dir: "auto", class: c({ "button-info-left": t.position === "left", "button-info-right": t.position === "right", "button-info-right-visible": t.position === "right" && e(i).annotator, "button-info-left-visible": t.position === "left" && e(i).annotator }), style: b({ background: t.backgroundColor, color: t.color }) }, $(t.titles.annotator), 7)) : u("", !0) ], 32)) : u("", !0) ], 12, it) ], 4)), [ [e(ot), q] ]); } }, rt = /* @__PURE__ */ et(lt, [["__scopeId", "data-v-7bde71b6"]]); function ft({ elementId: t, fileName: A, canPrint: f = !0 }) { const d = k(!1), B = k(!1), M = k(null); async function F() { !f || d.value || (d.value = !0, clearTimeout(M.value), M.value = setTimeout(async () => { if (f) try { const { default: h } = await import("./pdf-CDVxhECX.js"); await h({ domElement: document.getElementById(t), fileName: A }); } catch (h) { console.error("Error generating PDF:", h); } finally { d.value = !1; } }, 100)); } async function T() { !f || B.value || (B.value = !0, clearTimeout(M.value), M.value = setTimeout(async () => { if (f) try { const { default: h } = await import("./img-DGzWcJ4Y.js"); await h({ domElement: document.getElementById(t), fileName: A, format: "png" }); } catch (h) { console.error("Error generating image:", h); } finally { B.value = !1; } }, 100)); } return { generatePdf: F, generateImage: T, isPrinting: d, isImaging: B }; } export { rt as U, ft as u, ot as v };