UNPKG

vue-data-ui-hq

Version:

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

602 lines (601 loc) 23.8 kB
import { computed as v, onMounted as Fe, ref as i, watch as Ie, openBlock as s, createElementBlock as u, normalizeClass as E, unref as e, normalizeStyle as V, createBlock as $, createCommentVNode as c, createSlots as Ae, withCtx as h, renderSlot as d, normalizeProps as O, guardReactiveProps as N, createVNode as ue, createElementVNode as _, Fragment as ce, renderList as de, createTextVNode as he, toDisplayString as M, nextTick as Ee } from "vue"; import { u as Ve, o as Me, e as ve, g as De, c as pe, t as Be, a as Ge, p as D, b as ze, d as Ue, J as ye, M as We, f as k, X as He, i as ge, x as fe, y as Xe, q as je, r as Re } from "./index-WrV3SAID.js"; import { L as Ye } from "./Legend-7H4oi6Sq.js"; import { _ as qe } from "./Title-BR-xoRp4.js"; import { _ as Je } from "./Tooltip-ho4JxRm-.js"; import { D as Ke } from "./DataTable-DNPvKWC0.js"; import { u as Qe, U as Ze } from "./usePrinter-kVpf1iV8.js"; import et from "./vue-ui-skeleton-Qec_XSRf.js"; import tt from "./vue-ui-accordion-BQCDXXDs.js"; import { u as be } from "./useNestedProp-Cj0kHD7k.js"; import { _ as ot } from "./PackageVersion-1NslmM8M.js"; import { P as lt } from "./PenAndPaper-BF1ZRVm3.js"; import { u as at } from "./useUserOptionState-BIvW1Kz7.js"; import { _ as st } from "./_plugin-vue_export-helper-CHgC5LLL.js"; const rt = ["id"], nt = { key: 1, ref: "noTitle", class: "vue-data-ui-no-title-space", style: "height:36px; width: 100%;background:transparent" }, it = { key: 2, style: "width:100%;background:transparent;padding-bottom:24px" }, ut = ["xmlns", "viewBox"], ct = ["width", "height"], dt = ["id"], ht = ["stdDeviation"], vt = ["d", "stroke", "stroke-width"], pt = ["d", "stroke", "stroke-width"], yt = ["filter"], gt = ["d", "stroke", "stroke-width"], ft = ["d", "stroke-width", "onMouseenter", "onClick"], bt = { key: 5, class: "vue-data-ui-watermark" }, mt = ["onClick"], kt = { key: 0 }, Ct = { key: 1 }, wt = { key: 8, ref: "source", dir: "auto" }, $t = ["innerHTML"], xt = { __name: "vue-ui-galaxy", props: { config: { type: Object, default() { return {}; } }, dataset: { type: Array, default() { return []; } } }, emits: ["selectLegend", "selectDatapoint"], setup(me, { expose: ke, emit: Ce }) { const { vue_ui_galaxy: we } = Ve(), y = me, L = v(() => !!y.dataset && y.dataset.length); Fe(() => { X(); }); function X() { Me(y.dataset) ? ve({ componentName: "VueUiGalaxy", type: "dataset" }) : y.dataset.forEach((o, a) => { De({ datasetObject: o, requiredAttributes: ["name", "values"] }).forEach((l) => { ve({ componentName: "VueUiGalaxy", type: "datasetSerieAttribute", property: l, index: a }); }); }); } const T = i(pe()), F = i(null), $e = i(null), B = i(!1), G = i(""), g = i(null), j = i(0), R = i(0), Y = i(0), q = i(0), t = v({ get: () => Q(), set: (o) => o }), { userOptionsVisible: z, setUserOptionsVisibility: J, keepUserOptionState: K } = at({ config: t.value }); function Q() { const o = be({ userConfig: y.config, defaultConfig: we }); return o.theme ? { ...be({ userConfig: Be.vue_ui_galaxy[o.theme] || y.config, defaultConfig: o }), customPalette: Ge[o.theme] || D } : o; } Ie(() => y.config, (o) => { t.value = Q(), z.value = !t.value.showOnChartHover, X(), R.value += 1, Y.value += 1, q.value += 1; }, { deep: !0 }); const { isPrinting: Z, isImaging: ee, generatePdf: te, generateImage: oe } = Qe({ elementId: `galaxy_${T.value}`, fileName: t.value.style.chart.title.text || "vue-ui-galaxy" }), xe = v(() => t.value.userOptions.show && !t.value.style.chart.title.text), _e = v(() => ze(t.value.customPalette)), b = i({ dataLabels: { show: t.value.style.chart.layout.labels.dataLabels.show }, showTable: t.value.table.show, showTooltip: t.value.style.chart.tooltip.show }), P = i({ height: 180, // or 250 if non fibo width: 250 }), le = Ce, p = i([]); function U(o) { p.value.includes(o.id) ? p.value = p.value.filter((a) => a !== o.id) : p.value.push(o.id), le("selectLegend", S.value.map((a) => ({ name: a.name, color: a.color, value: a.value }))); } const C = v(() => y.dataset.map((o, a) => ({ name: o.name, color: Ue(o.color) || _e.value[a] || D[a] || D[a % D.length], value: o.values ? ye(o.values).reduce((l, r) => l + r, 0) : 0, absoluteValues: ye(o.values), id: pe(), seriesIndex: a })).sort((o, a) => a.value - o.value)); function Te() { return C.value.map((o) => ({ name: o.name, color: o.color, value: o.value })); } const f = v(() => C.value.filter((o) => !p.value.includes(o.id)).map((o) => o.value).reduce((o, a) => o + a, 0)), Pe = i(190), ae = v(() => C.value.filter((o) => !p.value.includes(o.id))), S = v(() => { const o = []; for (let a = 0; a < ae.value.length; a += 1) { const l = ae.value[a]; let r = l.value / f.value * Pe.value; a > 0 && o.length && (r += o[a - 1].points), o.push({ points: r, ...l, seriesIndex: a, proportion: l.value / f.value, path: We({ points: r, startX: 115 + t.value.style.chart.layout.arcs.offsetX, startY: 90 + t.value.style.chart.layout.arcs.offsetY }) }); } return o.filter((a, l) => !p.value.includes(a.id)).toSorted((a, l) => l.points - a.points); }), x = i(!1); function Se(o) { x.value = o, j.value += 1; } const W = i(null); function Oe({ datapoint: o, _relativeIndex: a, seriesIndex: l, show: r = !1 }) { W.value = { datapoint: o, seriesIndex: l, series: C.value, config: t.value }, B.value = r, g.value = o.id; let n = ""; const w = t.value.style.chart.tooltip.customFormat; fe(w) && Xe(() => w({ seriesIndex: l, datapoint: o, series: C.value, config: t.value })) ? G.value = w({ seriesIndex: l, datapoint: o, series: C.value, config: t.value }) : (n += `<div style="width:100%;text-align:center;border-bottom:1px solid ${t.value.style.chart.tooltip.borderColor};padding-bottom:6px;margin-bottom:3px;">${o.name}</div>`, n += `<div style="display:flex;flex-direction:row;gap:6px;align-items:center;"><svg viewBox="0 0 12 12" height="14" width="14"><circle cx="6" cy="6" r="6" stroke="none" fill="${o.color}"/></svg>`, t.value.style.chart.tooltip.showValue && (n += `<b>${ge( t.value.style.chart.layout.labels.dataLabels.formatter, o.value, k({ p: t.value.style.chart.layout.labels.dataLabels.prefix, v: o.value, s: t.value.style.chart.layout.labels.dataLabels.suffix, r: t.value.style.chart.tooltip.roundingValue }), { datapoint: o, seriesIndex: l } )}</b>`), t.value.style.chart.tooltip.showPercentage && (t.value.style.chart.tooltip.showValue ? n += `<span>(${k({ v: o.proportion * 100, s: "%", r: t.value.style.chart.tooltip.roundingPercentage })})</span></div>` : n += `<b>${k({ v: o.proportion * 100, s: "%", r: t.value.style.chart.tooltip.roundingPercentage })}</b></div>`), G.value = `<div>${n}</div>`); } const se = v(() => C.value.map((o, a) => ({ ...o, proportion: (o.value || 0) / y.dataset.map((l) => (l.values || []).reduce((r, n) => r + n, 0)).reduce((l, r) => l + r, 0), opacity: p.value.includes(o.id) ? 0.5 : 1, shape: o.shape || "circle", segregate: () => U(o), isSegregated: p.value.includes(o.id) }))), Ne = v(() => ({ cy: "galaxy-div-legend", backgroundColor: t.value.style.chart.legend.backgroundColor, color: t.value.style.chart.legend.color, fontSize: t.value.style.chart.legend.fontSize, paddingBottom: 12, fontWeight: t.value.style.chart.legend.bold ? "bold" : "" })), m = v(() => { const o = S.value.map((l) => ({ name: l.name, color: l.color })), a = S.value.map((l) => l.value); return { head: o, body: a }; }); function re() { Ee(() => { const o = m.value.head.map((r, n) => [[ r.name ], [m.value.body[n]], [isNaN(m.value.body[n] / f.value) ? "-" : m.value.body[n] / f.value * 100]]), a = [[t.value.style.chart.title.text], [t.value.style.chart.title.subtitle.text], [[""], ["val"], ["%"]]].concat(o), l = je(a); Re({ csvContent: l, title: t.value.style.chart.title.text || "vue-ui-galaxy" }); }); } const I = v(() => { const o = [ ' <svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M18 16v2a1 1 0 0 1 -1 1h-11l6 -7l-6 -7h11a1 1 0 0 1 1 1v2" /></svg>', k({ p: t.value.style.chart.layout.labels.dataLabels.prefix, v: f.value, s: t.value.style.chart.layout.labels.dataLabels.suffix, r: t.value.table.td.roundingValue }), "100%" ], a = m.value.head.map((n, w) => { const Le = k({ p: t.value.style.chart.layout.labels.dataLabels.prefix, v: m.value.body[w], s: t.value.style.chart.layout.labels.dataLabels.suffix, r: t.value.table.td.roundingValue }); return [ { color: n.color, name: n.name }, Le, isNaN(m.value.body[w] / f.value) ? "-" : k({ v: m.value.body[w] / f.value * 100, s: "%", r: t.value.table.td.roundingPercentage }) ]; }), l = { th: { backgroundColor: t.value.table.th.backgroundColor, color: t.value.table.th.color, outline: t.value.table.th.outline }, td: { backgroundColor: t.value.table.td.backgroundColor, color: t.value.table.td.color, outline: t.value.table.td.outline }, breakpoint: t.value.table.responsiveBreakpoint }; return { colNames: [ t.value.table.columnNames.series, t.value.table.columnNames.value, t.value.table.columnNames.percentage ], head: o, body: a, config: l }; }); function ne() { b.value.showTable = !b.value.showTable; } function ie() { b.value.showTooltip = !b.value.showTooltip; } const A = i(!1); function H() { A.value = !A.value; } return ke({ getData: Te, generatePdf: te, generateCsv: re, generateImage: oe, toggleTable: ne, toggleTooltip: ie, toggleAnnotator: H }), (o, a) => (s(), u("div", { ref_key: "galaxyChart", ref: F, class: E(`vue-ui-galaxy ${e(x) ? "vue-data-ui-wrapper-fullscreen" : ""} ${e(t).useCssAnimation ? "" : "vue-ui-dna"}`), style: V(`font-family:${e(t).style.fontFamily};width:100%; text-align:center;${e(t).style.chart.title.text ? "" : "padding-top:36px"};background:${e(t).style.chart.backgroundColor}`), id: `galaxy_${e(T)}`, onMouseenter: a[3] || (a[3] = () => e(J)(!0)), onMouseleave: a[4] || (a[4] = () => e(J)(!1)) }, [ e(t).userOptions.buttons.annotator ? (s(), $(lt, { key: 0, parent: e(F), backgroundColor: e(t).style.chart.backgroundColor, color: e(t).style.chart.color, active: e(A), onClose: H }, null, 8, ["parent", "backgroundColor", "color", "active"])) : c("", !0), e(xe) ? (s(), u("div", nt, null, 512)) : c("", !0), e(t).style.chart.title.text ? (s(), u("div", it, [ (s(), $(qe, { key: `title_${e(R)}`, config: { title: { cy: "galaxy-div-title", ...e(t).style.chart.title }, subtitle: { cy: "galaxy-div-subtitle", ...e(t).style.chart.title.subtitle } } }, null, 8, ["config"])) ])) : c("", !0), e(t).userOptions.show && e(L) && (e(K) || e(z)) ? (s(), $(Ze, { ref_key: "details", ref: $e, key: `user_option_${e(j)}`, backgroundColor: e(t).style.chart.backgroundColor, color: e(t).style.chart.color, isPrinting: e(Z), isImaging: e(ee), uid: e(T), hasTooltip: e(t).userOptions.buttons.tooltip && e(t).style.chart.tooltip.show, hasPdf: e(t).userOptions.buttons.pdf, hasXls: e(t).userOptions.buttons.csv, hasImg: e(t).userOptions.buttons.img, hasTable: e(t).userOptions.buttons.table, hasFullscreen: e(t).userOptions.buttons.fullscreen, isTooltip: e(b).showTooltip, isFullscreen: e(x), titles: { ...e(t).userOptions.buttonTitles }, chartElement: e(F), position: e(t).userOptions.position, hasAnnotator: e(t).userOptions.buttons.annotator, isAnnotation: e(A), onToggleFullscreen: Se, onGeneratePdf: e(te), onGenerateCsv: re, onGenerateImage: e(oe), onToggleTable: ne, onToggleTooltip: ie, onToggleAnnotator: H, style: V({ visibility: e(K) ? e(z) ? "visible" : "hidden" : "visible" }) }, Ae({ _: 2 }, [ o.$slots.optionTooltip ? { name: "optionTooltip", fn: h(() => [ d(o.$slots, "optionTooltip", {}, void 0, !0) ]), key: "0" } : void 0, o.$slots.optionPdf ? { name: "optionPdf", fn: h(() => [ d(o.$slots, "optionPdf", {}, void 0, !0) ]), key: "1" } : void 0, o.$slots.optionCsv ? { name: "optionCsv", fn: h(() => [ d(o.$slots, "optionCsv", {}, void 0, !0) ]), key: "2" } : void 0, o.$slots.optionImg ? { name: "optionImg", fn: h(() => [ d(o.$slots, "optionImg", {}, void 0, !0) ]), key: "3" } : void 0, o.$slots.optionTable ? { name: "optionTable", fn: h(() => [ d(o.$slots, "optionTable", {}, void 0, !0) ]), key: "4" } : void 0, o.$slots.optionFullscreen ? { name: "optionFullscreen", fn: h(({ toggleFullscreen: l, isFullscreen: r }) => [ d(o.$slots, "optionFullscreen", O(N({ toggleFullscreen: l, isFullscreen: r })), void 0, !0) ]), key: "5" } : void 0, o.$slots.optionAnnotator ? { name: "optionAnnotator", fn: h(({ toggleAnnotator: l, isAnnotator: r }) => [ d(o.$slots, "optionAnnotator", O(N({ toggleAnnotator: l, isAnnotator: r })), void 0, !0) ]), key: "6" } : void 0 ]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasTooltip", "hasPdf", "hasXls", "hasImg", "hasTable", "hasFullscreen", "isTooltip", "isFullscreen", "titles", "chartElement", "position", "hasAnnotator", "isAnnotation", "onGeneratePdf", "onGenerateImage", "style"])) : c("", !0), e(L) ? (s(), u("svg", { key: 4, xmlns: e(He), class: E({ "vue-data-ui-fullscreen--on": e(x), "vue-data-ui-fulscreen--off": !e(x) }), viewBox: `0 0 ${e(P).width} ${e(P).height}`, style: V(`max-width:100%; overflow: visible; background:transparent;color:${e(t).style.chart.color}`) }, [ ue(ot), o.$slots["chart-background"] ? (s(), u("foreignObject", { key: 0, x: 0, y: 0, width: e(P).width, height: e(P).height, style: { pointerEvents: "none" } }, [ d(o.$slots, "chart-background", {}, void 0, !0) ], 8, ct)) : c("", !0), _("defs", null, [ _("filter", { id: `blur_${e(T)}`, x: "-50%", y: "-50%", width: "200%", height: "200%" }, [ _("feGaussianBlur", { in: "SourceGraphic", stdDeviation: 100 / e(t).style.chart.layout.arcs.gradient.intensity }, null, 8, ht) ], 8, dt) ]), (s(!0), u(ce, null, de(e(S), (l) => (s(), u("g", null, [ l.value ? (s(), u("path", { key: 0, d: l.path, fill: "none", stroke: e(t).style.chart.backgroundColor, "stroke-width": (e(t).style.chart.layout.arcs.strokeWidth + e(t).style.chart.layout.arcs.borderWidth) * (e(g) === l.id && e(t).style.chart.layout.arcs.hoverEffect.show ? e(t).style.chart.layout.arcs.hoverEffect.multiplicator : 1), "stroke-linecap": "round" }, null, 8, vt)) : c("", !0), l.value ? (s(), u("path", { key: 1, d: l.path, fill: "none", stroke: l.color, "stroke-width": e(t).style.chart.layout.arcs.strokeWidth * (e(g) === l.id && e(t).style.chart.layout.arcs.hoverEffect.show ? e(t).style.chart.layout.arcs.hoverEffect.multiplicator : 1), "stroke-linecap": "round", class: E(`${e(g) && e(g) !== l.id && e(t).useBlurOnHover ? "vue-ui-galaxy-blur" : ""}`) }, null, 10, pt)) : c("", !0), l.value && e(t).style.chart.layout.arcs.gradient.show ? (s(), u("g", { key: 2, filter: `url(#blur_${e(T)})` }, [ _("path", { d: l.path, fill: "none", stroke: e(t).style.chart.layout.arcs.gradient.color, "stroke-width": e(t).style.chart.layout.arcs.strokeWidth / 2 * (e(g) === l.id && e(t).style.chart.layout.arcs.hoverEffect.show ? e(t).style.chart.layout.arcs.hoverEffect.multiplicator : 1), "stroke-linecap": "round", class: E(`vue-ui-galaxy-gradient ${e(g) && e(g) !== l.id && e(t).useBlurOnHover ? "vue-ui-galaxy-blur" : ""}`) }, null, 10, gt) ], 8, yt)) : c("", !0) ]))), 256)), (s(!0), u(ce, null, de(e(S), (l, r) => (s(), u("g", null, [ l.value ? (s(), u("path", { key: 0, d: l.path, fill: "none", stroke: "transparent", "stroke-width": e(t).style.chart.layout.arcs.strokeWidth + e(t).style.chart.layout.arcs.borderWidth, "stroke-linecap": "round", onMouseenter: (n) => Oe({ datapoint: l, relativeIndex: r, seriesIndex: l.seriesIndex, show: !0 }), onMouseleave: a[0] || (a[0] = (n) => { B.value = !1, g.value = null; }), onClick: (n) => le("selectDatapoint", l) }, null, 40, ft)) : c("", !0) ]))), 256)), d(o.$slots, "svg", { svg: e(P) }, void 0, !0) ], 14, ut)) : c("", !0), o.$slots.watermark ? (s(), u("div", bt, [ d(o.$slots, "watermark", O(N({ isPrinting: e(Z) || e(ee) })), void 0, !0) ])) : c("", !0), e(L) ? c("", !0) : (s(), $(et, { key: 6, config: { type: "galaxy", style: { backgroundColor: e(t).style.chart.backgroundColor, galaxy: { color: "#CCCCCC" } } } }, null, 8, ["config"])), e(t).style.chart.legend.show ? (s(), $(Ye, { key: `legend_${e(q)}`, legendSet: e(se), config: e(Ne), onClickMarker: a[1] || (a[1] = ({ legend: l }) => U(l)) }, { item: h(({ legend: l, index: r }) => [ _("div", { onClick: (n) => U(l), style: V(`opacity:${e(p).includes(l.id) ? 0.5 : 1}`) }, [ he(M(l.name) + ": " + M(e(ge)( e(t).style.chart.layout.labels.dataLabels.formatter, l.value, e(k)({ p: e(t).style.chart.layout.labels.dataLabels.prefix, v: l.value, s: e(t).style.chart.layout.labels.dataLabels.suffix, r: e(t).style.chart.legend.roundingValue }), { datapoint: l, seriesIndex: r } )) + " ", 1), e(p).includes(l.id) ? (s(), u("span", Ct, " ( - % ) ")) : (s(), u("span", kt, " (" + M(isNaN(l.value / e(f)) ? "-" : e(k)({ v: l.value / e(f) * 100, s: "%", r: e(t).style.chart.legend.roundingPercentage })) + ") ", 1)) ], 12, mt) ]), _: 1 }, 8, ["legendSet", "config"])) : c("", !0), d(o.$slots, "legend", { legend: e(se) }, void 0, !0), o.$slots.source ? (s(), u("div", wt, [ d(o.$slots, "source", {}, void 0, !0) ], 512)) : c("", !0), ue(Je, { show: e(b).showTooltip && e(B), backgroundColor: e(t).style.chart.tooltip.backgroundColor, color: e(t).style.chart.tooltip.color, borderRadius: e(t).style.chart.tooltip.borderRadius, borderColor: e(t).style.chart.tooltip.borderColor, borderWidth: e(t).style.chart.tooltip.borderWidth, fontSize: e(t).style.chart.tooltip.fontSize, backgroundOpacity: e(t).style.chart.tooltip.backgroundOpacity, position: e(t).style.chart.tooltip.position, offsetY: e(t).style.chart.tooltip.offsetY, parent: e(F), content: e(G), isFullscreen: e(x), isCustom: e(fe)(e(t).style.chart.tooltip.customFormat) }, { "tooltip-before": h(() => [ d(o.$slots, "tooltip-before", O(N({ ...e(W) })), void 0, !0) ]), "tooltip-after": h(() => [ d(o.$slots, "tooltip-after", O(N({ ...e(W) })), void 0, !0) ]), _: 3 }, 8, ["show", "backgroundColor", "color", "borderRadius", "borderColor", "borderWidth", "fontSize", "backgroundOpacity", "position", "offsetY", "parent", "content", "isFullscreen", "isCustom"]), e(L) ? (s(), $(tt, { key: 9, hideDetails: "", config: { open: e(b).showTable, maxHeight: 1e4, body: { backgroundColor: e(t).style.chart.backgroundColor, color: e(t).style.chart.color }, head: { backgroundColor: e(t).style.chart.backgroundColor, color: e(t).style.chart.color } } }, { content: h(() => [ (s(), $(Ke, { key: `table_${e(Y)}`, colNames: e(I).colNames, head: e(I).head, body: e(I).body, config: e(I).config, title: `${e(t).style.chart.title.text}${e(t).style.chart.title.subtitle.text ? ` : ${e(t).style.chart.title.subtitle.text}` : ""}`, onClose: a[2] || (a[2] = (l) => e(b).showTable = !1) }, { th: h(({ th: l }) => [ _("div", { innerHTML: l, style: { display: "flex", "align-items": "center" } }, null, 8, $t) ]), td: h(({ td: l }) => [ he(M(l.name || l), 1) ]), _: 1 }, 8, ["colNames", "head", "body", "config", "title"])) ]), _: 1 }, 8, ["config"])) : c("", !0) ], 46, rt)); } }, Bt = /* @__PURE__ */ st(xt, [["__scopeId", "data-v-31c4c9ad"]]); export { Bt as default };