UNPKG

vue-data-ui

Version:

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

538 lines (537 loc) • 18.9 kB
import { useCssVars as Ie, computed as s, ref as u, watch as R, onMounted as Pe, onBeforeUnmount as ze, onUpdated as Ae, nextTick as ue, createElementBlock as v, openBlock as m, createElementVNode as d, createCommentVNode as x, renderSlot as Fe, normalizeStyle as $, createVNode as He, withDirectives as oe, unref as Z, Fragment as re, renderList as se, normalizeClass as L, vModelText as de, toDisplayString as ve } from "vue"; import Ve from "./BaseIcon-rw8rKNKS.js"; import { t as We, u as Xe } from "./useResponsive-vZgZwV-S.js"; import { c as Ue, S as me, R as ce, X as Oe, G as he } from "./index-BaaDnc4F.js"; import { _ as Ze } from "./_plugin-vue_export-helper-CHgC5LLL.js"; const Ge = { class: "vue-data-ui-slicer-labels", style: { position: "relative", "z-index": "1", "pointer-events": "none" } }, je = { key: 0, style: { width: "100%", position: "relative" } }, qe = { key: 0, class: "minimap", style: { width: "100%" } }, Je = ["xmlns", "viewBox"], Ke = ["id"], Qe = ["stop-color"], Ye = ["d", "stroke"], _e = ["x", "width", "height", "fill", "rx"], et = ["d", "fill"], tt = ["x", "width", "height", "rx", "fill"], lt = ["x", "width", "height", "fill", "rx"], at = ["d", "fill"], nt = ["d", "stroke"], it = ["cx", "cy", "stroke", "fill"], ut = ["cx", "cy", "stroke", "fill"], ot = ["x1", "x2", "y2", "stroke"], rt = ["x", "height", "width", "onMouseenter"], st = ["min", "max"], dt = ["min", "max"], vt = { __name: "Slicer", props: { background: { type: String, default: "#FFFFFF" }, borderColor: { type: String, default: "#FFFFFF" }, fontSize: { type: Number, default: 14 }, labelLeft: { type: String, default: "" }, labelRight: { type: String, default: "" }, textColor: { type: String, default: "#1A1A1A" }, inputColor: { type: String, default: "#1A1A1A" }, max: { type: Number, default: 0 }, min: { type: Number, default: 0 }, selectColor: { type: String, default: "#4A4A4A" }, useResetSlot: { type: Boolean, default: !1 }, valueStart: { type: [Number, String], default: 0 }, valueEnd: { type: [Number, String], default: 0 }, minimap: { type: Array, default: [] }, smoothMinimap: { type: Boolean, default: !1 }, minimapSelectedColor: { type: String, default: "#1f77b4" }, minimapSelectionRadius: { type: Number, default: 12 }, minimapLineColor: { type: String, default: "#2D353C" }, minimapSelectedColorOpacity: { type: Number, default: 0.2 }, minimapSelectedIndex: { type: Number, default: null }, minimapIndicatorColor: { type: String, default: "#2D353C" }, refreshStartPoint: { type: Number, default: 0 }, refreshEndPoint: { type: Number, default: null }, enableRangeHandles: { type: Boolean, default: !1 }, enableSelectionDrag: { type: Boolean, default: !0 }, verticalHandles: { type: Boolean, default: !1 } }, emits: ["update:start", "update:end", "reset", "trapMouse"], setup(a, { expose: fe, emit: ge }) { Ie((e) => ({ a9eaaa56: xe.value, 43003349: w.value, "084765fa": be.value, 23357479: a.selectColor, "3d8e0af2": ye.value })); const t = a, f = u(null), o = u(t.min), r = u(t.max), M = s(() => !!t.minimap.length), D = u(Ue()), pe = s(() => t.refreshEndPoint === null ? t.max : t.refreshEndPoint), y = ge, b = s(() => { const e = t.max - t.min, l = (o.value - t.min) / e * 100, n = (r.value - t.min) / e * 100; return { left: `${l}%`, width: `${n - l}%`, background: t.selectColor, tooltipLeft: `calc(${l}% - ${G.value ? 0 : U.value / 2}px)`, tooltipRight: `calc(${n}% - ${j.value ? B.value : B.value / 2}px)`, arrowLeft: !G.value, arrowRight: !j.value }; }), G = s(() => f.value ? f.value.getBoundingClientRect().width * ((o.value - t.min) / (t.max - t.min)) - U.value / 2 < 0 : !1), j = s(() => f.value ? f.value.getBoundingClientRect().width * ((r.value - t.min) / (t.max - t.min)) + B.value / 2 > f.value.getBoundingClientRect().width : !1), xe = s(() => t.inputColor), ye = s(() => t.background), be = s(() => `${t.selectColor}33`), w = s(() => t.borderColor), q = s(() => { let e = []; for (let l = 0; l < t.minimap.length; l += 1) e.push(l); return e; }); function J() { y("reset"); } function we() { Number(o.value) > Number(r.value) - 1 && (o.value = Number(r.value) - 1), y("update:start", Number(o.value)); } function Se() { Number(r.value) < Number(o.value) + 1 && (r.value = Number(o.value) + 1), y("update:end", Number(r.value)); } R( () => t.min, (e) => { Number(o.value) < Number(e) && (o.value = Number(e)), Number(r.value) < Number(e) && (r.value = Number(e)); } ), R( () => t.max, (e) => { Number(o.value) > Number(e) && (o.value = Number(e)), Number(r.value) > Number(e) && (r.value = Number(e)); } ); const T = u(null), i = u({ width: 1, height: 1 }), E = u(null); Pe(() => { if (M.value) { const e = We(() => { const { width: l, height: n } = Xe({ chart: T.value }); i.value.width = l, i.value.height = n - 47; }); E.value = new ResizeObserver(e), E.value.observe(T.value); } }), ze(() => { E.value && E.value.disconnect(); }); const c = s(() => t.minimap.length ? i.value.width / t.minimap.length : 0), g = s(() => { if (!t.minimap.length) return []; const e = Math.max(...t.minimap), l = Math.min(...t.minimap) - 10, n = e - (l > 0 ? 0 : l), h = t.minimap.map((Be, De) => { const Te = Be - l; return { x: i.value.width / t.minimap.length * De + c.value / 2, y: i.value.height - Te / n * (i.value.height * 0.9) }; }), S = t.smoothMinimap ? me(h) : ce(h), O = [...h].slice(t.valueStart, t.valueEnd), Ee = t.smoothMinimap ? me(O) : ce(O); return { fullSet: S, selectionSet: Ee, sliced: O, firstPlot: h[t.valueStart], lastPlot: h[t.valueEnd - 1] }; }), p = s(() => ({ x: c.value * o.value + c.value / 2, width: i.value.width * ((r.value - o.value) / t.max) - c.value })), N = u(t.minimapSelectedIndex); R(() => t.minimapSelectedIndex, (e) => { N.value = e + t.valueStart; }, { immediate: !0 }); function ke(e) { N.value = e, e >= t.valueStart && e < t.valueEnd && y("trapMouse", e - t.valueStart); } const Ce = u(0), I = u(null), P = u(null); function z(e) { o.value = e, I.value && (I.value.value = e), y("update:start", Number(o.value)); } function A(e) { r.value = e, P.value && (P.value.value = e), y("update:end", Number(r.value)); } const F = s(() => t.valueEnd - t.valueStart), H = u(!1); let V = u(null); const $e = s(() => f.value ? (f.value.getBoundingClientRect().width - 48) / (t.max - t.min) : 20), Me = s(() => (f.value.getBoundingClientRect().width - 48) / (t.max - t.min) * F.value), Ne = u(2.5), K = s(() => { const e = f.value.getBoundingClientRect().width - 48; return Math.ceil((t.max - t.min) / ((e - Me.value) / Ne.value)); }), Q = (e) => { if (C.value = !0, !t.enableSelectionDrag) return; const l = e.type === "touchstart"; if ((l ? e.targetTouches[0].target : e.target).classList.contains("range-handle")) return; H.value = !0, V.value = l ? e.targetTouches[0].clientX : e.clientX; const h = l ? Re : Y, S = l ? Le : ee; window.addEventListener(l ? "touchmove" : "mousemove", h, { passive: !1 }), window.addEventListener(l ? "touchend" : "mouseup", S); }; function Y(e) { _(e.clientX); } function Re(e) { f.value.contains(e.target) && (e.target.classList.contains("range-handle") || (e.preventDefault(), _(e.targetTouches[0].clientX))); } function _(e) { if (!H.value) return; const l = e - V.value; if (Math.abs(l) > $e.value) { if (l > 0) { if (Number(r.value) + 1 <= t.max) { const n = Math.min(t.max, Number(r.value) + K.value); A(n), z(n - F.value); } } else if (Number(o.value) - 1 >= t.min) { const n = Math.max(0, Number(o.value) - K.value); z(n), A(n + F.value); } V.value = e; } } function ee() { te("mousemove", "mouseup"); } function Le() { te("touchmove", "touchend"); } function te(e, l) { H.value = !1, window.removeEventListener(e, Y), window.removeEventListener(l, ee); } const k = u(!1), W = u(null), X = u(null), U = u(1), B = u(1), C = u(!1); function le() { W.value && (U.value = W.value.getBoundingClientRect().width); } function ae() { X.value && (B.value = X.value.getBoundingClientRect().width); } const ne = u(0); function ie(e) { ne.value = e === "start" ? 1 : 0; } return Ae(() => { le(), ae(); }), R(() => t.labelLeft, () => { ue(le); }, { deep: !0 }), R(() => t.labelRight, () => { ue(ae); }, { deep: !0 }), fe({ setStartValue: z, setEndValue: A }), (e, l) => (m(), v("div", { "data-html2canvas-ignore": "", style: { padding: "0 24px" }, class: "vue-data-ui-zoom", ref_key: "zoomWrapper", ref: f, onMousedown: Q, onTouchstart: Q, onTouchend: l[11] || (l[11] = (n) => C.value = !1) }, [ d("div", Ge, [ a.valueStart !== a.refreshStartPoint || a.valueEnd !== pe.value ? (m(), v("div", je, [ a.useResetSlot ? Fe(e.$slots, "reset-action", { key: 1, reset: J }, void 0, !0) : (m(), v("button", { key: 0, tabindex: "0", role: "button", class: "vue-data-ui-refresh-button", style: $({ top: M.value ? "36px" : "-16px", pointerEvents: "all !important" }), onClick: J }, [ He(Ve, { name: "refresh", stroke: a.textColor }, null, 8, ["stroke"]) ], 4)) ])) : x("", !0) ]), d("div", { class: "double-range-slider", ref_key: "minimapWrapper", ref: T, style: { "z-index": "0" }, onMouseenter: l[9] || (l[9] = (n) => C.value = !0), onMouseleave: l[10] || (l[10] = (n) => C.value = !1) }, [ M.value ? (m(), v("div", qe, [ (m(), v("svg", { xmlns: Z(Oe), viewBox: `0 0 ${i.value.width < 0 ? 0 : i.value.width} ${i.value.height < 0 ? 0 : i.value.height}` }, [ d("defs", null, [ d("linearGradient", { id: D.value, x1: "0%", y1: "0%", x2: "0%", y2: "100%" }, [ d("stop", { offset: "0%", "stop-color": `${a.minimapLineColor}50` }, null, 8, Qe), l[12] || (l[12] = d("stop", { offset: "100%", "stop-color": "transparent" }, null, -1)) ], 8, Ke) ]), d("path", { d: `M${g.value.fullSet}`, stroke: `${a.minimapLineColor}`, fill: "none", "stroke-width": "1", "stroke-linecap": "round", "stroke-linejoin": "round", style: { opacity: "1" } }, null, 8, Ye), d("rect", { x: p.value.x, width: p.value.width < 0 ? 0 : p.value.width, height: Math.max(i.value.height, 0), y: 0, fill: w.value, rx: a.minimapSelectionRadius, stroke: "none" }, null, 8, _e), d("path", { d: `M${c.value / 2},${Math.max(i.value.height, 0)} ${g.value.fullSet} L${i.value.width - c.value / 2},${Math.max(i.value.height, 0)}Z`, fill: `url(#${D.value})`, stroke: "none", style: { opacity: "1" } }, null, 8, et), d("rect", { x: p.value.x, width: p.value.width < 0 ? 0 : p.value.width, height: Math.max(i.value.height, 0), y: 0, rx: a.minimapSelectionRadius, fill: w.value }, null, 8, tt), d("rect", { x: p.value.x, width: p.value.width < 0 ? 0 : p.value.width, height: Math.max(i.value.height, 0), y: 0, fill: a.minimapSelectedColor, rx: a.minimapSelectionRadius, style: $({ opacity: a.minimapSelectedColorOpacity }) }, null, 12, lt), d("path", { d: `M${g.value.sliced[0].x},${Math.max(i.value.height, 0)} ${g.value.selectionSet} L${g.value.sliced.at(-1).x},${Math.max(i.value.height, 0)}Z`, fill: `url(#${D.value})`, stroke: "none", style: { opacity: "1" } }, null, 8, at), d("path", { d: `M ${g.value.selectionSet}`, stroke: `${a.minimapLineColor}`, fill: "transparent", "stroke-width": "2", "stroke-linecap": "round", "stroke-linejoin": "round" }, null, 8, nt), d("circle", { cx: g.value.firstPlot.x, cy: g.value.firstPlot.y, "stroke-width": "0.5", stroke: w.value, r: "3", fill: a.minimapLineColor }, null, 8, it), d("circle", { cx: g.value.lastPlot.x, cy: g.value.lastPlot.y, "stroke-width": "0.5", stroke: w.value, r: "3", fill: a.minimapLineColor }, null, 8, ut), N.value !== null ? (m(!0), v(re, { key: 0 }, se(q.value, (n, h) => (m(), v("g", null, [ N.value === n && n >= a.valueStart && n < a.valueEnd ? (m(), v("line", { key: 0, x1: c.value * h + c.value / 2, x2: c.value * h + c.value / 2, y1: 0, y2: Math.max(i.value.height, 0), stroke: a.minimapIndicatorColor, "stroke-linecap": "round", "stroke-dasharray": "2", "stroke-width": "1" }, null, 8, ot)) : x("", !0) ]))), 256)) : x("", !0), (m(!0), v(re, null, se(q.value, (n, h) => (m(), v("rect", { x: c.value * h, y: 0, height: Math.max(i.value.height, 0), width: c.value < 0 ? 0 : c.value, fill: "transparent", style: $([{ "pointer-events": "all !important" }, { cursor: n >= a.valueStart && n < a.valueEnd && a.enableSelectionDrag ? k.value ? "grabbing" : "grab" : "default" }]), onMousedown: l[0] || (l[0] = (S) => k.value = !0), onMouseup: l[1] || (l[1] = (S) => k.value = !1), onMouseenter: (S) => ke(n), onMouseleave: l[2] || (l[2] = (S) => { N.value = null, y("trapMouse", null); }) }, null, 44, rt))), 256)) ], 8, Je)) ])) : x("", !0), l[13] || (l[13] = d("div", { class: "slider-track" }, null, -1)), d("div", { class: L({ "range-highlight": !0, move: a.enableSelectionDrag }), onMousedown: l[3] || (l[3] = (n) => k.value = !0), onMouseup: l[4] || (l[4] = (n) => k.value = !1), style: $({ ...b.value, cursor: k.value ? "grabbing" : "grab" }) }, null, 38), a.enableRangeHandles ? oe((m(), v("input", { ref_key: "rangeStart", ref: I, key: `range-min${Ce.value}`, type: "range", class: L({ "range-left": !0, "range-handle": !0, "range-minimap": M.value && a.verticalHandles }), min: a.min, max: a.max, "onUpdate:modelValue": l[5] || (l[5] = (n) => o.value = n), onInput: we, onMouseenter: l[6] || (l[6] = (n) => ie("start")) }, null, 42, st)), [ [de, o.value] ]) : x("", !0), a.enableRangeHandles ? oe((m(), v("input", { key: 2, ref_key: "rangeEnd", ref: P, type: "range", class: L({ "range-right": !0, "range-handle": !0, "range-minimap": M.value && a.verticalHandles }), min: a.min, max: a.max, "onUpdate:modelValue": l[7] || (l[7] = (n) => r.value = n), onInput: Se, onMouseenter: l[8] || (l[8] = (n) => ie("end")) }, null, 42, dt)), [ [de, r.value] ]) : x("", !0), a.labelLeft ? (m(), v("div", { key: 3, ref_key: "tooltipLeft", ref: W, class: L({ "range-tooltip": !0, "range-tooltip-visible": C.value, "range-tooltip-arrow": b.value.arrowLeft && !a.verticalHandles, "range-tooltip-arrow-left": !b.value.arrowLeft && !a.verticalHandles }), style: $({ left: b.value.tooltipLeft, color: Z(he)(a.selectColor), backgroundColor: a.selectColor, border: `1px solid ${w.value}`, zIndex: `${ne.value + 4}` }) }, ve(a.labelLeft), 7)) : x("", !0), a.labelRight ? (m(), v("div", { key: 4, ref_key: "tooltipRight", ref: X, class: L({ "range-tooltip": !0, "range-tooltip-visible": C.value, "range-tooltip-arrow": b.value.arrowRight && !a.verticalHandles, "range-tooltip-arrow-right": !b.value.arrowRight && !a.verticalHandles }), style: $({ left: b.value.tooltipRight, color: Z(he)(a.selectColor), backgroundColor: a.selectColor, border: `1px solid ${w.value}`, zIndex: "4" }) }, ve(a.labelRight), 7)) : x("", !0) ], 544) ], 544)); } }, pt = /* @__PURE__ */ Ze(vt, [["__scopeId", "data-v-04e0735b"]]); export { pt as S };