vue-data-ui
Version:
A user-empowering data visualization Vue 3 components library for eloquent data storytelling
338 lines (337 loc) • 14 kB
JavaScript
import { computed as f, ref as c, watch as J, onMounted as he, onBeforeUnmount as de, createElementBlock as v, openBlock as n, unref as s, normalizeStyle as S, createBlock as _, createCommentVNode as h, createSlots as ye, withCtx as g, renderSlot as y, normalizeProps as $, guardReactiveProps as O, normalizeClass as z, createVNode as fe, Fragment as K, renderList as Q, toDisplayString as pe } from "vue";
import { u as ge, c as me, a as ke, o as we, e as be, w as Z, m as Ce, X as _e, i as $e, v as ee, f as Oe } from "./index-BaaDnc4F.js";
import { _ as Ie } from "./Title-D_MGglyN.js";
import { u as Pe, U as xe } from "./usePrinter-y4-4tCWT.js";
import { t as Ae, u as Fe } from "./useResponsive-vZgZwV-S.js";
import Se from "./vue-ui-skeleton-6RiQNJSb.js";
import { u as te } from "./useNestedProp-D8vQcOps.js";
import { _ as ze } from "./PackageVersion-D9Lm1C1X.js";
import { P as Me } from "./PenAndPaper-DR58HO_U.js";
import { u as Te } from "./useUserOptionState-BIvW1Kz7.js";
import { u as Ne } from "./useChartAccessibility-BWojgys7.js";
import { _ as Re } from "./_plugin-vue_export-helper-CHgC5LLL.js";
const Ue = ["id"], Xe = ["xmlns", "viewBox"], Le = ["width", "height"], Be = ["x1", "x2", "y1", "y2", "stroke", "stroke-width", "stroke-linecap"], Ee = ["d", "fill"], Ge = ["cx", "cy", "r", "stroke", "stroke-width"], je = ["x", "y", "font-size", "fill", "font-weight"], De = {
key: 5,
class: "vue-data-ui-watermark"
}, Ye = {
__name: "vue-ui-wheel",
props: {
config: {
type: Object,
default() {
return {};
}
},
dataset: {
type: Object,
default() {
return {};
}
}
},
setup(ae, { expose: le }) {
const { vue_ui_wheel: oe } = ge(), d = ae, I = f(() => !!d.dataset && Object.keys(d.dataset).length), P = c(me()), se = c(null), M = c(0), m = c(null), T = c(null), N = c(null), R = c(null), U = c(0), e = f({
get: () => E(),
set: (t) => t
}), { userOptionsVisible: x, setUserOptionsVisibility: X, keepUserOptionState: L } = Te({ config: e.value }), { svgRef: B } = Ne({ config: e.value.style.chart.title });
function E() {
const t = te({
userConfig: d.config,
defaultConfig: oe
});
return t.theme ? {
...te({
userConfig: ke.vue_ui_wheel[t.theme] || d.config,
defaultConfig: t
})
} : t;
}
J(() => d.config, (t) => {
e.value = E(), x.value = !e.value.userOptions.showOnChartHover, W(), U.value += 1;
}, { deep: !0 });
const { isPrinting: G, isImaging: j, generatePdf: D, generateImage: Y } = Pe({
elementId: P.value,
fileName: e.value.style.chart.title.text || "vue-ui-wheel"
}), ne = f(() => e.value.userOptions.show && !e.value.style.chart.title.text), l = c({
size: 360,
height: 360,
width: 360
}), A = c(e.value.style.chart.layout.percentage.fontSize), u = f(() => ({
radius: Math.min(l.value.width, l.value.height) * 0.9 / 2,
centerX: l.value.width / 2,
centerY: l.value.height / 2
}));
function H(t, o = 1) {
return {
x: u.value.centerX + u.value.radius * Math.cos(29.85 + t * Math.PI / 180) * o,
y: u.value.centerY + u.value.radius * Math.sin(29.85 + t * Math.PI / 180) * o
};
}
const r = c(e.value.style.chart.animation.use ? 0 : d.dataset.percentage || 0);
J(() => d.dataset, (t) => {
e.value.style.chart.animation.use ? q(t.percentage) : r.value = t.percentage || 0;
}, { deep: !0 });
const k = c(null);
he(() => {
W();
});
function W() {
if (we(d.dataset) && be({
componentName: "VueUiWheel",
type: "dataset"
}), q(d.dataset.percentage || 0), e.value.responsive) {
const t = Ae(() => {
const { width: o, height: a } = Fe({
chart: m.value,
title: e.value.style.chart.title.text ? T.value : null,
source: N.value,
noTitle: R.value
});
requestAnimationFrame(() => {
l.value.width = o, l.value.height = a, A.value = e.value.style.chart.layout.percentage.fontSize / 360 * Math.min(o, a);
});
});
k.value = new ResizeObserver(t), k.value.observe(m.value.parentNode);
}
}
de(() => {
k.value && k.value.disconnect();
});
function q(t) {
let o = e.value.style.chart.animation.speed;
const a = Math.abs(t - r.value) / (o * 120);
function i() {
r.value < t ? r.value = Math.min(r.value + a, t) : r.value > t && (r.value = Math.max(r.value - a, t)), r.value !== t && requestAnimationFrame(i);
}
i();
}
const p = f(() => Math.max(100, e.value.style.chart.layout.wheel.ticks.quantity)), w = f(() => 100 / p.value), V = f(() => {
const t = [];
for (let o = 0; o < p.value; o += 1) {
const a = r.value > o * w.value ? e.value.style.chart.layout.wheel.ticks.activeColor : e.value.style.chart.layout.wheel.ticks.inactiveColor, { x: i, y: ie } = H(l.value.size / p.value * o), { x: ce, y: ve } = H(l.value.size / p.value * o, e.value.style.chart.layout.wheel.ticks.sizeRatio);
t.push({
x1: i,
y1: ie,
x2: ce,
y2: ve,
color: e.value.style.chart.layout.wheel.ticks.gradient.show ? Z(a, o * w.value / p.value * (e.value.style.chart.layout.wheel.ticks.gradient.shiftHueIntensity / 100)) : a
});
}
return t;
}), ue = f(() => Ce({ series: V.value.map((t) => ({
name: "",
value: 1,
color: t.color
})) }, u.value.centerX, u.value.centerY, u.value.radius, u.value.radius, 1.99999, 2, 1, 360, 105.25, u.value.radius * (1 - e.value.style.chart.layout.wheel.ticks.sizeRatio))), b = c(!1);
function re(t) {
b.value = t, M.value += 1;
}
const C = c(!1);
function F() {
C.value = !C.value;
}
return le({
generatePdf: D,
generateImage: Y,
toggleAnnotator: F
}), (t, o) => (n(), v("div", {
class: "vue-ui-wheel",
ref_key: "wheelChart",
ref: m,
id: P.value,
style: S(`font-family:${e.value.style.fontFamily};width:100%; text-align:center;background:${e.value.style.chart.backgroundColor};${e.value.responsive ? "height:100%" : ""}`),
onMouseenter: o[0] || (o[0] = () => s(X)(!0)),
onMouseleave: o[1] || (o[1] = () => s(X)(!1))
}, [
e.value.userOptions.buttons.annotator ? (n(), _(Me, {
key: 0,
svgRef: s(B),
backgroundColor: e.value.style.chart.backgroundColor,
color: e.value.style.chart.color,
active: C.value,
onClose: F
}, null, 8, ["svgRef", "backgroundColor", "color", "active"])) : h("", !0),
ne.value ? (n(), v("div", {
key: 1,
ref_key: "noTitle",
ref: R,
class: "vue-data-ui-no-title-space",
style: "height:36px; width: 100%;background:transparent"
}, null, 512)) : h("", !0),
e.value.style.chart.title.text ? (n(), v("div", {
key: 2,
ref_key: "chartTitle",
ref: T,
style: "width:100%;background:transparent;padding-bottom:12px"
}, [
(n(), _(Ie, {
key: `title_${U.value}`,
config: {
title: {
cy: "wheel-title",
...e.value.style.chart.title
},
subtitle: {
cy: "wheel-subtitle",
...e.value.style.chart.title.subtitle
}
}
}, null, 8, ["config"]))
], 512)) : h("", !0),
e.value.userOptions.show && I.value && (s(L) || s(x)) ? (n(), _(xe, {
ref_key: "details",
ref: se,
key: `user_options_${M.value}`,
backgroundColor: e.value.style.chart.backgroundColor,
color: e.value.style.chart.color,
isPrinting: s(G),
isImaging: s(j),
uid: P.value,
hasPdf: e.value.userOptions.buttons.pdf,
hasImg: e.value.userOptions.buttons.img,
hasFullscreen: e.value.userOptions.buttons.fullscreen,
hasXls: !1,
isFullscreen: b.value,
position: e.value.userOptions.position,
titles: { ...e.value.userOptions.buttonTitles },
hasAnnotator: e.value.userOptions.buttons.annotator,
isAnnotation: C.value,
chartElement: m.value,
onToggleFullscreen: re,
onGeneratePdf: s(D),
onGenerateImage: s(Y),
onToggleAnnotator: F,
style: S({
visibility: s(L) ? s(x) ? "visible" : "hidden" : "visible"
})
}, ye({ _: 2 }, [
t.$slots.menuIcon ? {
name: "menuIcon",
fn: g(({ isOpen: a, color: i }) => [
y(t.$slots, "menuIcon", $(O({ isOpen: a, color: i })), void 0, !0)
]),
key: "0"
} : void 0,
t.$slots.optionPdf ? {
name: "optionPdf",
fn: g(() => [
y(t.$slots, "optionPdf", {}, void 0, !0)
]),
key: "1"
} : void 0,
t.$slots.optionImg ? {
name: "optionImg",
fn: g(() => [
y(t.$slots, "optionImg", {}, void 0, !0)
]),
key: "2"
} : void 0,
t.$slots.optionFullscreen ? {
name: "optionFullscreen",
fn: g(({ toggleFullscreen: a, isFullscreen: i }) => [
y(t.$slots, "optionFullscreen", $(O({ toggleFullscreen: a, isFullscreen: i })), void 0, !0)
]),
key: "3"
} : void 0,
t.$slots.optionAnnotator ? {
name: "optionAnnotator",
fn: g(({ toggleAnnotator: a, isAnnotator: i }) => [
y(t.$slots, "optionAnnotator", $(O({ toggleAnnotator: a, isAnnotator: i })), void 0, !0)
]),
key: "4"
} : void 0
]), 1032, ["backgroundColor", "color", "isPrinting", "isImaging", "uid", "hasPdf", "hasImg", "hasFullscreen", "isFullscreen", "position", "titles", "hasAnnotator", "isAnnotation", "chartElement", "onGeneratePdf", "onGenerateImage", "style"])) : h("", !0),
I.value ? (n(), v("svg", {
key: 4,
ref_key: "svgRef",
ref: B,
xmlns: s(_e),
class: z({ "vue-data-ui-fullscreen--on": b.value, "vue-data-ui-fulscreen--off": !b.value }),
viewBox: `0 0 ${l.value.width <= 0 ? 10 : l.value.width} ${l.value.height <= 0 ? 10 : l.value.height}`,
style: S(`max-width:100%;overflow:visible;background:transparent;color:${e.value.style.chart.color}`)
}, [
fe(ze),
t.$slots["chart-background"] ? (n(), v("foreignObject", {
key: 0,
x: 0,
y: 0,
width: l.value.width <= 0 ? 10 : l.value.width,
height: l.value.height <= 0 ? 10 : l.value.height,
style: {
pointerEvents: "none"
}
}, [
y(t.$slots, "chart-background", {}, void 0, !0)
], 8, Le)) : h("", !0),
e.value.style.chart.layout.wheel.ticks.type === "classic" ? (n(!0), v(K, { key: 1 }, Q(V.value, (a, i) => (n(), v("line", {
x1: a.x1,
x2: a.x2,
y1: a.y1,
y2: a.y2,
stroke: a.color,
"stroke-width": e.value.style.chart.layout.wheel.ticks.strokeWidth / 360 * Math.min(l.value.width, l.value.height),
"stroke-linecap": e.value.style.chart.layout.wheel.ticks.rounded ? "round" : "butt",
class: z({ "vue-ui-tick-animated": e.value.style.chart.animation.use && i * w.value <= r.value })
}, null, 10, Be))), 256)) : (n(!0), v(K, { key: 2 }, Q(ue.value, (a, i) => (n(), v("path", {
d: a.arcSlice,
fill: a.color,
class: z({ "vue-ui-tick-animated": e.value.style.chart.animation.use && i * w.value <= r.value })
}, null, 10, Ee))), 256)),
e.value.style.chart.layout.innerCircle.show ? (n(), v("circle", {
key: 3,
cx: u.value.centerX,
cy: u.value.centerY,
r: u.value.radius * 0.8 <= 0 ? 1e-4 : u.value.radius * 0.8,
stroke: e.value.style.chart.layout.innerCircle.stroke,
"stroke-width": e.value.style.chart.layout.innerCircle.strokeWidth,
fill: "none"
}, null, 8, Ge)) : h("", !0),
e.value.style.chart.layout.percentage.show ? (n(), v("text", {
key: 4,
x: u.value.centerX,
y: u.value.centerY + A.value / 3,
"font-size": A.value,
fill: e.value.style.chart.layout.wheel.ticks.gradient.show ? s(Z)(e.value.style.chart.layout.wheel.ticks.activeColor, r.value / 100 * (e.value.style.chart.layout.wheel.ticks.gradient.shiftHueIntensity / 100)) : e.value.style.chart.layout.wheel.ticks.activeColor,
"text-anchor": "middle",
"font-weight": e.value.style.chart.layout.percentage.bold ? "bold" : "normal",
style: { "font-variant-numeric": "tabluar-nums" }
}, pe(s($e)(
e.value.style.chart.layout.percentage.formatter,
s(ee)(r.value),
s(Oe)({
v: s(ee)(r.value),
s: "%",
r: e.value.style.chart.layout.percentage.rounding
})
)), 9, je)) : h("", !0),
y(t.$slots, "svg", { svg: l.value }, void 0, !0)
], 14, Xe)) : h("", !0),
t.$slots.watermark ? (n(), v("div", De, [
y(t.$slots, "watermark", $(O({ isPrinting: s(G) || s(j) })), void 0, !0)
])) : h("", !0),
t.$slots.source ? (n(), v("div", {
key: 6,
ref_key: "source",
ref: N,
dir: "auto"
}, [
y(t.$slots, "source", {}, void 0, !0)
], 512)) : h("", !0),
I.value ? h("", !0) : (n(), _(Se, {
key: 7,
config: {
type: "wheel",
style: {
backgroundColor: e.value.style.chart.backgroundColor,
wheel: {
color: "#CCCCCC"
}
}
}
}, null, 8, ["config"]))
], 44, Ue));
}
}, ot = /* @__PURE__ */ Re(Ye, [["__scopeId", "data-v-a0e08156"]]);
export {
ot as default
};