@flowtools/uplot 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -1
- package/dist/index.es.js +30 -29
- package/dist/index.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
## usage
|
|
8
8
|
|
|
9
9
|
```shell
|
|
10
|
-
pnpm add @flowtools/uplot
|
|
10
|
+
pnpm add @flowtools/uplot uplot @vueuse/core
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
## Usage
|
|
@@ -55,6 +55,7 @@ You can use header and footer slots to add or customize the header and legend. B
|
|
|
55
55
|
</template>
|
|
56
56
|
</Uplot>
|
|
57
57
|
</template>
|
|
58
|
+
```
|
|
58
59
|
|
|
59
60
|
## Interacting with the uplot
|
|
60
61
|
|
package/dist/index.es.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { defineComponent as U, ref as
|
|
1
|
+
import { defineComponent as U, ref as k, onMounted as V, watch as b, nextTick as $, openBlock as u, createElementBlock as p, renderSlot as D, unref as f, createElementVNode as g, createTextVNode as P, toDisplayString as h, createCommentVNode as S, Fragment as F, renderList as N, normalizeClass as L, normalizeStyle as j } from "vue";
|
|
2
2
|
import M from "uplot";
|
|
3
|
-
import { useElementSize as
|
|
3
|
+
import { useElementSize as R, useVModel as C } from "@vueuse/core";
|
|
4
4
|
const T = (a) => {
|
|
5
5
|
if (typeof a == "object" && a !== null) {
|
|
6
6
|
if (typeof Object.getPrototypeOf == "function") {
|
|
@@ -30,10 +30,10 @@ c.withOptions = (a, ...r) => {
|
|
|
30
30
|
const s = c(...r);
|
|
31
31
|
return c.options = B, s;
|
|
32
32
|
};
|
|
33
|
-
const
|
|
33
|
+
const q = { class: "__uplot-root" }, G = {
|
|
34
34
|
key: 0,
|
|
35
35
|
class: "extra-info"
|
|
36
|
-
},
|
|
36
|
+
}, H = /* @__PURE__ */ g("br", null, null, -1), I = { style: { "text-align": "left" } }, J = { class: "__uplot-legend" }, K = ["onClick"], Q = {
|
|
37
37
|
key: 1,
|
|
38
38
|
class: "__uplot-legend-value"
|
|
39
39
|
}, W = {
|
|
@@ -44,7 +44,7 @@ const G = { class: "__uplot-root" }, H = {
|
|
|
44
44
|
props: {
|
|
45
45
|
options: null,
|
|
46
46
|
data: null,
|
|
47
|
-
|
|
47
|
+
noResetScale: { type: Boolean, default: !1 },
|
|
48
48
|
showDebug: { type: Boolean, default: !1 },
|
|
49
49
|
noFooter: { type: Boolean, default: !1 },
|
|
50
50
|
zoom: { default: () => [null, null] },
|
|
@@ -52,7 +52,7 @@ const G = { class: "__uplot-root" }, H = {
|
|
|
52
52
|
},
|
|
53
53
|
emits: ["select", "cursor", "update:zoom", "update:series"],
|
|
54
54
|
setup(a, { expose: r, emit: s }) {
|
|
55
|
-
const o = a, v =
|
|
55
|
+
const o = a, v = k(), { width: y, height: w } = R(v), x = C(o, "zoom", s, { passive: !0 }), i = C(o, "series", s, { passive: !0 }), E = {
|
|
56
56
|
title: void 0,
|
|
57
57
|
legend: {
|
|
58
58
|
show: !1
|
|
@@ -87,7 +87,7 @@ const G = { class: "__uplot-root" }, H = {
|
|
|
87
87
|
],
|
|
88
88
|
setSelect: [
|
|
89
89
|
(e) => {
|
|
90
|
-
s("select", e.select), o.showDebug && console.log("setSelect", e.select),
|
|
90
|
+
s("select", e.select), o.showDebug && console.log("setSelect", e.select), x.value = [
|
|
91
91
|
e.posToVal(e.select.left, "x"),
|
|
92
92
|
e.posToVal(e.select.left + e.select.width, "x")
|
|
93
93
|
];
|
|
@@ -95,7 +95,7 @@ const G = { class: "__uplot-root" }, H = {
|
|
|
95
95
|
],
|
|
96
96
|
setScale: [
|
|
97
97
|
(e) => {
|
|
98
|
-
|
|
98
|
+
x.value = [
|
|
99
99
|
e.scales.x.min || null,
|
|
100
100
|
e.scales.x.max || null
|
|
101
101
|
];
|
|
@@ -104,36 +104,36 @@ const G = { class: "__uplot-root" }, H = {
|
|
|
104
104
|
}
|
|
105
105
|
};
|
|
106
106
|
let n;
|
|
107
|
-
const
|
|
108
|
-
function
|
|
109
|
-
n && n.destroy(), n = new M({ width: 100, height: 100, ...c(o.options, E) }, o.data, v.value),
|
|
110
|
-
|
|
107
|
+
const z = k();
|
|
108
|
+
function O() {
|
|
109
|
+
n && n.destroy(), n = new M({ width: 100, height: 100, ...c(o.options, E) }, o.data, v.value), z.value = n, o.zoom[0] !== null && o.zoom[1] !== null && n.setScale("x", { min: o.zoom[0], max: o.zoom[1] }), setTimeout(() => {
|
|
110
|
+
A();
|
|
111
111
|
}, 0);
|
|
112
112
|
}
|
|
113
113
|
V(() => {
|
|
114
|
-
|
|
114
|
+
O();
|
|
115
115
|
}), b([y, w], () => {
|
|
116
116
|
$(() => {
|
|
117
|
-
|
|
117
|
+
A();
|
|
118
118
|
});
|
|
119
119
|
}), b(o.data, (e) => {
|
|
120
|
-
if (o.
|
|
120
|
+
if (o.noResetScale) {
|
|
121
121
|
n.setData(e);
|
|
122
122
|
return;
|
|
123
123
|
}
|
|
124
124
|
n.setData(e, !0), n.redraw();
|
|
125
125
|
}), b(o.options, (e, l) => {
|
|
126
|
-
o.showDebug && console.log("watch options", e, l),
|
|
126
|
+
o.showDebug && console.log("watch options", e, l), O();
|
|
127
127
|
});
|
|
128
|
-
function
|
|
128
|
+
function A() {
|
|
129
129
|
n.setSize({ width: y.value, height: w.value }), o.showDebug && console.log("resize", n);
|
|
130
130
|
}
|
|
131
131
|
function m(e) {
|
|
132
132
|
var l, t;
|
|
133
133
|
typeof e == "object" && (e = ((l = i.value) == null ? void 0 : l.indexOf(e)) || -1), n.setSeries(e, { show: !n.series[e].show }), (t = i.value) != null && t[e] && (i.value[e].show = n.series[e].show);
|
|
134
134
|
}
|
|
135
|
-
return r({ toggleShow: m, uplot:
|
|
136
|
-
|
|
135
|
+
return r({ toggleShow: m, uplot: z }), (e, l) => (u(), p("div", q, [
|
|
136
|
+
D(e.$slots, "header", {
|
|
137
137
|
series: f(i),
|
|
138
138
|
toggleShow: m
|
|
139
139
|
}),
|
|
@@ -142,17 +142,18 @@ const G = { class: "__uplot-root" }, H = {
|
|
|
142
142
|
ref: v,
|
|
143
143
|
class: "__uplot"
|
|
144
144
|
}, null, 512),
|
|
145
|
-
a.showDebug ? (u(), p("div",
|
|
145
|
+
a.showDebug ? (u(), p("div", G, [
|
|
146
146
|
P(h(f(y)) + " x " + h(f(w)) + " ", 1),
|
|
147
|
-
|
|
148
|
-
g("pre",
|
|
149
|
-
])) :
|
|
150
|
-
|
|
147
|
+
H,
|
|
148
|
+
g("pre", I, h(f(i)), 1)
|
|
149
|
+
])) : S("", !0),
|
|
150
|
+
a.noFooter ? S("", !0) : D(e.$slots, "footer", {
|
|
151
|
+
key: 1,
|
|
151
152
|
series: f(i),
|
|
152
153
|
toggleShow: m
|
|
153
154
|
}, () => [
|
|
154
|
-
g("div",
|
|
155
|
-
(u(!0), p(
|
|
155
|
+
g("div", J, [
|
|
156
|
+
(u(!0), p(F, null, N(f(i), (t, d) => {
|
|
156
157
|
var _;
|
|
157
158
|
return u(), p("div", {
|
|
158
159
|
key: t.label,
|
|
@@ -164,9 +165,9 @@ const G = { class: "__uplot-root" }, H = {
|
|
|
164
165
|
key: 0,
|
|
165
166
|
style: j({ color: t.stroke || "black" }),
|
|
166
167
|
class: "__uplot-legend-label"
|
|
167
|
-
}, h(t.label), 5)) :
|
|
168
|
-
t.value ? (u(), p("span",
|
|
169
|
-
], 14,
|
|
168
|
+
}, h(t.label), 5)) : S("", !0),
|
|
169
|
+
t.value ? (u(), p("span", Q, h(t.value), 1)) : (u(), p("span", W, "--"))
|
|
170
|
+
], 14, K);
|
|
170
171
|
}), 128))
|
|
171
172
|
])
|
|
172
173
|
])
|
package/dist/index.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(i,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("uplot"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","uplot","@vueuse/core"],e):(i=typeof globalThis<"u"?globalThis:i||self,e(i["change-name"]={},i.vue,i.Uplot,i.core))})(this,function(i,e,z,
|
|
1
|
+
(function(i,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("uplot"),require("@vueuse/core")):typeof define=="function"&&define.amd?define(["exports","vue","uplot","@vueuse/core"],e):(i=typeof globalThis<"u"?globalThis:i||self,e(i["change-name"]={},i.vue,i.Uplot,i.core))})(this,function(i,e,z,h){"use strict";const U="",w=c=>{if(typeof c=="object"&&c!==null){if(typeof Object.getPrototypeOf=="function"){const r=Object.getPrototypeOf(c);return r===Object.prototype||r===null}return Object.prototype.toString.call(c)==="[object Object]"}return!1},d=(...c)=>c.reduce((r,n)=>{if(Array.isArray(n))throw new TypeError("Arguments provided to ts-deepmerge must be objects, not arrays.");return n&&Object.keys(n).forEach(o=>{["__proto__","constructor","prototype"].includes(o)||(Array.isArray(r[o])&&Array.isArray(n[o])?r[o]=d.options.mergeArrays?Array.from(new Set(r[o].concat(n[o]))):n[o]:w(r[o])&&w(n[o])?r[o]=d(r[o],n[o]):r[o]=n[o])}),r},{}),b={mergeArrays:!0};d.options=b,d.withOptions=(c,...r)=>{d.options={mergeArrays:!0,...c};const n=d(...r);return d.options=b,n};const E={class:"__uplot-root"},O={key:0,class:"extra-info"},D=e.createElementVNode("br",null,null,-1),A={style:{"text-align":"left"}},V={class:"__uplot-legend"},j=["onClick"],C={key:1,class:"__uplot-legend-value"},T={key:2,class:"__uplot-legend-value"},N=e.defineComponent({__name:"Uplot",props:{options:null,data:null,noResetScale:{type:Boolean,default:!1},showDebug:{type:Boolean,default:!1},noFooter:{type:Boolean,default:!1},zoom:{default:()=>[null,null]},series:null},emits:["select","cursor","update:zoom","update:series"],setup(c,{expose:r,emit:n}){const o=c,_=e.ref(),{width:g,height:y}=h.useElementSize(_),S=h.useVModel(o,"zoom",n,{passive:!0}),p=h.useVModel(o,"series",n,{passive:!0}),P={title:void 0,legend:{show:!1},hooks:{init:[t=>{o.showDebug&&console.log("init",t),p.value=t.series.map((s,l)=>({label:s.label,stroke:typeof s.stroke=="function"?s.stroke(t,l):null,value:null,data:null,show:s.show}))}],setCursor:[t=>{n("cursor",t.cursor),p.value=t.series.map((s,l)=>{var f,u;return{label:s.label,stroke:typeof s.stroke=="function"?s.stroke(t,l):null,value:t.cursor.idx&&t.data[l][t.cursor.idx]?typeof s.value=="function"?s.value(t,t.data[l][t.cursor.idx],l,t.cursor.idx):t.data[l][t.cursor.idx]:null,data:(f=t.cursor)!=null&&f.idx?t.data[l][(u=t.cursor)==null?void 0:u.idx]:null,show:s.show}})}],setSelect:[t=>{n("select",t.select),o.showDebug&&console.log("setSelect",t.select),S.value=[t.posToVal(t.select.left,"x"),t.posToVal(t.select.left+t.select.width,"x")]}],setScale:[t=>{S.value=[t.scales.x.min||null,t.scales.x.max||null]}]}};let a;const k=e.ref();function B(){a&&a.destroy(),a=new z({width:100,height:100,...d(o.options,P)},o.data,_.value),k.value=a,o.zoom[0]!==null&&o.zoom[1]!==null&&a.setScale("x",{min:o.zoom[0],max:o.zoom[1]}),setTimeout(()=>{x()},0)}e.onMounted(()=>{B()}),e.watch([g,y],()=>{e.nextTick(()=>{x()})}),e.watch(o.data,t=>{if(o.noResetScale){a.setData(t);return}a.setData(t,!0),a.redraw()}),e.watch(o.options,(t,s)=>{o.showDebug&&console.log("watch options",t,s),B()});function x(){a.setSize({width:g.value,height:y.value}),o.showDebug&&console.log("resize",a)}function m(t){var s,l;typeof t=="object"&&(t=((s=p.value)==null?void 0:s.indexOf(t))||-1),a.setSeries(t,{show:!a.series[t].show}),(l=p.value)!=null&&l[t]&&(p.value[t].show=a.series[t].show)}return r({toggleShow:m,uplot:k}),(t,s)=>(e.openBlock(),e.createElementBlock("div",E,[e.renderSlot(t.$slots,"header",{series:e.unref(p),toggleShow:m}),e.createElementVNode("div",{ref_key:"el",ref:_,class:"__uplot"},null,512),c.showDebug?(e.openBlock(),e.createElementBlock("div",O,[e.createTextVNode(e.toDisplayString(e.unref(g))+" x "+e.toDisplayString(e.unref(y))+" ",1),D,e.createElementVNode("pre",A,e.toDisplayString(e.unref(p)),1)])):e.createCommentVNode("",!0),c.noFooter?e.createCommentVNode("",!0):e.renderSlot(t.$slots,"footer",{key:1,series:e.unref(p),toggleShow:m},()=>[e.createElementVNode("div",V,[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(e.unref(p),(l,f)=>{var u;return e.openBlock(),e.createElementBlock("div",{key:l.label,class:e.normalizeClass(["__uplot-legend-series",[`__uplot-${(u=l.label)==null?void 0:u.toLowerCase()}`,`__uplot-i-${f}`]]),style:e.normalizeStyle({backgroundColor:l.show?"":"lightgrey"}),onClick:M=>m(f)},[f!==0?(e.openBlock(),e.createElementBlock("span",{key:0,style:e.normalizeStyle({color:l.stroke||"black"}),class:"__uplot-legend-label"},e.toDisplayString(l.label),5)):e.createCommentVNode("",!0),l.value?(e.openBlock(),e.createElementBlock("span",C,e.toDisplayString(l.value),1)):(e.openBlock(),e.createElementBlock("span",T,"--"))],14,j)}),128))])])]))}}),$="";i.Uplot=N,Object.defineProperty(i,Symbol.toStringTag,{value:"Module"})});
|