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