UNPKG

vue-data-ui-hq

Version:

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

200 lines (199 loc) 7.46 kB
import { computed as n, onMounted as N, ref as A, watch as M, openBlock as r, createElementBlock as u, normalizeStyle as y, unref as e, toDisplayString as g, createCommentVNode as c, createVNode as D, renderSlot as S, createElementVNode as f, normalizeClass as G, createBlock as I } from "vue"; import { u as U, o as q, e as z, g as P, c as R, t as T, N as X, X as H, i as V, v as p, f as Y } from "./index-WrV3SAID.js"; import { u as O } from "./useNestedProp-Cj0kHD7k.js"; import J from "./vue-ui-skeleton-Qec_XSRf.js"; import { _ as K } from "./PackageVersion-1NslmM8M.js"; const Q = ["xmlns", "viewBox"], W = ["width", "height"], Z = ["id"], ee = ["stop-color"], te = ["stop-color"], ae = ["d", "stroke", "stroke-linecap"], oe = ["d", "stroke", "stroke-linecap", "stroke-dashoffset"], se = ["x", "y", "font-size", "fill", "font-weight"], le = { key: 4, ref: "source", dir: "auto" }, de = { __name: "vue-ui-sparkgauge", props: { config: { type: Object, default() { return {}; } }, dataset: { type: Object, default() { return {}; } } }, setup(j) { const { vue_ui_sparkgauge: E } = U(), s = j, v = n(() => !!s.dataset && Object.keys(s.dataset).length); N(() => { h(); }); function h() { q(s.dataset) ? z({ componentName: "VueUiSparkgauge", type: "dataset" }) : P({ datasetObject: s.dataset, requiredAttributes: ["value", "min", "max"] }).forEach((a) => { z({ componentName: "VueUiSparkgauge", type: "datasetAttribute", property: a }); }); } const b = A(R()), t = n({ get: () => k(), set: (a) => a }); function k() { const a = O({ userConfig: s.config, defaultConfig: E }); return a.theme ? { ...O({ userConfig: T.vue_ui_sparkgauge[a.theme] || s.config, defaultConfig: a }) } : a; } M(() => s.config, (a) => { t.value = k(), h(); }, { deep: !0 }); const i = n(() => ({ height: t.value.style.height, width: 128, base: t.value.style.basePosition })), l = n(() => { const a = s.dataset.min ?? 0, d = s.dataset.max ?? 0, B = d - a; return { min: a, max: d, diff: B }; }), o = A(t.value.style.animation.show ? l.value.min : s.dataset.value); M(() => s.dataset.value, () => { x(s.dataset.value || 0); }); const _ = n(() => o.value > l.value.max ? l.value.max : o.value < l.value.min ? l.value.min : o.value), $ = n(() => l.value.diff / t.value.style.animation.speedMs); N(() => { x(s.dataset.value || 0); }); function x(a) { function d() { o.value < a ? o.value = Math.min(o.value + $.value, a) : o.value > a && (o.value = Math.max(o.value - $.value, a)), o.value !== a && requestAnimationFrame(d); } d(); } const m = n(() => s.dataset.title ?? ""), w = n(() => o.value >= 0 ? (_.value - l.value.min) / l.value.diff : (Math.abs(l.value.min) - Math.abs(_.value)) / l.value.diff), C = n(() => X(t.value.style.colors.min, t.value.style.colors.max, l.value.min, l.value.max, o.value)), L = n(() => t.value.style.dataLabel.autoColor ? C.value : t.value.style.dataLabel.color), F = n(() => t.value.style.track.autoColor ? C.value : t.value.style.track.color); return (a, d) => (r(), u("div", { style: y(`font-family:${e(t).style.fontFamily};width: 100%; background:${e(t).style.background}`) }, [ e(t).style.title.show && e(m) && e(t).style.title.position === "top" ? (r(), u("div", { key: 0, class: "vue-data-ui-sparkgauge-label", style: y(`font-size:${e(t).style.title.fontSize}px;text-align:${e(t).style.title.textAlign};font-weight:${e(t).style.title.bold ? "bold" : "normal"};color:${e(t).style.title.color}`) }, g(e(m)), 5)) : c("", !0), e(v) ? (r(), u("svg", { key: 1, xmlns: e(H), viewBox: `0 0 ${e(i).width} ${e(i).height}`, style: "overflow: visible; background:transparent; width:100%;" }, [ D(K), a.$slots["chart-background"] ? (r(), u("foreignObject", { key: 0, x: 0, y: 0, width: e(i).width, height: e(i).height, style: { pointerEvents: "none" } }, [ S(a.$slots, "chart-background") ], 8, W)) : c("", !0), f("defs", null, [ f("linearGradient", { id: `gradient_${e(b)}`, x1: "-10%", y1: "100%", x2: "110%", y2: "100%" }, [ f("stop", { offset: "0%", "stop-color": e(t).style.colors.min }, null, 8, ee), f("stop", { offset: "100%", "stop-color": e(t).style.colors.max }, null, 8, te) ], 8, Z) ]), f("path", { d: `M10 ${e(i).base} A 1 1 0 1 1 118 ${e(i).base}`, stroke: e(t).style.gutter.color, "stroke-width": 8, "stroke-linecap": e(t).style.gutter.strokeLinecap, fill: "none" }, null, 8, ae), e(w) !== 0 ? (r(), u("path", { key: 1, d: `M10 ${e(i).base} A 1 1 0 1 1 118 ${e(i).base}`, stroke: e(t).style.colors.showGradient ? `url(#gradient_${e(b)})` : e(F), "stroke-width": 8, "stroke-linecap": e(t).style.track.strokeLinecap, fill: "none", "stroke-dasharray": 169.5, "stroke-dashoffset": 169.5 - 169.5 * e(w), class: G({ "vue-ui-sparkgauge-track": e(t).style.animation.show }), style: y(e(t).style.animation.show ? `animation: vue-ui-sparkgauge-animation ${e(t).style.animation.speedMs}ms ease-in;` : "") }, null, 14, oe)) : c("", !0), f("text", { "text-anchor": "middle", x: e(i).width / 2, y: e(i).base + 6 + e(t).style.dataLabel.offsetY, "font-size": e(t).style.dataLabel.fontSize, fill: e(L), "font-weight": e(t).style.dataLabel.bold ? "bold" : "normal" }, g(e(V)( e(t).style.dataLabel.formatter, e(p)(e(o)), e(Y)({ p: e(t).style.dataLabel.prefix, v: e(p)(e(o)), s: e(t).style.dataLabel.suffix, r: e(t).style.dataLabel.rounding }), { datapoint: e(p)(e(o)), color: e(L) } )), 9, se) ], 8, Q)) : c("", !0), e(v) ? c("", !0) : (r(), I(J, { key: 2, config: { type: "gauge", style: { backgroundColor: e(t).style.background, gauge: { color: "#CCCCCC" } } } }, null, 8, ["config"])), e(t).style.title.show && e(m) && e(t).style.title.position === "bottom" ? (r(), u("div", { key: 3, class: "vue-data-ui-sparkgauge-label", style: y(`font-size:${e(t).style.title.fontSize}px;text-align:${e(t).style.title.textAlign};font-weight:${e(t).style.title.bold ? "bold" : "normal"};font-weight:${e(t).style.title.bold ? "bold" : "normal"};color:${e(t).style.title.color}`) }, g(e(m)), 5)) : c("", !0), a.$slots.source ? (r(), u("div", le, [ S(a.$slots, "source") ], 512)) : c("", !0) ], 4)); } }; export { de as default };