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