UNPKG

vue-data-ui

Version:

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

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