@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.
Files changed (47) hide show
  1. package/README.md +144 -0
  2. package/build/bar.cjs +1 -0
  3. package/build/bar.d.ts +10 -0
  4. package/build/bar.js +44 -0
  5. package/build/base/chart.d.ts +137 -0
  6. package/build/base/color.d.ts +18 -0
  7. package/build/base/dragable.d.ts +29 -0
  8. package/build/base/field.d.ts +18 -0
  9. package/build/base/index.d.ts +5 -0
  10. package/build/base/point.d.ts +15 -0
  11. package/build/brush/brush.d.ts +49 -0
  12. package/build/brush/crop.d.ts +12 -0
  13. package/build/brush/index.d.ts +2 -0
  14. package/build/brush/range.d.ts +6 -0
  15. package/build/brush/thumb.d.ts +6 -0
  16. package/build/chart-Cj4Fiwnb.js +965 -0
  17. package/build/chart-Dr9ZOezr.cjs +1 -0
  18. package/build/dataset-Bv37sY1L.js +18 -0
  19. package/build/dataset-D4KLCpTU.cjs +1 -0
  20. package/build/heatmap-BlMqliH5.cjs +1 -0
  21. package/build/heatmap-Br4YjrBg.js +859 -0
  22. package/build/heatmap.cjs +1 -0
  23. package/build/heatmap.d.ts +91 -0
  24. package/build/heatmap.js +5 -0
  25. package/build/index.cjs +1 -0
  26. package/build/index.d.ts +7 -0
  27. package/build/index.js +20 -0
  28. package/build/legend/index.d.ts +1 -0
  29. package/build/legend/legend.d.ts +20 -0
  30. package/build/line.cjs +1 -0
  31. package/build/line.d.ts +11 -0
  32. package/build/line.js +23 -0
  33. package/build/otdr.cjs +1 -0
  34. package/build/otdr.d.ts +186 -0
  35. package/build/otdr.js +417 -0
  36. package/build/tooltip/crosshair.d.ts +20 -0
  37. package/build/tooltip/index.d.ts +2 -0
  38. package/build/tooltip/tooltip.d.ts +12 -0
  39. package/build/type.d.ts +78 -0
  40. package/build/util/dataset.d.ts +6 -0
  41. package/build/util/date.d.ts +1 -0
  42. package/build/util/env.d.ts +15 -0
  43. package/build/util/event.d.ts +6 -0
  44. package/build/util/index.d.ts +6 -0
  45. package/build/util/numeric.d.ts +26 -0
  46. package/build/util/style.d.ts +3 -0
  47. package/package.json +53 -0
