vue-data-ui
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
496 lines (495 loc) • 20.7 kB
JavaScript
import { useCssVars as $e, computed as d, defineAsyncComponent as A, onMounted as Pe, ref as p, watch as Fe, createElementBlock as u, openBlock as l, unref as i, normalizeStyle as oe, normalizeClass as S, createBlock as M, createCommentVNode as c, createSlots as Oe, withCtx as C, renderSlot as f, normalizeProps as U, guardReactiveProps as Y, createVNode as Ie, createElementVNode as v, Fragment as N, renderList as ae, toDisplayString as Ae } from "vue";
import { u as Se, o as Me, e as le, g as Ue, c as Ye, t as Ne, p as $, a as Te, b as Ve, v as g, d as T, X as qe, s as Le, i as Ee, f as Ge } from "./index-BLtEpj8j.js";
import { u as re } from "./useNestedProp-Bw1KcAmj.js";
import { u as We } from "./usePrinter-DnRwTdvS.js";
import { u as Be } from "./useUserOptionState-BIvW1Kz7.js";
import { u as Re } from "./useChartAccessibility-9icAAmYg.js";
import je from "./Title-DkG60EPg.js";
import ze from "./img-D-vWHxhM.js";
import { _ as De } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const He = ["id"], Xe = {
key: 1,
ref: "noTitle",
class: "vue-data-ui-no-title-space",
style: "height:36px; width: 100%;background:transparent"
}, Je = {
key: 2,
style: "width:100%"
}, Ke = ["xmlns", "viewBox"], Qe = ["width", "height"], Ze = {
id: "vueUiPill",
clipPathUnits: "objectBoundingBox"
}, et = ["fill"], tt = ["id"], st = ["stop-color"], ot = ["stop-color"], at = ["stop-color"], lt = { "clip-path": "url(#vueUiPill)" }, rt = ["x", "y", "height", "width"], nt = ["x", "y", "height", "width", "fill"], ut = ["x1", "x2", "y1", "y2", "stroke-width", "stroke"], it = ["x1", "x2", "y1", "y2", "stroke-width", "stroke"], ct = ["x1", "x2", "y1", "y2", "stroke-width", "stroke"], ht = ["x1", "x2", "y1", "y2", "stroke-width", "stroke"], dt = ["x1", "x2", "y1", "y2", "stroke-width", "stroke"], vt = ["x1", "x2", "y1", "y2", "stroke-width", "stroke"], yt = ["x1", "x2", "y1", "y2", "stroke-width", "stroke"], ft = ["x1", "x2", "y1", "y2", "stroke-width", "stroke"], gt = ["x", "y", "height", "width"], pt = ["y", "x", "fill", "font-size", "font-weight"], mt = {
key: 5,
class: "vue-data-ui-watermark"
}, kt = {
key: 6,
ref: "source",
dir: "auto"
}, bt = {
__name: "vue-ui-thermometer",
props: {
dataset: {
type: Object,
default() {
return {};
}
},
config: {
type: Object,
default() {
return {};
}
}
},
setup(P, { expose: ne }) {
$e((s) => ({
"7efc96cd": me.value,
"4d37cb61": pe.value,
"295a76e4": ge.value
}));
const ue = A(() => import("./PackageVersion-CnRyWKP-.js")), ie = A(() => import("./PenAndPaper-7BWf7zgA.js")), ce = A(() => import("./vue-ui-skeleton-CsMU8DwQ.js")), he = A(() => import("./UserOptions-DGw0HvSp.js")), { vue_ui_thermometer: de } = Se(), r = P, V = d(() => !!r.dataset && Object.keys(r.dataset).length);
Pe(() => {
B();
});
function B() {
Me(r.dataset) ? le({
componentName: "VueUiThermometer",
type: "dataset"
}) : Ue({
datasetObject: r.dataset,
requiredAttributes: ["value", "from", "to"]
}).forEach((s) => {
le({
componentName: "VueUiThermometer",
type: "datasetAttribute",
property: s
});
});
}
const m = p(Ye()), k = p(null), R = p(0), j = p(0), e = d({
get: () => X(),
set: (s) => s
}), { userOptionsVisible: q, setUserOptionsVisibility: z, keepUserOptionState: D } = Be({ config: e.value }), { svgRef: H } = Re({ config: e.value.style.title });
function X() {
const s = re({
userConfig: r.config,
defaultConfig: de
});
return s.theme ? {
...re({
userConfig: Te.vue_ui_thermometer[s.theme] || r.config,
defaultConfig: s
}),
customPalette: Ne[s.theme] || $
} : s;
}
Fe(() => r.config, (s) => {
e.value = X(), q.value = !e.value.userOptions.showOnChartHover, B(), j.value += 1;
}, { deep: !0 });
const { isPrinting: J, isImaging: K, generatePdf: Q, generateImage: Z } = We({
elementId: `thermometer__${m.value}`,
fileName: e.value.style.title.text || "vue-ui-thermometer",
options: e.value.userOptions.print
}), ve = d(() => e.value.userOptions.show && !e.value.style.title.text), F = d(() => Ve(e.value.customPalette)), ye = d(() => e.value.style.chart.thermometer.width), y = d(() => r.dataset.steps || 10), h = p({
top: e.value.style.chart.padding.top,
left: e.value.style.chart.padding.left,
right: e.value.style.chart.padding.right,
bottom: e.value.style.chart.padding.bottom
});
function O(s, a, t) {
const n = [], x = ee(s), w = ee(a);
for (let _ = 0; _ < t; _++) {
const xe = L(x.red, w.red, _, t), we = L(x.green, w.green, _, t), _e = L(x.blue, w.blue, _, t), Ce = `#${E(xe)}${E(we)}${E(_e)}`;
n.push(Ce);
}
return n;
}
function ee(s) {
const a = s.slice(1);
return {
red: parseInt(a.slice(0, 2), 16),
green: parseInt(a.slice(2, 4), 16),
blue: parseInt(a.slice(4, 6), 16)
};
}
function L(s, a, t, n) {
return Math.round(s + (a - s) * t / n);
}
function E(s) {
return s.toString(16).padStart(2, "0");
}
const o = d(() => {
const s = ye.value + h.value.left + h.value.right, a = e.value.style.chart.height;
return {
width: s,
left: h.value.left,
right: s - h.value.right,
top: h.value.top,
bottom: a - h.value.bottom,
height: a
};
}), fe = d(() => o.value), G = d(() => {
const s = g(r.dataset.from) < 0 ? Math.abs(g(r.dataset.from)) : g(r.dataset.from), a = g(r.dataset.to) < 0 ? Math.abs(g(r.dataset.to)) : g(r.dataset.to);
let t = 0;
return g(r.dataset.to) > 0 ? t = s + a : s > a ? t = s - a : t = a - s, (1 - (Math.abs(g(r.dataset.from)) + g(r.dataset.value)) / t) * (o.value.height - h.value.top - h.value.bottom);
}), ge = d(() => `${G.value}px`), pe = d(() => `${o.value.height - e.value.style.chart.padding.bottom - h.value.top}px`), me = d(() => `${e.value.style.chart.animation.speedMs}ms`), ke = d(() => {
if (r.dataset.colors) {
if (!r.dataset.colors.from)
return O(F.value[0] || $[0], T(r.dataset.colors.to), y.value || 10);
if (!r.dataset.colors.to)
return O(T(r.dataset.colors.from), F.value[1] || $[1], y.value || 10);
} else
return O(F.value[1] || $[1], F.value[0] || $[0], y.value || 10);
return O(T(r.dataset.colors.from), T(r.dataset.colors.to), y.value || 10);
}), te = d(() => {
const s = [];
let a = 0;
const t = o.value.height - h.value.top - h.value.bottom;
for (let n = 0; n < t - 1; n += t / y.value)
s.push({
x: o.value.left,
y: o.value.top + n,
qYLess: o.value.top + n + t / y.value / 4,
halfY: o.value.top + n + t / y.value / 2,
qYMore: o.value.top + n + t / y.value / 4 * 3,
color: ke.value[a],
height: t / y.value
}), a += 1;
return s;
}), b = p(!1);
function se(s) {
b.value = s, R.value += 1;
}
const I = p(!1);
function W() {
I.value = !I.value;
}
async function be({ scale: s = 2 } = {}) {
if (!k.value) return;
const { width: a, height: t } = k.value.getBoundingClientRect(), n = a / t, { imageUri: x, base64: w } = await ze({ domElement: k.value, base64: !0, img: !0, scale: s });
return {
imageUri: x,
base64: w,
title: e.value.style.title.text,
width: a,
height: t,
aspectRatio: n
};
}
return ne({
getImage: be,
generatePdf: Q,
generateImage: Z,
toggleAnnotator: W,
toggleFullscreen: se
}), (s, a) => (l(), u("div", {
ref_key: "thermoChart",
ref: k,
class: S(`vue-ui-thermometer ${b.value ? "vue-data-ui-wrapper-fullscreen" : ""}`),
style: oe(`width:100%;background:${e.value.style.chart.backgroundColor};color:${e.value.style.chart.color};font-family:${e.value.style.fontFamily}`),
id: `thermometer__${m.value}`,
onMouseenter: a[0] || (a[0] = () => i(z)(!0)),
onMouseleave: a[1] || (a[1] = () => i(z)(!1))
}, [
e.value.userOptions.buttons.annotator ? (l(), M(i(ie), {
key: 0,
svgRef: i(H),
backgroundColor: e.value.style.chart.backgroundColor,
color: e.value.style.chart.color,
active: I.value,
onClose: W
}, null, 8, ["svgRef", "backgroundColor", "color", "active"])) : c("", !0),
ve.value ? (l(), u("div", Xe, null, 512)) : c("", !0),
e.value.style.title.text ? (l(), u("div", Je, [
(l(), M(je, {
key: `title_${j.value}`,
config: {
title: {
cy: "thermometer-div-title",
...e.value.style.title
},
subtitle: {
cy: "thermometer-div-subtitle",
...e.value.style.title.subtitle
}
}
}, null, 8, ["config"]))
])) : c("", !0),
e.value.userOptions.show && V.value && (i(D) || i(q)) ? (l(), M(i(he), {
ref: "details",
key: `user_options_${R.value}`,
backgroundColor: e.value.style.chart.backgroundColor,
color: e.value.style.chart.color,
isImaging: i(K),
isPrinting: i(J),
uid: m.value,
hasPdf: e.value.userOptions.buttons.pdf,
hasImg: e.value.userOptions.buttons.img,
hasFullscreen: e.value.userOptions.buttons.fullscreen,
hasXls: !1,
isFullscreen: b.value,
titles: { ...e.value.userOptions.buttonTitles },
chartElement: k.value,
position: e.value.userOptions.position,
hasAnnotator: e.value.userOptions.buttons.annotator,
isAnnotation: I.value,
callbacks: e.value.userOptions.callbacks,
printScale: e.value.userOptions.print.scale,
onToggleFullscreen: se,
onGeneratePdf: i(Q),
onGenerateImage: i(Z),
onToggleAnnotator: W,
style: oe({
visibility: i(D) ? i(q) ? "visible" : "hidden" : "visible"
})
}, Oe({ _: 2 }, [
s.$slots.menuIcon ? {
name: "menuIcon",
fn: C(({ isOpen: t, color: n }) => [
f(s.$slots, "menuIcon", U(Y({ isOpen: t, color: n })), void 0, !0)
]),
key: "0"
} : void 0,
s.$slots.optionPdf ? {
name: "optionPdf",
fn: C(() => [
f(s.$slots, "optionPdf", {}, void 0, !0)
]),
key: "1"
} : void 0,
s.$slots.optionImg ? {
name: "optionImg",
fn: C(() => [
f(s.$slots, "optionImg", {}, void 0, !0)
]),
key: "2"
} : void 0,
s.$slots.optionFullscreen ? {
name: "optionFullscreen",
fn: C(({ toggleFullscreen: t, isFullscreen: n }) => [
f(s.$slots, "optionFullscreen", U(Y({ toggleFullscreen: t, isFullscreen: n })), void 0, !0)
]),
key: "3"
} : void 0,
s.$slots.optionAnnotator ? {
name: "optionAnnotator",
fn: C(({ toggleAnnotator: t, isAnnotator: n }) => [
f(s.$slots, "optionAnnotator", U(Y({ toggleAnnotator: t, isAnnotator: n })), void 0, !0)
]),
key: "4"
} : void 0
]), 1032, ["backgroundColor", "color", "isImaging", "isPrinting", "uid", "hasPdf", "hasImg", "hasFullscreen", "isFullscreen", "titles", "chartElement", "position", "hasAnnotator", "isAnnotation", "callbacks", "printScale", "onGeneratePdf", "onGenerateImage", "style"])) : c("", !0),
V.value ? (l(), u("svg", {
key: 4,
ref_key: "svgRef",
ref: H,
xmlns: i(qe),
class: S({ "vue-data-ui-fullscreen--on": b.value, "vue-data-ui-fulscreen--off": !b.value }),
width: "100%",
viewBox: `0 0 ${o.value.width} ${o.value.height}`,
style: "background:transparent"
}, [
Ie(i(ue)),
s.$slots["chart-background"] ? (l(), u("foreignObject", {
key: 0,
x: 0,
y: 0,
width: o.value.width,
height: o.value.height,
style: {
pointerEvents: "none"
}
}, [
f(s.$slots, "chart-background", {}, void 0, !0)
], 8, Qe)) : c("", !0),
v("defs", null, [
v("clipPath", Ze, [
v("rect", {
x: "0",
y: "0",
width: "1",
height: "1",
rx: "0.5",
ry: "0.07",
fill: e.value.style.chart.backgroundColor
}, null, 8, et)
]),
(l(!0), u(N, null, ae(te.value, (t, n) => (l(), u("linearGradient", {
id: `vueUiThermometerGradient_${n}_${m.value}`,
x1: "0%",
y1: "0%",
x2: "100%",
y2: "0%"
}, [
v("stop", {
offset: "0%",
"stop-color": t.color
}, null, 8, st),
v("stop", {
offset: "50%",
"stop-color": i(Le)(t.color, 100 - e.value.style.chart.graduations.gradient.intensity)
}, null, 8, ot),
v("stop", {
offset: "100%",
"stop-color": t.color
}, null, 8, at)
], 8, tt))), 256))
]),
v("g", lt, [
v("rect", {
x: o.value.left,
y: o.value.top,
height: o.value.height - h.value.top - h.value.bottom,
width: o.value.width - h.value.left - h.value.right,
fill: "#FFFFFF"
}, null, 8, rt),
(l(!0), u(N, null, ae(te.value, (t, n) => (l(), u("g", {
key: `graduation_${n}`
}, [
v("rect", {
x: t.x,
y: t.y,
height: t.height,
width: o.value.width - e.value.style.chart.padding.left - e.value.style.chart.padding.right,
fill: e.value.style.chart.graduations.gradient.show ? `url(#vueUiThermometerGradient_${n}_${m.value})` : t.color,
"shape-rendering": "crispEdges"
}, null, 8, nt),
e.value.style.chart.graduations.show && ["both", "left"].includes(e.value.style.chart.graduations.sides) ? (l(), u("line", {
key: 0,
x1: t.x,
x2: t.x + 10,
y1: t.y,
y2: t.y,
"stroke-width": e.value.style.chart.graduations.strokeWidth,
stroke: e.value.style.chart.graduations.stroke,
"stroke-linecap": "round"
}, null, 8, ut)) : c("", !0),
e.value.style.chart.graduations.showIntermediate ? (l(), u(N, { key: 1 }, [
e.value.style.chart.graduations.show && ["both", "left"].includes(e.value.style.chart.graduations.sides) ? (l(), u("line", {
key: 0,
x1: t.x,
x2: t.x + 5,
y1: t.halfY,
y2: t.halfY,
"stroke-width": e.value.style.chart.graduations.strokeWidth / 2,
stroke: e.value.style.chart.graduations.stroke,
"stroke-linecap": "round"
}, null, 8, it)) : c("", !0),
e.value.style.chart.graduations.show && ["both", "left"].includes(e.value.style.chart.graduations.sides) ? (l(), u("line", {
key: 1,
x1: t.x,
x2: t.x + 2.5,
y1: t.qYLess,
y2: t.qYLess,
"stroke-width": e.value.style.chart.graduations.strokeWidth / 2,
stroke: e.value.style.chart.graduations.stroke,
"stroke-linecap": "round"
}, null, 8, ct)) : c("", !0),
e.value.style.chart.graduations.show && ["both", "left"].includes(e.value.style.chart.graduations.sides) ? (l(), u("line", {
key: 2,
x1: t.x,
x2: t.x + 2.5,
y1: t.qYMore,
y2: t.qYMore,
"stroke-width": e.value.style.chart.graduations.strokeWidth / 2,
stroke: e.value.style.chart.graduations.stroke,
"stroke-linecap": "round"
}, null, 8, ht)) : c("", !0)
], 64)) : c("", !0),
e.value.style.chart.graduations.show && ["both", "right"].includes(e.value.style.chart.graduations.sides) ? (l(), u("line", {
key: 2,
x1: o.value.right,
x2: o.value.right - 10,
y1: t.y,
y2: t.y,
"stroke-width": e.value.style.chart.graduations.strokeWidth,
stroke: e.value.style.chart.graduations.stroke,
"stroke-linecap": "round"
}, null, 8, dt)) : c("", !0),
e.value.style.chart.graduations.showIntermediate ? (l(), u(N, { key: 3 }, [
e.value.style.chart.graduations.show && ["both", "right"].includes(e.value.style.chart.graduations.sides) ? (l(), u("line", {
key: 0,
x1: o.value.right,
x2: o.value.right - 5,
y1: t.halfY,
y2: t.halfY,
"stroke-width": e.value.style.chart.graduations.strokeWidth / 2,
stroke: e.value.style.chart.graduations.stroke,
"stroke-linecap": "round"
}, null, 8, vt)) : c("", !0),
e.value.style.chart.graduations.show && ["both", "right"].includes(e.value.style.chart.graduations.sides) ? (l(), u("line", {
key: 1,
x1: o.value.right,
x2: o.value.right - 2.5,
y1: t.qYLess,
y2: t.qYLess,
"stroke-width": e.value.style.chart.graduations.strokeWidth / 2,
stroke: e.value.style.chart.graduations.stroke,
"stroke-linecap": "round"
}, null, 8, yt)) : c("", !0),
e.value.style.chart.graduations.show && ["both", "right"].includes(e.value.style.chart.graduations.sides) ? (l(), u("line", {
key: 2,
x1: o.value.right,
x2: o.value.right - 2.5,
y1: t.qYMore,
y2: t.qYMore,
"stroke-width": e.value.style.chart.graduations.strokeWidth / 2,
stroke: e.value.style.chart.graduations.stroke,
"stroke-linecap": "round"
}, null, 8, ft)) : c("", !0)
], 64)) : c("", !0)
]))), 128)),
v("rect", {
class: S({ "vue-ui-thermometer-temperature": e.value.style.chart.animation.use }),
x: o.value.left,
y: o.value.top,
height: G.value,
width: o.value.width - e.value.style.chart.padding.left - e.value.style.chart.padding.right,
fill: "#FFFFFF66"
}, null, 10, gt)
]),
v("text", {
class: S({ "vue-ui-thermometer-temperature-value": e.value.style.chart.animation.use }),
y: G.value + o.value.top + e.value.style.chart.label.fontSize / 3,
x: o.value.left - 10,
"text-anchor": "end",
fill: e.value.style.chart.label.color,
"font-size": e.value.style.chart.label.fontSize,
"font-weight": e.value.style.chart.label.bold ? "bold" : "normal"
}, Ae(i(Ee)(
e.value.style.chart.label.formatter,
P.dataset.value,
i(Ge)({
p: e.value.style.chart.label.prefix,
v: P.dataset.value,
s: e.value.style.chart.label.suffix,
r: e.value.style.chart.label.rounding
}),
{ datapoint: P.dataset }
)), 11, pt),
f(s.$slots, "svg", { svg: fe.value }, void 0, !0)
], 10, Ke)) : c("", !0),
s.$slots.watermark ? (l(), u("div", mt, [
f(s.$slots, "watermark", U(Y({ isPrinting: i(J) || i(K) })), void 0, !0)
])) : c("", !0),
s.$slots.source ? (l(), u("div", kt, [
f(s.$slots, "source", {}, void 0, !0)
], 512)) : c("", !0),
V.value ? c("", !0) : (l(), M(i(ce), {
key: 7,
config: {
type: "thermometer",
style: {
backgroundColor: e.value.style.chart.backgroundColor,
thermometer: {
color: "#CCCCCC"
}
}
}
}, null, 8, ["config"]))
], 46, He));
}
}, At = /* @__PURE__ */ De(bt, [["__scopeId", "data-v-8985051a"]]);
export {
At as default
};