vue-data-ui
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
650 lines (649 loc) • 25 kB
JavaScript
import { ref as m, computed as P, onMounted as ee, onBeforeUnmount as te, withDirectives as oe, createElementBlock as s, openBlock as o, normalizeStyle as v, createElementVNode as x, withKeys as ne, withModifiers as le, renderSlot as k, normalizeProps as h, guardReactiveProps as ie, createVNode as se, normalizeClass as d, createCommentVNode as a, Fragment as $, createBlock as f, toDisplayString as c, mergeProps as M, unref as ae } from "vue";
import { v as ue } from "./vClickOutside-C6WiFswA.js";
import r from "./BaseIcon-CbVDYv89.js";
import D from "./img-CqYIrJ8I.js";
import { _ as re } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const fe = ["title"], ve = ["data-open"], ge = {
__name: "UserOptions",
props: {
hasPdf: {
type: Boolean,
default: !0
},
hasXls: {
type: Boolean,
default: !0
},
hasImg: {
type: Boolean,
default: !1
},
hasSvg: {
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
},
callbacks: {
type: Object,
default() {
return {};
}
},
printScale: {
type: Number,
default: 2
},
tableDialog: {
type: Boolean,
default: !1
},
hasZoom: {
type: Boolean,
default: !1
},
isZoom: {
type: Boolean,
default: !1
}
},
emits: [
"generatePdf",
"generateCsv",
"generateImage",
"toggleTable",
"toggleLabels",
"toggleSort",
"toggleFullscreen",
"toggleStack",
"toggleTooltip",
"toggleAnimation",
"toggleAnnotator",
"generateSvg",
"toggleZoom"
],
setup(e, { expose: X, emit: N }) {
const i = e, g = N;
async function U() {
if (i.callbacks.pdf) {
const { imageUri: l, base64: t } = await D({ domElement: i.chartElement, base64: !0, img: !0, scale: i.printScale });
i.callbacks.pdf({ domElement: i.chartElement, base64: t, imageUri: l });
} else
g("generatePdf");
}
function j() {
g("generateCsv", i.callbacks.csv);
}
async function V() {
if (i.callbacks.img) {
const { imageUri: l, base64: t } = await D({ domElement: i.chartElement, base64: !0, img: !0, scale: i.printScale });
i.callbacks.img({ domElement: i.chartElement, imageUri: l, base64: t });
} else
g("generateImage");
}
function K() {
g("generateSvg", { isCb: !!i.callbacks.svg });
}
const C = m(!1);
function W() {
i.callbacks.table ? i.callbacks.table() : (C.value = !C.value, g("toggleTable"));
}
function q(l) {
C.value = l;
}
X({
setTableIconState: q
});
const y = m(!1), H = m(!0);
function I() {
b.value = window.innerWidth > 600, y.value = !y.value, y.value && (H.value = !1);
}
function R() {
i.isPrinting || i.isImaging || (y.value = !1);
}
function G() {
y.value && R();
}
const F = m(i.isLabelActive);
function J() {
i.callbacks.labels ? i.callbacks.labels() : (F.value = !F.value, g("toggleLabels"));
}
const S = m(i.isAnimation);
function z() {
i.callbacks.animation ? i.callbacks.animation() : (S.value = !S.value, g("toggleAnimation"));
}
const E = m(i.isZoom);
function O() {
i.callbacks.zoom ? i.callbacks.zoom() : (E.value = !E.value, g("toggleZoom"));
}
const B = P({
get: () => i.isAnnotation,
set: (l) => l
});
function L() {
i.callbacks.annotator ? i.callbacks.annotator() : (B.value = !B.value, g("toggleAnnotator"));
}
function Q() {
i.callbacks.sort ? i.callbacks.sort() : g("toggleSort");
}
const A = m(i.isStacked);
function Y() {
i.callbacks.stack ? i.callbacks.stack() : (A.value = !A.value, g("toggleStack"));
}
const T = m(i.isTooltip);
function p() {
i.callbacks.tooltip ? i.callbacks.tooltip() : (T.value = !T.value, g("toggleTooltip"));
}
const _ = P({
get: () => i.isFullscreen,
set: (l) => g("toggleFullscreen", l)
});
function Z() {
if (!i.chartElement) return;
const l = !i.isFullscreen;
_.value = l, l ? i.chartElement.requestFullscreen() : document.exitFullscreen();
}
function w() {
const l = !!document.fullscreenElement;
g("toggleFullscreen", l);
}
ee(() => {
document.addEventListener("fullscreenchange", w);
}), te(() => {
document.removeEventListener("fullscreenchange", w);
});
const b = m(window.innerWidth > 600), n = m({
tooltip: !1,
pdf: !1,
csv: !1,
img: !1,
table: !1,
labels: !1,
sort: !1,
stack: !1,
fullscreen: !1,
animation: !1,
annotator: !1,
svg: !1,
zoom: !1
});
return (l, t) => oe((o(), s("div", {
"data-dom-to-png-ignore": "",
class: "vue-ui-user-options",
style: v(`z-index: ${e.zIndex}; height: 34px; position: ${e.isFullscreen ? "fixed" : "absolute"}; top: 0; ${e.position === "right" ? `right:${e.isFullscreen ? "12px" : "0"}` : `left:${e.isFullscreen ? "12px" : "0"}`}; padding: 4px; background:transparent;`)
}, [
x("div", {
tabindex: "0",
title: y.value ? e.titles.close || "" : e.titles.open || "",
style: v(`width:32px; position: absolute; top: 0;${e.position === "right" ? `right: ${e.offsetX ? e.offsetX : e.noOffset ? 0 : 4}px` : `left: ${e.noOffset ? 0 : 4}px`}; padding: 0 0px; display: flex; align-items:center;justify-content:center;height: 36px; cursor:pointer; background:transparent`),
onClick: le(I, ["stop"]),
onKeypress: ne(I, ["enter"])
}, [
k(l.$slots, "menuIcon", h(ie({ isOpen: y.value, color: e.color })), () => [
se(r, {
name: y.value ? "close" : "menu",
stroke: e.color,
"stroke-width": 2
}, null, 8, ["name", "stroke"])
], !0)
], 44, fe),
x("div", {
"data-open": y.value,
class: d({ "vue-ui-user-options-drawer": !0 }),
style: v(`background:${e.backgroundColor}; ${e.position === "right" ? `right: ${e.offsetX ? e.offsetX : e.noOffset ? 0 : 4}px` : `left: ${e.noOffset ? 0 : 4}px`}`)
}, [
e.hasTooltip ? (o(), s("button", {
key: 0,
tabindex: "0",
class: "vue-ui-user-options-button",
onClick: p,
onMouseenter: t[0] || (t[0] = (u) => n.value.tooltip = !0),
onMouseout: t[1] || (t[1] = (u) => n.value.tooltip = !1)
}, [
l.$slots.optionTooltip ? k(l.$slots, "optionTooltip", { key: 0 }, void 0, !0) : (o(), s($, { key: 1 }, [
T.value ? (o(), f(r, {
key: 0,
name: "tooltip",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"])) : (o(), f(r, {
key: 1,
name: "tooltipDisabled",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"]))
], 64)),
b.value && e.titles.tooltip ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-left-visible": e.position === "left" && n.value.tooltip, "button-info-right-visible": e.position === "right" && n.value.tooltip }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.tooltip), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasPdf ? (o(), s("button", {
key: 1,
tabindex: "0",
class: "vue-ui-user-options-button",
onClick: U,
onMouseenter: t[2] || (t[2] = (u) => n.value.pdf = !0),
onMouseout: t[3] || (t[3] = (u) => n.value.pdf = !1)
}, [
l.$slots.optionPdf ? k(l.$slots, "optionPdf", { key: 0 }, void 0, !0) : (o(), s($, { key: 1 }, [
e.isPrinting ? (o(), f(r, {
key: 0,
name: "spin",
isSpin: "",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"])) : (o(), f(r, {
key: 1,
name: "pdf",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"]))
], 64)),
b.value && e.titles.pdf ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.pdf, "button-info-left-visible": e.position === "left" && n.value.pdf }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.pdf), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasXls ? (o(), s("button", {
key: 2,
tabindex: "0",
class: "vue-ui-user-options-button",
onClick: j,
onMouseenter: t[4] || (t[4] = (u) => n.value.csv = !0),
onMouseout: t[5] || (t[5] = (u) => n.value.csv = !1)
}, [
l.$slots.optionCsv ? k(l.$slots, "optionCsv", { key: 0 }, void 0, !0) : (o(), f(r, {
key: 1,
name: "excel",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"])),
b.value && e.titles.csv ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.csv, "button-info-left-visible": e.position === "left" && n.value.csv }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.csv), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasImg ? (o(), s("button", {
key: 3,
tabindex: "0",
class: "vue-ui-user-options-button",
onClick: V,
onMouseenter: t[6] || (t[6] = (u) => n.value.img = !0),
onMouseout: t[7] || (t[7] = (u) => n.value.img = !1)
}, [
l.$slots.optionImg ? k(l.$slots, "optionImg", { key: 0 }, void 0, !0) : (o(), s($, { key: 1 }, [
e.isImaging ? (o(), f(r, {
key: 0,
name: "spin",
isSpin: "",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"])) : (o(), f(r, {
key: 1,
name: "image",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"]))
], 64)),
b.value && e.titles.img ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.img, "button-info-left-visible": e.position === "left" && n.value.img }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.img), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasSvg ? (o(), s("button", {
key: 4,
tabindex: "0",
class: "vue-ui-user-options-button",
onClick: K,
onMouseenter: t[8] || (t[8] = (u) => n.value.svg = !0),
onMouseout: t[9] || (t[9] = (u) => n.value.svg = !1)
}, [
l.$slots.optionSvg ? k(l.$slots, "optionSvg", { key: 0 }, void 0, !0) : (o(), f(r, {
key: 1,
name: "svg",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"])),
b.value && e.titles.svg ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.svg, "button-info-left-visible": e.position === "left" && n.value.svg }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.svg), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasTable ? (o(), s("button", {
key: 5,
tabindex: "0",
class: "vue-ui-user-options-button",
onClick: W,
onMouseenter: t[10] || (t[10] = (u) => n.value.table = !0),
onMouseout: t[11] || (t[11] = (u) => n.value.table = !1)
}, [
l.$slots.optionTable ? k(l.$slots, "optionTable", { key: 0 }, void 0, !0) : (o(), s($, { key: 1 }, [
e.tableDialog ? (o(), f(r, {
key: 0,
name: C.value ? "tableDialogClose" : "tableDialogOpen",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["name", "stroke"])) : (o(), f(r, {
key: 1,
name: C.value ? "tableClose" : "tableOpen",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["name", "stroke"]))
], 64)),
b.value && e.titles.table ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.table, "button-info-left-visible": e.position === "left" && n.value.table }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.table), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasLabel ? (o(), s("button", {
key: 6,
tabindex: "0",
class: "vue-ui-user-options-button",
onClick: J,
onMouseenter: t[12] || (t[12] = (u) => n.value.labels = !0),
onMouseout: t[13] || (t[13] = (u) => n.value.labels = !1)
}, [
l.$slots.optionLabels ? k(l.$slots, "optionLabels", { key: 0 }, void 0, !0) : (o(), f(r, {
key: 1,
name: F.value ? "labelClose" : "labelOpen",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["name", "stroke"])),
b.value && e.titles.labels ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.labels, "button-info-left-visible": e.position === "left" && n.value.labels }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.labels), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasSort ? (o(), s("button", {
key: 7,
tabindex: "0",
class: "vue-ui-user-options-button",
onClick: Q,
onMouseenter: t[14] || (t[14] = (u) => n.value.sort = !0),
onMouseout: t[15] || (t[15] = (u) => n.value.sort = !1)
}, [
l.$slots.optionSort ? k(l.$slots, "optionSort", { key: 0 }, void 0, !0) : (o(), f(r, {
key: 1,
name: "sort",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"])),
b.value && e.titles.sort ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.sort, "button-info-left-visible": e.position === "left" && n.value.sort }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.sort), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasStack ? (o(), s("button", {
key: 8,
tabindex: "0",
class: "vue-ui-user-options-button",
onClick: Y,
onMouseenter: t[16] || (t[16] = (u) => n.value.stack = !0),
onMouseout: t[17] || (t[17] = (u) => n.value.stack = !1)
}, [
l.$slots.optionStack ? k(l.$slots, "optionStack", h(M({ key: 0 }, { isStack: A.value })), void 0, !0) : (o(), s($, { key: 1 }, [
A.value ? (o(), f(r, {
key: 0,
name: "unstack",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"])) : (o(), f(r, {
key: 1,
name: "stack",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"]))
], 64)),
b.value && e.titles.stack ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.stack, "button-info-left-visible": e.position === "left" && n.value.stack }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.stack), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasFullscreen ? (o(), s("button", {
key: 9,
tabindex: "0",
class: "vue-ui-user-options-button",
onMouseenter: t[18] || (t[18] = (u) => n.value.fullscreen = !0),
onMouseout: t[19] || (t[19] = (u) => n.value.fullscreen = !1),
onClick: t[20] || (t[20] = (u) => Z(e.isFullscreen ? "out" : "in"))
}, [
l.$slots.optionFullscreen ? k(l.$slots, "optionFullscreen", h(M({ key: 0 }, { toggleFullscreen: Z, isFullscreen: e.isFullscreen })), void 0, !0) : (o(), s($, { key: 1 }, [
e.isFullscreen ? (o(), f(r, {
key: 0,
name: "exitFullscreen",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"])) : a("", !0),
e.isFullscreen ? a("", !0) : (o(), f(r, {
key: 1,
name: "fullscreen",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"]))
], 64)),
b.value && e.titles.fullscreen ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.fullscreen, "button-info-left-visible": e.position === "left" && n.value.fullscreen }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.fullscreen), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasZoom ? (o(), s("button", {
key: 10,
tabindex: "0",
class: "vue-ui-user-options-button",
onMouseenter: t[21] || (t[21] = (u) => n.value.zoom = !0),
onMouseout: t[22] || (t[22] = (u) => n.value.zoom = !1),
onClick: t[23] || (t[23] = (u) => O())
}, [
l.$slots.optionZoom ? k(l.$slots, "optionZoom", h(M({ key: 0 }, { toggleZoom: O, isZoomLocked: !e.isZoom })), void 0, !0) : (o(), s($, { key: 1 }, [
e.isZoom ? (o(), f(r, {
key: 0,
name: "zoomUnlock",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"])) : a("", !0),
e.isZoom ? a("", !0) : (o(), f(r, {
key: 1,
name: "zoomLock",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"]))
], 64)),
b.value && e.titles.zoom ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.zoom, "button-info-left-visible": e.position === "left" && n.value.zoom }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.zoom), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasAnimation ? (o(), s("button", {
key: 11,
tabindex: "0",
class: "vue-ui-user-options-button",
onMouseenter: t[24] || (t[24] = (u) => n.value.animation = !0),
onMouseout: t[25] || (t[25] = (u) => n.value.animation = !1),
onClick: z
}, [
l.$slots.optionAnimation ? k(l.$slots, "optionAnimation", h(M({ key: 0 }, { toggleAnimation: z, isAnimated: S.value })), void 0, !0) : (o(), s($, { key: 1 }, [
S.value ? (o(), f(r, {
key: 0,
name: "play",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"])) : a("", !0),
S.value ? a("", !0) : (o(), f(r, {
key: 1,
name: "pause",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"]))
], 64)),
b.value && e.titles.fullscreen ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.animation, "button-info-left-visible": e.position === "left" && n.value.animation }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.animation), 7)) : a("", !0)
], 32)) : a("", !0),
e.hasAnnotator ? (o(), s("button", {
key: 12,
tabindex: "0",
class: "vue-ui-user-options-button",
onMouseenter: t[26] || (t[26] = (u) => n.value.annotator = !0),
onMouseout: t[27] || (t[27] = (u) => n.value.annotator = !1),
onClick: L
}, [
l.$slots.optionAnnotator ? k(l.$slots, "optionAnnotator", h(M({ key: 0 }, { toggleAnnotator: L, isAnnotator: B.value })), void 0, !0) : (o(), s($, { key: 1 }, [
B.value ? (o(), f(r, {
key: 0,
name: "annotatorDisabled",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"])) : a("", !0),
B.value ? a("", !0) : (o(), f(r, {
key: 1,
name: "annotator",
stroke: e.color,
style: { "pointer-events": "none" }
}, null, 8, ["stroke"]))
], 64)),
b.value && e.titles.annotator ? (o(), s("div", {
key: 2,
dir: "auto",
class: d({ "button-info-left": e.position === "left", "button-info-right": e.position === "right", "button-info-right-visible": e.position === "right" && n.value.annotator, "button-info-left-visible": e.position === "left" && n.value.annotator }),
style: v({ background: e.backgroundColor, color: e.color })
}, c(e.titles.annotator), 7)) : a("", !0)
], 32)) : a("", !0)
], 12, ve)
], 4)), [
[ae(ue), G]
]);
}
}, ye = /* @__PURE__ */ re(ge, [["__scopeId", "data-v-fd5fc9ca"]]);
export {
ye as default
};