UNPKG

vue-data-ui

Version:

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

261 lines (260 loc) • 10.7 kB
import { defineAsyncComponent as K, ref as p, toRefs as Q, onMounted as F, computed as n, watch as z, createElementBlock as i, openBlock as r, normalizeStyle as y, createCommentVNode as f, createBlock as W, toDisplayString as k, unref as u, createVNode as Z, createElementVNode as g, renderSlot as N, normalizeClass as ee } from "vue"; import { u as te, a as C } from "./useNestedProp-2p4Tjzc8.js"; import { c as ae, t as le, o as oe, g as E, l as se, am as ne, X as re, a as ue, U as A, d as ie } from "./lib-2iaAPQ_c.js"; import { u as ce, B as ve } from "./BaseScanner-BMpwQAfz.js"; import { u as de } from "./useThemeCheck-DGJ31Vi5.js"; import { u as fe } from "./useChartAccessibility-9icAAmYg.js"; const M = { style: { background: "#1A1A1A", title: { color: "#CCCCCC" }, dataLabel: { color: "#CCCCCC" }, gutter: { color: "#3A3A3A" } } }, O = { style: { background: "#FFF8E1", title: { color: "#424242" }, dataLabel: { color: "#424242" }, colors: { min: "#F57C00", max: "#D32F2F" }, gutter: { color: "#5D403740" } } }, j = { style: { background: "#1E1E1E", title: { color: "#BDBDBD" }, dataLabel: { color: "#BDBDBD" }, colors: { min: "#F57C00", max: "#D32F2F" }, gutter: { color: "#5D403740" } } }, T = { style: { background: "#1A1A1A", title: { color: "#66CC66" }, dataLabel: { color: "#AACCAA" }, colors: { min: "#334C33", max: "#33CC33" }, track: { color: "#33CC33" }, gutter: { color: "#333333" } } }, I = { style: { background: "#fbfafa", title: { color: "#8A9892" }, dataLabel: { color: "#A0AC94" }, colors: { min: "#C09E85", max: "#B9B99D" }, track: { color: "#B9B99D" }, gutter: { color: "#f5f0eb" } } }, U = { style: { background: "#f6f6fb", title: { color: "#50606C" }, dataLabel: { color: "#61747E" }, colors: { min: "#92B0AB", max: "#4A6A75" }, track: { color: "#4A6A75" }, gutter: { color: "#e1e5e8" } } }, P = { default: {}, dark: M, celebration: O, celebrationNight: j, hack: T, zen: I, concrete: U }, ze = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, celebration: O, celebrationNight: j, concrete: U, dark: M, default: P, hack: T, zen: I }, Symbol.toStringTag, { value: "Module" })), ge = ["xmlns", "viewBox"], me = ["width", "height"], ye = ["id"], be = ["stop-color"], he = ["stop-color"], pe = ["d", "stroke", "stroke-linecap"], ke = ["d", "stroke", "stroke-linecap", "stroke-dashoffset"], Ce = ["x", "y", "width", "height"], Ae = ["x", "y", "font-size", "fill", "font-weight"], _e = { key: 2, ref: "source", dir: "auto" }, xe = { __name: "vue-ui-sparkgauge", props: { config: { type: Object, default() { return {}; } }, dataset: { type: Object, default() { return {}; } } }, setup(R) { const G = K(() => import("./PackageVersion-Br3DrrFh.js")), { vue_ui_sparkgauge: V } = te(), { isThemeValid: q, warnInvalidTheme: X } = de(), c = R, _ = p(ae()), e = p(h()), { loading: b, FINAL_DATASET: v } = ce({ ...Q(c), FINAL_CONFIG: e, prepareConfig: h, skeletonDataset: { value: 0, min: -1, max: 1, title: "" }, skeletonConfig: le({ defaultConfig: e.value, userConfig: { style: { animation: { show: !1 }, background: "#99999930", colors: { min: "#CACACA", max: "#6A6A6A" }, track: { autoColor: !0 }, gutter: { color: "#6A6A6A80" } } } }) }), { svgRef: Y } = fe({ config: { text: c.dataset?.title || "" } }); function h() { const t = C({ userConfig: c.config, defaultConfig: V }), o = t.theme; if (!o) return t; if (!q.value(t)) return X(t), t; const d = C({ userConfig: P[o] || c.config, defaultConfig: t }); return C({ userConfig: c.config, defaultConfig: d }); } F(() => { w(); }); const x = n(() => e.value.debug); function w() { oe(c.dataset) ? E({ componentName: "VueUiSparkgauge", type: "dataset", debug: x.value }) : se({ datasetObject: c.dataset, requiredAttributes: ["value", "min", "max"] }).forEach((t) => { E({ componentName: "VueUiSparkgauge", type: "datasetAttribute", property: t, debug: x.value }); }); } z(() => c.config, (t) => { e.value = h(), a.value = e.value.style.animation.show ? s.value.min : v.value.value, w(); }, { deep: !0 }); const l = n(() => ({ height: e.value.style.height, width: 128, base: e.value.style.basePosition })), s = n(() => { const t = v.value.min ?? 0, o = v.value.max ?? 0, d = o - t; return { min: t, max: o, diff: d }; }), a = p(e.value.style.animation.show ? s.value.min : v.value.value); z(() => v.value.value, () => { $(v.value.value || 0); }); const H = n(() => a.value > s.value.max ? s.value.max : a.value < s.value.min ? s.value.min : a.value), L = n(() => s.value.diff / e.value.style.animation.speedMs); F(() => { $(v.value.value || 0); }); function $(t) { function o() { a.value < t ? a.value = Math.min(a.value + L.value, t) : a.value > t && (a.value = Math.max(a.value - L.value, t)), a.value !== t && requestAnimationFrame(o); } o(); } const m = n(() => v.value.title ?? ""), S = n(() => { const t = s.value.diff; if (!isFinite(t) || t === 0) return 0; const o = s.value.min, d = H.value; return d >= 0 ? (d - o) / t : (Math.abs(o) - Math.abs(d)) / t; }), B = n(() => ne(e.value.style.colors.min, e.value.style.colors.max, s.value.min, s.value.max, a.value)), D = n(() => e.value.style.dataLabel.autoColor ? B.value : e.value.style.dataLabel.color), J = n(() => e.value.style.track.autoColor ? B.value : e.value.style.track.color); return (t, o) => (r(), i("div", { class: "vue-data-ui-component vue-ui-sparkgauge", style: y(`font-family:${e.value.style.fontFamily};width: 100%; background:${e.value.style.background}`) }, [ e.value.style.title.show && m.value && e.value.style.title.position === "top" ? (r(), i("div", { key: 0, class: "vue-data-ui-sparkgauge-label", style: y(`font-size:${e.value.style.title.fontSize}px;text-align:${e.value.style.title.textAlign};font-weight:${e.value.style.title.bold ? "bold" : "normal"};color:${e.value.style.title.color}`) }, k(m.value), 5)) : f("", !0), (r(), i("svg", { ref_key: "svgRef", ref: Y, xmlns: u(re), viewBox: `0 0 ${l.value.width} ${l.value.height}`, style: "overflow: visible; background:transparent; width:100%;" }, [ Z(u(G)), t.$slots["chart-background"] && !u(b) ? (r(), i("foreignObject", { key: 0, x: 0, y: 0, width: l.value.width, height: l.value.height, style: { pointerEvents: "none" } }, [ N(t.$slots, "chart-background") ], 8, me)) : f("", !0), g("defs", null, [ g("linearGradient", { id: `gradient_${_.value}`, x1: "-10%", y1: "100%", x2: "110%", y2: "100%" }, [ g("stop", { offset: "0%", "stop-color": e.value.style.colors.min }, null, 8, be), g("stop", { offset: "100%", "stop-color": e.value.style.colors.max }, null, 8, he) ], 8, ye) ]), g("path", { d: `M10 ${l.value.base} A 1 1 0 1 1 118 ${l.value.base}`, stroke: e.value.style.gutter.color, "stroke-width": 8, "stroke-linecap": e.value.style.gutter.strokeLinecap, fill: "none" }, null, 8, pe), S.value !== 0 ? (r(), i("path", { key: 1, d: `M10 ${l.value.base} A 1 1 0 1 1 118 ${l.value.base}`, stroke: e.value.style.colors.showGradient ? `url(#gradient_${_.value})` : J.value, "stroke-width": 8, "stroke-linecap": e.value.style.track.strokeLinecap, fill: "none", "stroke-dasharray": 169.5, "stroke-dashoffset": 169.5 - 169.5 * S.value, class: ee({ "vue-ui-sparkgauge-track": e.value.style.animation.show }), style: y(e.value.style.animation.show ? `animation: vue-ui-sparkgauge-animation ${e.value.style.animation.speedMs}ms ease-in;` : "") }, null, 14, ke)) : f("", !0), u(b) ? (r(), i("rect", { key: 2, x: l.value.width / 2 - e.value.style.dataLabel.fontSize / 2, y: l.value.base + 6 + e.value.style.dataLabel.offsetY - e.value.style.dataLabel.fontSize, width: e.value.style.dataLabel.fontSize, height: e.value.style.dataLabel.fontSize, fill: "#6A6A6A50", rx: 3 }, null, 8, Ce)) : (r(), i("text", { key: 3, "text-anchor": "middle", x: l.value.width / 2, y: l.value.base + 6 + e.value.style.dataLabel.offsetY, "font-size": e.value.style.dataLabel.fontSize, fill: D.value, "font-weight": e.value.style.dataLabel.bold ? "bold" : "normal" }, k(u(ue)( e.value.style.dataLabel.formatter, u(A)(a.value), u(ie)({ p: e.value.style.dataLabel.prefix, v: u(A)(a.value), s: e.value.style.dataLabel.suffix, r: e.value.style.dataLabel.rounding }), { datapoint: u(A)(a.value), color: D.value } )), 9, Ae)) ], 8, ge)), e.value.style.title.show && m.value && e.value.style.title.position === "bottom" ? (r(), i("div", { key: 1, class: "vue-data-ui-sparkgauge-label", style: y(`font-size:${e.value.style.title.fontSize}px;text-align:${e.value.style.title.textAlign};font-weight:${e.value.style.title.bold ? "bold" : "normal"};font-weight:${e.value.style.title.bold ? "bold" : "normal"};color:${e.value.style.title.color}`) }, k(m.value), 5)) : f("", !0), t.$slots.source ? (r(), i("div", _e, [ N(t.$slots, "source") ], 512)) : f("", !0), u(b) ? (r(), W(ve, { key: 3 })) : f("", !0) ], 4)); } }, Ne = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({ __proto__: null, default: xe }, Symbol.toStringTag, { value: "Module" })); export { xe as _, Ne as a, ze as v };