UNPKG

vue-data-ui

Version:

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

302 lines (301 loc) • 11.2 kB
import { defineAsyncComponent as V, useSlots as R, onMounted as z, computed as g, ref as k, watch as L, nextTick as Y, createElementBlock as c, openBlock as u, normalizeStyle as p, unref as o, renderSlot as _, createCommentVNode as v, createBlock as Z, normalizeProps as ee, mergeProps as O, createElementVNode as d, toDisplayString as f, Fragment as T, renderList as te, createVNode as le } from "vue"; import { u as ae, c as oe, t as se, p as x, a as ne, b as ue, o as re, e as E, g as ie, d as ce, s as $, i as b, f as w, X as ve, w as de } from "./index-BLtEpj8j.js"; import { u as B } from "./useNestedProp-Bw1KcAmj.js"; const pe = ["onClick"], fe = { key: 1 }, ye = ["xmlns", "viewBox"], me = ["id"], ge = ["stop-color"], he = ["stop-color"], ke = ["height", "width", "fill", "rx"], xe = ["height", "width", "fill", "rx"], be = ["height", "width", "fill", "rx"], we = { key: 2, ref: "source", dir: "auto" }, Se = { __name: "vue-ui-sparkbar", props: { config: { type: Object, default() { return {}; } }, dataset: { type: Array, default() { return []; } }, /** * Used in VueUiRadar's tooltip exclusively */ backgroundOpacity: { type: Number, default: null } }, emits: ["selectDatapoint"], setup(C, { emit: M }) { const U = V(() => import("./PackageVersion-CnRyWKP-.js")), j = V(() => import("./vue-ui-skeleton-CsMU8DwQ.js")), { vue_ui_sparkbar: G } = ae(), a = C, W = R(); z(() => { W["chart-background"] && console.warn("VueUiSparkbar does not support the #chart-background slot."); }); const S = g(() => !!a.dataset && a.dataset.length), A = k(oe()), e = g({ get: () => N(), set: (t) => t }); function N() { const t = B({ userConfig: a.config, defaultConfig: G }); return t.theme ? { ...B({ userConfig: ne.vue_ui_sparkbar[t.theme] || a.config, defaultConfig: t }), customPalette: se[t.theme] || x } : t; } L(() => a.config, (t) => { e.value = N(); }, { deep: !0 }); const q = g(() => ue(e.value.customPalette)), y = k(a.dataset.map((t) => ({ ...t, value: e.value.style.animation.show ? 0 : t.value || 0, formatter: t.formatter || null }))), D = k(null); z(async () => { re(a.dataset) && E({ componentName: "VueUiSparkbar", type: "dataset" }), F(); }); function F() { if (e.value.style.animation.show) { let P = function() { i += l / t, i < l ? (y.value = y.value.map((n, h) => ({ ...n, value: n.value += s[h] })), D.value = requestAnimationFrame(P)) : y.value = a.dataset.map((n) => ({ ...n, value: n.value || 0, formatter: n.formatter || null })); }; const t = e.value.style.animation.animationFrames, s = a.dataset.map((n, h) => n.value / t), l = a.dataset.map((n) => n.value || 0).reduce((n, h) => n + h, 0); let i = 0; P(); } } L(() => a.dataset, async (t) => { cancelAnimationFrame(D.value), y.value = a.dataset.map((s) => ({ ...s, value: e.value.style.animation.show ? 0 : s.value || 0, formatter: s.formatter || null })), Y(F); }, { deep: !0 }); const r = k({ width: 500, height: 16 }), H = g(() => Math.max(...a.dataset.map((t) => t.value))), X = g(() => (a.dataset.forEach((t, s) => { ie({ datasetObject: t, requiredAttributes: ["name", "value"] }).forEach((l) => { E({ componentName: "VueUiSparkbar", type: "datasetSerieAttribute", property: l, index: s }); }); }), y.value.map((t, s) => ({ ...t, value: t.value || 0, color: ce(t.color) || q.value[s] || x[s] || x[s % x.length] })))); function J(t) { return t / H.value; } function I(t) { return e.value.style.layout.independant ? t.target ? t.value / t.target : e.value.style.layout.percentage ? t.value > 100 ? 1 : t.value / 100 : e.value.style.layout.target === 0 ? 1 : t.value / e.value.style.layout.target : J(t.value); } function m(t) { return e.value.style.layout.independant && t.target || e.value.style.layout.target; } const K = M; function Q(t, s) { K("selectDatapoint", { datapoint: t, index: s }); } return (t, s) => (u(), c("div", { class: "vue-ui-sparkbar", style: p({ width: "100%", fontFamily: e.value.style.fontFamily, background: a.backgroundOpacity !== null ? o($)(e.value.style.backgroundColor, a.backgroundOpacity) : e.value.style.backgroundColor }) }, [ t.$slots.title ? _(t.$slots, "title", ee(O({ key: 0 }, { title: { ...t.title, title: e.value.style.title.text, subtitle: e.value.style.title.subtitle.text } }))) : v("", !0), !t.$slots.title && e.value.style.title.text ? (u(), c("div", { key: 1, class: "vue-ui-sparkbar-title-container", style: p({ background: e.value.style.title.backgroundColor, margin: e.value.style.title.margin, textAlign: e.value.style.title.textAlign }) }, [ d("div", { class: "vue-ui-sparkbar-title", style: p({ fontSize: e.value.style.title.fontSize + "px", color: e.value.style.title.color, fontWeight: e.value.style.title.bold ? "bold" : "normal" }) }, f(e.value.style.title.text), 5), e.value.style.title.subtitle.text ? (u(), c("div", { key: 0, class: "vue-ui-sparkbar-subtitle", style: p({ fontSize: e.value.style.title.subtitle.fontSize + "px", color: e.value.style.title.subtitle.color, fontWeight: e.value.style.title.subtitle.bold ? "bold" : "normal" }) }, f(e.value.style.title.subtitle.text), 5)) : v("", !0) ], 4)) : v("", !0), (u(!0), c(T, null, te(X.value, (l, i) => (u(), c(T, null, [ S.value ? (u(), c("div", { key: 0, style: p(`display:flex !important;${["left", "right"].includes(e.value.style.labels.name.position) ? `flex-direction: ${e.value.style.labels.name.position === "right" ? "row-reverse" : "row"} !important` : "flex-direction:column !important"};gap:${e.value.style.gap}px !important;align-items:center;${C.dataset.length > 0 && i !== C.dataset.length - 1 ? "margin-bottom:6px" : ""}`), onClick: () => Q(l, i) }, [ _(t.$slots, "data-label", O({ ref_for: !0 }, { bar: { ...l, target: m(l), valueLabel: o(b)( l.formatter, l.value, o(w)({ p: l.prefix || "", v: l.value, s: l.suffix || "", r: l.rounding || 0 }), { datapoint: l, seriesIndex: i } ), targetLabel: o(b)( l.formatter, m(l), o(w)({ p: l.prefix || "", v: m(l), s: l.suffix || "", r: l.rounding || 0 }), { datapoint: l, seriesIndex: i } ) } })), t.$slots["data-label"] ? v("", !0) : (u(), c("div", { key: 0, style: p({ width: e.value.style.labels.name.width, color: e.value.style.labels.name.color, fontSize: e.value.style.labels.fontSize + "px", fontWeight: e.value.style.labels.name.bold ? "bold" : "normal", textAlign: ["left", "right"].includes(e.value.style.labels.name.position) || ["top", "top-left"].includes(e.value.style.labels.name.position) ? "left" : e.value.style.labels.name.position === "top-center" ? "center" : "right" }) }, [ d("span", null, f(l.name), 1), e.value.style.labels.value.show ? (u(), c("span", { key: 0, style: p(`font-weight:${e.value.style.labels.value.bold ? "bold" : "normal"}`) }, ": " + f(o(b)( l.formatter, l.value, o(w)({ p: l.prefix || "", v: l.value, s: l.suffix || "", r: l.rounding || 0 }), { datapoint: l, seriesIndex: i } )), 5)) : v("", !0), e.value.style.layout.showTargetValue ? (u(), c("span", fe, f(" " + e.value.style.layout.targetValueText) + " " + f(o(b)( l.formatter, m(l), o(w)({ p: l.prefix || "", v: m(l), s: l.suffix || "", r: l.rounding || 0 }), { datapoint: l, seriesIndex: i } )), 1)) : v("", !0) ], 4)), (u(), c("svg", { xmlns: o(ve), viewBox: `0 0 ${r.value.width} ${r.value.height}`, width: "100%" }, [ le(o(U)), d("defs", null, [ d("linearGradient", { x1: "0%", y1: "0%", x2: "100%", y2: "0%", id: `sparkbar_gradient_${i}_${A.value}` }, [ d("stop", { offset: "0%", "stop-color": o($)(o(de)(l.color, 0.03), 100 - e.value.style.bar.gradient.intensity) }, null, 8, ge), d("stop", { offset: "100%", "stop-color": l.color }, null, 8, he) ], 8, me) ]), d("rect", { height: r.value.height, width: r.value.width, x: 0, y: 0, fill: o($)(e.value.style.gutter.backgroundColor, e.value.style.gutter.opacity), rx: r.value.height / 2 }, null, 8, ke), d("rect", { height: r.value.height, width: r.value.width * I(l), x: 0, y: 0, fill: e.value.style.bar.gradient.underlayerColor, rx: r.value.height / 2 }, null, 8, xe), d("rect", { height: r.value.height, width: r.value.width * I(l), x: 0, y: 0, fill: e.value.style.bar.gradient.show ? `url(#sparkbar_gradient_${i}_${A.value})` : l.color, rx: r.value.height / 2 }, null, 8, be) ], 8, ye)) ], 12, pe)) : v("", !0) ], 64))), 256)), t.$slots.source ? (u(), c("div", we, [ _(t.$slots, "source") ], 512)) : v("", !0), S.value ? v("", !0) : (u(), Z(o(j), { key: 3, config: { type: "sparkbar", style: { backgroundColor: e.value.style.backgroundColor, sparkbar: { color: "#CCCCCC" } } } }, null, 8, ["config"])) ], 4)); } }; export { Se as default };