vue-data-ui
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
499 lines (495 loc) • 19.6 kB
JavaScript
import { ref as g, computed as f, onMounted as ge, watch as K, onBeforeUnmount as fe, createElementBlock as o, openBlock as r, unref as u, normalizeStyle as H, normalizeClass as Q, createBlock as w, createCommentVNode as i, createElementVNode as x, createSlots as me, withCtx as p, renderSlot as m, normalizeProps as L, guardReactiveProps as $, createVNode as ye, Fragment as M, renderList as T, toDisplayString as O } from "vue";
import { u as pe, o as be, e as Z, g as ke, c as we, l as xe, D as _e, d as Ce, i as A, f as B, X as Le, a as $e } from "./index-CHWA6Lnw.js";
import { u as ee } from "./useNestedProp-ByBiJC9_.js";
import { _ as Oe } from "./Title-BwZtefYd.js";
import { L as Ae } from "./Legend-BMXzxIhA.js";
import { u as Be, U as Pe } from "./usePrinter-DibtVl2x.js";
import { _ as Fe } from "./PackageVersion-DcMafJMi.js";
import { P as Ie } from "./PenAndPaper-ljJaW1FE.js";
import Se from "./vue-ui-skeleton-BSUFPx4a.js";
import { u as He } from "./useUserOptionState-BIvW1Kz7.js";
import { u as Me } from "./useChartAccessibility-BWojgys7.js";
import { _ as Te } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Ue = ["id"], Ne = {
key: 1,
ref: "noTitle",
class: "vue-data-ui-no-title-space",
style: "height:36px; width: 100%;background:transparent"
}, ze = ["xmlns", "viewBox"], Re = ["width", "height"], We = { key: 1 }, Ee = ["x", "y", "height", "width", "fill", "stroke"], De = ["x", "y", "height", "width", "rx", "fill", "stroke", "stroke-width"], Ve = ["x", "y", "height", "width", "fill", "stroke", "stroke-width"], je = ["x", "y", "font-size", "font-weight", "fill"], Ge = ["x", "y", "height", "width", "rx", "fill", "stroke", "stroke-width"], qe = { key: 3 }, Xe = ["x", "y", "fill", "font-size", "font-weight"], Ye = { key: 4 }, Je = ["x1", "x2", "y1", "y2", "stroke"], Ke = {
key: 5,
class: "vue-data-ui-watermark"
}, Qe = {
class: "vue-ui-bullet-legend-item",
dir: "auto"
}, Ze = { style: { "margin-right": "2px" } }, et = {
key: 7,
ref: "source",
dir: "auto"
}, tt = {
__name: "vue-ui-bullet",
props: {
config: {
type: Object,
default() {
return {};
}
},
dataset: {
type: Object,
default() {
return {};
}
}
},
setup(te, { expose: ae }) {
const { vue_ui_bullet: le } = pe(), n = te, U = g(null), se = g(null), N = g(0), re = g(null), oe = g(0), y = f({
get: () => n.dataset.hasOwnProperty("value"),
set: (t) => t
}), b = f(() => n.dataset.segments ? Array.isArray(n.dataset.segments) ? n.dataset.segments.length ? !0 : (console.warn(`VueUiBullet: dataset segments is empty. Provide segments with this datastructure:
segments: [
{
name: string;
from: number;
to: number;
color?: string;
},
{...}
]
`), y.value = !1, !1) : (console.warn(`VueUiBullet: dataset segments must be an array of objects with this datastructure:
segments: [
{
name: string;
from: number;
to: number;
color?: string;
},
{...}
]
`), y.value = !1, !1) : (console.warn(`VueUiBullet: dataset segments is empty. Provide segments with this datastructure:
segments: [
{
name: string;
from: number;
to: number;
color?: string;
},
{...}
]
`), y.value = !1, !1));
ge(z);
function z() {
be(n.dataset) ? Z({
componentName: "VueUiBullet",
type: "dataset"
}) : b.value ? n.dataset.segments.forEach((t, s) => {
ke({
datasetObject: t,
requiredAttributes: ["name", "from", "to"]
}).forEach((a) => {
y.value = !1, Z({
componentName: "VueUiBullet segment",
type: "datasetSerieAttribute",
property: a,
index: s
});
});
}) : y.value = !1, e.value.style.chart.animation.show && j(n.dataset.value || 0);
}
const P = g(we());
function R() {
const t = ee({
userConfig: n.config,
defaultConfig: le
});
return t.theme ? {
...ee({
userConfig: $e.vue_ui_bullet[t.theme] || n.config,
defaultConfig: t
})
} : t;
}
const e = f({
get: () => R(),
set: (t) => t
}), { userOptionsVisible: F, setUserOptionsVisibility: W, keepUserOptionState: E } = He({ config: e.value }), { svgRef: D } = Me({ config: e.value.style.chart.title });
K(() => n.config, (t) => {
e.value = R(), F.value = !e.value.userOptions.showOnChartHover, z(), N.value += 1;
}, { deep: !0 });
const l = f(() => {
const t = e.value.style.chart.height, s = e.value.style.chart.width, a = e.value.style.chart.padding.left, d = s - e.value.style.chart.padding.right, C = e.value.style.chart.padding.top, v = t - e.value.style.chart.padding.bottom;
return {
height: t,
width: s,
left: a,
right: d,
top: C,
bottom: v,
chartWidth: d - a,
chartHeight: v - C
};
}), ne = f(() => {
if (!b.value) return [];
const t = [];
for (let s = 0; s < n.dataset.segments.length; s += 1)
t.push(xe(e.value.style.chart.segments.baseColor, s / n.dataset.segments.length));
return t;
}), I = f(() => b.value ? {
min: Math.min(...n.dataset.segments.map((t) => t.from)),
max: Math.max(...n.dataset.segments.map((t) => t.to))
} : { min: 0, max: 1 }), c = g(ue());
K(() => n.dataset, (t) => {
e.value.style.chart.animation.show ? j(t.value || 0) : c.value = t.value || 0;
}, { deep: !0 });
function ue() {
return e.value.style.chart.animation.show ? I.value.min : n.dataset.value || 0;
}
const V = g(null);
function j(t) {
const s = Math.abs(t - c.value) / e.value.style.chart.animation.animationFrames;
function a() {
c.value < t ? c.value = Math.min(c.value + s, t) : c.value > t && (c.value = Math.max(c.value - s, t)), c.value !== t && (V.value = requestAnimationFrame(a));
}
a();
}
fe(() => {
cancelAnimationFrame(V.value);
});
const h = f(() => {
if (!b.value)
return [];
const t = _e(I.value.min, I.value.max, e.value.style.chart.segments.ticks.divisions), s = t.min >= 0 ? 0 : Math.abs(t.min), a = {
x: l.value.left + (n.dataset.target + s) / (t.max + s) * l.value.chartWidth - e.value.style.chart.target.width / 2
}, d = {
width: (c.value + s) / (t.max + s) * l.value.chartWidth
}, C = t.ticks.map((v) => ({
value: v,
y: l.value.bottom + e.value.style.chart.segments.dataLabels.fontSize + 3 + e.value.style.chart.segments.dataLabels.offsetY,
x: l.value.left + (v + s) / (t.max + s) * l.value.chartWidth
}));
return {
scale: t,
target: a,
value: d,
ticks: C,
chunks: n.dataset.segments.map((v, de) => ({
...v,
color: v.color ? Ce(v.color) : ne.value[de],
x: l.value.left + l.value.chartWidth * ((v.from + s) / (t.max + s)),
y: l.value.top,
height: l.value.chartHeight,
width: l.value.chartWidth * (Math.abs(v.to - v.from) / (t.max + s))
}))
};
}), G = f(() => !h.value || !h.value.chunks || !h.value.chunks.length ? [] : h.value.chunks.map((t) => {
const s = A(
e.value.style.chart.segments.dataLabels.formatter,
t.from,
B({
p: e.value.style.chart.segments.dataLabels.prefix,
v: t.from,
s: e.value.style.chart.segments.dataLabels.suffix,
r: e.value.style.chart.segments.dataLabels.rounding
})
), a = A(
e.value.style.chart.segments.dataLabels.formatter,
t.to,
B({
p: e.value.style.chart.segments.dataLabels.prefix,
v: t.to,
s: e.value.style.chart.segments.dataLabels.suffix,
r: e.value.style.chart.segments.dataLabels.rounding
})
);
return {
...t,
shape: "square",
value: `${s} - ${a}`
};
})), ie = f(() => ({
cy: "bullet-div-legend",
backgroundColor: "transparent",
color: e.value.style.chart.legend.color,
fontSize: e.value.style.chart.legend.fontSize,
paddingBottom: 6,
fontWeight: e.value.style.chart.legend.bold ? "bold" : ""
})), { isPrinting: q, isImaging: X, generatePdf: Y, generateImage: J } = Be({
elementId: `bullet_${P.value}`,
fileName: e.value.style.chart.title.text || "vue-ui-bullet"
}), ce = f(() => e.value.userOptions.show && !e.value.style.chart.title.text), k = g(!1);
function he(t) {
k.value = t, oe.value += 1;
}
function ve() {
return h.value;
}
const _ = g(!1);
function S() {
_.value = !_.value;
}
return ae({
getData: ve,
generatePdf: Y,
generateImage: J,
toggleAnnotator: S
}), (t, s) => (r(), o("div", {
ref_key: "bulletChart",
ref: U,
class: Q(`vue-ui-bullet ${k.value ? "vue-data-ui-wrapper-fullscreen" : ""}`),
style: H(`font-family:${e.value.style.fontFamily};width:100%;background:${e.value.style.chart.backgroundColor}`),
id: `bullet_${P.value}`,
onMouseenter: s[0] || (s[0] = () => u(W)(!0)),
onMouseleave: s[1] || (s[1] = () => u(W)(!1))
}, [
e.value.userOptions.buttons.annotator ? (r(), w(Ie, {
key: 0,
svgRef: u(D),
backgroundColor: e.value.style.chart.backgroundColor,
color: e.value.style.chart.color,
active: _.value,
onClose: S
}, null, 8, ["svgRef", "backgroundColor", "color", "active"])) : i("", !0),
ce.value ? (r(), o("div", Ne, null, 512)) : i("", !0),
e.value.style.chart.title.text ? (r(), o("div", {
key: 2,
ref_key: "chartTitle",
ref: se,
style: "width:100%;background:transparent;"
}, [
(r(), w(Oe, {
lineHeight: "1.3rem",
key: `title_${N.value}`,
config: {
title: {
cy: "bullet-div-title",
...e.value.style.chart.title
},
subtitle: {
cy: "bullet-div-subtitle",
...e.value.style.chart.title.subtitle
}
}
}, null, 8, ["config"]))
], 512)) : i("", !0),
e.value.userOptions.show && y.value && (u(E) || u(F)) ? (r(), w(Pe, {
key: 3,
ref: "details",
backgroundColor: e.value.style.chart.backgroundColor,
color: e.value.style.chart.color,
isPrinting: u(q),
isImaging: u(X),
uid: P.value,
hasTooltip: !1,
hasPdf: e.value.userOptions.buttons.pdf,
hasImg: e.value.userOptions.buttons.img,
hasXls: !1,
hasTable: !1,
hasLabel: !1,
hasFullscreen: e.value.userOptions.buttons.fullscreen,
isFullscreen: k.value,
chartElement: U.value,
position: e.value.userOptions.position,
titles: { ...e.value.userOptions.buttonTitles },
hasAnnotator: e.value.userOptions.buttons.annotator,
isAnnotation: _.value,
onToggleFullscreen: he,
onGeneratePdf: u(Y),
onGenerateImage: u(J),
onToggleAnnotator: S,
style: H({
visibility: u(E) ? u(F) ? "visible" : "hidden" : "visible"
})
}, me({ _: 2 }, [
t.$slots.menuIcon ? {
name: "menuIcon",
fn: p(({ isOpen: a, color: d }) => [
m(t.$slots, "menuIcon", L($({ isOpen: a, color: d })), void 0, !0)
]),
key: "0"
} : void 0,
t.$slots.optionPdf ? {
name: "optionPdf",
fn: p(() => [
m(t.$slots, "optionPdf", {}, void 0, !0)
]),
key: "1"
} : void 0,
t.$slots.optionImg ? {
name: "optionImg",
fn: p(() => [
m(t.$slots, "optionImg", {}, void 0, !0)
]),
key: "2"
} : void 0,
t.$slots.optionFullscreen ? {
name: "optionFullscreen",
fn: p(({ toggleFullscreen: a, isFullscreen: d }) => [
m(t.$slots, "optionFullscreen", L($({ toggleFullscreen: a, isFullscreen: d })), void 0, !0)
]),
key: "3"
} : void 0,
t.$slots.optionAnnotator ? {
name: "optionAnnotator",
fn: p(({ toggleAnnotator: a, isAnnotator: d }) => [
m(t.$slots, "optionAnnotator", L($({ toggleAnnotator: a, isAnnotator: d })), void 0, !0)
]),
key: "4"
} : void 0
]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasImg", "hasFullscreen", "isFullscreen", "chartElement", "position", "titles", "hasAnnotator", "isAnnotation", "onGeneratePdf", "onGenerateImage", "style"])) : i("", !0),
y.value ? (r(), o("svg", {
key: 4,
ref_key: "svgRef",
ref: D,
xmlns: u(Le),
class: Q({ "vue-data-ui-fullscreen--on": k.value, "vue-data-ui-fulscreen--off": !k.value, "vue-ui-bullet-svg": !0 }),
viewBox: `0 0 ${l.value.width} ${l.value.height}`,
style: H(`width: 100%; overflow: visible; background:transparent;color:${e.value.style.chart.color}`)
}, [
ye(Fe),
t.$slots["chart-background"] ? (r(), o("foreignObject", {
key: 0,
x: 0,
y: 0,
width: l.value.width,
height: l.value.height,
style: {
pointerEvents: "none"
}
}, [
m(t.$slots, "chart-background", {}, void 0, !0)
], 8, Re)) : i("", !0),
b.value ? (r(), o("g", We, [
(r(!0), o(M, null, T(h.value.chunks, (a) => (r(), o("rect", {
x: a.x,
y: a.y,
height: a.height,
width: a.width,
fill: a.color,
"stroke-width": 1,
stroke: e.value.style.chart.backgroundColor
}, null, 8, Ee))), 256)),
e.value.style.chart.target.onTop ? i("", !0) : (r(), o("rect", {
key: 0,
x: h.value.target.x,
y: l.value.top + (l.value.chartHeight - l.value.chartHeight * e.value.style.chart.target.heightRatio) / 2,
height: l.value.chartHeight * e.value.style.chart.target.heightRatio,
width: e.value.style.chart.target.width,
rx: e.value.style.chart.target.rounded ? e.value.style.chart.target.width / 2 : 0,
fill: e.value.style.chart.target.color,
stroke: e.value.style.chart.target.stroke,
"stroke-width": e.value.style.chart.target.strokeWidth
}, null, 8, De)),
x("rect", {
x: l.value.left,
y: l.value.top + (l.value.chartHeight - l.value.chartHeight * e.value.style.chart.valueBar.heightRatio) / 2,
height: l.value.chartHeight * e.value.style.chart.valueBar.heightRatio,
width: h.value.value.width,
fill: e.value.style.chart.valueBar.color,
stroke: e.value.style.chart.valueBar.stroke,
"stroke-width": e.value.style.chart.valueBar.strokeWidth
}, null, 8, Ve),
e.value.style.chart.valueBar.label.show ? (r(), o("text", {
key: 1,
x: l.value.left + h.value.value.width,
y: l.value.top - 6 + e.value.style.chart.valueBar.label.offsetY,
"font-size": e.value.style.chart.valueBar.label.fontSize,
"font-weight": e.value.style.chart.valueBar.label.bold ? "bold" : "normal",
fill: e.value.style.chart.valueBar.label.color,
"text-anchor": "middle"
}, O(u(A)(
e.value.style.chart.segments.dataLabels.formatter,
c.value,
u(B)({
p: e.value.style.chart.segments.dataLabels.prefix,
v: c.value,
s: e.value.style.chart.segments.dataLabels.suffix,
r: e.value.style.chart.segments.dataLabels.rounding
})
)), 9, je)) : i("", !0),
e.value.style.chart.target.onTop ? (r(), o("rect", {
key: 2,
x: h.value.target.x,
y: l.value.top + (l.value.chartHeight - l.value.chartHeight * e.value.style.chart.target.heightRatio) / 2,
height: l.value.chartHeight * e.value.style.chart.target.heightRatio,
width: e.value.style.chart.target.width,
rx: e.value.style.chart.target.rounded ? e.value.style.chart.target.width / 2 : 0,
fill: e.value.style.chart.target.color,
stroke: e.value.style.chart.target.stroke,
"stroke-width": e.value.style.chart.target.strokeWidth
}, null, 8, Ge)) : i("", !0),
e.value.style.chart.segments.dataLabels.show ? (r(), o("g", qe, [
(r(!0), o(M, null, T(h.value.ticks, (a) => (r(), o("text", {
x: a.x,
y: a.y,
"text-anchor": "middle",
fill: e.value.style.chart.segments.dataLabels.color,
"font-size": e.value.style.chart.segments.dataLabels.fontSize + "px",
"font-weight": e.value.style.chart.segments.dataLabels.bold ? "bold" : "normal"
}, O(u(A)(
e.value.style.chart.segments.dataLabels.formatter,
a.value,
u(B)({
p: e.value.style.chart.segments.dataLabels.prefix,
v: a.value,
s: e.value.style.chart.segments.dataLabels.suffix,
r: e.value.style.chart.segments.dataLabels.rounding
})
)), 9, Xe))), 256))
])) : i("", !0),
e.value.style.chart.segments.dataLabels.show && e.value.style.chart.segments.ticks.show ? (r(), o("g", Ye, [
(r(!0), o(M, null, T(h.value.ticks, (a) => (r(), o("line", {
x1: a.x,
x2: a.x,
y1: l.value.bottom,
y2: l.value.bottom + 3,
stroke: e.value.style.chart.segments.ticks.stroke,
"stroke-width": 1,
"stroke-linecap": "round"
}, null, 8, Je))), 256))
])) : i("", !0)
])) : i("", !0),
m(t.$slots, "svg", { svg: l.value }, void 0, !0)
], 14, ze)) : i("", !0),
t.$slots.watermark ? (r(), o("div", Ke, [
m(t.$slots, "watermark", L($({ isPrinting: u(q) || u(X) })), void 0, !0)
])) : i("", !0),
y.value ? i("", !0) : (r(), w(Se, {
key: 6,
config: {
type: "bullet",
style: {
backgroundColor: e.value.style.chart.backgroundColor,
bullet: {
color: "#CCCCCC"
}
}
}
}, null, 8, ["config"])),
x("div", {
ref_key: "chartLegend",
ref: re
}, [
e.value.style.chart.legend.show ? (r(), w(Ae, {
key: 0,
clickable: !1,
legendSet: G.value,
config: ie.value
}, {
item: p(({ legend: a }) => [
x("div", Qe, [
x("span", Ze, O(a.name) + ":", 1),
x("span", null, O(a.value), 1)
])
]),
_: 1
}, 8, ["legendSet", "config"])) : i("", !0),
m(t.$slots, "legend", { legend: G.value }, void 0, !0)
], 512),
t.$slots.source ? (r(), o("div", et, [
m(t.$slots, "source", {}, void 0, !0)
], 512)) : i("", !0)
], 46, Ue));
}
}, gt = /* @__PURE__ */ Te(tt, [["__scopeId", "data-v-1ef5edae"]]);
export {
gt as default
};