UNPKG

vue-data-ui

Version:

A user-empowering data visualization Vue 3 components library for eloquent data storytelling

314 lines (313 loc) • 13.5 kB
import { useCssVars as le, computed as _, defineAsyncComponent as N, onMounted as ae, ref as D, watch as se, createElementBlock as s, openBlock as a, normalizeStyle as $, createCommentVNode as c, createBlock as V, createElementVNode as h, createTextVNode as oe, toDisplayString as p, unref as n, createVNode as ie, renderSlot as I, Fragment as f, renderList as g, normalizeClass as E } from "vue"; import { u as ue, o as re, e as H, g as ne, c as ve, a as de, s as b, i as F, f as O, X as ce, w as z } from "./index-BLtEpj8j.js"; import { u as W } from "./useNestedProp-Bw1KcAmj.js"; import { u as ye } from "./useChartAccessibility-9icAAmYg.js"; import { _ as he } from "./Shape-Cqnzky8X.js"; import { _ as fe } from "./_plugin-vue_export-helper-CHgC5LLL.js"; const ge = { key: 0 }, pe = { key: 1 }, be = ["xmlns", "viewBox"], me = ["width", "height"], _e = ["id"], xe = ["stop-color"], ke = ["stop-color"], we = ["id"], $e = ["stop-color"], Ce = ["stop-color"], Le = ["id"], ze = ["stop-color"], Se = ["stop-color"], Ae = { key: 1 }, Me = ["x", "y", "height", "width", "fill", "stroke", "stroke-width", "rx"], Ne = { key: 2 }, De = ["x", "y", "font-size", "font-weight", "fill"], Ve = ["x", "y", "font-size", "fill"], Ie = ["x", "y", "font-size", "fill"], Ee = ["height", "width", "x", "onMouseover", "stroke", "stroke-width", "rx", "stroke-dasharray", "onClick"], He = { key: 2, ref: "source", dir: "auto" }, Fe = { __name: "vue-ui-sparkhistogram", props: { config: { type: Object, default() { return {}; } }, dataset: { type: Array, default() { return []; } } }, emits: ["selectDatapoint"], setup(B, { emit: U }) { le((l) => ({ "2d6ebc7a": J.value })); const j = N(() => import("./PackageVersion-CnRyWKP-.js")), R = N(() => import("./vue-ui-skeleton-CsMU8DwQ.js")), { vue_ui_sparkhistogram: X } = ue(), d = B, S = _(() => !!d.dataset && d.dataset.length); ae(() => { A(); }); function A() { re(d.dataset) ? H({ componentName: "VueUiSparkHistogram", type: "dataset" }) : d.dataset.forEach((l, u) => { ne({ datasetObject: l, requiredAttributes: ["value"] }).forEach((t) => { H({ componentName: "VueUiSparkHistogram", type: "datasetSerieAttribute", property: t, index: u }); }); }); } const m = D(ve()), e = _({ get: () => M(), set: (l) => l }), { svgRef: G } = ye({ config: e.value.style.title }); function M() { const l = W({ userConfig: d.config, defaultConfig: X }); return l.theme ? { ...W({ userConfig: de.vue_ui_sparkhistogram[l.theme] || d.config, defaultConfig: l }) } : l; } se(() => d.config, (l) => { e.value = M(), A(); }, { deep: !0 }); const v = _(() => { const l = e.value.style.layout.height, u = e.value.style.layout.width, t = e.value.style.layout.padding.top, o = l - e.value.style.layout.padding.bottom, y = e.value.style.layout.padding.left, x = u - e.value.style.layout.padding.right, k = t + (l - t - e.value.style.layout.padding.bottom) / 2, C = l - e.value.style.layout.padding.top - e.value.style.layout.padding.bottom, w = u - e.value.style.layout.padding.left - e.value.style.layout.padding.right; return { bottom: o, centerY: k, drawingHeight: C, drawingWidth: w, height: l, left: y, right: x, top: t, width: u }; }), Y = _(() => Math.max(...d.dataset.map((l) => Math.abs(l.value || 0)))); function q(l) { return Math.abs(l) / Y.value; } const r = _(() => d.dataset.map((l, u) => { const t = q(l.value || 0), o = v.value.drawingHeight * t, y = v.value.drawingWidth / d.dataset.length, x = y * (e.value.style.bars.gap / 100), k = y - x, C = v.value.centerY - o / 2, w = v.value.left + (x / 2 + u * y), K = v.value.left + u * y, L = typeof l.intensity > "u" ? 100 : Math.round(l.intensity * 100), Q = l.color ? l.color : l.value >= 0 ? b(e.value.style.bars.colors.positive, L) : b(e.value.style.bars.colors.negative, L), Z = l.color ? l.color : l.value >= 0 ? e.value.style.bars.colors.positive : e.value.style.bars.colors.negative, ee = l.color ? `url(#gradient_datapoint_${u}_${m.value})` : l.value >= 0 ? `url(#gradient_positive_${u}_${m.value})` : `url(#gradient_negative_${u}_${m.value})`, te = w + k / 2; return { ...l, color: Q, gradient: ee, height: o, intensity: L, proportion: t, stroke: Z, textAnchor: te, trapX: K, unitWidth: y, width: k, x: w, y: C }; })), i = D(null), P = U; function T(l, u) { P("selectDatapoint", { datapoint: l, index: u }); } const J = _(() => `${e.value.style.animation.speedMs}ms`); return (l, u) => (a(), s("div", { class: "vue-ui-spark-histogram", style: $(`width:100%;background:${e.value.style.backgroundColor};font-family:${e.value.style.fontFamily}`), onMouseleave: u[1] || (u[1] = (t) => i.value = null) }, [ e.value.style.title.text ? (a(), s("div", { key: 0, style: $(`width:calc(100% - 12px);background:transparent;margin:0 auto;margin:${e.value.style.title.margin};padding: 0 6px;text-align:${e.value.style.title.textAlign}`) }, [ h("div", { style: $(`font-size:${e.value.style.title.fontSize}px;color:${e.value.style.title.color};font-weight:${e.value.style.title.bold ? "bold" : "normal"}`) }, [ oe(p(e.value.style.title.text) + " ", 1), i.value !== null ? (a(), s("span", ge, "- " + p(r.value[i.value].timeLabel || "") + " " + p(n(F)( e.value.style.labels.value.formatter, r.value[i.value].value, n(O)({ p: e.value.style.labels.value.prefix, v: r.value[i.value].value, s: e.value.style.labels.value.suffix, r: e.value.style.labels.value.rounding }), { datapoint: r.value[i.value], seriesIndex: i.value } )), 1)) : c("", !0), ![void 0, null].includes(i.value) && ![null, void 0].includes(r.value[i.value].valueLabel) ? (a(), s("span", pe, "(" + p(r.value[i.value].valueLabel || 0) + ")", 1)) : c("", !0) ], 4), e.value.style.title.subtitle.text ? (a(), s("div", { key: 0, style: $(`font-size:${e.value.style.title.subtitle.fontSize}px;color:${e.value.style.title.subtitle.color};font-weight:${e.value.style.title.subtitle.bold ? "bold" : "normal"}`) }, p(e.value.style.title.subtitle.text), 5)) : c("", !0) ], 4)) : c("", !0), S.value ? (a(), s("svg", { key: 1, ref_key: "svgRef", ref: G, xmlns: n(ce), viewBox: `0 0 ${v.value.width} ${v.value.height}`, style: { overflow: "visible" } }, [ ie(n(j)), l.$slots["chart-background"] ? (a(), s("foreignObject", { key: 0, x: 0, y: 0, width: v.value.width, height: v.value.height, style: { pointerEvents: "none" } }, [ I(l.$slots, "chart-background", {}, void 0, !0) ], 8, me)) : c("", !0), h("defs", null, [ (a(!0), s(f, null, g(r.value, (t, o) => (a(), s("radialGradient", { id: `gradient_positive_${o}_${m.value}`, cy: "50%", cx: "50%", r: "50%", fx: "50%", fy: "50%" }, [ h("stop", { offset: "0%", "stop-color": n(b)(n(z)(e.value.style.bars.colors.positive, 0.05), t.intensity) }, null, 8, xe), h("stop", { offset: "100%", "stop-color": n(b)(e.value.style.bars.colors.positive, t.intensity) }, null, 8, ke) ], 8, _e))), 256)), (a(!0), s(f, null, g(r.value, (t, o) => (a(), s("radialGradient", { id: `gradient_negative_${o}_${m.value}`, cy: "50%", cx: "50%", r: "50%", fx: "50%", fy: "50%" }, [ h("stop", { offset: "0%", "stop-color": n(b)(n(z)(e.value.style.bars.colors.negative, 0.05), t.intensity) }, null, 8, $e), h("stop", { offset: "100%", "stop-color": n(b)(e.value.style.bars.colors.negative, t.intensity) }, null, 8, Ce) ], 8, we))), 256)), (a(!0), s(f, null, g(r.value, (t, o) => (a(), s("radialGradient", { id: `gradient_datapoint_${o}_${m.value}`, cy: "50%", cx: "50%", r: "50%", fx: "50%", fy: "50%" }, [ h("stop", { offset: "0%", "stop-color": n(b)(n(z)(t.color, 0.05), t.intensity) }, null, 8, ze), h("stop", { offset: "100%", "stop-color": n(b)(t.color, t.intensity) }, null, 8, Se) ], 8, Le))), 256)) ]), !e.value.style.bars.shape || e.value.style.bars.shape === "square" ? (a(), s("g", Ae, [ (a(!0), s(f, null, g(r.value, (t, o) => (a(), s("rect", { x: t.x, y: t.y, height: t.height, width: t.width, fill: e.value.style.bars.colors.gradient.show ? t.gradient : t.color, stroke: t.stroke, "stroke-width": e.value.style.bars.strokeWidth, rx: `${e.value.style.bars.borderRadius * t.proportion / 12}%`, class: E({ "vue-ui-sparkhistogram-shape": e.value.style.animation.show }) }, null, 10, Me))), 256)) ])) : (a(), s("g", Ne, [ (a(!0), s(f, null, g(r.value, (t, o) => (a(), V(he, { plot: { x: t.x + t.width / 2, y: t.y + t.height / 2 }, color: e.value.style.bars.colors.gradient.show ? t.gradient : t.color, shape: e.value.style.bars.shape, radius: t.height * 0.4, class: E({ "vue-ui-sparkhistogram-shape": e.value.style.animation.show }) }, null, 8, ["plot", "color", "shape", "radius", "class"]))), 256)) ])), (a(!0), s(f, null, g(r.value, (t, o) => (a(), s("text", { "text-anchor": "middle", x: t.textAnchor, y: t.y - e.value.style.labels.value.fontSize / 3 + e.value.style.labels.value.offsetY, "font-size": e.value.style.labels.value.fontSize, "font-weight": e.value.style.labels.value.bold ? "bold" : "normal", fill: e.value.style.labels.value.color }, p(n(F)( e.value.style.labels.value.formatter, t.value, n(O)({ p: e.value.style.labels.value.prefix, v: t.value, s: e.value.style.labels.value.suffix, r: e.value.style.labels.value.rounding }), { datapoint: r.value[i.value], seriesIndex: i.value } )), 9, De))), 256)), (a(!0), s(f, null, g(r.value, (t, o) => (a(), s("g", null, [ t.valueLabel ? (a(), s("text", { key: 0, x: t.textAnchor, y: t.y + t.height + e.value.style.labels.valueLabel.fontSize, "font-size": e.value.style.labels.valueLabel.fontSize, "text-anchor": "middle", fill: e.value.style.labels.valueLabel.color }, p(t.valueLabel), 9, Ve)) : c("", !0) ]))), 256)), (a(!0), s(f, null, g(r.value, (t, o) => (a(), s("g", null, [ t.timeLabel ? (a(), s("text", { key: 0, x: t.textAnchor, y: v.value.height - e.value.style.labels.timeLabel.fontSize / 2, "font-size": e.value.style.labels.timeLabel.fontSize, fill: e.value.style.labels.timeLabel.color, "text-anchor": "middle" }, p(t.timeLabel), 9, Ie)) : c("", !0) ]))), 256)), (a(!0), s(f, null, g(r.value, (t, o) => (a(), s("g", null, [ h("rect", { height: v.value.height, width: t.unitWidth, fill: "transparent", x: t.trapX, y: 0, onMouseover: (y) => i.value = o, onMouseleave: u[0] || (u[0] = (y) => i.value = null), stroke: i.value !== null && i.value === o ? e.value.style.selector.stroke : "", "stroke-width": i.value !== null && i.value === o ? e.value.style.selector.strokeWidth : 0, rx: e.value.style.selector.borderRadius, "stroke-dasharray": e.value.style.selector.strokeDasharray, onClick: () => T(t, o) }, null, 40, Ee) ]))), 256)) ], 8, be)) : c("", !0), l.$slots.source ? (a(), s("div", He, [ I(l.$slots, "source", {}, void 0, !0) ], 512)) : c("", !0), S.value ? c("", !0) : (a(), V(n(R), { key: 3, config: { type: "sparkHistogram", style: { backgroundColor: e.value.style.backgroundColor, sparkHistogram: { color: "#CCCCCC" } } } }, null, 8, ["config"])) ], 36)); } }, Xe = /* @__PURE__ */ fe(Fe, [["__scopeId", "data-v-4d2045fb"]]); export { Xe as default };