@data-vision/interactive-chart 0.0.8
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 +144 -0
- package/build/bar.cjs +1 -0
- package/build/bar.d.ts +10 -0
- package/build/bar.js +44 -0
- package/build/base/chart.d.ts +137 -0
- package/build/base/color.d.ts +18 -0
- package/build/base/dragable.d.ts +29 -0
- package/build/base/field.d.ts +18 -0
- package/build/base/index.d.ts +5 -0
- package/build/base/point.d.ts +15 -0
- package/build/brush/brush.d.ts +49 -0
- package/build/brush/crop.d.ts +12 -0
- package/build/brush/index.d.ts +2 -0
- package/build/brush/range.d.ts +6 -0
- package/build/brush/thumb.d.ts +6 -0
- package/build/chart-Cj4Fiwnb.js +965 -0
- package/build/chart-Dr9ZOezr.cjs +1 -0
- package/build/dataset-Bv37sY1L.js +18 -0
- package/build/dataset-D4KLCpTU.cjs +1 -0
- package/build/heatmap-BlMqliH5.cjs +1 -0
- package/build/heatmap-Br4YjrBg.js +859 -0
- package/build/heatmap.cjs +1 -0
- package/build/heatmap.d.ts +91 -0
- package/build/heatmap.js +5 -0
- package/build/index.cjs +1 -0
- package/build/index.d.ts +7 -0
- package/build/index.js +20 -0
- package/build/legend/index.d.ts +1 -0
- package/build/legend/legend.d.ts +20 -0
- package/build/line.cjs +1 -0
- package/build/line.d.ts +11 -0
- package/build/line.js +23 -0
- package/build/otdr.cjs +1 -0
- package/build/otdr.d.ts +186 -0
- package/build/otdr.js +417 -0
- package/build/tooltip/crosshair.d.ts +20 -0
- package/build/tooltip/index.d.ts +2 -0
- package/build/tooltip/tooltip.d.ts +12 -0
- package/build/type.d.ts +78 -0
- package/build/util/dataset.d.ts +6 -0
- package/build/util/date.d.ts +1 -0
- package/build/util/env.d.ts +15 -0
- package/build/util/event.d.ts +6 -0
- package/build/util/index.d.ts +6 -0
- package/build/util/numeric.d.ts +26 -0
- package/build/util/style.d.ts +3 -0
- package/package.json +53 -0
|
@@ -0,0 +1,965 @@
|
|
|
1
|
+
class $ {
|
|
2
|
+
_value;
|
|
3
|
+
listeners = [];
|
|
4
|
+
constructor(t) {
|
|
5
|
+
this._value = t;
|
|
6
|
+
}
|
|
7
|
+
get value() {
|
|
8
|
+
return this._value;
|
|
9
|
+
}
|
|
10
|
+
set value(t) {
|
|
11
|
+
this._value = t;
|
|
12
|
+
}
|
|
13
|
+
addEventListener(t) {
|
|
14
|
+
this.listeners.push(t);
|
|
15
|
+
}
|
|
16
|
+
removeEventListener(t) {
|
|
17
|
+
this.listeners = this.listeners.filter(
|
|
18
|
+
(e) => e !== t
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
emitChangeEvent() {
|
|
22
|
+
for (const t of this.listeners)
|
|
23
|
+
t(this._value);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
class g {
|
|
27
|
+
x;
|
|
28
|
+
y;
|
|
29
|
+
constructor(t, e) {
|
|
30
|
+
this.x = t, this.y = e;
|
|
31
|
+
}
|
|
32
|
+
add(t) {
|
|
33
|
+
let { x: e, y: i } = this;
|
|
34
|
+
return typeof t == "number" ? (e += t, i += t) : (e += t.x, i += t.y), new g(e, i);
|
|
35
|
+
}
|
|
36
|
+
sub(t) {
|
|
37
|
+
let { x: e, y: i } = this;
|
|
38
|
+
return typeof t == "number" ? (e -= t, i -= t) : (e -= t.x, i -= t.y), new g(e, i);
|
|
39
|
+
}
|
|
40
|
+
multiply(t) {
|
|
41
|
+
let { x: e, y: i } = this;
|
|
42
|
+
return typeof t == "number" ? (e *= t, i *= t) : (e *= t.x, i *= t.y), new g(e, i);
|
|
43
|
+
}
|
|
44
|
+
divide(t) {
|
|
45
|
+
let { x: e, y: i } = this;
|
|
46
|
+
return typeof t == "number" ? (e /= t, i /= t) : (e /= t.x, i /= t.y), new g(e, i);
|
|
47
|
+
}
|
|
48
|
+
static origin() {
|
|
49
|
+
return new g(0, 0);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function T(o) {
|
|
53
|
+
let t = "";
|
|
54
|
+
for (const [e, i] of Object.entries(o))
|
|
55
|
+
t += `${e.replace(/[A-Z]/g, (s) => "-" + s.toLowerCase())}: ${i};`;
|
|
56
|
+
return t;
|
|
57
|
+
}
|
|
58
|
+
function y(o, t) {
|
|
59
|
+
for (const e in t) {
|
|
60
|
+
const i = t[e];
|
|
61
|
+
o.style.setProperty(e, `${i}`);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function k(o, t) {
|
|
65
|
+
const e = g.origin();
|
|
66
|
+
if (t) {
|
|
67
|
+
const s = t.getBoundingClientRect();
|
|
68
|
+
e.x = s.x, e.y = s.y;
|
|
69
|
+
}
|
|
70
|
+
let i;
|
|
71
|
+
if ("touches" in o) {
|
|
72
|
+
const s = o, [n] = s.touches;
|
|
73
|
+
i = new g(n.clientX, n.clientY);
|
|
74
|
+
} else
|
|
75
|
+
i = new g(o.clientX, o.clientY);
|
|
76
|
+
return i.sub(e);
|
|
77
|
+
}
|
|
78
|
+
function A(o, t) {
|
|
79
|
+
let e = null;
|
|
80
|
+
function i() {
|
|
81
|
+
e && (clearTimeout(e), e = null);
|
|
82
|
+
}
|
|
83
|
+
function s(...n) {
|
|
84
|
+
i(), e = setTimeout(() => {
|
|
85
|
+
o.apply(this, n);
|
|
86
|
+
}, t);
|
|
87
|
+
}
|
|
88
|
+
return s.cancel = i, s;
|
|
89
|
+
}
|
|
90
|
+
const G = (o) => [...o].reduce((t, e) => Math.min(t, e), 1 / 0), B = (o) => [...o].reduce((t, e) => Math.max(t, e), -1 / 0), D = ([o, t]) => o < t ? [o, t] : [t, o];
|
|
91
|
+
function V(o, t = 1) {
|
|
92
|
+
const [e, i] = o;
|
|
93
|
+
return D([t - e, t - i]);
|
|
94
|
+
}
|
|
95
|
+
function q([o, t], [e, i], [s, n] = [0, 1]) {
|
|
96
|
+
let a = o + e, r = t + i;
|
|
97
|
+
return a < s && (a = s, r = a + t - o), r > n && (r = n, a = r - t + o), [a, r];
|
|
98
|
+
}
|
|
99
|
+
function z(o, [t, e]) {
|
|
100
|
+
return o >= t && o <= e;
|
|
101
|
+
}
|
|
102
|
+
function Y({ x: o, y: t }, { left: e, top: i, right: s, bottom: n }) {
|
|
103
|
+
return z(o, [e, s]) && z(t, [i, n]);
|
|
104
|
+
}
|
|
105
|
+
function E(o, [t, e]) {
|
|
106
|
+
return Math.max(t, Math.min(o, e));
|
|
107
|
+
}
|
|
108
|
+
function W(o, t, e) {
|
|
109
|
+
const i = E(o.left, t), s = E(o.right, t), n = E(o.top, e), a = E(o.bottom, e);
|
|
110
|
+
return {
|
|
111
|
+
left: i,
|
|
112
|
+
top: n,
|
|
113
|
+
right: s,
|
|
114
|
+
bottom: a
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
function j({ left: o, top: t, right: e, bottom: i }, s) {
|
|
118
|
+
return {
|
|
119
|
+
left: o * s,
|
|
120
|
+
top: t * s,
|
|
121
|
+
right: e * s,
|
|
122
|
+
bottom: i * s
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
function P(o) {
|
|
126
|
+
return +o.toExponential().match(/-?\d+$/)[0];
|
|
127
|
+
}
|
|
128
|
+
function X(o) {
|
|
129
|
+
const t = String(o).match(/\.\d+$/);
|
|
130
|
+
return t ? 1 - t[0].length : P(o);
|
|
131
|
+
}
|
|
132
|
+
function I(o, t, [e, i]) {
|
|
133
|
+
let s = Math.floor(e / t) * t;
|
|
134
|
+
const n = Math.abs(t);
|
|
135
|
+
for (; s < e; )
|
|
136
|
+
s += n;
|
|
137
|
+
const a = [e], r = Math.abs(t / 6);
|
|
138
|
+
for (let c = 0; c < Math.ceil(o); c++) {
|
|
139
|
+
const h = s + n * c;
|
|
140
|
+
(h > e + r && h < i - r || e < 0 && h === 0) && a.push(h);
|
|
141
|
+
}
|
|
142
|
+
return a.push(i), a;
|
|
143
|
+
}
|
|
144
|
+
function O(o, [t, e]) {
|
|
145
|
+
const [i, s] = o, n = s - i, a = P(n);
|
|
146
|
+
let r = Math.pow(10, a);
|
|
147
|
+
s <= 0 && (r = -r);
|
|
148
|
+
let c = Math.abs(n / r);
|
|
149
|
+
if (c < t || c > e) {
|
|
150
|
+
const p = [2, 4, 5, 8, 10];
|
|
151
|
+
for (const d of p) {
|
|
152
|
+
const u = c < t ? r / d : r * d, f = Math.abs(n / u);
|
|
153
|
+
if (z(f, [t, e])) {
|
|
154
|
+
r = u, c = f;
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const h = I(c, r, o), x = X(r);
|
|
160
|
+
return {
|
|
161
|
+
rules: h,
|
|
162
|
+
density: x
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
class H {
|
|
166
|
+
_value;
|
|
167
|
+
mediaQuery;
|
|
168
|
+
listener;
|
|
169
|
+
constructor(t) {
|
|
170
|
+
this.listener = t, this.onMediaChange = this.onMediaChange.bind(this), this.createMediaMatch();
|
|
171
|
+
}
|
|
172
|
+
createMediaMatch() {
|
|
173
|
+
this._value = window.devicePixelRatio, this.mediaQuery = window.matchMedia(`(resolution: ${this.value}dppx)`), this.mediaQuery.addEventListener("change", this.onMediaChange);
|
|
174
|
+
}
|
|
175
|
+
get value() {
|
|
176
|
+
return this._value;
|
|
177
|
+
}
|
|
178
|
+
onMediaChange() {
|
|
179
|
+
this.dispose(), this.createMediaMatch(), this.listener(this._value);
|
|
180
|
+
}
|
|
181
|
+
dispose() {
|
|
182
|
+
this.mediaQuery.removeEventListener("change", this.onMediaChange);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
function U(o, t) {
|
|
186
|
+
const { width: e, hangingBaseline: i } = o.measureText(t);
|
|
187
|
+
return {
|
|
188
|
+
width: e,
|
|
189
|
+
height: i ?? 0
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
class R extends $ {
|
|
193
|
+
element;
|
|
194
|
+
dragging = !1;
|
|
195
|
+
origin = g.origin();
|
|
196
|
+
constructor(t, e) {
|
|
197
|
+
super(e), this.onPointerDown = this.onPointerDown.bind(this), this.onPointerMove = this.onPointerMove.bind(this), this.onPointerUp = this.onPointerUp.bind(this), t.addEventListener("mousedown", this.onPointerDown), t.addEventListener("touchstart", this.onPointerDown), window.addEventListener("mousemove", this.onPointerMove), window.addEventListener("touchmove", this.onPointerMove), window.addEventListener("mouseup", this.onPointerUp), window.addEventListener("touchend", this.onPointerUp), this.element = t;
|
|
198
|
+
}
|
|
199
|
+
set value(t) {
|
|
200
|
+
super.value = t, this.resize();
|
|
201
|
+
}
|
|
202
|
+
onPointerDown(t) {
|
|
203
|
+
this.dragging = !0, this.origin = k(t), this.onStart(t);
|
|
204
|
+
}
|
|
205
|
+
getStyle(t) {
|
|
206
|
+
return "";
|
|
207
|
+
}
|
|
208
|
+
onUpdate({ value: t }) {
|
|
209
|
+
return t;
|
|
210
|
+
}
|
|
211
|
+
isEqual(t, e) {
|
|
212
|
+
return String(t) === String(e);
|
|
213
|
+
}
|
|
214
|
+
onStart(t) {
|
|
215
|
+
}
|
|
216
|
+
onEnd(t) {
|
|
217
|
+
}
|
|
218
|
+
resize() {
|
|
219
|
+
const { _value: t, dragging: e } = this, i = this.getStyle({
|
|
220
|
+
value: t,
|
|
221
|
+
dragging: e
|
|
222
|
+
});
|
|
223
|
+
i !== "" && this.element.setAttribute("style", i);
|
|
224
|
+
}
|
|
225
|
+
onPointerMove(t) {
|
|
226
|
+
if (this.dragging) {
|
|
227
|
+
const e = k(t), i = this.onUpdate({
|
|
228
|
+
value: this._value,
|
|
229
|
+
offset: e,
|
|
230
|
+
delta: e.sub(this.origin),
|
|
231
|
+
event: t
|
|
232
|
+
});
|
|
233
|
+
this.isEqual(i, this._value) || (this._value = i, this.emitChangeEvent(), this.resize()), this.origin = e;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
onPointerUp(t) {
|
|
237
|
+
this.dragging = !1, this.onEnd(t);
|
|
238
|
+
}
|
|
239
|
+
dispose() {
|
|
240
|
+
this.element.removeEventListener("pointerdown", this.onPointerDown), this.element.removeEventListener("touchstart", this.onPointerDown), window.removeEventListener("pointermove", this.onPointerMove), window.removeEventListener("touchmove", this.onPointerMove), window.removeEventListener("pointerup", this.onPointerUp), window.removeEventListener("touchend", this.onPointerUp);
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
class K extends R {
|
|
244
|
+
root;
|
|
245
|
+
container;
|
|
246
|
+
option;
|
|
247
|
+
constructor(t, e) {
|
|
248
|
+
const i = document.createElement("div");
|
|
249
|
+
super(i, e.initValue), this.root = t, this.option = e, this.getStyle = e.getStyle, this.container = i, this.root.appendChild(i), this.resize();
|
|
250
|
+
}
|
|
251
|
+
onStart(t) {
|
|
252
|
+
this.option.onStart?.(t);
|
|
253
|
+
}
|
|
254
|
+
onUpdate(t) {
|
|
255
|
+
return this.option.onUpdate(t);
|
|
256
|
+
}
|
|
257
|
+
onEnd(t) {
|
|
258
|
+
this.option.onEnd?.(t);
|
|
259
|
+
}
|
|
260
|
+
dispose() {
|
|
261
|
+
super.dispose(), this.root.removeChild(this.container);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
class F {
|
|
265
|
+
root;
|
|
266
|
+
container;
|
|
267
|
+
style = {
|
|
268
|
+
position: "absolute",
|
|
269
|
+
display: "none",
|
|
270
|
+
userSelect: "none"
|
|
271
|
+
};
|
|
272
|
+
inheritStyle;
|
|
273
|
+
constructor(t, e) {
|
|
274
|
+
this.root = t, this.inheritStyle = e, this.container = document.createElement("div"), this.root.appendChild(this.container), this.setContainer();
|
|
275
|
+
}
|
|
276
|
+
setContainer(t) {
|
|
277
|
+
this.container.setAttribute(
|
|
278
|
+
"style",
|
|
279
|
+
T({
|
|
280
|
+
...this.style,
|
|
281
|
+
...this.inheritStyle,
|
|
282
|
+
...t
|
|
283
|
+
})
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
update({ top: t, right: e, bottom: i, left: s }) {
|
|
287
|
+
this.setContainer({
|
|
288
|
+
display: "block",
|
|
289
|
+
inset: `${t}px ${e}px ${i}px ${s}px`
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
hide() {
|
|
293
|
+
this.setContainer({
|
|
294
|
+
display: "none"
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
dispose() {
|
|
298
|
+
this.root.removeChild(this.container);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
class Z {
|
|
302
|
+
root;
|
|
303
|
+
xTooltip;
|
|
304
|
+
yTooltip;
|
|
305
|
+
constructor(t, e) {
|
|
306
|
+
this.root = t, this.xTooltip = this.createTooltip(e), this.root.appendChild(this.xTooltip), this.yTooltip = this.createTooltip(e), this.root.appendChild(this.yTooltip);
|
|
307
|
+
}
|
|
308
|
+
createTooltip(t) {
|
|
309
|
+
const e = document.createElement("div");
|
|
310
|
+
return e.setAttribute("style", T({
|
|
311
|
+
position: "absolute",
|
|
312
|
+
fontSize: "calc(var(--scale) * 12px)",
|
|
313
|
+
userSelect: "none",
|
|
314
|
+
padding: "calc(var(--scale) * 5px) calc(var(--scale) * 6px)",
|
|
315
|
+
borderRadius: "4px",
|
|
316
|
+
...t,
|
|
317
|
+
display: "none"
|
|
318
|
+
})), e;
|
|
319
|
+
}
|
|
320
|
+
updateTooltip(t, e, i) {
|
|
321
|
+
y(t, {
|
|
322
|
+
display: "block",
|
|
323
|
+
...i
|
|
324
|
+
}), t.innerText = e;
|
|
325
|
+
}
|
|
326
|
+
update(t, e) {
|
|
327
|
+
t ? this.updateTooltip(this.xTooltip, t.content, {
|
|
328
|
+
left: `${t.offset.x}px`,
|
|
329
|
+
top: `${t.offset.y}px`,
|
|
330
|
+
transform: "translateX(-50%)"
|
|
331
|
+
}) : y(this.xTooltip, {
|
|
332
|
+
display: "none"
|
|
333
|
+
}), e ? this.updateTooltip(this.yTooltip, e.content, {
|
|
334
|
+
left: `${e.offset.x}px`,
|
|
335
|
+
top: `${e.offset.y}px`,
|
|
336
|
+
transform: "translate(-100%, -50%)"
|
|
337
|
+
}) : y(this.yTooltip, {
|
|
338
|
+
display: "none"
|
|
339
|
+
});
|
|
340
|
+
}
|
|
341
|
+
hide() {
|
|
342
|
+
y(this.xTooltip, {
|
|
343
|
+
display: "none"
|
|
344
|
+
}), y(this.yTooltip, {
|
|
345
|
+
display: "none"
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
dispose() {
|
|
349
|
+
this.root.removeChild(this.xTooltip), this.root.removeChild(this.yTooltip);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
class Q {
|
|
353
|
+
root;
|
|
354
|
+
container;
|
|
355
|
+
axisX;
|
|
356
|
+
axisY;
|
|
357
|
+
option;
|
|
358
|
+
constructor(t, e) {
|
|
359
|
+
this.root = t, this.option = e, this.container = this.createContainer(), this.setEdge(e.edge), this.axisX = this.createAxis(), this.axisY = this.createAxis();
|
|
360
|
+
}
|
|
361
|
+
createContainer() {
|
|
362
|
+
const t = document.createElement("div");
|
|
363
|
+
return y(t, {
|
|
364
|
+
inset: "0",
|
|
365
|
+
userSelect: "none",
|
|
366
|
+
display: "none"
|
|
367
|
+
}), this.root.appendChild(t), t;
|
|
368
|
+
}
|
|
369
|
+
createAxis() {
|
|
370
|
+
const { style: t } = this.option, e = document.createElement("div");
|
|
371
|
+
return y(e, {
|
|
372
|
+
position: "absolute",
|
|
373
|
+
...t
|
|
374
|
+
}), this.container.appendChild(e), e;
|
|
375
|
+
}
|
|
376
|
+
setEdge(t) {
|
|
377
|
+
y(this.container, {
|
|
378
|
+
"--edge-top": `calc(${t.top}px * var(--scale))`,
|
|
379
|
+
"--edge-bottom": `calc(${t.bottom}px * var(--scale))`,
|
|
380
|
+
"--edge-left": `calc(${t.left}px * var(--scale))`,
|
|
381
|
+
"--edge-right": `calc(${t.right}px * var(--scale))`
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
update({ x: t, y: e }) {
|
|
385
|
+
y(this.axisX, {
|
|
386
|
+
width: "1px",
|
|
387
|
+
left: `${t}px`,
|
|
388
|
+
top: "var(--edge-top)",
|
|
389
|
+
bottom: "var(--edge-bottom)"
|
|
390
|
+
}), y(this.axisY, {
|
|
391
|
+
"--gradient-angle": "45deg",
|
|
392
|
+
height: "1px",
|
|
393
|
+
top: `${e}px`,
|
|
394
|
+
left: "var(--edge-left)",
|
|
395
|
+
right: "var(--edge-right)"
|
|
396
|
+
}), y(this.container, {
|
|
397
|
+
display: "block"
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
hide() {
|
|
401
|
+
y(this.container, {
|
|
402
|
+
display: "none"
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
dispose() {
|
|
406
|
+
this.root.removeChild(this.container);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
var M = /* @__PURE__ */ ((o) => (o[o.none = -1] = "none", o[o.crop = 0] = "crop", o[o.zoom = 1] = "zoom", o[o.move = 2] = "move", o))(M || {});
|
|
410
|
+
class l extends R {
|
|
411
|
+
root;
|
|
412
|
+
resizeObserver;
|
|
413
|
+
dpr;
|
|
414
|
+
canvasContainer;
|
|
415
|
+
canvas;
|
|
416
|
+
static version = "0.1.6";
|
|
417
|
+
static config = {
|
|
418
|
+
xMin: 0,
|
|
419
|
+
xMax: 1e4,
|
|
420
|
+
yMin: 0,
|
|
421
|
+
yMax: 1e3,
|
|
422
|
+
grid: {
|
|
423
|
+
left: 65,
|
|
424
|
+
top: 10,
|
|
425
|
+
right: 30,
|
|
426
|
+
bottom: 35
|
|
427
|
+
},
|
|
428
|
+
controlType: M.crop,
|
|
429
|
+
xUnit: "",
|
|
430
|
+
yUnit: "",
|
|
431
|
+
xMinScale: 3,
|
|
432
|
+
xMaxScale: 8,
|
|
433
|
+
yMinScale: 3,
|
|
434
|
+
yMaxScale: 8,
|
|
435
|
+
responsiveScale: !0,
|
|
436
|
+
backgroundColor: "#fff",
|
|
437
|
+
gridColor: "#ccc",
|
|
438
|
+
textColor: "#222",
|
|
439
|
+
accentColor: "#36f",
|
|
440
|
+
fontSize: 12,
|
|
441
|
+
cropStyle: {
|
|
442
|
+
backgroundColor: "#36f4"
|
|
443
|
+
},
|
|
444
|
+
tooltip: {
|
|
445
|
+
enabled: !0,
|
|
446
|
+
style: {}
|
|
447
|
+
},
|
|
448
|
+
crosshair: {
|
|
449
|
+
enabled: !0,
|
|
450
|
+
style: {
|
|
451
|
+
"--gradient-angle": "0",
|
|
452
|
+
background: "repeating-linear-gradient(var(--gradient-angle), transparent 0 2px, var(--accent-color) 2px 5px)"
|
|
453
|
+
}
|
|
454
|
+
},
|
|
455
|
+
axisXScaleOffset: {
|
|
456
|
+
x: 0,
|
|
457
|
+
y: 15
|
|
458
|
+
},
|
|
459
|
+
axisYScaleOffset: {
|
|
460
|
+
x: 5,
|
|
461
|
+
y: 0
|
|
462
|
+
},
|
|
463
|
+
xLimit: [-1 / 0, 1 / 0],
|
|
464
|
+
yLimit: [-1 / 0, 1 / 0],
|
|
465
|
+
wheelZoom: !0,
|
|
466
|
+
dataSampleMethod: "none"
|
|
467
|
+
};
|
|
468
|
+
width = 0;
|
|
469
|
+
height = 0;
|
|
470
|
+
context;
|
|
471
|
+
xMin = l.config.xMin;
|
|
472
|
+
xMax = l.config.xMax;
|
|
473
|
+
yMin = l.config.yMin;
|
|
474
|
+
yMax = l.config.yMax;
|
|
475
|
+
data = null;
|
|
476
|
+
tooltip = null;
|
|
477
|
+
crosshair = null;
|
|
478
|
+
crop;
|
|
479
|
+
controlType = l.config.controlType;
|
|
480
|
+
prevControlType = l.config.controlType;
|
|
481
|
+
wheelZoom = l.config.wheelZoom;
|
|
482
|
+
cropOrigin = g.origin();
|
|
483
|
+
cropOffset = g.origin();
|
|
484
|
+
inCrop = !1;
|
|
485
|
+
grid = { ...l.config.grid };
|
|
486
|
+
xMinScale = l.config.xMinScale;
|
|
487
|
+
xMaxScale = l.config.xMaxScale;
|
|
488
|
+
yMinScale = l.config.yMinScale;
|
|
489
|
+
yMaxScale = l.config.yMaxScale;
|
|
490
|
+
xUnit = l.config.xUnit;
|
|
491
|
+
yUnit = l.config.yUnit;
|
|
492
|
+
raf;
|
|
493
|
+
shouldUpdate = !1;
|
|
494
|
+
snapshot = null;
|
|
495
|
+
useSnapshot = !1;
|
|
496
|
+
constructor(t) {
|
|
497
|
+
const e = document.createElement("div");
|
|
498
|
+
super(e, 0), this.root = t, this.resizeObserver = new ResizeObserver(
|
|
499
|
+
A(this.onResize, 200)
|
|
500
|
+
), this.resizeObserver.observe(t), this.onDprChange = this.onDprChange.bind(this), this.dpr = new H(this.onDprChange), this.canvas = document.createElement("canvas"), this.context = this.canvas.getContext("2d"), this.context.scale(this.dpr.value, this.dpr.value);
|
|
501
|
+
const i = this.initCanvas(e, this.canvas);
|
|
502
|
+
this.onMouseMove = this.onMouseMove.bind(this), i.addEventListener("mousemove", this.onMouseMove), this.onMouseLeave = this.onMouseLeave.bind(this), i.addEventListener("mouseleave", this.onMouseLeave), this.onWheel = this.onWheel.bind(this), i.addEventListener("wheel", this.onWheel), this.onDblClick = this.onDblClick.bind(this), i.addEventListener("dblclick", this.onDblClick), this.setRoot(this.root), this.root.appendChild(i), this.canvasContainer = i;
|
|
503
|
+
const { tooltip: s, crosshair: n, cropStyle: a, dataSampleMethod: r } = l.config;
|
|
504
|
+
if (s.enabled && (this.tooltip = new Z(i, {
|
|
505
|
+
backgroundColor: "var(--accent-color)",
|
|
506
|
+
fontSize: `${l.config.fontSize}px`,
|
|
507
|
+
...s.style
|
|
508
|
+
})), n.enabled) {
|
|
509
|
+
const c = { ...this.scaleGrid };
|
|
510
|
+
this.crosshair = new Q(i, {
|
|
511
|
+
edge: c,
|
|
512
|
+
style: n.style
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
this.crop = new F(i, {
|
|
516
|
+
border: "1px solid var(--accent-color)",
|
|
517
|
+
...a
|
|
518
|
+
}), r === "lttb" && console.warn("lttb sample not implemented."), this.updateDraw();
|
|
519
|
+
}
|
|
520
|
+
get $root() {
|
|
521
|
+
return this.root;
|
|
522
|
+
}
|
|
523
|
+
get $canvas() {
|
|
524
|
+
return this.canvas;
|
|
525
|
+
}
|
|
526
|
+
setData(t) {
|
|
527
|
+
this.data = t, this.shouldUpdate = !0;
|
|
528
|
+
}
|
|
529
|
+
setControlType(t) {
|
|
530
|
+
this.controlType = t, this.setCursor();
|
|
531
|
+
}
|
|
532
|
+
draw(t) {
|
|
533
|
+
throw new Error("Chart.prototype.draw not implemented");
|
|
534
|
+
}
|
|
535
|
+
drawSnapshot(t) {
|
|
536
|
+
throw new Error("Chart.prototype.drawSnapshot not implemented");
|
|
537
|
+
}
|
|
538
|
+
drawAnnotations(t) {
|
|
539
|
+
}
|
|
540
|
+
sample(t, e) {
|
|
541
|
+
let i = 0;
|
|
542
|
+
const s = [...t];
|
|
543
|
+
switch (e) {
|
|
544
|
+
case "none":
|
|
545
|
+
case "lttb":
|
|
546
|
+
default:
|
|
547
|
+
i = s[Math.floor(s.length / 2)];
|
|
548
|
+
break;
|
|
549
|
+
case "max":
|
|
550
|
+
i = B(t);
|
|
551
|
+
break;
|
|
552
|
+
case "min":
|
|
553
|
+
i = G(t);
|
|
554
|
+
break;
|
|
555
|
+
case "avg":
|
|
556
|
+
i = s.reduce(
|
|
557
|
+
(n, a) => n + a,
|
|
558
|
+
0
|
|
559
|
+
) / s.length;
|
|
560
|
+
break;
|
|
561
|
+
}
|
|
562
|
+
return i;
|
|
563
|
+
}
|
|
564
|
+
updateDraw() {
|
|
565
|
+
this.raf = requestAnimationFrame(this.updateDraw.bind(this));
|
|
566
|
+
const {
|
|
567
|
+
context: t,
|
|
568
|
+
dpr: e,
|
|
569
|
+
width: i,
|
|
570
|
+
height: s,
|
|
571
|
+
drawWidth: n,
|
|
572
|
+
drawHeight: a,
|
|
573
|
+
scaleGrid: r,
|
|
574
|
+
rect: c,
|
|
575
|
+
xMin: h,
|
|
576
|
+
xMax: x,
|
|
577
|
+
yMin: p,
|
|
578
|
+
yMax: d,
|
|
579
|
+
xMinScale: u,
|
|
580
|
+
xMaxScale: f,
|
|
581
|
+
yMinScale: m,
|
|
582
|
+
yMaxScale: v,
|
|
583
|
+
snapshot: w,
|
|
584
|
+
useSnapshot: b
|
|
585
|
+
} = this;
|
|
586
|
+
if (i > 0 && s > 0 && this.shouldUpdate) {
|
|
587
|
+
t.clearRect(r.left, r.top, n, a);
|
|
588
|
+
const S = O([h, x], [u, f]);
|
|
589
|
+
this.drawVerticalGrid(S);
|
|
590
|
+
const C = O([p, d], [m, v]);
|
|
591
|
+
this.drawHorizontalGrid(C), t.textRendering = "optimizeLegibility", t.textBaseline = "middle", t.font = `${l.config.fontSize * e.value}px sans-serif`, b && w !== null ? (t.putImageData(w, 0, 0), this.drawSnapshot(t), this.useSnapshot = !1) : (this.draw(t), this.drawSnapshot(t)), t.clearRect(0, 0, i, r.top), t.clearRect(0, 0, r.left, s), t.clearRect(0, c.y, i, r.bottom), t.clearRect(c.x, 0, r.right, s), this.drawAxisX(S), this.drawAxisY(C), this.drawAnnotations(t), this.shouldUpdate = !1;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
drawVerticalGrid({ rules: t }) {
|
|
595
|
+
const { context: e, scaleGrid: i, rect: s, scale: n, xMin: a } = this;
|
|
596
|
+
e.save(), e.strokeStyle = l.config.gridColor;
|
|
597
|
+
for (let r = 0, c = t.length; r < c; r++) {
|
|
598
|
+
e.beginPath();
|
|
599
|
+
const h = i.left + (t[r] - a) / n.x;
|
|
600
|
+
e.moveTo(h, i.top), e.lineTo(h, s.y), r > 0 && e.setLineDash([2, 2]), e.stroke();
|
|
601
|
+
}
|
|
602
|
+
e.restore();
|
|
603
|
+
}
|
|
604
|
+
drawAxisX({ rules: t, density: e }) {
|
|
605
|
+
for (let i = 0, s = t.length; i < s; i++)
|
|
606
|
+
this.drawScaleX(t[i], e, [0, s - 1].includes(i));
|
|
607
|
+
}
|
|
608
|
+
drawScaleX(t, e, i = !1) {
|
|
609
|
+
const { context: s, scaleGrid: n, rect: a, xMin: r, scale: c, dpr: h, xUnit: x } = this, p = l.config.axisXScaleOffset, d = n.left + (t - r) / c.x;
|
|
610
|
+
let u = a.y + p.y;
|
|
611
|
+
s.lineWidth = h.value, s.strokeStyle = l.config.gridColor, s.beginPath(), s.moveTo(d, a.y), s.lineTo(d, u - p.y * 0.6), s.stroke();
|
|
612
|
+
const f = this.getScaleText(t, e, x), { width: m, height: v } = U(s, f);
|
|
613
|
+
i ? (s.fillStyle = l.config.accentColor, u += v * 1.5) : (s.fillStyle = l.config.textColor, u += v / 4), s.fillText(f, d - m / 2, u);
|
|
614
|
+
}
|
|
615
|
+
drawHorizontalGrid({ rules: t }) {
|
|
616
|
+
const { context: e, scaleGrid: i, rect: s, scale: n, yMin: a } = this;
|
|
617
|
+
e.save(), e.strokeStyle = l.config.gridColor;
|
|
618
|
+
for (let r = 0, c = t.length; r < c; r++) {
|
|
619
|
+
e.beginPath();
|
|
620
|
+
const h = s.y - (t[r] - a) / n.y;
|
|
621
|
+
e.moveTo(i.left, h), e.lineTo(s.x, h), r > 0 && e.setLineDash([2, 2]), e.stroke();
|
|
622
|
+
}
|
|
623
|
+
e.restore();
|
|
624
|
+
}
|
|
625
|
+
drawAxisY({ rules: t, density: e }) {
|
|
626
|
+
for (let i of t)
|
|
627
|
+
this.drawScaleY(i, e);
|
|
628
|
+
}
|
|
629
|
+
drawScaleY(t, e) {
|
|
630
|
+
const { context: i, scaleGrid: s, yMin: n, rect: a, scale: r, yUnit: c } = this, h = l.config.axisYScaleOffset, x = s.left, p = a.y - (t - n) / r.y;
|
|
631
|
+
i.strokeStyle = l.config.gridColor, i.fillStyle = l.config.textColor, i.beginPath(), i.moveTo(x - h.x, p), i.lineTo(x, p), i.stroke();
|
|
632
|
+
const d = this.getScaleText(t, e, c), { width: u, height: f } = U(i, d);
|
|
633
|
+
i.fillText(d, x - u - h.x * 2, p + f / 2);
|
|
634
|
+
}
|
|
635
|
+
getScaleText(t, e, i) {
|
|
636
|
+
return t.toFixed(e < 0 ? -e : 0) + i;
|
|
637
|
+
}
|
|
638
|
+
setRoot(t) {
|
|
639
|
+
y(t, {
|
|
640
|
+
position: "relative",
|
|
641
|
+
userSelect: "none",
|
|
642
|
+
"--accent-color": l.config.accentColor
|
|
643
|
+
});
|
|
644
|
+
}
|
|
645
|
+
get cursor() {
|
|
646
|
+
switch (this.controlType) {
|
|
647
|
+
case M.crop:
|
|
648
|
+
return "crosshair";
|
|
649
|
+
case M.move:
|
|
650
|
+
return "move";
|
|
651
|
+
case M.zoom:
|
|
652
|
+
return "zoom-in";
|
|
653
|
+
default:
|
|
654
|
+
return "default";
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
setCursor(t) {
|
|
658
|
+
y(this.canvasContainer, {
|
|
659
|
+
cursor: t ?? this.cursor
|
|
660
|
+
});
|
|
661
|
+
}
|
|
662
|
+
initCanvas(t, e) {
|
|
663
|
+
const { cursor: i, dpr: s } = this;
|
|
664
|
+
return t.setAttribute(
|
|
665
|
+
"style",
|
|
666
|
+
T({
|
|
667
|
+
position: "relative",
|
|
668
|
+
height: "100%",
|
|
669
|
+
overflow: "hidden",
|
|
670
|
+
cursor: i,
|
|
671
|
+
"--scale": 1 / s.value
|
|
672
|
+
})
|
|
673
|
+
), e.setAttribute(
|
|
674
|
+
"style",
|
|
675
|
+
T({
|
|
676
|
+
display: "block",
|
|
677
|
+
width: "100%",
|
|
678
|
+
height: "100%"
|
|
679
|
+
})
|
|
680
|
+
), t.appendChild(e), t;
|
|
681
|
+
}
|
|
682
|
+
get scaleGrid() {
|
|
683
|
+
const { left: t, top: e, right: i, bottom: s } = l.config.grid, { value: n } = this.dpr;
|
|
684
|
+
return {
|
|
685
|
+
left: t * n,
|
|
686
|
+
top: e * n,
|
|
687
|
+
right: i * n,
|
|
688
|
+
bottom: s * n
|
|
689
|
+
};
|
|
690
|
+
}
|
|
691
|
+
get bounds() {
|
|
692
|
+
const { xMin: t, xMax: e, yMin: i, yMax: s } = this;
|
|
693
|
+
return {
|
|
694
|
+
x: [t, e],
|
|
695
|
+
y: [i, s]
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
get rectBounds() {
|
|
699
|
+
const { grid: t, rect: e, dpr: i } = this, { left: s, top: n } = t, { x: a, y: r } = e.divide(i.value);
|
|
700
|
+
return {
|
|
701
|
+
left: s,
|
|
702
|
+
top: n,
|
|
703
|
+
right: a,
|
|
704
|
+
bottom: r
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
get rect() {
|
|
708
|
+
const { width: t, height: e, scaleGrid: i } = this;
|
|
709
|
+
return new g(t - i.right, e - i.bottom);
|
|
710
|
+
}
|
|
711
|
+
get drawWidth() {
|
|
712
|
+
const { rect: t, scaleGrid: e } = this;
|
|
713
|
+
return t.x - e.left;
|
|
714
|
+
}
|
|
715
|
+
get drawHeight() {
|
|
716
|
+
const { rect: t, scaleGrid: e } = this;
|
|
717
|
+
return t.y - e.top;
|
|
718
|
+
}
|
|
719
|
+
updateCanvas() {
|
|
720
|
+
const t = this.dpr.value;
|
|
721
|
+
if (this.width = Math.floor(this.root.clientWidth * t), this.height = Math.floor(this.root.clientHeight * t), this.canvas.width = this.width, this.canvas.height = this.height, l.config.responsiveScale) {
|
|
722
|
+
const { width: e } = U(this.context, "0000000" + this.xUnit);
|
|
723
|
+
this.xMinScale = Math.max(3, Math.floor(this.drawWidth / e / 8)), this.xMaxScale = this.xMinScale * 3, this.yMinScale = Math.max(3, Math.floor(this.drawHeight / 40 / 8)), this.yMaxScale = this.yMinScale * 3;
|
|
724
|
+
}
|
|
725
|
+
this.shouldUpdate = !0;
|
|
726
|
+
}
|
|
727
|
+
onDprChange(t) {
|
|
728
|
+
y(
|
|
729
|
+
this.canvasContainer,
|
|
730
|
+
{
|
|
731
|
+
"--scale": 1 / t
|
|
732
|
+
}
|
|
733
|
+
), this.updateCanvas(), this.context.scale(t, t), this.crosshair?.setEdge(this.scaleGrid);
|
|
734
|
+
}
|
|
735
|
+
setUnit(t, e) {
|
|
736
|
+
this.xUnit = t ?? this.xUnit, this.yUnit = e ?? this.yUnit, this.shouldUpdate = !0;
|
|
737
|
+
}
|
|
738
|
+
getOffset(t) {
|
|
739
|
+
return k(t, this.canvasContainer);
|
|
740
|
+
}
|
|
741
|
+
onMouseMove(t) {
|
|
742
|
+
const {
|
|
743
|
+
dpr: e,
|
|
744
|
+
rectBounds: i,
|
|
745
|
+
xMin: s,
|
|
746
|
+
yMin: n,
|
|
747
|
+
scale: a,
|
|
748
|
+
dragging: r,
|
|
749
|
+
tooltip: c,
|
|
750
|
+
crosshair: h,
|
|
751
|
+
xUnit: x,
|
|
752
|
+
yUnit: p
|
|
753
|
+
} = this, d = this.getOffset(t), { left: u, bottom: f } = i, m = e.value;
|
|
754
|
+
if (Y(d, i) && !r) {
|
|
755
|
+
const v = s + (d.x - u) * m * a.x, w = n + (f - d.y) * m * a.y, { xLabel: b, yLabel: S } = l.config.tooltip;
|
|
756
|
+
c?.update({
|
|
757
|
+
offset: {
|
|
758
|
+
x: d.x,
|
|
759
|
+
y: f
|
|
760
|
+
},
|
|
761
|
+
content: b ? b(v, x) : v.toFixed(1) + x
|
|
762
|
+
}, {
|
|
763
|
+
offset: {
|
|
764
|
+
x: u,
|
|
765
|
+
y: d.y
|
|
766
|
+
},
|
|
767
|
+
content: S ? S(w, p) : w.toFixed(1) + p
|
|
768
|
+
}), h?.update(d);
|
|
769
|
+
} else
|
|
770
|
+
h?.hide(), c?.hide();
|
|
771
|
+
}
|
|
772
|
+
onMouseLeave() {
|
|
773
|
+
this.tooltip?.hide(), this.crosshair?.hide();
|
|
774
|
+
}
|
|
775
|
+
onWheel(t) {
|
|
776
|
+
if (this.wheelZoom) {
|
|
777
|
+
t.preventDefault();
|
|
778
|
+
const {
|
|
779
|
+
xMin: e,
|
|
780
|
+
xMax: i,
|
|
781
|
+
yMin: s,
|
|
782
|
+
yMax: n,
|
|
783
|
+
grid: a,
|
|
784
|
+
rectBounds: r,
|
|
785
|
+
drawWidth: c,
|
|
786
|
+
drawHeight: h,
|
|
787
|
+
scale: x
|
|
788
|
+
} = this, { xLimit: p, yLimit: d } = l.config, [u, f] = p, [m, v] = d, { x: w, y: b } = this.getOffset(t), { right: S, bottom: C } = r, L = {
|
|
789
|
+
x: t.deltaY * x.x / c,
|
|
790
|
+
y: t.deltaY * x.y / h
|
|
791
|
+
};
|
|
792
|
+
this.xMin = Math.max(
|
|
793
|
+
u,
|
|
794
|
+
e - L.x * (w - a.left)
|
|
795
|
+
), this.xMax = Math.min(
|
|
796
|
+
f,
|
|
797
|
+
i + L.x * (S - w)
|
|
798
|
+
), this.yMin = Math.max(
|
|
799
|
+
m,
|
|
800
|
+
s - L.y * (C - b)
|
|
801
|
+
), this.yMax = Math.min(
|
|
802
|
+
v,
|
|
803
|
+
n + L.y * (b - a.top)
|
|
804
|
+
), this.shouldUpdate = !0;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
onDblClick() {
|
|
808
|
+
this.reset();
|
|
809
|
+
}
|
|
810
|
+
onResize = () => {
|
|
811
|
+
this.resize();
|
|
812
|
+
};
|
|
813
|
+
get scale() {
|
|
814
|
+
const { xMin: t, xMax: e, yMin: i, yMax: s, drawWidth: n, drawHeight: a } = this;
|
|
815
|
+
return new g((e - t) / n, (s - i) / a);
|
|
816
|
+
}
|
|
817
|
+
getRatioOffset(t) {
|
|
818
|
+
const { xMin: e, xMax: i, yMin: s, yMax: n } = this;
|
|
819
|
+
return {
|
|
820
|
+
x: e + (i - e) * t,
|
|
821
|
+
y: s + (n - s) * t
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
setMoveBounds({ x: t, y: e }) {
|
|
825
|
+
const { xLimit: i, yLimit: s } = l.config, [n, a] = i, [r, c] = s, h = this.xMax - this.xMin, x = this.yMax - this.yMin;
|
|
826
|
+
let p = this.xMin + t, d = this.xMax + t, u = this.yMin + e, f = this.yMax + e;
|
|
827
|
+
return p < n && (p = n, d = p + h), d > a && (d = a, p = d - h), u < r && (u = r, f = u + x), f > c && (f = c, u = f - x), {
|
|
828
|
+
xMin: p,
|
|
829
|
+
xMax: d,
|
|
830
|
+
yMin: u,
|
|
831
|
+
yMax: f
|
|
832
|
+
};
|
|
833
|
+
}
|
|
834
|
+
/*
|
|
835
|
+
private setZoomBounds({ x, y }: Point) {
|
|
836
|
+
const { xLimit, yLimit } = Chart.config
|
|
837
|
+
const [, xMaxLimit] = xLimit
|
|
838
|
+
const [, yMaxLimit] = yLimit
|
|
839
|
+
const xMax = Math.min(this.xMax + x, xMaxLimit)
|
|
840
|
+
const yMax = Math.min(this.yMax + y, yMaxLimit)
|
|
841
|
+
return {
|
|
842
|
+
xMax,
|
|
843
|
+
yMax
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
*/
|
|
847
|
+
// @override
|
|
848
|
+
onStart(t) {
|
|
849
|
+
if (t.ctrlKey && (this.prevControlType = this.controlType, this.controlType = M.move), this.setCursor(), this.controlType === M.crop) {
|
|
850
|
+
const e = this.getOffset(t);
|
|
851
|
+
this.cropOrigin = this.cropOffset = e, this.inCrop = !0;
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
// @override
|
|
855
|
+
onUpdate({ value: t, delta: e }) {
|
|
856
|
+
const {
|
|
857
|
+
scale: i,
|
|
858
|
+
dpr: s,
|
|
859
|
+
controlType: n,
|
|
860
|
+
inCrop: a,
|
|
861
|
+
cropOffset: r
|
|
862
|
+
} = this, { xMin: c, xMax: h, yMin: x, yMax: p } = this.setMoveBounds(
|
|
863
|
+
new g(-1, 1).multiply(e).multiply(i).multiply(s.value)
|
|
864
|
+
);
|
|
865
|
+
switch (n) {
|
|
866
|
+
case M.crop:
|
|
867
|
+
a && (this.cropOffset = r.add(e), this.updateCrop());
|
|
868
|
+
break;
|
|
869
|
+
case M.move:
|
|
870
|
+
this.xMin = c, this.xMax = h, this.yMin = x, this.yMax = p, this.shouldUpdate = !0;
|
|
871
|
+
break;
|
|
872
|
+
case M.zoom:
|
|
873
|
+
this.xMax = h, this.yMax = p, this.shouldUpdate = !0;
|
|
874
|
+
break;
|
|
875
|
+
}
|
|
876
|
+
return t;
|
|
877
|
+
}
|
|
878
|
+
// @override
|
|
879
|
+
onEnd(t) {
|
|
880
|
+
switch (this.controlType) {
|
|
881
|
+
case M.crop:
|
|
882
|
+
if (this.inCrop) {
|
|
883
|
+
const { scale: e, rect: i, scaleGrid: s, xMin: n, yMin: a, dpr: r, cropRange: c } = this, { left: h, top: x, right: p, bottom: d } = c, u = r.value;
|
|
884
|
+
p - h > 1 && d - x > 1 && (this.xMin += (h * u - s.left) * e.x, this.xMax = (p * u - s.left) * e.x + n, this.yMin += (i.y - d * u) * e.y, this.yMax = (i.y - x * u) * e.y + a), this.crop.hide(), this.cropOrigin = this.cropOffset = g.origin(), this.inCrop = !1, this.shouldUpdate = !0;
|
|
885
|
+
}
|
|
886
|
+
break;
|
|
887
|
+
case M.move:
|
|
888
|
+
break;
|
|
889
|
+
case M.zoom:
|
|
890
|
+
break;
|
|
891
|
+
}
|
|
892
|
+
t.ctrlKey && (this.controlType = this.prevControlType, this.setCursor());
|
|
893
|
+
}
|
|
894
|
+
get cropRange() {
|
|
895
|
+
const { cropOrigin: t, cropOffset: e, rectBounds: i } = this, [s, n] = D([t.x, e.x]), [a, r] = D([t.y, e.y]);
|
|
896
|
+
return W(
|
|
897
|
+
{
|
|
898
|
+
left: s,
|
|
899
|
+
top: a,
|
|
900
|
+
right: n,
|
|
901
|
+
bottom: r
|
|
902
|
+
},
|
|
903
|
+
[i.left, i.right],
|
|
904
|
+
[i.top, i.bottom]
|
|
905
|
+
);
|
|
906
|
+
}
|
|
907
|
+
updateCrop() {
|
|
908
|
+
const { cropRange: t, width: e, height: i, dpr: s } = this, { left: n, top: a, right: r, bottom: c } = t, h = s.value;
|
|
909
|
+
n === r || a === c ? this.crop.hide() : this.crop.update({
|
|
910
|
+
left: n,
|
|
911
|
+
top: a,
|
|
912
|
+
right: e / h - r,
|
|
913
|
+
bottom: i / h - c
|
|
914
|
+
});
|
|
915
|
+
}
|
|
916
|
+
setCenter(t, e) {
|
|
917
|
+
let { x: i, y: s } = g.origin().sub(this.getRatioOffset(0.5));
|
|
918
|
+
if (arguments.length === 1)
|
|
919
|
+
if (Array.isArray(t)) {
|
|
920
|
+
const [n, a] = t;
|
|
921
|
+
i += n, s += a;
|
|
922
|
+
} else typeof t != "number" && (i += t.x, s += t.y);
|
|
923
|
+
else arguments.length === 2 && typeof t == "number" && typeof e == "number" && (i += t, s += e);
|
|
924
|
+
this.xMin += i, this.xMax += i, this.yMin += s, this.yMax += s, this.shouldUpdate = !0;
|
|
925
|
+
}
|
|
926
|
+
setBounds(t, e, i, s) {
|
|
927
|
+
this.xMin = t ?? this.xMin, this.xMax = e ?? this.xMax, this.yMin = i ?? this.yMin, this.yMax = s ?? this.yMax, this.shouldUpdate = !0;
|
|
928
|
+
}
|
|
929
|
+
resize() {
|
|
930
|
+
super.resize(), this.updateCanvas();
|
|
931
|
+
}
|
|
932
|
+
reset(t) {
|
|
933
|
+
const { xMin: e, xMax: i, yMin: s, yMax: n } = l.config;
|
|
934
|
+
this.xMin = e, this.xMax = i, this.yMin = s, this.yMax = n, t?.(), this.shouldUpdate = !0;
|
|
935
|
+
}
|
|
936
|
+
// @override
|
|
937
|
+
dispose() {
|
|
938
|
+
super.dispose(), cancelAnimationFrame(this.raf), this.tooltip?.dispose(), this.dpr.dispose(), this.resizeObserver.disconnect(), this.canvasContainer.removeEventListener("mousemove", this.onMouseMove), this.canvasContainer.removeEventListener("mouseleave", this.onMouseLeave), this.canvasContainer.removeEventListener("dblclick", this.onDblClick), this.canvasContainer.removeEventListener("wheel", this.onWheel), this.root.removeChild(this.canvasContainer);
|
|
939
|
+
}
|
|
940
|
+
}
|
|
941
|
+
export {
|
|
942
|
+
l as C,
|
|
943
|
+
R as D,
|
|
944
|
+
$ as F,
|
|
945
|
+
g as P,
|
|
946
|
+
Z as T,
|
|
947
|
+
M as a,
|
|
948
|
+
K as b,
|
|
949
|
+
B as c,
|
|
950
|
+
E as d,
|
|
951
|
+
D as e,
|
|
952
|
+
T as f,
|
|
953
|
+
G as g,
|
|
954
|
+
y as h,
|
|
955
|
+
H as i,
|
|
956
|
+
Q as j,
|
|
957
|
+
F as k,
|
|
958
|
+
k as l,
|
|
959
|
+
U as m,
|
|
960
|
+
V as n,
|
|
961
|
+
O as o,
|
|
962
|
+
Y as p,
|
|
963
|
+
q as r,
|
|
964
|
+
j as s
|
|
965
|
+
};
|