@@ -0,0 +1,859 @@
1
+ import { b as D, d as Y, r as B, F as G, e as P, f as b, h as $, D as X, P as m, i as q, T as K, j as J, k as N, l as Q, n as V, o as Z, m as E, s as H, p as _ } from "./chart-Cj4Fiwnb.js";
2
+ class C {
3
+ r;
4
+ g;
5
+ b;
6
+ constructor(e, t, i) {
7
+ this.r = e, this.g = t, this.b = i;
8
+ }
9
+ getIntervalValue(e, t, i) {
10
+ return Math.abs((t - e) * i + e);
11
+ }
12
+ interval(e, t) {
13
+ const i = Math.max(0, t);
14
+ return new C(
15
+ this.getIntervalValue(this.r, e.r, i),
16
+ this.getIntervalValue(this.g, e.g, i),
17
+ this.getIntervalValue(this.b, e.b, i)
18
+ );
19
+ }
20
+ toHexValue(e) {
21
+ return e.toString(16).padStart(2, "0");
22
+ }
23
+ toHex() {
24
+ return "#" + [
25
+ this.r,
26
+ this.g,
27
+ this.b
28
+ ].map(this.toHexValue).join("");
29
+ }
30
+ toString() {
31
+ return `rgb(${this.r}, ${this.g}, ${this.b})`;
32
+ }
33
+ }
34
+ class ee {
35
+ colors;
36
+ constructor(e) {
37
+ this.colors = e;
38
+ }
39
+ addColor(e) {
40
+ this.colors.push(e);
41
+ }
42
+ toString() {
43
+ return this.colors.map(
44
+ (e) => e.toHex()
45
+ );
46
+ }
47
+ getOffsetColor(e) {
48
+ if (e < 1) {
49
+ const t = (this.colors.length - 1) * e, i = Math.floor(t);
50
+ return this.colors[i].interval(this.colors[i + 1], t - i);
51
+ }
52
+ return this.colors[this.colors.length - 1];
53
+ }
54
+ }
55
+ function M(d, e = "HH:mm:ss.xxx") {
56
+ const t = /* @__PURE__ */ new Map();
57
+ return t.set("Y", d.getFullYear()).set("M", d.getMonth() + 1).set("D", d.getDate()).set("H", d.getHours()).set("m", d.getMinutes()).set("s", d.getSeconds()).set("x", String(d.getMilliseconds()).padStart(3, "0")), e.replace(
58
+ new RegExp("(" + [...t.keys()].join("+|") + "+)", "g"),
59
+ (i, s, r, n) => String(t.get(n[r])).padStart(i.length, "0")
60
+ );
61
+ }
62
+ class te extends D {
63
+ constructor(e, t) {
64
+ super(e, t);
65
+ }
66
+ onUpdate(e) {
67
+ return Y(e.value + this.option.onUpdate(e), [0, 1]);
68
+ }
69
+ }
70
+ class ie extends D {
71
+ constructor(e, t) {
72
+ super(e, t);
73
+ }
74
+ onUpdate(e) {
75
+ return B(e.value, this.option.onUpdate(e));
76
+ }
77
+ }
78
+ const re = {
79
+ initValue: [0, 1]
80
+ };
81
+ class A extends G {
82
+ root;
83
+ container;
84
+ thumbSize = 10;
85
+ startThumb;
86
+ endThumb;
87
+ range;
88
+ resizeObserver;
89
+ width;
90
+ height;
91
+ brushLabel;
92
+ labelInput;
93
+ constructor(e, t) {
94
+ const { initValue: i, labelInput: s, style: r } = {
95
+ ...re,
96
+ ...t
97
+ };
98
+ super(i), this.root = e, this.container = this.createContainer(r), this.root.appendChild(this.container), this.brushLabel = s, this.brushLabel && this.initBrushLabelInput(), this.resizeObserver = new ResizeObserver(this.onResize), this.resizeObserver.observe(this.container), this.width = this.container.clientWidth, this.height = this.container.clientHeight, this.onStartValueChange = this.onStartValueChange.bind(this), this.onEndValueChange = this.onEndValueChange.bind(this), this.onRangeValueChange = this.onRangeValueChange.bind(this);
99
+ const [n, a] = i;
100
+ this.startThumb = this.createThumb(n, this.onStartValueChange), this.endThumb = this.createThumb(a, this.onEndValueChange), this.range = this.createRange(i, this.onRangeValueChange);
101
+ }
102
+ get value() {
103
+ return P(this._value);
104
+ }
105
+ set value([e, t]) {
106
+ this._value = [e, t], this.range.value = [e, t], this.startThumb.value = e, this.endThumb.value = t, this.updateBrushLabelInput();
107
+ }
108
+ getFormatLabel(e) {
109
+ const { from: t } = this.brushLabel;
110
+ return t(e);
111
+ }
112
+ updateBrushLabelInput() {
113
+ if (this.labelInput) {
114
+ const [e, t] = P(this._value), { start: i, end: s } = this.labelInput;
115
+ i.value = String(this.getFormatLabel(e)), s.value = String(this.getFormatLabel(t));
116
+ }
117
+ }
118
+ initBrushLabelInput() {
119
+ const e = {
120
+ position: "absolute",
121
+ height: "20px",
122
+ fontSize: "12px",
123
+ boxSizing: "border-box",
124
+ top: "0"
125
+ }, t = this.createLabelInput({
126
+ ...e,
127
+ width: "55px",
128
+ left: "-60px"
129
+ });
130
+ t.onchange = this.onStartLabelInputChange.bind(this);
131
+ const i = this.createLabelInput({
132
+ ...e,
133
+ width: "60px",
134
+ right: "-65px"
135
+ });
136
+ i.onchange = this.onEndLabelInputChange.bind(this), this.labelInput = {
137
+ start: t,
138
+ end: i
139
+ }, this.updateBrushLabelInput();
140
+ }
141
+ createLabelInput(e) {
142
+ const t = document.createElement("input");
143
+ return t.setAttribute("style", b(e)), t.setAttribute("type", "number"), this.container.appendChild(t), t;
144
+ }
145
+ createThumb(e, t) {
146
+ const i = this.getStyle.bind(this), s = this.onUpdate.bind(this), r = new te(this.container, {
147
+ initValue: e,
148
+ getStyle: i,
149
+ onUpdate: s
150
+ });
151
+ return r.addEventListener(t), r;
152
+ }
153
+ emitChangeEvent() {
154
+ for (const e of this.listeners)
155
+ e(this.value);
156
+ }
157
+ getRangeStyle({ value: [e, t] }) {
158
+ const { trackWidth: i, thumbSize: s } = this, r = s / 2;
159
+ return b({
160
+ position: "absolute",
161
+ left: i * e + r + "px",
162
+ top: "0",
163
+ backgroundColor: "hsla(240deg 100% 50% / 40%)",
164
+ cursor: "move",
165
+ right: i * (1 - t) + r + "px",
166
+ bottom: "0",
167
+ zIndex: "1"
168
+ });
169
+ }
170
+ createRange(e, t) {
171
+ const i = this.getRangeStyle.bind(this), s = new ie(this.container, {
172
+ initValue: e,
173
+ getStyle: i,
174
+ onUpdate: ({ value: [r, n], ...a }) => [
175
+ this.onUpdate({
176
+ value: r,
177
+ ...a
178
+ }),
179
+ this.onUpdate({
180
+ value: n,
181
+ ...a
182
+ })
183
+ ]
184
+ });
185
+ return s.addEventListener(t), s;
186
+ }
187
+ updateRangeValue() {
188
+ this.range.value = this.value, this.emitChangeEvent();
189
+ }
190
+ onStartValueChange(e) {
191
+ const [, t] = this._value;
192
+ this._value = [e, t], this.updateRangeValue(), this.updateBrushLabelInput();
193
+ }
194
+ onStartLabelInputChange(e) {
195
+ const t = e.target, i = +t.value, [s, r] = this._value, n = this.brushLabel.to(i);
196
+ if (n < r) {
197
+ const a = Math.max(0, n);
198
+ this._value = [a, r], this.startThumb.value = a, this.updateRangeValue(), n < 0 && (t.value = "0");
199
+ }
200
+ }
201
+ onEndValueChange(e) {
202
+ const [t] = this._value;
203
+ this._value = [t, e], this.updateRangeValue(), this.updateBrushLabelInput();
204
+ }
205
+ onEndLabelInputChange(e) {
206
+ const t = e.target, i = +t.value, [s] = this._value, r = this.brushLabel.to(i);
207
+ if (r > s) {
208
+ const n = Math.min(1, r);
209
+ this._value = [s, n], this.endThumb.value = n, this.updateRangeValue(), r > 1 && (t.value = String(this.brushLabel.from(1)));
210
+ }
211
+ }
212
+ onRangeValueChange([e, t]) {
213
+ this._value = [e, t], this.startThumb.value = e, this.endThumb.value = t, this.emitChangeEvent(), this.updateBrushLabelInput();
214
+ }
215
+ get trackWidth() {
216
+ return this.width - this.thumbSize;
217
+ }
218
+ onResize = () => {
219
+ this.width = this.container.clientWidth, this.height = this.container.clientHeight, this.startThumb.resize(), this.endThumb.resize(), this.range.resize();
220
+ };
221
+ onUpdate({ delta: e }) {
222
+ return e.x / this.trackWidth;
223
+ }
224
+ getStyle({ value: e }) {
225
+ const { thumbSize: t, trackWidth: i } = this;
226
+ return b({
227
+ position: "absolute",
228
+ backgroundColor: "hsl(240deg 100% 50%)",
229
+ width: `${t}px`,
230
+ userSelect: "none",
231
+ cursor: "ew-resize",
232
+ left: `${i * e}px`,
233
+ top: "0",
234
+ bottom: "0",
235
+ zIndex: "2"
236
+ });
237
+ }
238
+ createContainer(e) {
239
+ const t = document.createElement("div");
240
+ return t.setAttribute(
241
+ "style",
242
+ b({
243
+ position: "relative",
244
+ height: "20px",
245
+ backgroundColor: "#ddd",
246
+ ...e
247
+ })
248
+ ), t;
249
+ }
250
+ setStyle(e) {
251
+ $(this.container, e);
252
+ }
253
+ dispose() {
254
+ this.startThumb.dispose(), this.endThumb.dispose(), this.resizeObserver.disconnect(), this.root.removeChild(this.container);
255
+ }
256
+ }
257
+ class se extends A {
258
+ _root;
259
+ _container;
260
+ colors;
261
+ thumbSize = 4;
262
+ constructor(e, {
263
+ initValue: t = [0, 1],
264
+ colors: i,
265
+ style: s
266
+ }) {
267
+ const r = document.createElement("div");
268
+ super(r, {
269
+ initValue: t,
270
+ style: {
271
+ flexGrow: "1",
272
+ height: "100%",
273
+ backgroundColor: "#ccc"
274
+ }
275
+ }), this.height = 180, this.colors = i, this._root = e, this._container = this.setContainer(r, s), this.createScale();
276
+ }
277
+ get trackHeight() {
278
+ return this.height - this.thumbSize;
279
+ }
280
+ setContainer(e, t) {
281
+ const i = this.height;
282
+ return e.setAttribute(
283
+ "style",
284
+ b({
285
+ display: "flex",
286
+ width: "60px",
287
+ height: `${i}px`,
288
+ fontSize: "10px",
289
+ userSelect: "none",
290
+ ...t
291
+ })
292
+ ), this._root.appendChild(e), e;
293
+ }
294
+ createScale() {
295
+ const e = document.createElement("div");
296
+ e.setAttribute("style", b({
297
+ position: "relative",
298
+ minWidth: "40px"
299
+ }));
300
+ let t = 255;
301
+ for (; t >= 0; ) {
302
+ const i = document.createElement("span");
303
+ i.innerText = String(t), i.setAttribute("style", b({
304
+ position: "absolute",
305
+ paddingLeft: "5px",
306
+ left: "0",
307
+ top: (1 - t / 255) * 100 + "%",
308
+ fontSize: "inherit"
309
+ })), e.appendChild(i), t -= 51;
310
+ }
311
+ return this._container.appendChild(e), e;
312
+ }
313
+ onUpdate({ delta: e }) {
314
+ return e.y / this.trackHeight;
315
+ }
316
+ getStyle({ value: e }) {
317
+ const { thumbSize: t, trackHeight: i } = this;
318
+ return b({
319
+ position: "absolute",
320
+ width: "100%",
321
+ height: `${t}px`,
322
+ backgroundColor: "#222",
323
+ userSelect: "none",
324
+ cursor: "ns-resize",
325
+ left: "0",
326
+ top: `${i * e}px`,
327
+ right: "0",
328
+ zIndex: "2"
329
+ });
330
+ }
331
+ getRangeStyle({ value: e }) {
332
+ const [t, i] = e, { trackHeight: s, height: r, colors: n } = this, a = s * t, h = s * (1 - i);
333
+ let u = {
334
+ position: "absolute",
335
+ left: "0",
336
+ top: a + "px",
337
+ userSelect: "none",
338
+ cursor: "move",
339
+ right: "0",
340
+ bottom: h + "px",
341
+ zIndex: "1"
342
+ };
343
+ if (n) {
344
+ const c = n.join(", ");
345
+ u = {
346
+ ...u,
347
+ backgroundImage: `linear-gradient(0, ${c})`,
348
+ backgroundSize: `100% ${r}px`,
349
+ backgroundPosition: `0 -${a}px`
350
+ };
351
+ }
352
+ return b(u);
353
+ }
354
+ dispose() {
355
+ super.dispose(), this._root.removeChild(this._container);
356
+ }
357
+ }
358
+ class o extends X {
359
+ constructor(e) {
360
+ const t = document.createElement("div"), i = o.defaultRange;
361
+ super(t, i), Object.defineProperty(this, "root", {
362
+ enumerable: !0,
363
+ configurable: !0,
364
+ writable: !0,
365
+ value: void 0
366
+ }), Object.defineProperty(this, "resizeObserver", {
367
+ enumerable: !0,
368
+ configurable: !0,
369
+ writable: !0,
370
+ value: void 0
371
+ }), Object.defineProperty(this, "dpr", {
372
+ enumerable: !0,
373
+ configurable: !0,
374
+ writable: !0,
375
+ value: void 0
376
+ }), Object.defineProperty(this, "canvasContainer", {
377
+ enumerable: !0,
378
+ configurable: !0,
379
+ writable: !0,
380
+ value: void 0
381
+ }), Object.defineProperty(this, "canvas", {
382
+ enumerable: !0,
383
+ configurable: !0,
384
+ writable: !0,
385
+ value: void 0
386
+ }), Object.defineProperty(this, "width", {
387
+ enumerable: !0,
388
+ configurable: !0,
389
+ writable: !0,
390
+ value: 0
391
+ }), Object.defineProperty(this, "height", {
392
+ enumerable: !0,
393
+ configurable: !0,
394
+ writable: !0,
395
+ value: 0
396
+ }), Object.defineProperty(this, "context", {
397
+ enumerable: !0,
398
+ configurable: !0,
399
+ writable: !0,
400
+ value: void 0
401
+ }), Object.defineProperty(this, "dataCache", {
402
+ enumerable: !0,
403
+ configurable: !0,
404
+ writable: !0,
405
+ value: []
406
+ }), Object.defineProperty(this, "dataLength", {
407
+ enumerable: !0,
408
+ configurable: !0,
409
+ writable: !0,
410
+ value: 1e4
411
+ }), Object.defineProperty(this, "precision", {
412
+ enumerable: !0,
413
+ configurable: !0,
414
+ writable: !0,
415
+ value: 1
416
+ }), Object.defineProperty(this, "cropMode", {
417
+ enumerable: !0,
418
+ configurable: !0,
419
+ writable: !0,
420
+ value: !0
421
+ }), Object.defineProperty(this, "cropOrigin", {
422
+ enumerable: !0,
423
+ configurable: !0,
424
+ writable: !0,
425
+ value: m.origin()
426
+ }), Object.defineProperty(this, "cropOffset", {
427
+ enumerable: !0,
428
+ configurable: !0,
429
+ writable: !0,
430
+ value: m.origin()
431
+ }), Object.defineProperty(this, "gradient", {
432
+ enumerable: !0,
433
+ configurable: !0,
434
+ writable: !0,
435
+ value: new ee([
436
+ new C(0, 0, 255),
437
+ new C(0, 255, 0),
438
+ new C(255, 255, 0),
439
+ new C(255, 128, 0),
440
+ new C(255, 0, 0)
441
+ ])
442
+ }), Object.defineProperty(this, "brush", {
443
+ enumerable: !0,
444
+ configurable: !0,
445
+ writable: !0,
446
+ value: void 0
447
+ }), Object.defineProperty(this, "legend", {
448
+ enumerable: !0,
449
+ configurable: !0,
450
+ writable: !0,
451
+ value: void 0
452
+ }), Object.defineProperty(this, "tooltip", {
453
+ enumerable: !0,
454
+ configurable: !0,
455
+ writable: !0,
456
+ value: void 0
457
+ }), Object.defineProperty(this, "crop", {
458
+ enumerable: !0,
459
+ configurable: !0,
460
+ writable: !0,
461
+ value: void 0
462
+ }), Object.defineProperty(this, "crosshair", {
463
+ enumerable: !0,
464
+ configurable: !0,
465
+ writable: !0,
466
+ value: void 0
467
+ }), Object.defineProperty(this, "grid", {
468
+ enumerable: !0,
469
+ configurable: !0,
470
+ writable: !0,
471
+ value: { ...o.config.grid }
472
+ }), Object.defineProperty(this, "range", {
473
+ enumerable: !0,
474
+ configurable: !0,
475
+ writable: !0,
476
+ value: o.defaultRange
477
+ }), Object.defineProperty(this, "dataRange", {
478
+ enumerable: !0,
479
+ configurable: !0,
480
+ writable: !0,
481
+ value: o.defaultDataRange
482
+ }), Object.defineProperty(this, "raf", {
483
+ enumerable: !0,
484
+ configurable: !0,
485
+ writable: !0,
486
+ value: void 0
487
+ }), Object.defineProperty(this, "onResize", {
488
+ enumerable: !0,
489
+ configurable: !0,
490
+ writable: !0,
491
+ value: () => {
492
+ this.resize();
493
+ }
494
+ }), this.root = e, this.resizeObserver = new ResizeObserver(this.onResize), this.resizeObserver.observe(e), this.onDprChange = this.onDprChange.bind(this), this.dpr = new q(this.onDprChange), this.canvas = document.createElement("canvas"), this.context = this.canvas.getContext("2d");
495
+ const s = this.dpr.value;
496
+ this.context.scale(s, s), this.canvasContainer = this.initCanvas(t, this.canvas), this.onMouseMove = this.onMouseMove.bind(this), this.canvasContainer.addEventListener("mousemove", this.onMouseMove), this.onMouseLeave = this.onMouseLeave.bind(this), this.canvasContainer.addEventListener("mouseleave", this.onMouseLeave), this.onDblClick = this.onDblClick.bind(this), this.canvasContainer.addEventListener("dblclick", this.onDblClick), this.root.appendChild(this.canvasContainer), this.updateCanvas();
497
+ const r = this.grid;
498
+ o.config.legend || (r.right = 70), this.updateGrid();
499
+ const n = { ...this.grid }, a = this.brushLabelFrom.bind(this), h = this.brushLabelTo.bind(this);
500
+ this.brush = new A(e, {
501
+ initValue: i,
502
+ labelInput: {
503
+ from: a,
504
+ to: h
505
+ },
506
+ style: {
507
+ margin: `0 ${r.right}px 0 ${r.left}px`
508
+ }
509
+ }), this.onBrushValueChange = this.onBrushValueChange.bind(this), this.brush.addEventListener(this.onBrushValueChange), o.config.legend && (this.legend = new se(this.canvasContainer, {
510
+ colors: this.gradient.toString(),
511
+ initValue: this.dataRange,
512
+ style: {
513
+ position: "absolute",
514
+ top: `${r.top}px`,
515
+ right: "0"
516
+ }
517
+ }), this.onLegendValueChange = this.onLegendValueChange.bind(this), this.legend.addEventListener(this.onLegendValueChange)), this.tooltip = new K(this.canvasContainer, {
518
+ fontSize: `${o.config.fontSize}px`,
519
+ backgroundColor: o.config.accentColor,
520
+ ...o.config.tooltipStyle
521
+ }), this.crosshair = new J(this.canvasContainer, {
522
+ edge: n,
523
+ style: {
524
+ color: "#eee"
525
+ }
526
+ }), this.crop = new N(this.canvasContainer, {
527
+ backgroundColor: "#0006",
528
+ ...o.config.cropStyle
529
+ }), this.updateDraw();
530
+ }
531
+ get $root() {
532
+ return this.root;
533
+ }
534
+ get $canvas() {
535
+ return this.canvas;
536
+ }
537
+ updateGrid() {
538
+ const { left: e, top: t, right: i, bottom: s } = o.config.grid, r = this.dpr.value;
539
+ this.grid = {
540
+ left: e * r,
541
+ top: t * r,
542
+ right: i * r,
543
+ bottom: s * r
544
+ };
545
+ }
546
+ get maxCacheSize() {
547
+ return Math.min(this.height, o.config.maxCacheSize);
548
+ }
549
+ get drawRatio() {
550
+ return this.drawHeight / this.maxCacheSize;
551
+ }
552
+ brushLabelFrom(e) {
553
+ return Math.round(e * this.precision * this.dataLength);
554
+ }
555
+ brushLabelTo(e) {
556
+ return e / this.precision / this.dataLength;
557
+ }
558
+ reset() {
559
+ this.brush.value = o.defaultRange, this.range = o.defaultRange;
560
+ }
561
+ setCursor(e) {
562
+ $(this.canvasContainer, {
563
+ cursor: e
564
+ });
565
+ }
566
+ getOffset(e) {
567
+ return Q(e, this.canvasContainer);
568
+ }
569
+ onStart(e) {
570
+ if (this.cropMode = !e.ctrlKey, this.cropMode) {
571
+ const t = this.getOffset(e);
572
+ this.cropOrigin = this.cropOffset = t;
573
+ } else
574
+ this.setCursor("move");
575
+ }
576
+ onUpdate({ value: e, delta: t }) {
577
+ if (this.cropMode)
578
+ this.cropOffset = this.cropOffset.add(t), this.updateCrop();
579
+ else {
580
+ const [i, s] = this.range;
581
+ if (this.dataLength > 0 && s - i < 1) {
582
+ const r = -t.x * this.scale / this.dataLength, n = B([i, s], [r, r]);
583
+ this.isEqual([i, s], n) || (this.brush.value = n, this.range = n);
584
+ }
585
+ }
586
+ return e;
587
+ }
588
+ get scale() {
589
+ const [e, t] = this.pointRange;
590
+ return (t - e) / this.drawWidth;
591
+ }
592
+ get cropRange() {
593
+ const { cropOrigin: e, cropOffset: t, rect: i, grid: s, dpr: r } = this, [n, a] = P([e.x, Math.abs(t.x)]), h = r.value;
594
+ return [
595
+ Math.max(n, s.left / h),
596
+ Math.min(a, i.x / h)
597
+ ];
598
+ }
599
+ updateCrop() {
600
+ const { cropRange: e, width: t, grid: i, dpr: s } = this, [r, n] = e, a = s.value;
601
+ this.crop.update({
602
+ left: r,
603
+ top: i.top / a,
604
+ right: t / a - n,
605
+ bottom: i.bottom / a
606
+ });
607
+ }
608
+ onEnd() {
609
+ if (this.cropMode) {
610
+ const [e, t] = this.cropRange;
611
+ if (t - e >= 10) {
612
+ const [i] = this.pointRange, { left: s } = this.grid, r = [e - s, t - s].map((n) => (n * this.scale + i) / this.dataLength);
613
+ this.brush.value = r, this.range = r;
614
+ }
615
+ this.crop.hide(), this.cropMode = !1;
616
+ }
617
+ this.setCursor("crosshair");
618
+ }
619
+ get rect() {
620
+ const { width: e, height: t, grid: i } = this;
621
+ return new m(e - i.right, t - i.bottom);
622
+ }
623
+ get drawWidth() {
624
+ const { rect: e, grid: t } = this;
625
+ return e.x - t.left;
626
+ }
627
+ get drawHeight() {
628
+ const { rect: e, grid: t } = this;
629
+ return e.y - t.top;
630
+ }
631
+ get pointRange() {
632
+ return this.range.map((e) => e * this.dataLength);
633
+ }
634
+ onBrushValueChange(e) {
635
+ this.range = e;
636
+ }
637
+ onLegendValueChange(e) {
638
+ this.dataRange = V(e);
639
+ }
640
+ setDataLength(e) {
641
+ this.dataLength = e / this.precision;
642
+ }
643
+ setPrecision(e) {
644
+ this.precision !== e && (this.precision = e, this.brush.updateBrushLabelInput());
645
+ }
646
+ setData(e) {
647
+ const t = this.dataCache.length;
648
+ if (t === this.maxCacheSize && this.dataCache.pop(), e.length > this.dataLength) {
649
+ if (t > 0) {
650
+ const [i, s] = this.pointRange, r = [
651
+ Math.max(0, i / e.length),
652
+ Math.min(1, s / e.length)
653
+ ];
654
+ this.range = r, this.brush.value = r;
655
+ }
656
+ this.dataLength = e.length, this.brush.updateBrushLabelInput();
657
+ }
658
+ this.dataCache.unshift([/* @__PURE__ */ new Date(), e]);
659
+ }
660
+ setDataFilter([e, t]) {
661
+ const i = [
662
+ 1 - t / 255,
663
+ 1 - e / 255
664
+ ];
665
+ this.dataRange = V(i), this.legend && (this.legend.value = i);
666
+ }
667
+ async updateDraw() {
668
+ this.raf = requestAnimationFrame(this.updateDraw.bind(this));
669
+ const { context: e, dataCache: t, gradient: i, grid: s, width: r, height: n, pointRange: a, scale: h, dpr: u, dataRange: c, drawWidth: g, drawHeight: f, maxCacheSize: l } = this;
670
+ if (!document.hidden && r > 0 && n > 0) {
671
+ e.clearRect(0, 0, r, n);
672
+ const w = Math.floor(g), O = e.createImageData(w, l), v = O.data, [R, y] = c.map((p) => p * 255), [x] = a;
673
+ for (let p = 0; p < v.length; p += 4) {
674
+ const U = p / 4 % w, j = Math.floor(p / 4 / w);
675
+ let I = 0, T = 0, k = 255, W = 255;
676
+ if (j < t.length) {
677
+ const [, F] = t[j];
678
+ let S = F.at(Math.floor(U * h) + x);
679
+ (!S || S < R || S > y) && (S = 0);
680
+ const z = i.getOffsetColor(S / 255);
681
+ I = z.r, T = z.g, k = z.b;
682
+ }
683
+ v[p] = I, v[p + 1] = T, v[p + 2] = k, v[p + 3] = W;
684
+ }
685
+ const L = await createImageBitmap(O);
686
+ e.drawImage(L, s.left, s.top, g, f), L.close(), e.font = `${o.config.fontSize * u.value}px sans-serif`, this.drawAxisX(e), this.drawAxisY(e);
687
+ }
688
+ }
689
+ drawAxisX(e) {
690
+ const { axisYScaleOffset: t, xMinScale: i, xMaxScale: s, config: r } = o, { grid: n, rect: a, pointRange: h, precision: u } = this, [c, g] = h.map((l) => l * u);
691
+ e.beginPath(), e.moveTo(n.left - t.x, a.y), e.lineTo(a.x, a.y), e.strokeStyle = r.gridColor, e.stroke();
692
+ const { rules: f } = Z([c, g], [i, s]);
693
+ for (let l of f)
694
+ this.drawScaleX(e, l, [c, g]);
695
+ }
696
+ drawScaleX(e, t, [i, s]) {
697
+ const { grid: r, drawWidth: n, rect: a } = this, h = o.axisXScaleOffset, u = r.left + (t - i) * n / (s - i) + h.x, c = a.y + h.y;
698
+ e.beginPath(), e.moveTo(u, r.top), e.lineTo(u, c - h.y / 2), e.strokeStyle = o.config.gridColor, e.stroke();
699
+ const g = Math.round(t) + o.config.xUnit, { width: f, height: l } = E(e, g);
700
+ e.fillStyle = o.config.textColor, e.fillText(g, u - f / 2, c + l / 2);
701
+ }
702
+ drawAxisY(e) {
703
+ const { dataCache: t, drawRatio: i, drawHeight: s, grid: r } = this;
704
+ if (t.length > 0) {
705
+ const n = s / 8;
706
+ for (let a = 0; a <= s; a += n) {
707
+ const h = Math.ceil(a / i);
708
+ if (h <= t.length) {
709
+ let u = Math.min(Math.floor(h), t.length - 1);
710
+ const [c] = t[u];
711
+ this.drawScaleY(e, M(c), new m(r.left, r.top + a), a === 0);
712
+ }
713
+ }
714
+ }
715
+ }
716
+ drawScaleY(e, t, { x: i, y: s }, r = !1) {
717
+ const n = o.axisYScaleOffset, { height: a } = E(e, t);
718
+ e.beginPath(), e.moveTo(i - n.x, s), e.lineTo(r ? i + this.drawWidth : i, s), e.strokeStyle = o.config.gridColor, e.stroke(), e.fillStyle = o.config.textColor, e.fillText(t, n.x, s + a / 2 + n.y);
719
+ }
720
+ onMouseMove(e) {
721
+ const { grid: t, rect: i, scale: s, dpr: r, drawRatio: n, pointRange: a, dataCache: h, precision: u, dragging: c, tooltip: g, crosshair: f } = this, l = this.getOffset(e), w = H({
722
+ ...t,
723
+ right: i.x,
724
+ bottom: i.y
725
+ }, 1 / r.value);
726
+ if (_(l, w) && !c) {
727
+ const [O] = a, v = {
728
+ x: O + (l.x * r.value - t.left) * s,
729
+ y: l.y - t.top
730
+ }, R = Math.round(v.x * u) + "m";
731
+ let y = null;
732
+ const x = Math.floor(v.y * r.value / n);
733
+ if (x >= 0 && x < h.length) {
734
+ const [L] = h[x];
735
+ y = M(L);
736
+ }
737
+ g.update({
738
+ offset: new m(l.x, i.y * r.value),
739
+ content: R
740
+ }, y ? {
741
+ offset: new m(w.left, l.y),
742
+ content: y
743
+ } : null), f.update(l);
744
+ } else
745
+ f.hide(), g.hide();
746
+ }
747
+ onMouseLeave() {
748
+ this.tooltip.hide(), this.crosshair.hide();
749
+ }
750
+ onDblClick() {
751
+ this.reset();
752
+ }
753
+ onDprChange(e) {
754
+ this.updateCanvas(), this.context.scale(e, e), this.updateGrid(), this.crosshair.setEdge(this.grid);
755
+ }
756
+ initCanvas(e, t) {
757
+ return t.setAttribute("style", b({
758
+ display: "block",
759
+ width: "100%",
760
+ height: "100%"
761
+ })), e.appendChild(t), e;
762
+ }
763
+ updateCanvas() {
764
+ const e = this.dpr.value;
765
+ this.width = this.root.clientWidth * e;
766
+ const t = this.root.clientHeight - o.brushHeight;
767
+ this.height = t * e, this.canvas.width = this.width, this.canvas.height = this.height, this.canvasContainer.setAttribute("style", b({
768
+ position: "relative",
769
+ height: `${t}px`,
770
+ cursor: "crosshair",
771
+ overflow: "hidden",
772
+ "--scale": 1 / e
773
+ }));
774
+ }
775
+ resize() {
776
+ super.resize(), this.updateCanvas();
777
+ }
778
+ // @override
779
+ dispose() {
780
+ super.dispose(), cancelAnimationFrame(this.raf), this.brush.dispose(), this.legend?.dispose(), this.tooltip.dispose(), this.crop.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.root.removeChild(this.canvasContainer);
781
+ }
782
+ }
783
+ Object.defineProperty(o, "version", {
784
+ enumerable: !0,
785
+ configurable: !0,
786
+ writable: !0,
787
+ value: "0.0.7"
788
+ });
789
+ Object.defineProperty(o, "config", {
790
+ enumerable: !0,
791
+ configurable: !0,
792
+ writable: !0,
793
+ value: {
794
+ xUnit: "m",
795
+ gridColor: "#aaa",
796
+ textColor: "#222",
797
+ accentColor: "#000",
798
+ fontSize: 13,
799
+ cropStyle: {},
800
+ tooltipStyle: {
801
+ color: "#fff"
802
+ },
803
+ maxCacheSize: 400,
804
+ legend: !0,
805
+ grid: {
806
+ left: 90,
807
+ top: 10,
808
+ right: 80,
809
+ bottom: 30
810
+ }
811
+ }
812
+ });
813
+ Object.defineProperty(o, "defaultRange", {
814
+ enumerable: !0,
815
+ configurable: !0,
816
+ writable: !0,
817
+ value: [0, 1]
818
+ });
819
+ Object.defineProperty(o, "defaultDataRange", {
820
+ enumerable: !0,
821
+ configurable: !0,
822
+ writable: !0,
823
+ value: [0, 1]
824
+ });
825
+ Object.defineProperty(o, "xMinScale", {
826
+ enumerable: !0,
827
+ configurable: !0,
828
+ writable: !0,
829
+ value: 3
830
+ });
831
+ Object.defineProperty(o, "xMaxScale", {
832
+ enumerable: !0,
833
+ configurable: !0,
834
+ writable: !0,
835
+ value: 12
836
+ });
837
+ Object.defineProperty(o, "axisXScaleOffset", {
838
+ enumerable: !0,
839
+ configurable: !0,
840
+ writable: !0,
841
+ value: new m(0, 15)
842
+ });
843
+ Object.defineProperty(o, "axisYScaleOffset", {
844
+ enumerable: !0,
845
+ configurable: !0,
846
+ writable: !0,
847
+ value: new m(5, 0)
848
+ });
849
+ Object.defineProperty(o, "brushHeight", {
850
+ enumerable: !0,
851
+ configurable: !0,
852
+ writable: !0,
853
+ value: 30
854
+ });
855
+ export {
856
+ ee as G,
857
+ o as H,
858
+ C as R
859
+ };