blazeplot 0.2.2 → 0.3.0

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 (63) hide show
  1. package/dist/Chart-BW9JaHs6.js +2903 -0
  2. package/dist/Chart-BW9JaHs6.js.map +1 -0
  3. package/dist/OverlayUtils-Cw1o8UH-.js +35 -0
  4. package/dist/OverlayUtils-Cw1o8UH-.js.map +1 -0
  5. package/dist/core/SeriesStore.d.ts +2 -0
  6. package/dist/core/SeriesStore.d.ts.map +1 -1
  7. package/dist/core/UniformRingBuffer.d.ts +67 -0
  8. package/dist/core/UniformRingBuffer.d.ts.map +1 -0
  9. package/dist/core/index.d.ts +3 -1
  10. package/dist/core/index.d.ts.map +1 -1
  11. package/dist/core/types.d.ts +5 -1
  12. package/dist/core/types.d.ts.map +1 -1
  13. package/dist/index.d.ts +5 -2
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +153 -2304
  16. package/dist/index.js.map +1 -1
  17. package/dist/interaction/AxisController.d.ts +45 -3
  18. package/dist/interaction/AxisController.d.ts.map +1 -1
  19. package/dist/interaction/index.d.ts +1 -0
  20. package/dist/interaction/index.d.ts.map +1 -1
  21. package/dist/linked.d.ts +3 -0
  22. package/dist/linked.d.ts.map +1 -0
  23. package/dist/linked.js +64 -0
  24. package/dist/linked.js.map +1 -0
  25. package/dist/plugins/crosshair.d.ts +3 -0
  26. package/dist/plugins/crosshair.d.ts.map +1 -0
  27. package/dist/plugins/crosshair.js +192 -0
  28. package/dist/plugins/crosshair.js.map +1 -0
  29. package/dist/plugins/interactions.js +87 -65
  30. package/dist/plugins/interactions.js.map +1 -1
  31. package/dist/plugins/navigator.d.ts +3 -0
  32. package/dist/plugins/navigator.d.ts.map +1 -0
  33. package/dist/plugins/navigator.js +147 -0
  34. package/dist/plugins/navigator.js.map +1 -0
  35. package/dist/plugins/selection.d.ts +3 -0
  36. package/dist/plugins/selection.d.ts.map +1 -0
  37. package/dist/plugins/selection.js +144 -0
  38. package/dist/plugins/selection.js.map +1 -0
  39. package/dist/plugins/tooltip.js +29 -45
  40. package/dist/plugins/tooltip.js.map +1 -1
  41. package/dist/react.d.ts +14 -0
  42. package/dist/react.d.ts.map +1 -0
  43. package/dist/react.js +30 -0
  44. package/dist/react.js.map +1 -0
  45. package/dist/ui/Chart.d.ts +79 -1
  46. package/dist/ui/Chart.d.ts.map +1 -1
  47. package/dist/ui/ChartLayout.d.ts +10 -0
  48. package/dist/ui/ChartLayout.d.ts.map +1 -1
  49. package/dist/ui/Crosshair.d.ts +60 -0
  50. package/dist/ui/Crosshair.d.ts.map +1 -0
  51. package/dist/ui/Interactions.d.ts.map +1 -1
  52. package/dist/ui/LinkedCharts.d.ts +23 -0
  53. package/dist/ui/LinkedCharts.d.ts.map +1 -0
  54. package/dist/ui/Navigator.d.ts +32 -0
  55. package/dist/ui/Navigator.d.ts.map +1 -0
  56. package/dist/ui/OverlayUtils.d.ts +17 -0
  57. package/dist/ui/OverlayUtils.d.ts.map +1 -0
  58. package/dist/ui/Selection.d.ts +64 -0
  59. package/dist/ui/Selection.d.ts.map +1 -0
  60. package/dist/ui/Tooltip.d.ts.map +1 -1
  61. package/dist/ui/theme.d.ts +12 -0
  62. package/dist/ui/theme.d.ts.map +1 -1
  63. package/package.json +29 -1
@@ -0,0 +1,2903 @@
1
+ import e from "regl";
2
+ //#region src/core/MinMaxPyramid.ts
3
+ var t = 16, n = class {
4
+ bucketSize;
5
+ levels = [];
6
+ levelLengths;
7
+ levelSampleWidths;
8
+ _builtLen = 0;
9
+ _lastRangeStart = NaN;
10
+ constructor(e = 2) {
11
+ if (this.bucketSize = e, !Number.isInteger(e) || e < 2) throw RangeError("MinMaxPyramid bucketSize must be an integer >= 2.");
12
+ this.levelLengths = new Uint32Array(t), this.levelSampleWidths = new Uint32Array(t);
13
+ }
14
+ build(e) {
15
+ this.levels = [], this.levelLengths.fill(0), this.levelSampleWidths.fill(0);
16
+ let n = e.length;
17
+ if (n === 0) {
18
+ this._builtLen = 0, this._lastRangeStart = NaN;
19
+ return;
20
+ }
21
+ let r = null, i = 0;
22
+ for (; n > 0 && i < t;) {
23
+ let t = Math.ceil(n / this.bucketSize), a = new Float32Array(t * 2);
24
+ for (let t = 0; t < n; t += this.bucketSize) {
25
+ let i = Infinity, o = -Infinity, s = Math.min(t + this.bucketSize, n);
26
+ for (let n = t; n < s; n++) if (r) {
27
+ let e = r[n * 2], t = r[n * 2 + 1];
28
+ e < i && (i = e), t > o && (o = t);
29
+ } else {
30
+ let t = e.getY(n);
31
+ t < i && (i = t), t > o && (o = t);
32
+ }
33
+ let c = Math.floor(t / this.bucketSize);
34
+ a[c * 2] = i, a[c * 2 + 1] = o;
35
+ }
36
+ if (this.levels[i] = a, this.levelLengths[i] = t, this.levelSampleWidths[i] = this.bucketSize ** (i + 1), t === 1) break;
37
+ r = a, n = t, i++;
38
+ }
39
+ this._builtLen = e.length, this._lastRangeStart = e.range?.start ?? NaN;
40
+ }
41
+ incrementalBuild(e) {
42
+ let t = e.length, n = e.range?.start ?? NaN;
43
+ if (t === 0) {
44
+ this.levels = [], this.levelLengths.fill(0), this.levelSampleWidths.fill(0), this._builtLen = 0, this._lastRangeStart = NaN;
45
+ return;
46
+ }
47
+ if (t < this._builtLen || n !== this._lastRangeStart) {
48
+ this.build(e);
49
+ return;
50
+ }
51
+ t !== this._builtLen && (this.appendTail(e, t - this._builtLen), this._builtLen = t);
52
+ }
53
+ appendTail(e, n) {
54
+ let r = e.length, i = this.bucketSize, a = r - n;
55
+ for (let n = 0; n < t; n++) {
56
+ let t = n === 0 ? r : this.levelLengths[n - 1], o = Math.floor(a / i), s = Math.ceil(t / i) - 1;
57
+ if (o > s) break;
58
+ this.levelSampleWidths[n] = i ** (n + 1), this.ensureLevelData(n, s + 1);
59
+ for (let r = o; r <= s; r++) {
60
+ let a = r * i, o = Math.min((r + 1) * i, t), s = Infinity, c = -Infinity;
61
+ if (n === 0) for (let t = a; t < o; t++) {
62
+ let n = e.getY(t);
63
+ n < s && (s = n), n > c && (c = n);
64
+ }
65
+ else {
66
+ let e = this.levels[n - 1];
67
+ for (let t = a; t < o; t++) {
68
+ let n = e[t * 2], r = e[t * 2 + 1];
69
+ n < s && (s = n), r > c && (c = r);
70
+ }
71
+ }
72
+ let l = this.levels[n];
73
+ l[r * 2] = s, l[r * 2 + 1] = c;
74
+ }
75
+ if (this.levelLengths[n] = s + 1, a = o, this.levelLengths[n] <= 1) break;
76
+ }
77
+ }
78
+ ensureLevelData(e, t) {
79
+ let n = t * 2, r = this.levels[e];
80
+ if (r && r.length >= n) return;
81
+ let i = r?.length ?? 0;
82
+ if (i <= 0) i = n;
83
+ else for (; i < n;) i = Math.max(n, Math.ceil(i * 1.5));
84
+ let a = new Float32Array(i);
85
+ r && a.set(r), this.levels[e] = a;
86
+ }
87
+ rangeMinMax(e, t, n) {
88
+ let r = Math.max(0, Math.floor(t)), i = Math.min(e.length, Math.ceil(n));
89
+ if (i <= r) return null;
90
+ let a = Infinity, o = -Infinity, s = r;
91
+ for (; s < i;) {
92
+ let t = -1, n = 1;
93
+ for (let e = this.levels.length - 1; e >= 0; e--) {
94
+ let r = this.levelSampleWidths[e], a = Math.floor(s / r);
95
+ if (r > 0 && s % r === 0 && s + r <= i && a < this.levelLengths[e]) {
96
+ t = e, n = r;
97
+ break;
98
+ }
99
+ }
100
+ if (t >= 0) {
101
+ let e = Math.floor(s / n), r = this.levels[t], i = r[e * 2], c = r[e * 2 + 1];
102
+ i < a && (a = i), c > o && (o = c), s += n;
103
+ } else {
104
+ let t = e.getY(s);
105
+ t < a && (a = t), t > o && (o = t), s++;
106
+ }
107
+ }
108
+ return Number.isFinite(a) && Number.isFinite(o) ? {
109
+ minY: a,
110
+ maxY: o
111
+ } : null;
112
+ }
113
+ query(e, t, n) {
114
+ if (t <= 0 || n.length <= 0) return {
115
+ buckets: new Float32Array(),
116
+ bucketCount: 0,
117
+ level: 0,
118
+ samplesPerPixel: 0
119
+ };
120
+ let r = n.length, i = Math.max(1, r / t), a = Math.min(Math.max(0, Math.ceil(Math.log2(i)) - 1), this.levels.length - 1), o = this.levels[a], s = this.levelLengths[a], c = this.levelSampleWidths[a];
121
+ if (!o || s === void 0 || c === void 0 || s === 0 || c === 0) return {
122
+ buckets: new Float32Array(),
123
+ bucketCount: 0,
124
+ level: 0,
125
+ samplesPerPixel: i
126
+ };
127
+ let l = Math.max(0, n.start), u = l + n.length, d = Math.max(0, Math.floor(l / c)), f = Math.min(s, Math.ceil(u / c)) - d;
128
+ if (f <= 0) return {
129
+ buckets: new Float32Array(),
130
+ bucketCount: 0,
131
+ level: a,
132
+ samplesPerPixel: i
133
+ };
134
+ let p = new Float32Array(f * 2);
135
+ for (let e = 0; e < f; e++) {
136
+ let t = (d + e) * 2;
137
+ p[e * 2] = o[t], p[e * 2 + 1] = o[t + 1];
138
+ }
139
+ return {
140
+ buckets: p,
141
+ bucketCount: f,
142
+ level: a,
143
+ samplesPerPixel: i
144
+ };
145
+ }
146
+ };
147
+ //#endregion
148
+ //#region src/core/SeriesStore.ts
149
+ function r(e) {
150
+ return "rangeMinMaxY" in e;
151
+ }
152
+ function i(e) {
153
+ return "getOpen" in e && "getHigh" in e && "getLow" in e && "getClose" in e;
154
+ }
155
+ function a(e) {
156
+ return "appendY" in e;
157
+ }
158
+ function o(e) {
159
+ return "copySamplesRange" in e;
160
+ }
161
+ function s(e) {
162
+ return "copyMinMaxSegments" in e;
163
+ }
164
+ function c(e) {
165
+ return "copyVisibleSamples" in e;
166
+ }
167
+ function l(e) {
168
+ return "copyVisiblePoints" in e;
169
+ }
170
+ var u = 64, d = 64, f = 1024;
171
+ function p(e, t, n, r, i) {
172
+ if (n === e) return t;
173
+ let a = (i - e) / (n - e);
174
+ return t + (r - t) * a;
175
+ }
176
+ var m = class {
177
+ config;
178
+ style;
179
+ dataset;
180
+ pyramid;
181
+ _dirty = !1;
182
+ _useDatasetRangeMinMax = !1;
183
+ _useRawMinMaxScan = !1;
184
+ _lastBuildLength = 0;
185
+ _lastBuildRangeStart = NaN;
186
+ _visible = !0;
187
+ constructor(e, t, i) {
188
+ this.dataset = e, this.config = t, this.pyramid = (t.mode === "line" || t.mode === "bar" || t.mode === "scatter") && t.downsample !== "none" ? new n() : null, this._useDatasetRangeMinMax = r(e), this.style = i, this.pyramid && e.length > 0 && !this._useDatasetRangeMinMax && this.pyramid.build(e), this._lastBuildLength = e.length, this._lastBuildRangeStart = e.range?.start ?? NaN;
189
+ }
190
+ get hasLOD() {
191
+ return this.pyramid !== null;
192
+ }
193
+ get dirty() {
194
+ return this._dirty;
195
+ }
196
+ get length() {
197
+ return this.dataset.length;
198
+ }
199
+ get visible() {
200
+ return this._visible;
201
+ }
202
+ setVisible(e) {
203
+ this._visible = e;
204
+ }
205
+ append(e, t) {
206
+ if (!("push" in this.dataset)) throw TypeError("SeriesStore dataset is not appendable.");
207
+ this.dataset.append(e, t), this._dirty = !0;
208
+ }
209
+ appendY(e) {
210
+ if (!a(this.dataset)) throw TypeError("SeriesStore dataset does not support appendY.");
211
+ this.dataset.appendY(e), this._dirty = !0;
212
+ }
213
+ markDirty() {
214
+ this._dirty = !0;
215
+ }
216
+ clear() {
217
+ if (!("clear" in this.dataset)) throw TypeError("SeriesStore dataset is not clearable.");
218
+ this.dataset.clear(), this._useDatasetRangeMinMax = r(this.dataset), this._useRawMinMaxScan = !1, this.pyramid && !this._useDatasetRangeMinMax && this.pyramid.build(this.dataset), this._lastBuildLength = this.dataset.length, this._lastBuildRangeStart = this.dataset.range?.start ?? NaN, this._dirty = !1;
219
+ }
220
+ rebuildPyramid() {
221
+ if (this._dirty) {
222
+ if (this.pyramid) {
223
+ let e = this.dataset.length, t = this.dataset.range?.start ?? NaN, n = e === this._lastBuildLength && t !== this._lastBuildRangeStart;
224
+ r(this.dataset) ? (this._useDatasetRangeMinMax = !0, this._useRawMinMaxScan = !1) : n ? (this._useDatasetRangeMinMax = !1, this._useRawMinMaxScan = !0) : (this.pyramid.incrementalBuild(this.dataset), this._useDatasetRangeMinMax = !1, this._useRawMinMaxScan = !1), this._lastBuildLength = e, this._lastBuildRangeStart = t;
225
+ }
226
+ this._dirty = !1;
227
+ }
228
+ }
229
+ query(e, t) {
230
+ if (!this.pyramid || !this.dataset.range) return {
231
+ buckets: new Float32Array(),
232
+ bucketCount: 0,
233
+ level: 0,
234
+ samplesPerPixel: 0
235
+ };
236
+ let n = this.dataset.lowerBoundX(e.xMin), r = this.dataset.upperBoundX(e.xMax), i = Math.max(0, r - n);
237
+ return this._useDatasetRangeMinMax ? this.queryRangeMinMax(n, i, t) : this.pyramid.query(e, t, {
238
+ start: n,
239
+ length: i
240
+ });
241
+ }
242
+ visibleSampleCount(e) {
243
+ let t = this.dataset.lowerBoundX(e.xMin), n = this.dataset.upperBoundX(e.xMax);
244
+ return Math.max(0, n - t);
245
+ }
246
+ sampleAt(e) {
247
+ return e < 0 || e >= this.dataset.length ? null : {
248
+ index: e,
249
+ x: this.dataset.getX(e),
250
+ y: this.dataset.getY(e)
251
+ };
252
+ }
253
+ nearestSampleByX(e, t) {
254
+ let n = this.visibleIndexRange(t);
255
+ if (n.start >= n.end) return null;
256
+ let r = this.dataset.lowerBoundX(e), i = Math.min(Math.max(r, n.start), n.end - 1), a = i - 1;
257
+ if (a >= n.start) {
258
+ let t = Math.abs(this.dataset.getX(i) - e);
259
+ Math.abs(this.dataset.getX(a) - e) <= t && (i = a);
260
+ }
261
+ return this.sampleAt(i);
262
+ }
263
+ nearestSampleByPoint(e, t, n, r, i, a = Infinity) {
264
+ let o = this.visibleIndexRange(n), s = n.xMax - n.xMin, c = n.yMax - n.yMin;
265
+ if (o.start >= o.end || r <= 0 || i <= 0 || s <= 0 || c <= 0) return null;
266
+ let l = r / s, d = i / c, f = -1, p = a < 0 ? -1 : Number.isFinite(a) ? a * a : Infinity, m = (n) => {
267
+ let r = (this.dataset.getX(n) - e) * l, i = (this.dataset.getY(n) - t) * d, a = r * r + i * i;
268
+ (a < p || f < 0 && a <= p) && (p = a, f = n);
269
+ }, h = this.dataset.lowerBoundX(e), g = Math.min(Math.max(h, o.start), o.end - 1);
270
+ if (m(g), g > o.start && m(g - 1), g + 1 < o.end && m(g + 1), this.hasPointIntervalBounds() && o.end - o.start > u) {
271
+ let n = this.pointIntervalDistanceSq(o.start, o.end, e, t, l, d), r = n <= p ? [{
272
+ start: o.start,
273
+ end: o.end,
274
+ lowerBoundSq: n
275
+ }] : [];
276
+ for (; r.length > 0;) {
277
+ let n = r.pop();
278
+ if (n.lowerBoundSq > p) continue;
279
+ let i = n.end - n.start;
280
+ if (i <= u) {
281
+ for (let e = n.start; e < n.end; e++) m(e);
282
+ continue;
283
+ }
284
+ let a = n.start + (i >> 1), o = this.pointIntervalDistanceSq(n.start, a, e, t, l, d), s = this.pointIntervalDistanceSq(a, n.end, e, t, l, d), c = {
285
+ start: n.start,
286
+ end: a,
287
+ lowerBoundSq: o
288
+ }, f = {
289
+ start: a,
290
+ end: n.end,
291
+ lowerBoundSq: s
292
+ };
293
+ o < s ? (s <= p && r.push(f), o <= p && r.push(c)) : (o <= p && r.push(c), s <= p && r.push(f));
294
+ }
295
+ } else {
296
+ let t = Math.min(h - 1, o.end - 1), n = Math.max(h, o.start);
297
+ for (; t >= o.start || n < o.end;) {
298
+ let r = t >= o.start ? this.pointXDistanceSq(t, e, l) : Infinity, i = n < o.end ? this.pointXDistanceSq(n, e, l) : Infinity;
299
+ if (r > p && i > p) break;
300
+ r <= i ? (r <= p && m(t), t--) : (i <= p && m(n), n++);
301
+ }
302
+ }
303
+ if (f < 0) return null;
304
+ let _ = this.sampleAt(f);
305
+ return _ ? {
306
+ ..._,
307
+ distancePx: Math.sqrt(p)
308
+ } : null;
309
+ }
310
+ copyRawVisible(e, t, n, r = 0) {
311
+ return this.copyVisibleSamples(e, t, n, "points", 0, r);
312
+ }
313
+ copyScatterVisible(e, t, n, r, i, a, o = 0) {
314
+ return this.copyVisiblePoints(e, t, n, r, i, a, o);
315
+ }
316
+ copyScatterRange(e, t, n, r, i, a = 0, o = 0, s = 0) {
317
+ if (i <= 0 || r.length < i * 2) return 0;
318
+ let c = Math.max(0, Math.floor(e)), l = Math.min(this.dataset.length, Math.ceil(t));
319
+ if (l <= c) return 0;
320
+ let u = n.yMax - n.yMin, d = Math.max(0, Math.floor(o)), f = u > 0 && d > 0 ? (Number.isFinite(s) ? Math.max(0, s) : 0) * .5 / d * u : 0, p = n.yMin - f, m = n.yMax + f, h = 0;
321
+ for (let e = c; e < l && h < i; e++) {
322
+ let t = this.dataset.getY(e);
323
+ if (t < p || t > m) continue;
324
+ let n = h * 2;
325
+ r[n] = this.dataset.getX(e) - a, r[n + 1] = t, h++;
326
+ }
327
+ return h;
328
+ }
329
+ copyRawVisibleClipped(e, t, n, r = 0) {
330
+ return this.copyClippedVisibleLine(e, t, n, r, "data");
331
+ }
332
+ copyRawVisibleClipSpace(e, t, n) {
333
+ return this.copyClippedVisibleLine(e, t, n, 0, "clip");
334
+ }
335
+ copyRawRange(e, t, n, r, i = 0) {
336
+ return this.copySampleRange(e, t, n, r, "points", 0, i);
337
+ }
338
+ copyAreaVisible(e, t, n, r = 0, i = 0) {
339
+ return this.copyVisibleSamples(e, t, n, "area", r, i) * 2;
340
+ }
341
+ copyAreaRange(e, t, n, r, i = 0, a = 0) {
342
+ return this.copySampleRange(e, t, n, r, "area", i, a) * 2;
343
+ }
344
+ copyMinMaxVisible(e, t, n, r = 0) {
345
+ return this.copyMinMaxSegments(e, t, n, "line-list", r) * 2;
346
+ }
347
+ copyMinMaxInstanced(e, t, n, r = 0) {
348
+ return this.copyMinMaxSegments(e, t, n, "instanced", r);
349
+ }
350
+ copyOhlcRange(e, t, n, r, a, o = 0) {
351
+ if (!i(this.dataset) || r <= 0 || n.length < r * 12) return 0;
352
+ let s = Math.max(0, Math.floor(e)), c = Math.min(this.dataset.length, Math.ceil(t)), l = Math.min(r, Math.max(0, c - s)), u = a * .5;
353
+ for (let e = 0; e < l; e++) {
354
+ let t = s + e, r = this.dataset.getX(t) - o, i = this.dataset.getOpen(t), a = this.dataset.getHigh(t), c = this.dataset.getLow(t), l = this.dataset.getClose(t), d = e * 12;
355
+ n[d] = r, n[d + 1] = c, n[d + 2] = r, n[d + 3] = a, n[d + 4] = r - u, n[d + 5] = i, n[d + 6] = r, n[d + 7] = i, n[d + 8] = r, n[d + 9] = l, n[d + 10] = r + u, n[d + 11] = l;
356
+ }
357
+ return l;
358
+ }
359
+ copyOhlcTuplesRange(e, t, n, r, a = 0) {
360
+ if (!i(this.dataset) || r <= 0 || n.length < r * 5) return 0;
361
+ let o = Math.max(0, Math.floor(e)), s = Math.min(this.dataset.length, Math.ceil(t)), c = Math.min(r, Math.max(0, s - o));
362
+ for (let e = 0; e < c; e++) {
363
+ let t = o + e, r = e * 5;
364
+ n[r] = this.dataset.getX(t) - a, n[r + 1] = this.dataset.getOpen(t), n[r + 2] = this.dataset.getHigh(t), n[r + 3] = this.dataset.getLow(t), n[r + 4] = this.dataset.getClose(t);
365
+ }
366
+ return c;
367
+ }
368
+ visibleIndexRange(e, t = 0) {
369
+ if (!e) return {
370
+ start: 0,
371
+ end: this.dataset.length
372
+ };
373
+ let n = Math.max(0, Math.floor(t));
374
+ return {
375
+ start: Math.max(0, this.dataset.lowerBoundX(e.xMin) - n),
376
+ end: Math.min(this.dataset.length, this.dataset.upperBoundX(e.xMax) + n)
377
+ };
378
+ }
379
+ pointXDistanceSq(e, t, n) {
380
+ let r = (this.dataset.getX(e) - t) * n;
381
+ return r * r;
382
+ }
383
+ pointIntervalDistanceSq(e, t, n, r, i, a) {
384
+ if (t <= e) return Infinity;
385
+ let o = this.dataset.getX(e), s = this.dataset.getX(t - 1), c = n < o ? (o - n) * i : n > s ? (n - s) * i : 0, l = this.pointIntervalMinMaxY(e, t);
386
+ if (!l) return Infinity;
387
+ let u = r < l.minY ? (l.minY - r) * a : r > l.maxY ? (r - l.maxY) * a : 0;
388
+ return c * c + u * u;
389
+ }
390
+ hasPointIntervalBounds() {
391
+ return r(this.dataset) || this.pyramid !== null && !this._dirty && !this._useRawMinMaxScan;
392
+ }
393
+ pointIntervalMinMaxY(e, t) {
394
+ return r(this.dataset) ? this.dataset.rangeMinMaxY(e, t) : this.pyramid && !this._dirty && !this._useRawMinMaxScan ? this.pyramid.rangeMinMax(this.dataset, e, t) : null;
395
+ }
396
+ copyClippedVisibleLine(e, t, n, r, i) {
397
+ if (n <= 0 || t.length < n * 2) return 0;
398
+ let a = e.xMax - e.xMin, o = e.yMax - e.yMin;
399
+ if (i === "clip" && (a <= 0 || o <= 0)) return 0;
400
+ let s = Math.max(0, this.dataset.lowerBoundX(e.xMin) - 1), c = Math.min(this.dataset.length, this.dataset.upperBoundX(e.xMax) + 1);
401
+ if (c - s <= 0) return 0;
402
+ let l = 0, u = NaN, d = NaN, f = (s, c) => {
403
+ let f = i === "clip" ? (s - e.xMin) / a * 2 - 1 : s - r, p = i === "clip" ? (c - e.yMin) / o * 2 - 1 : c;
404
+ if (l > 0 && f === u && p === d) return !0;
405
+ if (l >= n) return !1;
406
+ let m = l * 2;
407
+ return t[m] = f, t[m + 1] = p, l++, u = f, d = p, !0;
408
+ };
409
+ if (c - s === 1) {
410
+ let t = this.dataset.getX(s);
411
+ return t < e.xMin || t > e.xMax ? 0 : f(t, this.dataset.getY(s)) ? l : 0;
412
+ }
413
+ for (let t = s; t + 1 < c; t++) {
414
+ let n = this.dataset.getX(t), r = this.dataset.getY(t), i = this.dataset.getX(t + 1), a = this.dataset.getY(t + 1);
415
+ if (i < e.xMin || n > e.xMax) continue;
416
+ let o = Math.max(n, e.xMin), s = Math.min(i, e.xMax);
417
+ if (s < o) continue;
418
+ let c = p(n, r, i, a, o), l = p(n, r, i, a, s);
419
+ if (!f(o, c) || !f(s, l)) break;
420
+ }
421
+ return l;
422
+ }
423
+ copyVisiblePoints(e, t, n, r, i, a, o) {
424
+ if (l(this.dataset)) return this.dataset.copyVisiblePoints(e, t, n, o, r, i, a);
425
+ if (n <= 0 || t.length < n * 2) return 0;
426
+ let s = e.xMax - e.xMin, c = e.yMax - e.yMin, u = Math.max(1, Math.floor(r)), d = Math.max(1, Math.floor(i));
427
+ if (s <= 0 || c <= 0) return 0;
428
+ let f = (Number.isFinite(a) ? Math.max(0, a) : 0) * .5, p = f / u * s, m = f / d * c, h = e.xMin - p, g = e.xMax + p, _ = e.yMin - m, v = e.yMax + m, y = this.dataset.lowerBoundX(h), b = this.dataset.upperBoundX(g);
429
+ if (b <= y) return 0;
430
+ if (b - y <= n) return this.copyVisiblePointRange(y, b, _, v, t, n, o);
431
+ let x = this.hasPointIntervalBounds(), S = x ? this.pointIntervalMinMaxY(y, b) : null;
432
+ if (S && (S.maxY < _ || S.minY > v)) return 0;
433
+ if (b - y <= n * 4) {
434
+ let e = this.copyVisiblePointsExact(y, b, _, v, t, n, o);
435
+ if (!e.overflow) return e.count;
436
+ }
437
+ let ee = S !== null && S.minY >= _ && S.maxY <= v;
438
+ return this.copyVisiblePointBuckets(y, b, _, v, t, n, o, ee, x);
439
+ }
440
+ copyVisiblePointRange(e, t, n, r, i, a, o) {
441
+ let s = 0;
442
+ for (let c = e; c < t && s < a; c++) {
443
+ let e = this.dataset.getY(c);
444
+ if (e < n || e > r) continue;
445
+ let t = s * 2;
446
+ i[t] = this.dataset.getX(c) - o, i[t + 1] = e, s++;
447
+ }
448
+ return s;
449
+ }
450
+ copyVisiblePointBuckets(e, t, n, r, i, a, o, s, c) {
451
+ let l = t - e, u = this.stableScatterBucketWidth(l, a), d = Math.floor(e / u) * u, p = 0, m = (e) => {
452
+ let t = p * 2;
453
+ i[t] = this.dataset.getX(e) - o, i[t + 1] = this.dataset.getY(e), p++;
454
+ };
455
+ for (let l = d; l < t && p < a; l += u) {
456
+ let a = Math.min(t, l + u), d = Math.max(e, l);
457
+ if (a <= d) continue;
458
+ let h = Math.max(d, Math.min(a - 1, l + (u >> 1)));
459
+ if (s) {
460
+ m(h);
461
+ continue;
462
+ }
463
+ let g = c && a - d >= f ? this.pointIntervalMinMaxY(d, a) : null;
464
+ if (!(g && (g.maxY < n || g.minY > r))) {
465
+ if (g && g.minY >= n && g.maxY <= r) {
466
+ m(h);
467
+ continue;
468
+ }
469
+ for (let e = d; e < a; e++) {
470
+ let t = this.dataset.getY(e);
471
+ if (t < n || t > r) continue;
472
+ let a = p * 2;
473
+ i[a] = this.dataset.getX(e) - o, i[a + 1] = t, p++;
474
+ break;
475
+ }
476
+ }
477
+ }
478
+ return p;
479
+ }
480
+ stableScatterBucketWidth(e, t) {
481
+ let n = Math.max(1, Math.ceil(e / Math.max(1, t)));
482
+ return n <= 8 ? n : Math.ceil(n / 8) * 8;
483
+ }
484
+ copyVisiblePointsExact(e, t, n, r, i, a, o) {
485
+ let s = 0, c = !1, l = this.hasPointIntervalBounds(), u = (e) => {
486
+ let t = this.dataset.getY(e);
487
+ if (t < n || t > r) return !0;
488
+ if (s >= a) return c = !0, !1;
489
+ let l = s * 2;
490
+ return i[l] = this.dataset.getX(e) - o, i[l + 1] = t, s++, !0;
491
+ }, f = (e, t) => {
492
+ for (let n = e; n < t; n++) if (!u(n)) return !1;
493
+ return !0;
494
+ }, p = (e, t) => {
495
+ if (t <= e) return !0;
496
+ let i = l ? this.pointIntervalMinMaxY(e, t) : null;
497
+ if (i && (i.maxY < n || i.minY > r)) return !0;
498
+ if (t - e <= d || !l) return f(e, t);
499
+ let a = e + (t - e >> 1);
500
+ return p(e, a) && p(a, t);
501
+ };
502
+ return p(e, t), {
503
+ count: s,
504
+ overflow: c
505
+ };
506
+ }
507
+ copyVisibleSamples(e, t, n, r, i, a) {
508
+ if (c(this.dataset)) return this.dataset.copyVisibleSamples(e, t, n, r, i, a);
509
+ let o = r === "points" ? 2 : 4;
510
+ if (n <= 0 || t.length < n * o) return 0;
511
+ let s = this.dataset.lowerBoundX(e.xMin), l = this.dataset.upperBoundX(e.xMax), u = l - s;
512
+ if (u <= 0) return 0;
513
+ let d = Math.max(1, Math.ceil(u / n)), f = 0;
514
+ for (let e = s; e < l && f < n; e += d) {
515
+ let n = this.dataset.getX(e) - a, o = this.dataset.getY(e);
516
+ if (r === "points") {
517
+ let e = f * 2;
518
+ t[e] = n, t[e + 1] = o;
519
+ } else {
520
+ let e = f * 4;
521
+ t[e] = n, t[e + 1] = i, t[e + 2] = n, t[e + 3] = o;
522
+ }
523
+ f++;
524
+ }
525
+ return f;
526
+ }
527
+ copySampleRange(e, t, n, r, i, a, s) {
528
+ if (o(this.dataset)) return this.dataset.copySamplesRange(e, t, n, r, i, a, s);
529
+ let c = i === "points" ? 2 : 4;
530
+ if (r <= 0 || n.length < r * c) return 0;
531
+ let l = Math.max(0, Math.floor(e)), u = Math.min(this.dataset.length, Math.ceil(t)), d = Math.min(r, Math.max(0, u - l));
532
+ for (let e = 0; e < d; e++) {
533
+ let t = l + e, r = this.dataset.getX(t) - s, o = this.dataset.getY(t);
534
+ if (i === "points") {
535
+ let t = e * 2;
536
+ n[t] = r, n[t + 1] = o;
537
+ } else {
538
+ let t = e * 4;
539
+ n[t] = r, n[t + 1] = a, n[t + 2] = r, n[t + 3] = o;
540
+ }
541
+ }
542
+ return d;
543
+ }
544
+ copyMinMaxSegments(e, t, n, r, i) {
545
+ if (s(this.dataset)) return this.dataset.copyMinMaxSegments(e, t, n, r, i);
546
+ let a = r === "line-list" ? 4 : 3;
547
+ if (!this.pyramid || n <= 0 || t.length < n * a) return 0;
548
+ let o = this.dataset.lowerBoundX(e.xMin), c = this.dataset.upperBoundX(e.xMax), l = c - o;
549
+ if (l <= 0) return 0;
550
+ let u = Math.min(n, l);
551
+ for (let e = 0; e < u; e++) {
552
+ let n = o + Math.floor(e * l / u), a = o + Math.max(Math.floor((e + 1) * l / u), Math.floor(e * l / u) + 1), s = Math.min(c, a), d = this.minMaxForRange(n, s);
553
+ if (!d) continue;
554
+ let f = this.dataset.getX(n + (s - n >> 1)) - i, { minY: p, maxY: m } = d;
555
+ if (r === "line-list") {
556
+ let n = e * 4;
557
+ t[n] = f, t[n + 1] = p, t[n + 2] = f, t[n + 3] = m;
558
+ } else {
559
+ let n = e * 3;
560
+ t[n] = f, t[n + 1] = p, t[n + 2] = m;
561
+ }
562
+ }
563
+ return u;
564
+ }
565
+ minMaxForRange(e, t) {
566
+ return this._useDatasetRangeMinMax && r(this.dataset) ? this.dataset.rangeMinMaxY(e, t) : !this.pyramid || this._useRawMinMaxScan ? this.rawMinMaxForRange(e, t) : this.pyramid.rangeMinMax(this.dataset, e, t);
567
+ }
568
+ queryRangeMinMax(e, t, n) {
569
+ if (n <= 0 || t <= 0 || !r(this.dataset)) return {
570
+ buckets: new Float32Array(),
571
+ bucketCount: 0,
572
+ level: 0,
573
+ samplesPerPixel: 0
574
+ };
575
+ let i = Math.max(1, t / n), a = Math.max(0, Math.ceil(Math.log2(i)) - 1), o = 2 ** (a + 1), s = Math.max(0, e), c = s + t, l = Math.ceil(this.dataset.length / o), u = Math.max(0, Math.floor(s / o)), d = Math.min(l, Math.ceil(c / o)), f = Math.max(0, d - u), p = new Float32Array(f * 2);
576
+ for (let e = 0; e < f; e++) {
577
+ let t = (u + e) * o, n = Math.min(this.dataset.length, t + o), r = this.dataset.rangeMinMaxY(t, n);
578
+ r && (p[e * 2] = r.minY, p[e * 2 + 1] = r.maxY);
579
+ }
580
+ return {
581
+ buckets: p,
582
+ bucketCount: f,
583
+ level: a,
584
+ samplesPerPixel: i
585
+ };
586
+ }
587
+ rawMinMaxForRange(e, t) {
588
+ if (r(this.dataset)) return this.dataset.rangeMinMaxY(e, t);
589
+ let n = Math.max(0, Math.floor(e)), i = Math.min(this.dataset.length, Math.ceil(t));
590
+ if (i <= n) return null;
591
+ let a = Infinity, o = -Infinity;
592
+ for (let e = n; e < i; e++) {
593
+ let t = this.dataset.getY(e);
594
+ t < a && (a = t), t > o && (o = t);
595
+ }
596
+ return {
597
+ minY: a,
598
+ maxY: o
599
+ };
600
+ }
601
+ };
602
+ //#endregion
603
+ //#region src/core/search.ts
604
+ function h(e, t, n) {
605
+ let r = 0, i = e;
606
+ for (; r < i;) {
607
+ let e = r + (i - r >> 1);
608
+ t(e) < n ? r = e + 1 : i = e;
609
+ }
610
+ return r;
611
+ }
612
+ function g(e, t, n) {
613
+ let r = 0, i = e;
614
+ for (; r < i;) {
615
+ let e = r + (i - r >> 1);
616
+ t(e) <= n ? r = e + 1 : i = e;
617
+ }
618
+ return r;
619
+ }
620
+ //#endregion
621
+ //#region src/core/RingBuffer.ts
622
+ var _ = class e {
623
+ capacity;
624
+ _length = 0;
625
+ _head = 0;
626
+ xData;
627
+ yData;
628
+ treeBase;
629
+ minTree;
630
+ maxTree;
631
+ overflow;
632
+ constructor(t, n = {}) {
633
+ if (!Number.isInteger(t) || t <= 0) throw RangeError("RingBuffer capacity must be a positive integer.");
634
+ this.capacity = t, this.overflow = n.overflow ?? "wrap", this.xData = new Float64Array(t), this.yData = new Float32Array(t), this.treeBase = e.nextPowerOfTwo(t), this.minTree = new Float32Array(this.treeBase * 2), this.maxTree = new Float32Array(this.treeBase * 2), this.minTree.fill(Infinity), this.maxTree.fill(-Infinity);
635
+ }
636
+ get length() {
637
+ return this._length;
638
+ }
639
+ get range() {
640
+ return this._length === 0 ? null : {
641
+ start: this.getX(0),
642
+ end: this.getX(this._length - 1)
643
+ };
644
+ }
645
+ push(e, t) {
646
+ if (this._length >= this.capacity) {
647
+ if (this.overflow === "drop-new") return;
648
+ if (this.overflow === "error") throw RangeError("RingBuffer capacity exceeded.");
649
+ }
650
+ this.xData[this._head] = e, this.yData[this._head] = t, this.setTreeLeaf(this._head, t), this._head = (this._head + 1) % this.capacity, this._length < this.capacity && this._length++;
651
+ }
652
+ append(e, t) {
653
+ let n = Math.min(e.length, t.length);
654
+ if (!(n <= 0)) {
655
+ if (this.overflow !== "wrap") {
656
+ let r = this.capacity - this._length;
657
+ if (n > r && this.overflow === "error") throw RangeError("RingBuffer capacity exceeded.");
658
+ let i = Math.min(n, r);
659
+ if (i <= 0) return;
660
+ this.appendNoWrap(e, t, 0, i);
661
+ return;
662
+ }
663
+ if (n >= this.capacity) {
664
+ let r = n - this.capacity;
665
+ this._head = 0, this._length = this.capacity, this.copyIntoPhysical(0, e, t, r, this.capacity);
666
+ return;
667
+ }
668
+ this.appendNoWrap(e, t, 0, n);
669
+ }
670
+ }
671
+ get(e) {
672
+ return e < 0 || e >= this._length ? null : {
673
+ x: this.getX(e),
674
+ y: this.getY(e)
675
+ };
676
+ }
677
+ getX(e) {
678
+ return this.assertValidIndex(e), this.xData[this.logicalToPhysical(e)];
679
+ }
680
+ getY(e) {
681
+ return this.assertValidIndex(e), this.yData[this.logicalToPhysical(e)];
682
+ }
683
+ lowerBoundX(e) {
684
+ return h(this._length, (e) => this.getX(e), e);
685
+ }
686
+ upperBoundX(e) {
687
+ return g(this._length, (e) => this.getX(e), e);
688
+ }
689
+ rangeMinMaxY(e, t) {
690
+ let n = Math.max(0, Math.floor(e)), r = Math.min(this._length, Math.ceil(t));
691
+ if (r <= n) return null;
692
+ let i = this.logicalToPhysical(n), a = r - n;
693
+ if (i + a <= this.capacity) return this.queryPhysicalMinMax(i, i + a);
694
+ let o = this.queryPhysicalMinMax(i, this.capacity), s = this.queryPhysicalMinMax(0, (i + a) % this.capacity);
695
+ return o ? s ? {
696
+ minY: Math.min(o.minY, s.minY),
697
+ maxY: Math.max(o.maxY, s.maxY)
698
+ } : o : s;
699
+ }
700
+ clear() {
701
+ this._length = 0, this._head = 0, this.minTree.fill(Infinity), this.maxTree.fill(-Infinity);
702
+ }
703
+ appendNoWrap(e, t, n, r) {
704
+ let i = n, a = r;
705
+ for (; a > 0;) {
706
+ let n = Math.min(a, this.capacity - this._head);
707
+ this.copyIntoPhysical(this._head, e, t, i, n), this._head = (this._head + n) % this.capacity, this._length = Math.min(this.capacity, this._length + n), i += n, a -= n;
708
+ }
709
+ }
710
+ copyIntoPhysical(e, t, n, r, i) {
711
+ for (let a = 0; a < i; a++) {
712
+ let i = e + a, o = n[r + a];
713
+ this.xData[i] = t[r + a], this.yData[i] = o;
714
+ let s = this.treeBase + i;
715
+ this.minTree[s] = o, this.maxTree[s] = o;
716
+ }
717
+ this.recomputeTreeRange(e, e + i);
718
+ }
719
+ setTreeLeaf(e, t) {
720
+ let n = this.treeBase + e;
721
+ for (this.minTree[n] = t, this.maxTree[n] = t, n >>= 1; n >= 1;) this.recomputeTreeNode(n), n >>= 1;
722
+ }
723
+ recomputeTreeRange(e, t) {
724
+ let n = this.treeBase + e >> 1, r = this.treeBase + t - 1 >> 1;
725
+ for (; n >= 1;) {
726
+ for (let e = n; e <= r; e++) this.recomputeTreeNode(e);
727
+ if (n === 1) break;
728
+ n >>= 1, r >>= 1;
729
+ }
730
+ }
731
+ recomputeTreeNode(e) {
732
+ let t = e << 1, n = t + 1, r = this.minTree[t], i = this.minTree[n], a = this.maxTree[t], o = this.maxTree[n];
733
+ this.minTree[e] = r < i ? r : i, this.maxTree[e] = a > o ? a : o;
734
+ }
735
+ queryPhysicalMinMax(e, t) {
736
+ if (t <= e) return null;
737
+ let n = this.treeBase + e, r = this.treeBase + t, i = Infinity, a = -Infinity;
738
+ for (; n < r;) {
739
+ if (n & 1) {
740
+ let e = this.minTree[n], t = this.maxTree[n];
741
+ e < i && (i = e), t > a && (a = t), n++;
742
+ }
743
+ if (r & 1) {
744
+ r--;
745
+ let e = this.minTree[r], t = this.maxTree[r];
746
+ e < i && (i = e), t > a && (a = t);
747
+ }
748
+ n >>= 1, r >>= 1;
749
+ }
750
+ return Number.isFinite(i) && Number.isFinite(a) ? {
751
+ minY: i,
752
+ maxY: a
753
+ } : null;
754
+ }
755
+ logicalToPhysical(e) {
756
+ return (this._head - this._length + e + this.capacity) % this.capacity;
757
+ }
758
+ assertValidIndex(e) {
759
+ if (!Number.isInteger(e) || e < 0 || e >= this._length) throw RangeError(`RingBuffer index out of range: ${e}`);
760
+ }
761
+ static nextPowerOfTwo(e) {
762
+ return 2 ** Math.ceil(Math.log2(e));
763
+ }
764
+ }, v = "attribute vec2 position;\n\nuniform vec2 uScale;\nuniform vec2 uOffset;\n\nvoid main() {\n vec2 clipSpace = position * uScale + uOffset;\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n}\n", y = "precision mediump float;\n\nuniform vec4 uColor;\n\nvoid main() {\n gl_FragColor = uColor;\n}\n", b = "attribute float aX;\nattribute float aMinY;\nattribute float aMaxY;\nattribute float aSelect;\n\nuniform vec2 uScale;\nuniform vec2 uOffset;\n\nvoid main() {\n float y = (aSelect < 0.5) ? aMinY : aMaxY;\n vec2 position = vec2(aX, y);\n vec2 clipSpace = position * uScale + uOffset;\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n}\n", x = "precision mediump float;\n\nuniform vec4 uColor;\n\nvoid main() {\n gl_FragColor = uColor;\n}\n", S = "attribute vec2 aPosition;\nattribute vec2 aCorner;\n\nuniform vec2 uScale;\nuniform vec2 uOffset;\nuniform vec2 uCanvasSize;\nuniform float uPointSize;\n\nvoid main() {\n vec2 centerClip = aPosition * uScale + uOffset;\n vec2 pointSizeClip = vec2(2.0 / uCanvasSize.x, 2.0 / uCanvasSize.y) * uPointSize * 0.5;\n vec2 clipSpace = centerClip + aCorner * pointSizeClip;\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n}\n", ee = "precision mediump float;\n\nuniform vec4 uColor;\n\nvoid main() {\n gl_FragColor = uColor;\n}\n", te = "attribute vec2 aPosition;\n\nuniform vec2 uScale;\nuniform vec2 uOffset;\nuniform float uPointSize;\n\nvoid main() {\n vec2 clipSpace = aPosition * uScale + uOffset;\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n gl_PointSize = uPointSize;\n}\n", ne = "precision mediump float;\n\nuniform vec4 uColor;\n\nvoid main() {\n vec2 p = gl_PointCoord * 2.0 - 1.0;\n if (dot(p, p) > 1.0) discard;\n gl_FragColor = uColor;\n}\n", re = "attribute vec2 aPosition;\nattribute vec2 aCorner;\n\nuniform vec2 uScale;\nuniform vec2 uOffset;\nuniform float uBarWidth;\nuniform float uBaseline;\n\nvoid main() {\n float x = aPosition.x + aCorner.x * uBarWidth;\n float y = mix(uBaseline, aPosition.y, aCorner.y);\n vec2 clipSpace = vec2(x, y) * uScale + uOffset;\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n}\n", ie = "attribute float aX;\nattribute float aMinY;\nattribute float aMaxY;\nattribute vec2 aCorner;\n\nuniform vec2 uScale;\nuniform vec2 uOffset;\nuniform float uBarWidth;\n\nvoid main() {\n float x = aX + aCorner.x * uBarWidth;\n float y = mix(aMinY, aMaxY, aCorner.y);\n vec2 clipSpace = vec2(x, y) * uScale + uOffset;\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n}\n", ae = "precision mediump float;\n\nuniform vec4 uColor;\n\nvoid main() {\n gl_FragColor = uColor;\n}\n", C = {
765
+ line: {
766
+ vert: v,
767
+ frag: y
768
+ },
769
+ segment: {
770
+ vert: b,
771
+ frag: x
772
+ },
773
+ point: {
774
+ vert: S,
775
+ frag: ee
776
+ },
777
+ pointSprite: {
778
+ vert: te,
779
+ frag: ne
780
+ },
781
+ bar: {
782
+ vert: re,
783
+ frag: ae
784
+ },
785
+ barRange: {
786
+ vert: ie,
787
+ frag: ae
788
+ }
789
+ }, w = 3, T = 2, E = 4, oe = 4, se = .8, ce = 0, le = class {
790
+ backend;
791
+ lineProgram;
792
+ segmentProgram;
793
+ pointProgram;
794
+ pointSpriteProgram;
795
+ barProgram;
796
+ barRangeProgram;
797
+ segmentSelectBuffer;
798
+ pointCornerBuffer;
799
+ barCornerBuffer;
800
+ scaleUniform = new Float32Array(2);
801
+ offsetUniform = new Float32Array(2);
802
+ canvasSizeUniform = new Float32Array(2);
803
+ xOrigin = 0;
804
+ constructor(e) {
805
+ this.backend = e, this.lineProgram = this.backend.createProgram(C.line.vert, C.line.frag), this.segmentProgram = this.backend.createProgram(C.segment.vert, C.segment.frag), this.pointProgram = this.backend.createProgram(C.point.vert, C.point.frag), this.pointSpriteProgram = this.backend.createProgram(C.pointSprite.vert, C.pointSprite.frag), this.barProgram = this.backend.createProgram(C.bar.vert, C.bar.frag), this.barRangeProgram = this.backend.createProgram(C.barRange.vert, C.barRange.frag), this.segmentSelectBuffer = this.backend.createBuffer({
806
+ usage: "static",
807
+ type: "float",
808
+ length: 2
809
+ }), this.backend.updateBuffer(this.segmentSelectBuffer, new Float32Array([0, 1])), this.pointCornerBuffer = this.backend.createBuffer({
810
+ usage: "static",
811
+ type: "float",
812
+ length: 8
813
+ }), this.backend.updateBuffer(this.pointCornerBuffer, new Float32Array([
814
+ -1,
815
+ -1,
816
+ 1,
817
+ -1,
818
+ -1,
819
+ 1,
820
+ 1,
821
+ 1
822
+ ])), this.barCornerBuffer = this.backend.createBuffer({
823
+ usage: "static",
824
+ type: "float",
825
+ length: 8
826
+ }), this.backend.updateBuffer(this.barCornerBuffer, new Float32Array([
827
+ -.5,
828
+ 0,
829
+ .5,
830
+ 0,
831
+ -.5,
832
+ 1,
833
+ .5,
834
+ 1
835
+ ]));
836
+ }
837
+ get supportsInstancedSegments() {
838
+ return this.backend.capabilities.instancing;
839
+ }
840
+ get supportsInstancedPoints() {
841
+ return this.backend.capabilities.instancing;
842
+ }
843
+ get supportsInstancedBars() {
844
+ return this.backend.capabilities.instancing;
845
+ }
846
+ clear(e, t, n, r) {
847
+ this.backend.clear(e, t, n, r);
848
+ }
849
+ createFloatBuffer(e) {
850
+ return this.backend.createBuffer({
851
+ usage: "stream",
852
+ type: "float",
853
+ length: e
854
+ });
855
+ }
856
+ updateFloatBuffer(e, t, n = t.length) {
857
+ let r = Math.max(0, Math.min(n, t.length));
858
+ this.backend.updateBuffer(e, r === t.length ? t : t.subarray(0, r));
859
+ }
860
+ viewport(e, t, n, r) {
861
+ this.backend.viewport(e, t, n, r);
862
+ }
863
+ setXOrigin(e) {
864
+ this.xOrigin = Number.isFinite(e) ? e : 0;
865
+ }
866
+ getWebGLContext() {
867
+ return this.backend.getContext?.() ?? null;
868
+ }
869
+ drawLines(e, t, n, r) {
870
+ this.drawLinePrimitive("lines", e, t, n, r);
871
+ }
872
+ drawLineStrip(e, t, n, r) {
873
+ this.drawLinePrimitive("line_strip", e, t, n, r);
874
+ }
875
+ drawClipLineStrip(e, t, n) {
876
+ this.drawClipPrimitive("line_strip", e, t, n);
877
+ }
878
+ drawClipLines(e, t, n) {
879
+ this.drawClipPrimitive("lines", e, t, n);
880
+ }
881
+ drawMinMaxSegments(e, t, n, r) {
882
+ this.drawLines(e, t, n, r);
883
+ }
884
+ drawMinMaxSegmentsInstanced(e, t, n, r) {
885
+ this.writeCameraUniforms(r);
886
+ let i = w * E, a = {
887
+ buffer: e,
888
+ divisor: 1,
889
+ stride: i,
890
+ offset: 0
891
+ }, o = {
892
+ buffer: e,
893
+ divisor: 1,
894
+ stride: i,
895
+ offset: E
896
+ }, s = {
897
+ buffer: e,
898
+ divisor: 1,
899
+ stride: i,
900
+ offset: E * 2
901
+ }, c = {
902
+ buffer: this.segmentSelectBuffer,
903
+ divisor: 0,
904
+ stride: E,
905
+ offset: 0
906
+ };
907
+ this.backend.draw({
908
+ program: this.segmentProgram,
909
+ primitive: "lines",
910
+ count: 2,
911
+ instances: t,
912
+ attributes: {
913
+ aMaxY: s,
914
+ aMinY: o,
915
+ aSelect: c,
916
+ aX: a
917
+ },
918
+ uniforms: {
919
+ uScale: this.scaleUniform,
920
+ uOffset: this.offsetUniform,
921
+ uColor: n.color
922
+ }
923
+ });
924
+ }
925
+ drawPoints(e, t, n, r, i, a) {
926
+ this.supportsInstancedPoints ? this.drawPointsInstanced(e, t, n, r, i, a) : this.drawPointSprites(e, t, n, r);
927
+ }
928
+ drawPointsInstanced(e, t, n, r, i, a) {
929
+ this.writeCameraUniforms(r), this.canvasSizeUniform[0] = Math.max(1, i), this.canvasSizeUniform[1] = Math.max(1, a);
930
+ let o = {
931
+ buffer: e,
932
+ divisor: 1,
933
+ stride: T * E,
934
+ offset: 0,
935
+ size: 2
936
+ }, s = {
937
+ buffer: this.pointCornerBuffer,
938
+ divisor: 0,
939
+ stride: T * E,
940
+ offset: 0,
941
+ size: 2
942
+ };
943
+ this.backend.draw({
944
+ program: this.pointProgram,
945
+ primitive: "triangle_strip",
946
+ count: 4,
947
+ instances: t,
948
+ attributes: {
949
+ aCorner: s,
950
+ aPosition: o
951
+ },
952
+ uniforms: {
953
+ uScale: this.scaleUniform,
954
+ uOffset: this.offsetUniform,
955
+ uCanvasSize: this.canvasSizeUniform,
956
+ uPointSize: n.pointSize ?? oe,
957
+ uColor: n.color
958
+ }
959
+ });
960
+ }
961
+ drawPointSprites(e, t, n, r) {
962
+ this.writeCameraUniforms(r), this.backend.draw({
963
+ program: this.pointSpriteProgram,
964
+ primitive: "points",
965
+ count: t,
966
+ attributes: { aPosition: e },
967
+ uniforms: {
968
+ uScale: this.scaleUniform,
969
+ uOffset: this.offsetUniform,
970
+ uPointSize: n.pointSize ?? oe,
971
+ uColor: n.color
972
+ }
973
+ });
974
+ }
975
+ drawAreaStrip(e, t, n, r) {
976
+ this.writeCameraUniforms(r), this.backend.draw({
977
+ program: this.lineProgram,
978
+ primitive: "triangle_strip",
979
+ count: t,
980
+ attributes: { position: e },
981
+ uniforms: {
982
+ uScale: this.scaleUniform,
983
+ uOffset: this.offsetUniform,
984
+ uColor: n.fillColor ?? n.color
985
+ }
986
+ });
987
+ }
988
+ drawBarsInstanced(e, t, n, r) {
989
+ this.writeCameraUniforms(r);
990
+ let i = {
991
+ buffer: e,
992
+ divisor: 1,
993
+ stride: T * E,
994
+ offset: 0,
995
+ size: 2
996
+ }, a = {
997
+ buffer: this.barCornerBuffer,
998
+ divisor: 0,
999
+ stride: T * E,
1000
+ offset: 0,
1001
+ size: 2
1002
+ };
1003
+ this.backend.draw({
1004
+ program: this.barProgram,
1005
+ primitive: "triangle_strip",
1006
+ count: 4,
1007
+ instances: t,
1008
+ attributes: {
1009
+ aCorner: a,
1010
+ aPosition: i
1011
+ },
1012
+ uniforms: {
1013
+ uScale: this.scaleUniform,
1014
+ uOffset: this.offsetUniform,
1015
+ uBarWidth: n.barWidth ?? se,
1016
+ uBaseline: n.baseline ?? ce,
1017
+ uColor: n.color
1018
+ }
1019
+ });
1020
+ }
1021
+ drawBarRangesInstanced(e, t, n, r) {
1022
+ this.writeCameraUniforms(r);
1023
+ let i = w * E, a = {
1024
+ buffer: e,
1025
+ divisor: 1,
1026
+ stride: i,
1027
+ offset: 0
1028
+ }, o = {
1029
+ buffer: e,
1030
+ divisor: 1,
1031
+ stride: i,
1032
+ offset: E
1033
+ }, s = {
1034
+ buffer: e,
1035
+ divisor: 1,
1036
+ stride: i,
1037
+ offset: E * 2
1038
+ }, c = {
1039
+ buffer: this.barCornerBuffer,
1040
+ divisor: 0,
1041
+ stride: T * E,
1042
+ offset: 0,
1043
+ size: 2
1044
+ };
1045
+ this.backend.draw({
1046
+ program: this.barRangeProgram,
1047
+ primitive: "triangle_strip",
1048
+ count: 4,
1049
+ instances: t,
1050
+ attributes: {
1051
+ aCorner: c,
1052
+ aMaxY: s,
1053
+ aMinY: o,
1054
+ aX: a
1055
+ },
1056
+ uniforms: {
1057
+ uScale: this.scaleUniform,
1058
+ uOffset: this.offsetUniform,
1059
+ uBarWidth: n.barWidth ?? se,
1060
+ uColor: n.color
1061
+ }
1062
+ });
1063
+ }
1064
+ drawBarTriangles(e, t, n, r) {
1065
+ this.drawTrianglePrimitive(e, t, n, r);
1066
+ }
1067
+ drawLinePrimitive(e, t, n, r, i) {
1068
+ this.writeCameraUniforms(i), this.backend.draw({
1069
+ program: this.lineProgram,
1070
+ primitive: e,
1071
+ count: n,
1072
+ attributes: { position: t },
1073
+ uniforms: {
1074
+ uScale: this.scaleUniform,
1075
+ uOffset: this.offsetUniform,
1076
+ uColor: r.color
1077
+ }
1078
+ });
1079
+ }
1080
+ drawTrianglePrimitive(e, t, n, r) {
1081
+ this.writeCameraUniforms(r), this.backend.draw({
1082
+ program: this.lineProgram,
1083
+ primitive: "triangles",
1084
+ count: t,
1085
+ attributes: { position: e },
1086
+ uniforms: {
1087
+ uScale: this.scaleUniform,
1088
+ uOffset: this.offsetUniform,
1089
+ uColor: n.color
1090
+ }
1091
+ });
1092
+ }
1093
+ drawClipPrimitive(e, t, n, r) {
1094
+ this.scaleUniform[0] = 1, this.scaleUniform[1] = 1, this.offsetUniform[0] = 0, this.offsetUniform[1] = 0, this.backend.draw({
1095
+ program: this.lineProgram,
1096
+ primitive: e,
1097
+ count: n,
1098
+ attributes: { position: t },
1099
+ uniforms: {
1100
+ uScale: this.scaleUniform,
1101
+ uOffset: this.offsetUniform,
1102
+ uColor: r.color
1103
+ }
1104
+ });
1105
+ }
1106
+ writeCameraUniforms(e) {
1107
+ let t = e.xMin - this.xOrigin, n = e.xMax - this.xOrigin;
1108
+ this.scaleUniform[0] = e.xScale, this.scaleUniform[1] = e.yScale, this.offsetUniform[0] = -(t + n) / (n - t), this.offsetUniform[1] = e.yOffset;
1109
+ }
1110
+ dispose() {
1111
+ this.backend.destroy();
1112
+ }
1113
+ }, D = [
1114
+ 1024,
1115
+ 4096,
1116
+ 16384,
1117
+ 32768,
1118
+ 131072
1119
+ ], ue = class {
1120
+ regl;
1121
+ pool = [];
1122
+ preAllocated = !1;
1123
+ constructor(e) {
1124
+ this.regl = e;
1125
+ }
1126
+ get reglInstance() {
1127
+ return this.regl;
1128
+ }
1129
+ preAllocate() {
1130
+ if (!this.preAllocated) {
1131
+ this.preAllocated = !0;
1132
+ for (let e of D) this.pool.push(this.createEntry(e, "stream"));
1133
+ }
1134
+ }
1135
+ acquire(e, t = "stream") {
1136
+ let n = e, r = this.findFree(n);
1137
+ if (!r) {
1138
+ let e = this.roundUp(n);
1139
+ r = this.createEntry(e, t), this.pool.push(r);
1140
+ }
1141
+ return r.inUse = !0, {
1142
+ buffer: r.buffer,
1143
+ array: r.floatArray
1144
+ };
1145
+ }
1146
+ release(e) {
1147
+ for (let t of this.pool) if (t.buffer === e) {
1148
+ t.inUse = !1;
1149
+ return;
1150
+ }
1151
+ }
1152
+ destroy() {
1153
+ for (let e of this.pool) e.buffer.destroy();
1154
+ this.pool.length = 0, this.preAllocated = !1;
1155
+ }
1156
+ createEntry(e, t) {
1157
+ return {
1158
+ buffer: this.regl.buffer({
1159
+ length: e * 4,
1160
+ usage: t,
1161
+ type: "float"
1162
+ }),
1163
+ floatArray: new Float32Array(e),
1164
+ floatCapacity: e,
1165
+ inUse: !1
1166
+ };
1167
+ }
1168
+ findFree(e) {
1169
+ return this.pool.find((t) => !t.inUse && t.floatCapacity >= e);
1170
+ }
1171
+ roundUp(e) {
1172
+ for (let t of D) if (t >= e) return t;
1173
+ let t = D[D.length - 1], n = 1 << 32 - Math.clz32(e - 1);
1174
+ return Math.max(t * 2, n);
1175
+ }
1176
+ };
1177
+ //#endregion
1178
+ //#region src/render/ReglBackend.ts
1179
+ function de(e) {
1180
+ return e;
1181
+ }
1182
+ var fe = class {
1183
+ gl;
1184
+ regl;
1185
+ resources;
1186
+ nextProgramId = 1;
1187
+ commandCache = /* @__PURE__ */ new Map();
1188
+ scissorBox = null;
1189
+ capabilities;
1190
+ constructor(t) {
1191
+ let n = t.getContext("webgl2", {
1192
+ alpha: !0,
1193
+ antialias: !1,
1194
+ depth: !1,
1195
+ stencil: !1,
1196
+ premultipliedAlpha: !1,
1197
+ preserveDrawingBuffer: !1,
1198
+ powerPreference: "high-performance"
1199
+ });
1200
+ if (!n) throw Error("BlazePlot requires WebGL2, but this browser/context does not support it.");
1201
+ this.gl = n, this.regl = e({
1202
+ gl: de(this.gl),
1203
+ extensions: [],
1204
+ optionalExtensions: ["angle_instanced_arrays", "ext_disjoint_timer_query_webgl2"]
1205
+ }), this.capabilities = { instancing: this.regl.hasExtension("angle_instanced_arrays") }, this.resources = new ue(this.regl), this.resources.preAllocate();
1206
+ }
1207
+ createBuffer(e) {
1208
+ let { buffer: t } = this.resources.acquire(e.length, e.usage);
1209
+ return {
1210
+ length: e.length,
1211
+ type: e.type,
1212
+ buffer: t
1213
+ };
1214
+ }
1215
+ updateBuffer(e, t, n = 0) {
1216
+ if (t.length + n > e.length) throw RangeError("GPU buffer update exceeds allocated buffer length.");
1217
+ let r = e.type === "float" ? 4 : 2;
1218
+ this.asReglBuffer(e).buffer.subdata(t, n * r);
1219
+ }
1220
+ createProgram(e, t) {
1221
+ return {
1222
+ id: this.nextProgramId++,
1223
+ vert: e,
1224
+ frag: t
1225
+ };
1226
+ }
1227
+ draw(e) {
1228
+ if (e.count <= 0) return;
1229
+ let t = this.asReglProgram(e.program), n = Object.keys(e.attributes).sort(), r = Object.keys(e.uniforms).sort(), i = [
1230
+ t.id,
1231
+ e.primitive,
1232
+ n.join(","),
1233
+ r.join(","),
1234
+ e.instances === void 0 ? 0 : 1
1235
+ ].join("|"), a = this.commandCache.get(i);
1236
+ a || (a = this.createDrawCommand(t, e.primitive, n, r, e.instances !== void 0), this.commandCache.set(i, a));
1237
+ let o = {};
1238
+ for (let t of n) o[t] = this.resolveAttribute(e.attributes[t]);
1239
+ let s = {
1240
+ count: e.count,
1241
+ instances: e.instances ?? 0,
1242
+ attributes: o,
1243
+ uniforms: e.uniforms
1244
+ };
1245
+ this.scissorBox && (s.scissorEnable = !0, s.scissorBox = {
1246
+ x: this.scissorBox.x,
1247
+ y: this.scissorBox.y,
1248
+ width: this.scissorBox.w,
1249
+ height: this.scissorBox.h
1250
+ }), a(s);
1251
+ }
1252
+ dispose(e) {
1253
+ this.isReglBuffer(e) && this.resources.release(e.buffer);
1254
+ }
1255
+ clear(e, t, n, r) {
1256
+ this.regl.clear({ color: [
1257
+ e,
1258
+ t,
1259
+ n,
1260
+ r
1261
+ ] });
1262
+ }
1263
+ viewport(e, t, n, r) {
1264
+ this.regl.poll(), this.scissorBox = {
1265
+ x: e,
1266
+ y: t,
1267
+ w: n,
1268
+ h: r
1269
+ };
1270
+ }
1271
+ getContext() {
1272
+ return this.gl;
1273
+ }
1274
+ destroy() {
1275
+ this.resources.destroy(), this.regl.destroy();
1276
+ }
1277
+ createDrawCommand(e, t, n, r, i) {
1278
+ let a = {};
1279
+ for (let e of n) a[e] = (t, n) => n.attributes[e];
1280
+ let o = {};
1281
+ for (let e of r) o[e] = (t, n) => n.uniforms[e];
1282
+ return this.regl({
1283
+ vert: e.vert,
1284
+ frag: e.frag,
1285
+ attributes: a,
1286
+ uniforms: o,
1287
+ primitive: this.toReglPrimitive(t),
1288
+ count: (e, t) => t.count,
1289
+ instances: i ? (e, t) => t.instances : void 0,
1290
+ depth: { enable: !1 },
1291
+ scissor: {
1292
+ enable: (e, t) => t.scissorEnable ?? !1,
1293
+ box: (e, t) => t.scissorBox ?? {
1294
+ x: 0,
1295
+ y: 0,
1296
+ width: 0,
1297
+ height: 0
1298
+ }
1299
+ }
1300
+ });
1301
+ }
1302
+ resolveAttribute(e) {
1303
+ return "divisor" in e ? {
1304
+ buffer: this.asReglBuffer(e.buffer).buffer,
1305
+ divisor: e.divisor,
1306
+ stride: e.stride,
1307
+ offset: e.offset,
1308
+ size: e.size
1309
+ } : this.asReglBuffer(e).buffer;
1310
+ }
1311
+ asReglBuffer(e) {
1312
+ return e;
1313
+ }
1314
+ asReglProgram(e) {
1315
+ return e;
1316
+ }
1317
+ isReglBuffer(e) {
1318
+ return "length" in e && "type" in e && "buffer" in e;
1319
+ }
1320
+ toReglPrimitive(e) {
1321
+ switch (e) {
1322
+ case "line_strip": return "line strip";
1323
+ case "triangle_strip": return "triangle strip";
1324
+ default: return e;
1325
+ }
1326
+ }
1327
+ }, O = class e {
1328
+ _xMin = 0;
1329
+ _xMax = 1;
1330
+ _yMin = 0;
1331
+ _yMax = 1;
1332
+ get xMin() {
1333
+ return this._xMin;
1334
+ }
1335
+ get xMax() {
1336
+ return this._xMax;
1337
+ }
1338
+ get yMin() {
1339
+ return this._yMin;
1340
+ }
1341
+ get yMax() {
1342
+ return this._yMax;
1343
+ }
1344
+ get viewport() {
1345
+ return {
1346
+ xMin: this._xMin,
1347
+ xMax: this._xMax,
1348
+ yMin: this._yMin,
1349
+ yMax: this._yMax
1350
+ };
1351
+ }
1352
+ get xScale() {
1353
+ return 2 / (this._xMax - this._xMin);
1354
+ }
1355
+ get xOffset() {
1356
+ return -(this._xMin + this._xMax) / (this._xMax - this._xMin);
1357
+ }
1358
+ get yScale() {
1359
+ return 2 / (this._yMax - this._yMin);
1360
+ }
1361
+ get yOffset() {
1362
+ return -(this._yMin + this._yMax) / (this._yMax - this._yMin);
1363
+ }
1364
+ setViewport(t) {
1365
+ let n = {
1366
+ xMin: t.xMin ?? this._xMin,
1367
+ xMax: t.xMax ?? this._xMax,
1368
+ yMin: t.yMin ?? this._yMin,
1369
+ yMax: t.yMax ?? this._yMax
1370
+ };
1371
+ e.assertValidViewport(n), this._xMin = n.xMin, this._xMax = n.xMax, this._yMin = n.yMin, this._yMax = n.yMax;
1372
+ }
1373
+ pan(t) {
1374
+ let { dx: n, dy: r } = t;
1375
+ e.assertFinite("dx", n), e.assertFinite("dy", r);
1376
+ let i = this._xMax - this._xMin, a = this._yMax - this._yMin;
1377
+ this.setViewport({
1378
+ xMin: this._xMin + n * i,
1379
+ xMax: this._xMax + n * i,
1380
+ yMin: this._yMin + r * a,
1381
+ yMax: this._yMax + r * a
1382
+ });
1383
+ }
1384
+ zoom(t) {
1385
+ let { factor: n, cx: r, cy: i, axis: a } = t;
1386
+ if (e.assertFinite("factor", n), e.assertFinite("cx", r), e.assertFinite("cy", i), n <= 0) throw RangeError("Camera2D zoom factor must be > 0.");
1387
+ let o = this._xMax - this._xMin, s = this._yMax - this._yMin, c = this._xMin + o * r, l = this._yMin + s * i, u = a === "y" ? o : o / n, d = a === "x" ? s : s / n;
1388
+ this.setViewport({
1389
+ xMin: c - u * r,
1390
+ xMax: c + u * (1 - r),
1391
+ yMin: l - d * i,
1392
+ yMax: l + d * (1 - i)
1393
+ });
1394
+ }
1395
+ toClip(e, t) {
1396
+ return [e * this.xScale + this.xOffset, t * this.yScale + this.yOffset];
1397
+ }
1398
+ toScreen(e, t, n, r) {
1399
+ return [(e + 1) * .5 * n, (1 - t) * .5 * r];
1400
+ }
1401
+ clone() {
1402
+ let t = new e();
1403
+ return t.setViewport(this.viewport), t;
1404
+ }
1405
+ static assertValidViewport(t) {
1406
+ if (e.assertFinite("xMin", t.xMin), e.assertFinite("xMax", t.xMax), e.assertFinite("yMin", t.yMin), e.assertFinite("yMax", t.yMax), t.xMax <= t.xMin) throw RangeError("Camera2D requires xMax > xMin.");
1407
+ if (t.yMax <= t.yMin) throw RangeError("Camera2D requires yMax > yMin.");
1408
+ }
1409
+ static assertFinite(e, t) {
1410
+ if (!Number.isFinite(t)) throw RangeError(`Camera2D ${e} must be finite.`);
1411
+ }
1412
+ }, k = 1e3, A = 60 * k, j = 60 * A, M = 24 * j, N = 30 * M, P = 365 * M, pe = [
1413
+ {
1414
+ unit: "millisecond",
1415
+ count: 1,
1416
+ approxMs: 1
1417
+ },
1418
+ {
1419
+ unit: "millisecond",
1420
+ count: 5,
1421
+ approxMs: 5
1422
+ },
1423
+ {
1424
+ unit: "millisecond",
1425
+ count: 10,
1426
+ approxMs: 10
1427
+ },
1428
+ {
1429
+ unit: "millisecond",
1430
+ count: 50,
1431
+ approxMs: 50
1432
+ },
1433
+ {
1434
+ unit: "millisecond",
1435
+ count: 100,
1436
+ approxMs: 100
1437
+ },
1438
+ {
1439
+ unit: "millisecond",
1440
+ count: 250,
1441
+ approxMs: 250
1442
+ },
1443
+ {
1444
+ unit: "millisecond",
1445
+ count: 500,
1446
+ approxMs: 500
1447
+ },
1448
+ {
1449
+ unit: "second",
1450
+ count: 1,
1451
+ approxMs: k
1452
+ },
1453
+ {
1454
+ unit: "second",
1455
+ count: 5,
1456
+ approxMs: 5 * k
1457
+ },
1458
+ {
1459
+ unit: "second",
1460
+ count: 15,
1461
+ approxMs: 15 * k
1462
+ },
1463
+ {
1464
+ unit: "second",
1465
+ count: 30,
1466
+ approxMs: 30 * k
1467
+ },
1468
+ {
1469
+ unit: "minute",
1470
+ count: 1,
1471
+ approxMs: A
1472
+ },
1473
+ {
1474
+ unit: "minute",
1475
+ count: 5,
1476
+ approxMs: 5 * A
1477
+ },
1478
+ {
1479
+ unit: "minute",
1480
+ count: 15,
1481
+ approxMs: 15 * A
1482
+ },
1483
+ {
1484
+ unit: "minute",
1485
+ count: 30,
1486
+ approxMs: 30 * A
1487
+ },
1488
+ {
1489
+ unit: "hour",
1490
+ count: 1,
1491
+ approxMs: j
1492
+ },
1493
+ {
1494
+ unit: "hour",
1495
+ count: 3,
1496
+ approxMs: 3 * j
1497
+ },
1498
+ {
1499
+ unit: "hour",
1500
+ count: 6,
1501
+ approxMs: 6 * j
1502
+ },
1503
+ {
1504
+ unit: "hour",
1505
+ count: 12,
1506
+ approxMs: 12 * j
1507
+ },
1508
+ {
1509
+ unit: "day",
1510
+ count: 1,
1511
+ approxMs: M
1512
+ },
1513
+ {
1514
+ unit: "day",
1515
+ count: 2,
1516
+ approxMs: 2 * M
1517
+ },
1518
+ {
1519
+ unit: "day",
1520
+ count: 7,
1521
+ approxMs: 7 * M
1522
+ },
1523
+ {
1524
+ unit: "month",
1525
+ count: 1,
1526
+ approxMs: N
1527
+ },
1528
+ {
1529
+ unit: "month",
1530
+ count: 3,
1531
+ approxMs: 3 * N
1532
+ },
1533
+ {
1534
+ unit: "month",
1535
+ count: 6,
1536
+ approxMs: 6 * N
1537
+ },
1538
+ {
1539
+ unit: "year",
1540
+ count: 1,
1541
+ approxMs: P
1542
+ },
1543
+ {
1544
+ unit: "year",
1545
+ count: 2,
1546
+ approxMs: 2 * P
1547
+ },
1548
+ {
1549
+ unit: "year",
1550
+ count: 5,
1551
+ approxMs: 5 * P
1552
+ },
1553
+ {
1554
+ unit: "year",
1555
+ count: 10,
1556
+ approxMs: 10 * P
1557
+ }
1558
+ ], me = [
1559
+ "Jan",
1560
+ "Feb",
1561
+ "Mar",
1562
+ "Apr",
1563
+ "May",
1564
+ "Jun",
1565
+ "Jul",
1566
+ "Aug",
1567
+ "Sep",
1568
+ "Oct",
1569
+ "Nov",
1570
+ "Dec"
1571
+ ], he = [
1572
+ "January",
1573
+ "February",
1574
+ "March",
1575
+ "April",
1576
+ "May",
1577
+ "June",
1578
+ "July",
1579
+ "August",
1580
+ "September",
1581
+ "October",
1582
+ "November",
1583
+ "December"
1584
+ ], ge = [
1585
+ "Sun",
1586
+ "Mon",
1587
+ "Tue",
1588
+ "Wed",
1589
+ "Thu",
1590
+ "Fri",
1591
+ "Sat"
1592
+ ], _e = [
1593
+ "Sunday",
1594
+ "Monday",
1595
+ "Tuesday",
1596
+ "Wednesday",
1597
+ "Thursday",
1598
+ "Friday",
1599
+ "Saturday"
1600
+ ], F = class {
1601
+ camera;
1602
+ options;
1603
+ lastXTimeInterval = null;
1604
+ lastYTimeInterval = null;
1605
+ constructor(e, t = {}) {
1606
+ this.camera = e, this.options = t;
1607
+ }
1608
+ setOptions(e) {
1609
+ this.options = e, this.lastXTimeInterval = null, this.lastYTimeInterval = null;
1610
+ }
1611
+ getXTickValues(e, t = 10, n = []) {
1612
+ let r = this.options.x;
1613
+ if (r?.scale === "time") {
1614
+ let i = this.getTimeTickValues(this.camera.xMin, this.camera.xMax, e, t, 80, n, r);
1615
+ return this.lastXTimeInterval = this.lastTimeInterval, i;
1616
+ }
1617
+ return this.lastXTimeInterval = null, this.getScaledTickValues(this.camera.xMin, this.camera.xMax, e, t, 80, n, r, "x");
1618
+ }
1619
+ getYTickValues(e, t = 10, n = []) {
1620
+ let r = this.options.y;
1621
+ if (r?.scale === "time") {
1622
+ let i = this.getTimeTickValues(this.camera.yMin, this.camera.yMax, e, t, 48, n, r);
1623
+ return this.lastYTimeInterval = this.lastTimeInterval, i;
1624
+ }
1625
+ return this.lastYTimeInterval = null, this.getScaledTickValues(this.camera.yMin, this.camera.yMax, e, t, 48, n, r, "y");
1626
+ }
1627
+ formatValue(e, t = "y") {
1628
+ let n = t === "x" ? this.options.x : this.options.y, r = n?.tickFormat;
1629
+ if (typeof r == "function") return r(e, t);
1630
+ if (n?.scale && typeof n.scale == "object") return n.scale.formatTick?.(e, t) ?? this.formatLinearValue(e);
1631
+ if (n?.scale === "categorical") {
1632
+ let t = Math.round(e);
1633
+ return n.categories?.[t] ?? String(t);
1634
+ }
1635
+ if (n?.scale === "time") {
1636
+ let i = t === "x" ? this.lastXTimeInterval : this.lastYTimeInterval;
1637
+ return this.formatTimeValue(e, r, n.timezone ?? "local", i);
1638
+ }
1639
+ return this.formatLinearValue(e);
1640
+ }
1641
+ lastTimeInterval = null;
1642
+ getScaledTickValues(e, t, n, r, i, a, o, s) {
1643
+ let c = o?.scale;
1644
+ if (c && typeof c == "object") {
1645
+ a.length = 0;
1646
+ let n = c.ticks?.(e, t, r) ?? [];
1647
+ for (let e of n) a.push(e);
1648
+ return a;
1649
+ }
1650
+ return c === "log" ? this.getLogTickValues(e, t, n, r, i, a, o?.logBase) : c === "categorical" ? this.getCategoricalTickValues(e, t, r, a, o?.categories) : c === "symlog" ? this.getSymlogTickValues(e, t, n, r, i, a, o?.symlogConstant) : this.getLinearTickValues(e, t, n, r, i, a);
1651
+ }
1652
+ getLogTickValues(e, t, n, r, i, a, o = 10) {
1653
+ a.length = 0;
1654
+ let s = Number.isFinite(o) && o > 1 ? o : 10;
1655
+ if (n <= 0 || r <= 0 || e <= 0 || t <= e) return a;
1656
+ let c = Math.max(2, Math.min(r, Math.floor(n / i))), l = Math.floor(Math.log(e) / Math.log(s)), u = Math.ceil(Math.log(t) / Math.log(s)), d = Math.max(1, Math.ceil((u - l) / Math.max(1, c - 1)));
1657
+ for (let n = l; n <= u && a.length < r + 2; n += d) {
1658
+ let r = s ** n;
1659
+ r >= e / s && r <= t * s && a.push(r);
1660
+ }
1661
+ return a;
1662
+ }
1663
+ getSymlogTickValues(e, t, n, r, i, a, o = 1) {
1664
+ let s = Number.isFinite(o) && o > 0 ? o : 1, c = (e) => Math.sign(e) * Math.log1p(Math.abs(e) / s), l = (e) => Math.sign(e) * s * Math.expm1(Math.abs(e)), u = this.getLinearTickValues(c(e), c(t), n, r, i, a);
1665
+ for (let e = 0; e < u.length; e++) u[e] = this.normalizeTick(l(u[e]), Math.abs(l(u[1] ?? u[0] ?? 1) - l(u[0] ?? 0)) || 1);
1666
+ return u;
1667
+ }
1668
+ getCategoricalTickValues(e, t, n, r, i) {
1669
+ r.length = 0;
1670
+ let a = Math.max(0, Math.ceil(e)), o = Math.min(i ? i.length - 1 : Math.floor(t), Math.floor(t));
1671
+ if (o < a || n <= 0) return r;
1672
+ let s = Math.max(1, Math.ceil((o - a + 1) / n));
1673
+ for (let e = a; e <= o && r.length < n; e += s) r.push(e);
1674
+ return r;
1675
+ }
1676
+ formatLinearValue(e) {
1677
+ if (Math.abs(e) < 1e-12) return "0";
1678
+ let t = Math.abs(e);
1679
+ return t >= 1e6 || t < .001 ? e.toExponential(2) : t >= 100 ? e.toFixed(0) : t >= 10 ? e.toFixed(1) : e.toFixed(2);
1680
+ }
1681
+ getLinearTickValues(e, t, n, r, i, a) {
1682
+ if (a.length = 0, n <= 0 || r <= 0) return a;
1683
+ let o = t - e;
1684
+ if (!Number.isFinite(o) || o <= 0) return a;
1685
+ let s = Math.max(2, Math.min(r, Math.floor(n / i))), c = this.niceStep(o / (s - 1)), l = Math.floor(e / c), u = Math.ceil(t / c);
1686
+ for (let e = l; e <= u && a.length < r + 2; e++) a.push(this.normalizeTick(e * c, c));
1687
+ return a;
1688
+ }
1689
+ getTimeTickValues(e, t, n, r, i, a, o) {
1690
+ if (a.length = 0, this.lastTimeInterval = null, n <= 0 || r <= 0) return a;
1691
+ let s = t - e;
1692
+ if (!Number.isFinite(s) || s <= 0) return a;
1693
+ let c = Math.max(2, Math.min(r, Math.floor(n / i))), l = this.chooseTimeInterval(s / (c - 1)), u = o.timezone ?? "local";
1694
+ this.lastTimeInterval = l;
1695
+ let d = this.floorTime(e, l, u), f = 0;
1696
+ for (; d < e && f < 4;) {
1697
+ let e = this.advanceTime(d, l, u);
1698
+ if (e <= d) break;
1699
+ d = e, f++;
1700
+ }
1701
+ let p = this.floorTime(e, l, u);
1702
+ p < d && a.length === 0 && (d = p);
1703
+ for (let e = 0; e < r + 2 && d <= t; e++) {
1704
+ a.push(d);
1705
+ let e = this.advanceTime(d, l, u);
1706
+ if (e <= d) break;
1707
+ d = e;
1708
+ }
1709
+ return a.length === 0 && a.push(e, t), a;
1710
+ }
1711
+ chooseTimeInterval(e) {
1712
+ for (let t of pe) if (t.approxMs >= e) return t;
1713
+ let t = Math.max(10, Math.ceil(e / P)), n = 10 ** Math.floor(Math.log10(t)), r = t / n, i = r <= 1 ? n : r <= 2 ? 2 * n : r <= 5 ? 5 * n : 10 * n;
1714
+ return {
1715
+ unit: "year",
1716
+ count: i,
1717
+ approxMs: i * P
1718
+ };
1719
+ }
1720
+ floorTime(e, t, n) {
1721
+ if (!Number.isFinite(e)) return e;
1722
+ if (t.unit === "millisecond") return Math.floor(e / t.count) * t.count;
1723
+ let r = new Date(e), i = n === "utc", a = i ? r.getUTCFullYear() : r.getFullYear(), o = i ? r.getUTCMonth() : r.getMonth(), s = i ? r.getUTCDate() : r.getDate(), c = i ? r.getUTCHours() : r.getHours(), l = i ? r.getUTCMinutes() : r.getMinutes(), u = i ? r.getUTCSeconds() : r.getSeconds();
1724
+ switch (t.unit) {
1725
+ case "second": return this.makeTime(n, a, o, s, c, l, Math.floor(u / t.count) * t.count, 0);
1726
+ case "minute": return this.makeTime(n, a, o, s, c, Math.floor(l / t.count) * t.count, 0, 0);
1727
+ case "hour": return this.makeTime(n, a, o, s, Math.floor(c / t.count) * t.count, 0, 0, 0);
1728
+ case "day": return this.makeTime(n, a, o, Math.floor((s - 1) / t.count) * t.count + 1, 0, 0, 0, 0);
1729
+ case "month": return this.makeTime(n, a, Math.floor(o / t.count) * t.count, 1, 0, 0, 0, 0);
1730
+ case "year": return this.makeTime(n, Math.floor(a / t.count) * t.count, 0, 1, 0, 0, 0, 0);
1731
+ }
1732
+ }
1733
+ advanceTime(e, t, n) {
1734
+ let r = new Date(e), i = n === "utc";
1735
+ switch (t.unit) {
1736
+ case "millisecond": return e + t.count;
1737
+ case "second": return i ? r.setUTCSeconds(r.getUTCSeconds() + t.count) : r.setSeconds(r.getSeconds() + t.count), r.getTime();
1738
+ case "minute": return i ? r.setUTCMinutes(r.getUTCMinutes() + t.count) : r.setMinutes(r.getMinutes() + t.count), r.getTime();
1739
+ case "hour": return i ? r.setUTCHours(r.getUTCHours() + t.count) : r.setHours(r.getHours() + t.count), r.getTime();
1740
+ case "day": return i ? r.setUTCDate(r.getUTCDate() + t.count) : r.setDate(r.getDate() + t.count), r.getTime();
1741
+ case "month": return i ? r.setUTCMonth(r.getUTCMonth() + t.count) : r.setMonth(r.getMonth() + t.count), r.getTime();
1742
+ case "year": return i ? r.setUTCFullYear(r.getUTCFullYear() + t.count) : r.setFullYear(r.getFullYear() + t.count), r.getTime();
1743
+ }
1744
+ }
1745
+ makeTime(e, t, n, r, i, a, o, s) {
1746
+ return e === "utc" ? Date.UTC(t, n, r, i, a, o, s) : new Date(t, n, r, i, a, o, s).getTime();
1747
+ }
1748
+ formatTimeValue(e, t, n, r) {
1749
+ let i = new Date(e);
1750
+ if (t) return this.formatTimePattern(i, t, n);
1751
+ let a = r?.approxMs ?? 0;
1752
+ return a > 0 && a < k ? this.formatTimePattern(i, "%H:%M:%S.%L", n) : a > 0 && a < M ? this.formatTimePattern(i, "%H:%M:%S", n) : a > 0 && a < P ? this.formatTimePattern(i, "%b %d", n) : this.formatTimePattern(i, "%Y", n);
1753
+ }
1754
+ formatTimePattern(e, t, n) {
1755
+ let r = n === "utc", i = r ? e.getUTCFullYear() : e.getFullYear(), a = r ? e.getUTCMonth() : e.getMonth(), o = r ? e.getUTCDate() : e.getDate(), s = r ? e.getUTCDay() : e.getDay(), c = r ? e.getUTCHours() : e.getHours(), l = r ? e.getUTCMinutes() : e.getMinutes(), u = r ? e.getUTCSeconds() : e.getSeconds(), d = r ? e.getUTCMilliseconds() : e.getMilliseconds();
1756
+ return t.replace(/%[YymdbBaAHMSL%]/g, (e) => {
1757
+ switch (e) {
1758
+ case "%Y": return String(i).padStart(4, "0");
1759
+ case "%y": return String(i % 100).padStart(2, "0");
1760
+ case "%m": return String(a + 1).padStart(2, "0");
1761
+ case "%d": return String(o).padStart(2, "0");
1762
+ case "%b": return me[a] ?? "";
1763
+ case "%B": return he[a] ?? "";
1764
+ case "%a": return ge[s] ?? "";
1765
+ case "%A": return _e[s] ?? "";
1766
+ case "%H": return String(c).padStart(2, "0");
1767
+ case "%M": return String(l).padStart(2, "0");
1768
+ case "%S": return String(u).padStart(2, "0");
1769
+ case "%L": return String(d).padStart(3, "0");
1770
+ case "%%": return "%";
1771
+ default: return e;
1772
+ }
1773
+ });
1774
+ }
1775
+ niceStep(e) {
1776
+ let t = 10 ** Math.floor(Math.log10(e)), n = e / t;
1777
+ return n <= 1.5 ? t : n <= 3 ? 2 * t : n <= 7 ? 5 * t : 10 * t;
1778
+ }
1779
+ normalizeTick(e, t) {
1780
+ let n = Math.max(0, -Math.floor(Math.log10(t)) + 2), r = Number(e.toFixed(n));
1781
+ return Object.is(r, -0) ? 0 : r;
1782
+ }
1783
+ }, I = class {
1784
+ layout;
1785
+ config;
1786
+ options;
1787
+ xPool = [];
1788
+ yPool = [];
1789
+ y2Pool = [];
1790
+ xTicks = [];
1791
+ yTicks = [];
1792
+ y2Ticks = [];
1793
+ constructor(e, t, n = {}) {
1794
+ this.layout = e, this.config = t, this.options = n;
1795
+ }
1796
+ setOptions(e) {
1797
+ this.options = e;
1798
+ for (let e of [
1799
+ ...this.xPool,
1800
+ ...this.yPool,
1801
+ ...this.y2Pool
1802
+ ]) e.style.font = this.options.font ?? "11px ui-monospace, monospace, sans-serif", e.style.color = this.options.color ?? "#bfd6ff";
1803
+ }
1804
+ update(e, t, n = e, r = t) {
1805
+ let i = Math.max(1, this.layout.plot.clientWidth), a = Math.max(1, this.layout.plot.clientHeight);
1806
+ this.config.x.visible ? t.getXTickValues(i, 12, this.xTicks) : this.xTicks.length = 0, this.config.y.visible ? t.getYTickValues(a, 8, this.yTicks) : this.yTicks.length = 0, this.config.y2.visible ? r.getYTickValues(a, 8, this.y2Ticks) : this.y2Ticks.length = 0, this.updateAxis(this.xPool, this.xTicks, "x", e, i, a, t), this.updateAxis(this.yPool, this.yTicks, "y", e, i, a, t), this.updateAxis(this.y2Pool, this.y2Ticks, "y2", n, i, a, r);
1807
+ }
1808
+ dispose() {
1809
+ for (let e of this.xPool) e.remove();
1810
+ for (let e of this.yPool) e.remove();
1811
+ for (let e of this.y2Pool) e.remove();
1812
+ this.xPool = [], this.yPool = [], this.y2Pool = [];
1813
+ }
1814
+ parentForAxis(e) {
1815
+ return e === "x" ? this.config.x.position === "outside" ? this.layout.xAxis : this.layout.plot : e === "y2" ? this.config.y2.position === "outside" ? this.layout.y2Axis : this.layout.plot : this.config.y.position === "outside" ? this.layout.yAxis : this.layout.plot;
1816
+ }
1817
+ updateAxis(e, t, n, r, i, a, o) {
1818
+ let s = this.parentForAxis(n);
1819
+ for (; e.length < t.length;) {
1820
+ let t = document.createElement("div");
1821
+ t.style.position = "absolute", t.style.pointerEvents = "none", t.style.whiteSpace = "nowrap", t.style.font = this.options.font ?? "11px ui-monospace, monospace, sans-serif", t.style.color = this.options.color ?? "#bfd6ff", t.style.userSelect = "none", s.appendChild(t), e.push(t);
1822
+ }
1823
+ for (let t of e) t.parentElement !== s && s.appendChild(t);
1824
+ for (let n = t.length; n < e.length; n++) e[n].style.display = "none";
1825
+ for (let s = 0; s < t.length; s++) {
1826
+ let c = e[s], l = t[s], u = o.formatValue(l, n === "x" ? "x" : "y");
1827
+ if (c.textContent !== u && (c.textContent = u), c.style.display = "block", n === "x") {
1828
+ let [e] = r.toClip(l, r.yMin), t = (e + 1) * .5 * i;
1829
+ c.style.left = `${t}px`, c.style.right = "auto", c.style.transform = "translateX(-50%)", this.config.x.position === "outside" ? (c.style.top = "4px", c.style.bottom = "auto") : (c.style.top = "auto", c.style.bottom = "4px");
1830
+ } else {
1831
+ let e = n === "y2", t = e ? this.config.y2 : this.config.y, [, i] = r.toClip(r.xMin, l), o = (1 - i) * .5 * a;
1832
+ c.style.top = `${o}px`, c.style.bottom = "auto", c.style.transform = "translateY(-50%)", t.position === "outside" ? (c.style.left = e ? "4px" : "auto", c.style.right = e ? "auto" : "4px") : (c.style.left = e ? "auto" : "4px", c.style.right = e ? "4px" : "auto");
1833
+ }
1834
+ }
1835
+ }
1836
+ }, ve = class {
1837
+ root;
1838
+ plot;
1839
+ canvas;
1840
+ xAxis;
1841
+ yAxis;
1842
+ y2Axis;
1843
+ corner;
1844
+ cornerRight;
1845
+ title;
1846
+ subtitle;
1847
+ xAxisTitle;
1848
+ yAxisTitle;
1849
+ y2AxisTitle;
1850
+ externalCanvas;
1851
+ originalCanvasCssText;
1852
+ originalCanvasParent;
1853
+ constructor(e, t) {
1854
+ let n = e instanceof HTMLCanvasElement ? e : null;
1855
+ this.externalCanvas = n !== null, this.originalCanvasCssText = n?.style.cssText ?? "", this.originalCanvasParent = n?.parentElement ?? null, this.root = document.createElement("div"), this.plot = document.createElement("div"), this.canvas = n ?? document.createElement("canvas"), this.xAxis = document.createElement("div"), this.yAxis = document.createElement("div"), this.y2Axis = document.createElement("div"), this.corner = document.createElement("div"), this.cornerRight = document.createElement("div"), this.title = document.createElement("div"), this.subtitle = document.createElement("div"), this.xAxisTitle = document.createElement("div"), this.yAxisTitle = document.createElement("div"), this.y2AxisTitle = document.createElement("div"), this.root.className = "blazeplot-root", this.plot.className = "blazeplot-plot", this.canvas.classList.add("blazeplot-canvas"), this.xAxis.className = "blazeplot-axis blazeplot-axis-x", this.yAxis.className = "blazeplot-axis blazeplot-axis-y", this.y2Axis.className = "blazeplot-axis blazeplot-axis-y2", this.corner.className = "blazeplot-axis-corner", this.cornerRight.className = "blazeplot-axis-corner blazeplot-axis-corner-right", this.title.className = "blazeplot-title", this.subtitle.className = "blazeplot-subtitle", this.xAxisTitle.className = "blazeplot-axis-title blazeplot-axis-title-x", this.yAxisTitle.className = "blazeplot-axis-title blazeplot-axis-title-y", this.y2AxisTitle.className = "blazeplot-axis-title blazeplot-axis-title-y2", this.applyBaseStyles(), this.mount(e), this.update(t);
1856
+ }
1857
+ update(e) {
1858
+ let t = e.y.visible && e.y.position === "outside", n = e.y2.visible && e.y2.position === "outside", r = e.x.visible && e.x.position === "outside";
1859
+ this.root.style.gridTemplateColumns = `${t ? 52 : 0}px minmax(0, 1fr) ${n ? 52 : 0}px`, this.root.style.gridTemplateRows = `minmax(0, 1fr) ${r ? 28 : 0}px`, this.yAxis.style.display = t ? "block" : "none", this.y2Axis.style.display = n ? "block" : "none", this.xAxis.style.display = r ? "block" : "none", this.corner.style.display = r && t ? "block" : "none", this.cornerRight.style.display = r && n ? "block" : "none";
1860
+ }
1861
+ dispose() {
1862
+ this.externalCanvas && this.originalCanvasParent && (this.canvas.style.cssText = this.originalCanvasCssText, this.originalCanvasParent.insertBefore(this.canvas, this.root)), this.root.remove();
1863
+ }
1864
+ mount(e) {
1865
+ this.externalCanvas ? this.originalCanvasParent?.insertBefore(this.root, e) : e.appendChild(this.root), this.root.appendChild(this.yAxis), this.root.appendChild(this.plot), this.root.appendChild(this.y2Axis), this.root.appendChild(this.corner), this.root.appendChild(this.xAxis), this.root.appendChild(this.cornerRight), this.root.appendChild(this.title), this.root.appendChild(this.subtitle), this.root.appendChild(this.xAxisTitle), this.root.appendChild(this.yAxisTitle), this.root.appendChild(this.y2AxisTitle), this.plot.appendChild(this.canvas);
1866
+ }
1867
+ applyBaseStyles() {
1868
+ this.root.style.position = "relative", this.root.style.display = "grid", this.root.style.width = "100%", this.root.style.height = "100%", this.root.style.minWidth = "0", this.root.style.minHeight = "0", this.root.style.overflow = "hidden", this.root.style.boxSizing = "border-box", this.plot.style.position = "relative", this.plot.style.gridColumn = "2", this.plot.style.gridRow = "1", this.plot.style.minWidth = "0", this.plot.style.minHeight = "0", this.plot.style.overflow = "hidden", this.canvas.style.position = "absolute", this.canvas.style.inset = "0", this.canvas.style.display = "block", this.canvas.style.width = "100%", this.canvas.style.height = "100%", this.canvas.style.touchAction = "none", this.yAxis.style.position = "relative", this.yAxis.style.gridColumn = "1", this.yAxis.style.gridRow = "1", this.yAxis.style.minWidth = "0", this.yAxis.style.minHeight = "0", this.yAxis.style.overflow = "hidden", this.yAxis.style.pointerEvents = "none", this.y2Axis.style.position = "relative", this.y2Axis.style.gridColumn = "3", this.y2Axis.style.gridRow = "1", this.y2Axis.style.minWidth = "0", this.y2Axis.style.minHeight = "0", this.y2Axis.style.overflow = "hidden", this.y2Axis.style.pointerEvents = "none", this.xAxis.style.position = "relative", this.xAxis.style.gridColumn = "2", this.xAxis.style.gridRow = "2", this.xAxis.style.minWidth = "0", this.xAxis.style.minHeight = "0", this.xAxis.style.overflow = "hidden", this.xAxis.style.pointerEvents = "none", this.corner.style.gridColumn = "1", this.corner.style.gridRow = "2", this.corner.style.minWidth = "0", this.corner.style.minHeight = "0", this.corner.style.pointerEvents = "none", this.cornerRight.style.gridColumn = "3", this.cornerRight.style.gridRow = "2", this.cornerRight.style.minWidth = "0", this.cornerRight.style.minHeight = "0", this.cornerRight.style.pointerEvents = "none";
1869
+ for (let e of [
1870
+ this.title,
1871
+ this.subtitle,
1872
+ this.xAxisTitle,
1873
+ this.yAxisTitle,
1874
+ this.y2AxisTitle
1875
+ ]) e.style.position = "absolute", e.style.pointerEvents = "none", e.style.userSelect = "none", e.style.whiteSpace = "nowrap", e.style.zIndex = "18", e.style.display = "none";
1876
+ this.title.style.top = "6px", this.title.style.left = "50%", this.title.style.transform = "translateX(-50%)", this.title.style.textAlign = "center", this.subtitle.style.top = "26px", this.subtitle.style.left = "50%", this.subtitle.style.transform = "translateX(-50%)", this.subtitle.style.textAlign = "center", this.xAxisTitle.style.left = "50%", this.xAxisTitle.style.bottom = "4px", this.xAxisTitle.style.transform = "translateX(-50%)", this.xAxisTitle.style.textAlign = "center", this.yAxisTitle.style.left = "4px", this.yAxisTitle.style.top = "50%", this.yAxisTitle.style.transform = "translateY(-50%) rotate(-90deg)", this.yAxisTitle.style.transformOrigin = "left center", this.y2AxisTitle.style.right = "4px", this.y2AxisTitle.style.top = "50%", this.y2AxisTitle.style.transform = "translateY(-50%) rotate(90deg)", this.y2AxisTitle.style.transformOrigin = "right center";
1877
+ }
1878
+ }, L = {
1879
+ backgroundColor: [
1880
+ .02,
1881
+ .02,
1882
+ .02,
1883
+ 1
1884
+ ],
1885
+ backgroundCssColor: "rgba(5, 5, 5, 1)",
1886
+ gridColor: [
1887
+ .22,
1888
+ .22,
1889
+ .22,
1890
+ .45
1891
+ ],
1892
+ axisColor: "#d4d4d4",
1893
+ axisFont: "11px ui-monospace, monospace, sans-serif",
1894
+ seriesColors: [
1895
+ [
1896
+ .3,
1897
+ .6,
1898
+ 1,
1899
+ 1
1900
+ ],
1901
+ [
1902
+ .95,
1903
+ .35,
1904
+ .35,
1905
+ 1
1906
+ ],
1907
+ [
1908
+ .2,
1909
+ .8,
1910
+ .4,
1911
+ .9
1912
+ ],
1913
+ [
1914
+ .95,
1915
+ .72,
1916
+ .25,
1917
+ 1
1918
+ ],
1919
+ [
1920
+ .72,
1921
+ .45,
1922
+ .95,
1923
+ 1
1924
+ ],
1925
+ [
1926
+ .25,
1927
+ .85,
1928
+ .95,
1929
+ 1
1930
+ ]
1931
+ ],
1932
+ tooltipBackgroundColor: "rgba(10, 10, 10, 0.88)",
1933
+ tooltipTextColor: "#e5e5e5",
1934
+ tooltipFont: "11px/1.35 ui-monospace, monospace",
1935
+ legendBackgroundColor: "rgba(10, 10, 10, 0.88)",
1936
+ legendBorderColor: "transparent",
1937
+ legendTextColor: "#e5e5e5",
1938
+ legendMutedTextColor: "#888",
1939
+ legendFont: "11px/1.35 ui-monospace, monospace",
1940
+ titleColor: "#f8fafc",
1941
+ titleFont: "600 14px system-ui, sans-serif",
1942
+ subtitleColor: "#cbd5e1",
1943
+ subtitleFont: "12px system-ui, sans-serif",
1944
+ axisTitleColor: "#d4d4d4",
1945
+ axisTitleFont: "12px system-ui, sans-serif"
1946
+ };
1947
+ function R(e, t) {
1948
+ if (!e) return L;
1949
+ let n = z(e.backgroundColor, L.backgroundColor, t), r = e.seriesColors?.length ? e.seriesColors.map((e, n) => z(e, L.seriesColors[n % L.seriesColors.length], t)) : L.seriesColors;
1950
+ return {
1951
+ backgroundColor: n,
1952
+ backgroundCssColor: ye(e.backgroundColor, L.backgroundCssColor),
1953
+ gridColor: z(e.gridColor, L.gridColor, t),
1954
+ axisColor: e.axisColor ?? L.axisColor,
1955
+ axisFont: e.axisFont ?? L.axisFont,
1956
+ seriesColors: r,
1957
+ tooltipBackgroundColor: e.tooltipBackgroundColor ?? L.tooltipBackgroundColor,
1958
+ tooltipTextColor: e.tooltipTextColor ?? L.tooltipTextColor,
1959
+ tooltipFont: e.tooltipFont ?? L.tooltipFont,
1960
+ legendBackgroundColor: e.legendBackgroundColor ?? L.legendBackgroundColor,
1961
+ legendBorderColor: e.legendBorderColor ?? L.legendBorderColor,
1962
+ legendTextColor: e.legendTextColor ?? L.legendTextColor,
1963
+ legendMutedTextColor: e.legendMutedTextColor ?? L.legendMutedTextColor,
1964
+ legendFont: e.legendFont ?? L.legendFont,
1965
+ titleColor: e.titleColor ?? L.titleColor,
1966
+ titleFont: e.titleFont ?? L.titleFont,
1967
+ subtitleColor: e.subtitleColor ?? L.subtitleColor,
1968
+ subtitleFont: e.subtitleFont ?? L.subtitleFont,
1969
+ axisTitleColor: e.axisTitleColor ?? L.axisTitleColor,
1970
+ axisTitleFont: e.axisTitleFont ?? L.axisTitleFont
1971
+ };
1972
+ }
1973
+ function z(e, t, n) {
1974
+ if (!e) return t;
1975
+ if (typeof e != "string") return e;
1976
+ let r = be(e, n), i = xe(r ?? e, n);
1977
+ return V(r ?? e) ?? V(i ?? "") ?? t;
1978
+ }
1979
+ function ye(e, t) {
1980
+ return e ? typeof e == "string" ? e : B(e) : t;
1981
+ }
1982
+ function B(e) {
1983
+ return `rgba(${Math.round(e[0] * 255)}, ${Math.round(e[1] * 255)}, ${Math.round(e[2] * 255)}, ${e[3]})`;
1984
+ }
1985
+ function be(e, t) {
1986
+ let n = t?.ownerDocument ?? globalThis.document;
1987
+ if (!n?.documentElement || typeof getComputedStyle > "u") return null;
1988
+ let r = t instanceof HTMLElement ? t : n.documentElement, i = n.createElement("span");
1989
+ i.style.position = "absolute", i.style.visibility = "hidden", i.style.pointerEvents = "none", i.style.color = e, r.appendChild(i);
1990
+ let a = getComputedStyle(i).color;
1991
+ return i.remove(), a || null;
1992
+ }
1993
+ function V(e) {
1994
+ let t = e.trim();
1995
+ return Se(t) ?? Ce(t) ?? we(t);
1996
+ }
1997
+ function xe(e, t) {
1998
+ let n = t?.ownerDocument ?? globalThis.document;
1999
+ if (!n?.createElement) return null;
2000
+ let r = n.createElement("canvas").getContext("2d");
2001
+ if (!r) return null;
2002
+ let i = "#010203";
2003
+ r.fillStyle = i, r.fillStyle = e;
2004
+ let a = String(r.fillStyle);
2005
+ return a === i ? null : a;
2006
+ }
2007
+ function Se(e) {
2008
+ let t = e.match(/^rgba?\((.*)\)$/i);
2009
+ if (!t) return null;
2010
+ let n = t[1].trim().split("/").map((e) => e.trim()), r = n[0], i = n[1], a = r.includes(",") ? r.split(",").map((e) => e.trim()).filter(Boolean) : r.split(/\s+/).filter(Boolean);
2011
+ if (a.length < 3) return null;
2012
+ let o = H(a[0]), s = H(a[1]), c = H(a[2]), l = W(i ?? (a.length > 3 ? a[3] : void 0));
2013
+ return o === null || s === null || c === null || l === null ? null : [
2014
+ o,
2015
+ s,
2016
+ c,
2017
+ l
2018
+ ];
2019
+ }
2020
+ function Ce(e) {
2021
+ let t = e.match(/^color\(\s*srgb\s+(.+)\)$/i);
2022
+ if (!t) return null;
2023
+ let n = t[1].split("/").map((e) => e.trim()), r = n[0].split(/\s+/).filter(Boolean);
2024
+ if (r.length < 3) return null;
2025
+ let i = U(r[0]), a = U(r[1]), o = U(r[2]), s = W(n[1]);
2026
+ return i === null || a === null || o === null || s === null ? null : [
2027
+ i,
2028
+ a,
2029
+ o,
2030
+ s
2031
+ ];
2032
+ }
2033
+ function we(e) {
2034
+ let t = e.startsWith("#") ? e.slice(1) : "";
2035
+ if (![
2036
+ 3,
2037
+ 4,
2038
+ 6,
2039
+ 8
2040
+ ].includes(t.length) || !/^[\da-f]+$/i.test(t)) return null;
2041
+ let n = t.length <= 4 ? [...t].map((e) => e + e).join("") : t, r = Number.parseInt(n, 16);
2042
+ return Number.isFinite(r) ? [
2043
+ (r >> (n.length === 8 ? 24 : 16) & 255) / 255,
2044
+ (r >> (n.length === 8 ? 16 : 8) & 255) / 255,
2045
+ (r >> (n.length === 8 ? 8 : 0) & 255) / 255,
2046
+ n.length === 8 ? (r & 255) / 255 : 1
2047
+ ] : null;
2048
+ }
2049
+ function H(e) {
2050
+ return e.endsWith("%") ? G(Number.parseFloat(e) / 100) : G(Number.parseFloat(e) / 255);
2051
+ }
2052
+ function U(e) {
2053
+ return e.endsWith("%") ? G(Number.parseFloat(e) / 100) : G(Number.parseFloat(e));
2054
+ }
2055
+ function W(e) {
2056
+ return e ? e.endsWith("%") ? G(Number.parseFloat(e) / 100) : G(Number.parseFloat(e)) : 1;
2057
+ }
2058
+ function G(e) {
2059
+ return Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : null;
2060
+ }
2061
+ //#endregion
2062
+ //#region src/ui/Chart.ts
2063
+ var K = 16384, q = K >> 1, Te = K >> 1, J = 3, Ee = 4096, De = 12, Oe = 12, Y = 5, X = 64, ke = 4, Ae = K * 4;
2064
+ function Z(e) {
2065
+ return e === !1 ? {
2066
+ visible: !1,
2067
+ position: "inside"
2068
+ } : e === !0 || e === void 0 ? {
2069
+ visible: !0,
2070
+ position: "inside"
2071
+ } : {
2072
+ visible: e.visible !== !1,
2073
+ position: e.position ?? "inside",
2074
+ scale: e.scale,
2075
+ tickFormat: e.tickFormat,
2076
+ timezone: e.timezone,
2077
+ title: e.title
2078
+ };
2079
+ }
2080
+ function je(e) {
2081
+ return e === !1 ? {
2082
+ x: {
2083
+ visible: !1,
2084
+ position: "inside"
2085
+ },
2086
+ y: {
2087
+ visible: !1,
2088
+ position: "inside"
2089
+ },
2090
+ y2: {
2091
+ visible: !1,
2092
+ position: "inside"
2093
+ }
2094
+ } : e === !0 || e === void 0 ? {
2095
+ x: {
2096
+ visible: !0,
2097
+ position: "inside"
2098
+ },
2099
+ y: {
2100
+ visible: !0,
2101
+ position: "inside"
2102
+ },
2103
+ y2: {
2104
+ visible: !1,
2105
+ position: "inside"
2106
+ }
2107
+ } : {
2108
+ x: Z(e.x),
2109
+ y: Z(e.y),
2110
+ y2: Z(e.y2 ?? !1)
2111
+ };
2112
+ }
2113
+ function Me(e) {
2114
+ return typeof e == "string" ? e : e?.text ?? "";
2115
+ }
2116
+ function Ne(e) {
2117
+ return typeof e == "string" ? e.length > 0 : !!e && e.visible !== !1 && e.text.length > 0;
2118
+ }
2119
+ function Q(e) {
2120
+ return typeof e == "string" ? 0 : e?.offsetX ?? 0;
2121
+ }
2122
+ function $(e) {
2123
+ return typeof e == "string" ? 0 : e?.offsetY ?? 0;
2124
+ }
2125
+ var Pe = class {
2126
+ options;
2127
+ series = [];
2128
+ camera;
2129
+ rightCamera;
2130
+ axis;
2131
+ rightAxis;
2132
+ renderer;
2133
+ rawLineBuffer;
2134
+ rawLineData;
2135
+ minMaxInstanceBuffer;
2136
+ minMaxInstanceData;
2137
+ barTriangleBuffer;
2138
+ barTriangleData;
2139
+ gridBuffer;
2140
+ gridData;
2141
+ gridStyle;
2142
+ xTicks = [];
2143
+ yTicks = [];
2144
+ axisOverlay = null;
2145
+ normalizedAxes;
2146
+ resolvedTheme;
2147
+ _gridVisible;
2148
+ layout;
2149
+ stats = {
2150
+ fps: 0,
2151
+ frameMs: 0,
2152
+ pointsRendered: 0,
2153
+ drawCalls: 0,
2154
+ uploadBytes: 0,
2155
+ renderMode: "none"
2156
+ };
2157
+ resizeObserver = null;
2158
+ pluginDisposers = [];
2159
+ hoverSubscribers = /* @__PURE__ */ new Set();
2160
+ seriesSubscribers = /* @__PURE__ */ new Set();
2161
+ themeSubscribers = /* @__PURE__ */ new Set();
2162
+ renderSubscribers = /* @__PURE__ */ new Set();
2163
+ layoutReservations = /* @__PURE__ */ new Map();
2164
+ viewportSubscribers = /* @__PURE__ */ new Set();
2165
+ selectSubscribers = /* @__PURE__ */ new Set();
2166
+ seriesClickSubscribers = /* @__PURE__ */ new Set();
2167
+ pointerSubscribers = {
2168
+ click: /* @__PURE__ */ new Set(),
2169
+ dblclick: /* @__PURE__ */ new Set(),
2170
+ pointerdown: /* @__PURE__ */ new Set(),
2171
+ pointerup: /* @__PURE__ */ new Set(),
2172
+ pointermove: /* @__PURE__ */ new Set()
2173
+ };
2174
+ currentHover = null;
2175
+ lastPointerClientX = 0;
2176
+ lastPointerClientY = 0;
2177
+ pointerInPlot = !1;
2178
+ lastFrameAt = 0;
2179
+ currentXOrigin = 0;
2180
+ _rafId = 0;
2181
+ _hoverRafId = 0;
2182
+ handlePointerMove = (e) => {
2183
+ this.pointerInPlot = !0, this.lastPointerClientX = e.clientX, this.lastPointerClientY = e.clientY, this.scheduleHoverRefresh(), this.pointerSubscribers.pointermove.size > 0 && this.emitPointerEvent("pointermove", e);
2184
+ };
2185
+ handlePointerDown = (e) => {
2186
+ this.emitPointerEvent("pointerdown", e);
2187
+ };
2188
+ handlePointerUp = (e) => {
2189
+ this.emitPointerEvent("pointerup", e);
2190
+ };
2191
+ handleClick = (e) => {
2192
+ let t = this.emitPointerEvent("click", e), n = t?.items[0];
2193
+ t && n && this.emitSeriesClick({
2194
+ ...t,
2195
+ item: n
2196
+ });
2197
+ };
2198
+ handleDoubleClick = (e) => {
2199
+ this.emitPointerEvent("dblclick", e);
2200
+ };
2201
+ handlePointerLeave = () => {
2202
+ this.pointerInPlot = !1, this.emitHover(null);
2203
+ };
2204
+ constructor(e, t = {}) {
2205
+ this.options = t, this.resolvedTheme = R(t.theme, e), this.normalizedAxes = je(t.axes), this._gridVisible = t.grid !== !1, this.layout = new ve(e, this.normalizedAxes), this.layout.root.style.background = this.resolvedTheme.backgroundCssColor, this.applyCanvasSize(), this.camera = new O(), this.rightCamera = new O(), this.axis = new F(this.camera, {
2206
+ x: this.normalizedAxes.x,
2207
+ y: this.normalizedAxes.y
2208
+ }), this.rightAxis = new F(this.rightCamera, {
2209
+ x: this.normalizedAxes.x,
2210
+ y: this.normalizedAxes.y2
2211
+ }), this.renderer = new le(new fe(this.layout.canvas)), this.rawLineData = new Float32Array(K * 2), this.rawLineBuffer = this.renderer.createFloatBuffer(this.rawLineData.length), this.minMaxInstanceData = new Float32Array(Te * J), this.minMaxInstanceBuffer = this.renderer.createFloatBuffer(this.minMaxInstanceData.length), this.barTriangleData = new Float32Array(Ee * De), this.barTriangleBuffer = this.renderer.createFloatBuffer(this.barTriangleData.length), this.gridData = new Float32Array(X * 2), this.gridBuffer = this.renderer.createFloatBuffer(this.gridData.length), this.gridStyle = {
2212
+ color: t.gridStyle?.color ?? this.resolvedTheme.gridColor,
2213
+ lineWidth: t.gridStyle?.lineWidth ?? 1
2214
+ }, (this.normalizedAxes.x.visible || this.normalizedAxes.y.visible || this.normalizedAxes.y2.visible) && (this.axisOverlay = new I(this.layout, this.normalizedAxes, {
2215
+ color: this.resolvedTheme.axisColor,
2216
+ font: this.resolvedTheme.axisFont
2217
+ })), this.updateTextOverlays(), this.canvas.addEventListener("pointermove", this.handlePointerMove), this.canvas.addEventListener("pointerdown", this.handlePointerDown), this.canvas.addEventListener("pointerup", this.handlePointerUp), this.canvas.addEventListener("pointerleave", this.handlePointerLeave), this.canvas.addEventListener("click", this.handleClick), this.canvas.addEventListener("dblclick", this.handleDoubleClick), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(this.layout.plot));
2218
+ for (let e of t.plugins ?? []) {
2219
+ let t = e.install(this);
2220
+ typeof t == "function" ? this.pluginDisposers.push(t) : t && this.pluginDisposers.push(() => t.dispose());
2221
+ }
2222
+ }
2223
+ get canvas() {
2224
+ return this.layout.canvas;
2225
+ }
2226
+ get rootElement() {
2227
+ return this.layout.root;
2228
+ }
2229
+ get plotElement() {
2230
+ return this.layout.plot;
2231
+ }
2232
+ get xAxisElement() {
2233
+ return this.layout.xAxis;
2234
+ }
2235
+ get yAxisElement() {
2236
+ return this.layout.yAxis;
2237
+ }
2238
+ get y2AxisElement() {
2239
+ return this.layout.y2Axis;
2240
+ }
2241
+ get theme() {
2242
+ return this.resolvedTheme;
2243
+ }
2244
+ getWebGLContext() {
2245
+ return this.renderer.getWebGLContext();
2246
+ }
2247
+ getCamera(e = "left") {
2248
+ return e === "right" ? this.rightCamera : this.camera;
2249
+ }
2250
+ dataToPlot(e, t, n = "left") {
2251
+ let r = this.getCamera(n), [i, a] = r.toClip(e, t);
2252
+ return r.toScreen(i, a, this.canvas.clientWidth, this.canvas.clientHeight);
2253
+ }
2254
+ clientToData(e, t, n = "left") {
2255
+ let r = this.canvas.getBoundingClientRect();
2256
+ if (r.width <= 0 || r.height <= 0) return null;
2257
+ let i = e - r.left, a = t - r.top;
2258
+ if (i < 0 || a < 0 || i > r.width || a > r.height) return null;
2259
+ let o = this.getCamera(n).viewport;
2260
+ return [o.xMin + i / r.width * (o.xMax - o.xMin), o.yMax - a / r.height * (o.yMax - o.yMin)];
2261
+ }
2262
+ getViewport(e = "left") {
2263
+ return this.getCamera(e).viewport;
2264
+ }
2265
+ pan(e) {
2266
+ this.camera.pan(e), this.syncRightCameraX(), this.emitViewportChange(), this.refreshHover();
2267
+ }
2268
+ zoom(e) {
2269
+ this.camera.zoom(e), this.syncRightCameraX(), this.emitViewportChange(), this.refreshHover();
2270
+ }
2271
+ addSeries(e, t) {
2272
+ if ((e.mode === "ohlc" || e.mode === "candlestick") && !e.dataset) throw TypeError("OHLC and candlestick series require an OhlcDataset.");
2273
+ let n = e.dataset ?? this.createDefaultDataset(e), r = this.resolvedTheme.seriesColors, i = r[this.series.length % r.length] ?? this.resolvedTheme.seriesColors[0], a = t?.color ?? i, o = new m(n, e, {
2274
+ color: a,
2275
+ lineWidth: t?.lineWidth ?? 1,
2276
+ pointSize: t?.pointSize ?? 4,
2277
+ barWidth: t?.barWidth ?? .8,
2278
+ baseline: t?.baseline ?? 0,
2279
+ fillColor: t?.fillColor ?? [
2280
+ a[0],
2281
+ a[1],
2282
+ a[2],
2283
+ a[3] * .25
2284
+ ],
2285
+ tickWidth: t?.tickWidth ?? t?.barWidth ?? .8,
2286
+ upColor: t?.upColor ?? a,
2287
+ downColor: t?.downColor ?? t?.fillColor ?? [
2288
+ a[0],
2289
+ a[1],
2290
+ a[2],
2291
+ a[3] * .45
2292
+ ],
2293
+ wickColor: t?.wickColor ?? a
2294
+ });
2295
+ return this.series.push(o), this.emitSeriesChange(), o;
2296
+ }
2297
+ addLine(e, t) {
2298
+ return this.addSeries({
2299
+ ...e,
2300
+ mode: "line"
2301
+ }, t);
2302
+ }
2303
+ addArea(e, t) {
2304
+ return this.addSeries({
2305
+ ...e,
2306
+ mode: "area"
2307
+ }, t);
2308
+ }
2309
+ addScatter(e, t) {
2310
+ return this.addSeries({
2311
+ ...e,
2312
+ mode: "scatter"
2313
+ }, t);
2314
+ }
2315
+ addBar(e, t) {
2316
+ return this.addSeries({
2317
+ ...e,
2318
+ mode: "bar"
2319
+ }, t);
2320
+ }
2321
+ addOhlc(e, t) {
2322
+ return this.addSeries({
2323
+ ...e,
2324
+ mode: "ohlc"
2325
+ }, t);
2326
+ }
2327
+ addCandlestick(e, t) {
2328
+ return this.addSeries({
2329
+ ...e,
2330
+ mode: "candlestick"
2331
+ }, t);
2332
+ }
2333
+ createDefaultDataset(e) {
2334
+ let { capacity: t } = e;
2335
+ if (typeof t != "number" || !Number.isInteger(t) || t <= 0) throw TypeError("Series capacity must be a positive integer when no dataset is provided.");
2336
+ return new _(t, { overflow: e.overflow });
2337
+ }
2338
+ removeSeries(e) {
2339
+ let t = this.series.indexOf(e);
2340
+ return t === -1 ? !1 : (this.series.splice(t, 1), this.emitSeriesChange(), !0);
2341
+ }
2342
+ setSeriesVisible(e, t) {
2343
+ return this.series.includes(e) ? e.visible === t ? !0 : (e.setVisible(t), this.emitSeriesChange(), !0) : !1;
2344
+ }
2345
+ getSeriesState() {
2346
+ return this.series.map((e, t) => ({
2347
+ series: e,
2348
+ index: t,
2349
+ id: e.config.id,
2350
+ name: e.config.name,
2351
+ mode: e.config.mode,
2352
+ visible: e.visible,
2353
+ color: e.style.color,
2354
+ yAxis: e.config.yAxis ?? "left"
2355
+ }));
2356
+ }
2357
+ setViewport(e) {
2358
+ this.camera.setViewport(e), this.rightCamera.setViewport(e), this.emitViewportChange(), this.refreshHover();
2359
+ }
2360
+ setYViewport(e, t) {
2361
+ this.getCamera(e).setViewport(t), this.emitViewportChange(), this.refreshHover();
2362
+ }
2363
+ resize(e = globalThis.devicePixelRatio) {
2364
+ let t = this.applyCanvasSize(e);
2365
+ return t && this.refreshHover(), t;
2366
+ }
2367
+ getFrameStats(e = {
2368
+ fps: 0,
2369
+ frameMs: 0,
2370
+ pointsRendered: 0,
2371
+ drawCalls: 0,
2372
+ uploadBytes: 0,
2373
+ renderMode: "none"
2374
+ }) {
2375
+ return e.fps = this.stats.fps, e.frameMs = this.stats.frameMs, e.pointsRendered = this.stats.pointsRendered, e.drawCalls = this.stats.drawCalls, e.uploadBytes = this.stats.uploadBytes, e.renderMode = this.stats.renderMode, e;
2376
+ }
2377
+ getHoverState() {
2378
+ return this.currentHover;
2379
+ }
2380
+ setLayoutReservation(e, t) {
2381
+ t ? this.layoutReservations.set(e, t) : this.layoutReservations.delete(e), this.applyLayoutReservations(), this.resize();
2382
+ }
2383
+ subscribe(e, t) {
2384
+ if (e === "hover") {
2385
+ let e = t;
2386
+ return this.hoverSubscribers.add(e), () => this.hoverSubscribers.delete(e);
2387
+ }
2388
+ if (e === "themechange") {
2389
+ let e = t;
2390
+ return this.themeSubscribers.add(e), () => this.themeSubscribers.delete(e);
2391
+ }
2392
+ if (e === "render") {
2393
+ let e = t;
2394
+ return this.renderSubscribers.add(e), () => this.renderSubscribers.delete(e);
2395
+ }
2396
+ if (e === "viewportchange") {
2397
+ let e = t;
2398
+ return this.viewportSubscribers.add(e), () => this.viewportSubscribers.delete(e);
2399
+ }
2400
+ if (e === "select") {
2401
+ let e = t;
2402
+ return this.selectSubscribers.add(e), () => this.selectSubscribers.delete(e);
2403
+ }
2404
+ if (e === "seriesclick") {
2405
+ let e = t;
2406
+ return this.seriesClickSubscribers.add(e), () => this.seriesClickSubscribers.delete(e);
2407
+ }
2408
+ if (e in this.pointerSubscribers) {
2409
+ let n = t;
2410
+ return this.pointerSubscribers[e].add(n), () => this.pointerSubscribers[e].delete(n);
2411
+ }
2412
+ let n = t;
2413
+ return this.seriesSubscribers.add(n), () => this.seriesSubscribers.delete(n);
2414
+ }
2415
+ emitSelect(e) {
2416
+ let t = { selection: e };
2417
+ for (let e of this.selectSubscribers) e(t);
2418
+ }
2419
+ setTheme(e) {
2420
+ this.resolvedTheme = R(e, this.layout.root), this.applyTheme(), this.emitThemeChange(), this.refreshHover();
2421
+ }
2422
+ setGridVisible(e) {
2423
+ this._gridVisible = e;
2424
+ }
2425
+ getGridVisible() {
2426
+ return this._gridVisible;
2427
+ }
2428
+ setAxes(e) {
2429
+ this.normalizedAxes = je(e), this.axis.setOptions({
2430
+ x: this.normalizedAxes.x,
2431
+ y: this.normalizedAxes.y
2432
+ }), this.rightAxis.setOptions({
2433
+ x: this.normalizedAxes.x,
2434
+ y: this.normalizedAxes.y2
2435
+ }), this.layout.update(this.normalizedAxes), this.axisOverlay?.dispose(), this.axisOverlay = null, (this.normalizedAxes.x.visible || this.normalizedAxes.y.visible || this.normalizedAxes.y2.visible) && (this.axisOverlay = new I(this.layout, this.normalizedAxes, {
2436
+ color: this.resolvedTheme.axisColor,
2437
+ font: this.resolvedTheme.axisFont
2438
+ })), this.updateTextOverlays(), this.resize(), this.refreshHover();
2439
+ }
2440
+ pick(e, t, n = {}) {
2441
+ let r = this.canvas.getBoundingClientRect();
2442
+ if (r.width <= 0 || r.height <= 0) return null;
2443
+ let i = e - r.left, a = t - r.top;
2444
+ if (i < 0 || a < 0 || i > r.width || a > r.height) return null;
2445
+ let o = this.camera.viewport, s = o.xMin + i / r.width * (o.xMax - o.xMin), c = o.yMax - a / r.height * (o.yMax - o.yMin), l = n.mode ?? this.options.hover?.mode ?? "nearest-x", u = n.group ?? this.options.hover?.group ?? "x", d = n.maxDistancePx ?? this.options.hover?.maxDistancePx ?? Infinity, f = l === "nearest-point" ? this.findNearestPointCandidate(s, a, r.width, r.height, d) : this.findNearestXCandidate(s, r.width, d);
2446
+ if (!f) return null;
2447
+ let p = f.sample.x;
2448
+ return {
2449
+ clientX: e,
2450
+ clientY: t,
2451
+ plotX: i,
2452
+ plotY: a,
2453
+ dataX: s,
2454
+ dataY: c,
2455
+ anchorX: p,
2456
+ mode: l,
2457
+ group: u,
2458
+ maxDistancePx: d,
2459
+ items: u === "none" ? [this.createPickItem(f.sample, f.series, f.seriesIndex, e, t, r)] : this.collectPickItems(p, e, t, r)
2460
+ };
2461
+ }
2462
+ async screenshot(e = {}) {
2463
+ this.render();
2464
+ let t = this.layout.root.getBoundingClientRect(), n = this.layout.plot.getBoundingClientRect(), r = Number.isFinite(e.dpr) ? Math.max(1, e.dpr) : Math.max(1, globalThis.devicePixelRatio || 1), i = Math.max(1, Math.round(t.width * r)), a = Math.max(1, Math.round(t.height * r)), o = document.createElement("canvas");
2465
+ o.width = i, o.height = a;
2466
+ let s = o.getContext("2d");
2467
+ if (!s) throw Error("Unable to create a 2D canvas context for screenshot export.");
2468
+ return s.fillStyle = e.background ?? B(this.resolvedTheme.backgroundColor), s.fillRect(0, 0, i, a), s.drawImage(this.canvas, (n.left - t.left) * r, (n.top - t.top) * r, n.width * r, n.height * r), this.drawDomTextForScreenshot(s, t, r), new Promise((t, n) => {
2469
+ o.toBlob((e) => e ? t(e) : n(/* @__PURE__ */ Error("Unable to encode chart screenshot.")), e.type ?? "image/png", e.quality);
2470
+ });
2471
+ }
2472
+ start() {
2473
+ let e = () => {
2474
+ this._rafId = requestAnimationFrame(e), this.render();
2475
+ };
2476
+ this._rafId = requestAnimationFrame(e);
2477
+ }
2478
+ stop() {
2479
+ cancelAnimationFrame(this._rafId);
2480
+ }
2481
+ render() {
2482
+ let e = performance.now();
2483
+ this.lastFrameAt > 0 && (this.stats.fps = 1e3 / (e - this.lastFrameAt)), this.lastFrameAt = e, this.stats.pointsRendered = 0, this.stats.drawCalls = 0, this.stats.uploadBytes = 0, this.stats.renderMode = "none", this.options.viewportPolicy?.beforeRender?.(this.camera), this.syncRightCameraX();
2484
+ let [t, n, r, i] = this.resolvedTheme.backgroundColor;
2485
+ this.renderer.viewport(0, 0, this.canvas.width, this.canvas.height), this.renderer.clear(t, n, r, i);
2486
+ let a = this.camera.viewport;
2487
+ if (this.currentXOrigin = a.xMin, this.renderer.setXOrigin(this.currentXOrigin), this._gridVisible) {
2488
+ let e = this.writeGridVertices(a);
2489
+ e > 0 && (this.uploadGridData(e), this.renderer.drawClipLines(this.gridBuffer, e, this.gridStyle), this.stats.drawCalls++);
2490
+ }
2491
+ for (let e of this.series) e.visible && (e.rebuildPyramid(), this.drawSeries(e));
2492
+ this.axisOverlay?.update(this.camera, this.axis, this.rightCamera, this.rightAxis), this.emitRender(), this.stats.frameMs = performance.now() - e, this._hoverRafId !== 0 && (cancelAnimationFrame(this._hoverRafId), this._hoverRafId = 0), this.refreshHover();
2493
+ }
2494
+ dispose() {
2495
+ this.stop(), this.resizeObserver?.disconnect(), this._hoverRafId !== 0 && cancelAnimationFrame(this._hoverRafId), this._hoverRafId = 0, this.canvas.removeEventListener("pointermove", this.handlePointerMove), this.canvas.removeEventListener("pointerdown", this.handlePointerDown), this.canvas.removeEventListener("pointerup", this.handlePointerUp), this.canvas.removeEventListener("pointerleave", this.handlePointerLeave), this.canvas.removeEventListener("click", this.handleClick), this.canvas.removeEventListener("dblclick", this.handleDoubleClick);
2496
+ for (let e of this.pluginDisposers.splice(0)) e();
2497
+ this.axisOverlay?.dispose(), this.renderer.dispose(), this.layout.dispose();
2498
+ }
2499
+ applyTheme() {
2500
+ this.layout.root.style.background = this.resolvedTheme.backgroundCssColor, this.options.gridStyle?.color === void 0 && (this.gridStyle = {
2501
+ ...this.gridStyle,
2502
+ color: this.resolvedTheme.gridColor
2503
+ }), this.axisOverlay?.setOptions({
2504
+ color: this.resolvedTheme.axisColor,
2505
+ font: this.resolvedTheme.axisFont
2506
+ }), this.updateTextOverlays();
2507
+ }
2508
+ updateTextOverlays() {
2509
+ this.applyChartTextOverlay(this.layout.title, this.options.title, {
2510
+ color: this.resolvedTheme.titleColor,
2511
+ font: this.resolvedTheme.titleFont,
2512
+ top: 6
2513
+ }), this.applyChartTextOverlay(this.layout.subtitle, this.options.subtitle, {
2514
+ color: this.resolvedTheme.subtitleColor,
2515
+ font: this.resolvedTheme.subtitleFont,
2516
+ top: 26
2517
+ }), this.applyAxisTitleOverlay(this.layout.xAxisTitle, this.normalizedAxes.x.title, "x"), this.applyAxisTitleOverlay(this.layout.yAxisTitle, this.normalizedAxes.y.title, "y"), this.applyAxisTitleOverlay(this.layout.y2AxisTitle, this.normalizedAxes.y2.title, "y2");
2518
+ }
2519
+ applyChartTextOverlay(e, t, n) {
2520
+ let r = Ne(t);
2521
+ if (e.textContent = Me(t), e.style.display = r ? "block" : "none", !r) return;
2522
+ let i = typeof t == "string" ? "center" : t?.align ?? "center";
2523
+ e.style.color = typeof t == "string" ? n.color : t?.color ?? n.color, e.style.font = typeof t == "string" ? n.font : t?.font ?? n.font, e.style.top = `${n.top + $(t)}px`, e.style.left = i === "left" ? `${8 + Q(t)}px` : i === "right" ? "auto" : `calc(50% + ${Q(t)}px)`, e.style.right = i === "right" ? `${8 - Q(t)}px` : "auto", e.style.transform = i === "center" ? "translateX(-50%)" : "none", e.style.textAlign = i;
2524
+ }
2525
+ applyAxisTitleOverlay(e, t, n) {
2526
+ let r = Ne(t);
2527
+ e.textContent = Me(t), e.style.display = r ? "block" : "none", r && (e.style.color = typeof t == "string" ? this.resolvedTheme.axisTitleColor : t?.color ?? this.resolvedTheme.axisTitleColor, e.style.font = typeof t == "string" ? this.resolvedTheme.axisTitleFont : t?.font ?? this.resolvedTheme.axisTitleFont, n === "x" ? (e.style.left = `calc(50% + ${Q(t)}px)`, e.style.bottom = `${4 - $(t)}px`, e.style.transform = "translateX(-50%)") : n === "y" ? (e.style.left = `${4 + Q(t)}px`, e.style.top = `calc(50% + ${$(t)}px)`, e.style.transform = "translateY(-50%) rotate(-90deg)") : (e.style.right = `${4 - Q(t)}px`, e.style.top = `calc(50% + ${$(t)}px)`, e.style.transform = "translateY(-50%) rotate(90deg)"));
2528
+ }
2529
+ applyLayoutReservations() {
2530
+ let e = 0, t = 0, n = 0, r = 0;
2531
+ for (let i of this.layoutReservations.values()) e += Math.max(0, i.top ?? 0), t += Math.max(0, i.right ?? 0), n += Math.max(0, i.bottom ?? 0), r += Math.max(0, i.left ?? 0);
2532
+ this.layout.root.style.padding = `${e}px ${t}px ${n}px ${r}px`;
2533
+ }
2534
+ applyCanvasSize(e = globalThis.devicePixelRatio) {
2535
+ let t = Number.isFinite(e) ? Math.max(1, e) : 1, n = Math.max(1, Math.floor(this.canvas.clientWidth * t)), r = Math.max(1, Math.floor(this.canvas.clientHeight * t));
2536
+ return this.canvas.width === n && this.canvas.height === r ? !1 : (this.canvas.width = n, this.canvas.height = r, !0);
2537
+ }
2538
+ cameraForSeries(e) {
2539
+ return e.config.yAxis === "right" ? this.rightCamera : this.camera;
2540
+ }
2541
+ syncRightCameraX() {
2542
+ this.rightCamera.setViewport({
2543
+ xMin: this.camera.xMin,
2544
+ xMax: this.camera.xMax
2545
+ });
2546
+ }
2547
+ drawSeries(e) {
2548
+ let t = this.cameraForSeries(e), n = t.viewport;
2549
+ switch (e.config.mode) {
2550
+ case "area":
2551
+ this.drawAreaSeries(e, n, t);
2552
+ return;
2553
+ case "bar":
2554
+ this.drawBarSeries(e, n, t);
2555
+ return;
2556
+ case "ohlc":
2557
+ this.drawOhlcSeries(e, n, t);
2558
+ return;
2559
+ case "candlestick":
2560
+ this.drawCandlestickSeries(e, n, t);
2561
+ return;
2562
+ case "scatter":
2563
+ this.drawScatterSeries(e, n, t);
2564
+ return;
2565
+ default: this.drawLineSeries(e, n, t);
2566
+ }
2567
+ }
2568
+ drawLineSeries(e, t, n) {
2569
+ let r = e.visibleSampleCount(t), i = e.hasLOD && r > K - 2;
2570
+ if (i && this.renderer.supportsInstancedSegments) {
2571
+ let r = e.copyMinMaxInstanced(t, this.minMaxInstanceData, this.maxMinMaxSegments(), this.currentXOrigin);
2572
+ if (r <= 0) return;
2573
+ this.uploadMinMaxInstanceData(r), this.renderer.drawMinMaxSegmentsInstanced(this.minMaxInstanceBuffer, r, e.style, n), this.recordDraw("minmax", r * 2);
2574
+ return;
2575
+ }
2576
+ if (i) {
2577
+ let r = e.copyMinMaxVisible(t, this.rawLineData, this.maxMinMaxSegments(), this.currentXOrigin);
2578
+ if (r < 2) return;
2579
+ this.uploadRawLineData(r), this.renderer.drawMinMaxSegments(this.rawLineBuffer, r, e.style, n), this.recordDraw("minmax", r);
2580
+ return;
2581
+ }
2582
+ let a = e.copyRawVisibleClipSpace(t, this.rawLineData, K);
2583
+ a < 2 || (this.uploadRawLineData(a), this.renderer.drawClipLineStrip(this.rawLineBuffer, a, e.style), this.recordDraw("raw", a));
2584
+ }
2585
+ drawAreaSeries(e, t, n) {
2586
+ let r = e.visibleIndexRange(t, 1);
2587
+ if (r.end - r.start < 2) return;
2588
+ let i = e.style.baseline ?? 0;
2589
+ if (r.end - r.start > q) {
2590
+ let r = e.copyAreaVisible(t, this.rawLineData, q, i, this.currentXOrigin);
2591
+ r >= 4 && (this.uploadRawLineData(r), this.renderer.drawAreaStrip(this.rawLineBuffer, r, e.style, n), this.recordDraw("area", r));
2592
+ let a = e.copyRawVisible(t, this.rawLineData, q, this.currentXOrigin);
2593
+ a >= 2 && (this.uploadRawLineData(a), this.renderer.drawLineStrip(this.rawLineBuffer, a, e.style, n), this.recordDraw("area", a));
2594
+ return;
2595
+ }
2596
+ for (let t = r.start; t < r.end;) {
2597
+ let a = e.copyAreaRange(t, r.end, this.rawLineData, q, i, this.currentXOrigin);
2598
+ if (a < 4) break;
2599
+ this.uploadRawLineData(a), this.renderer.drawAreaStrip(this.rawLineBuffer, a, e.style, n), this.recordDraw("area", a), t += Math.max(1, (a >> 1) - 1);
2600
+ }
2601
+ for (let t = r.start; t < r.end;) {
2602
+ let i = e.copyRawRange(t, r.end, this.rawLineData, q, this.currentXOrigin);
2603
+ if (i < 2) break;
2604
+ this.uploadRawLineData(i), this.renderer.drawLineStrip(this.rawLineBuffer, i, e.style, n), this.recordDraw("area", i), t += Math.max(1, i - 1);
2605
+ }
2606
+ }
2607
+ drawOhlcSeries(e, t, n) {
2608
+ let r = e.visibleIndexRange(t), i = Math.floor(this.rawLineData.length / Oe);
2609
+ for (let t = r.start; t < r.end;) {
2610
+ let a = e.copyOhlcRange(t, r.end, this.rawLineData, i, e.style.tickWidth ?? e.style.barWidth ?? .8, this.currentXOrigin);
2611
+ if (a <= 0) break;
2612
+ let o = a * 6;
2613
+ this.uploadRawLineData(o), this.renderer.drawLines(this.rawLineBuffer, o, e.style, n), this.recordDraw("raw", o), t += a;
2614
+ }
2615
+ }
2616
+ drawCandlestickSeries(e, t, n) {
2617
+ let r = e.visibleIndexRange(t, 1), i = Math.min(Math.floor(this.rawLineData.length / Y), this.maxBarTriangleBars()), a = {
2618
+ ...e.style,
2619
+ color: e.style.wickColor ?? e.style.color
2620
+ }, o = {
2621
+ ...e.style,
2622
+ color: e.style.upColor ?? e.style.color
2623
+ }, s = {
2624
+ ...e.style,
2625
+ color: e.style.downColor ?? e.style.fillColor ?? e.style.color
2626
+ };
2627
+ for (let t = r.start; t < r.end;) {
2628
+ let c = e.copyOhlcTuplesRange(t, r.end, this.rawLineData, i, this.currentXOrigin);
2629
+ if (c <= 0) break;
2630
+ let l = this.writeCandlestickWicks(c);
2631
+ l > 0 && (this.uploadBarTriangleData(l), this.renderer.drawLines(this.barTriangleBuffer, l, a, n), this.recordDraw("raw", l));
2632
+ let u = e.style.barWidth ?? e.style.tickWidth ?? .8;
2633
+ this.drawCandlestickBodies(c, u, "up", o, n), this.drawCandlestickBodies(c, u, "down", s, n), t += c;
2634
+ }
2635
+ }
2636
+ drawScatterSeries(e, t, n) {
2637
+ let r = e.style.pointSize ?? ke, i = e.visibleSampleCount(t);
2638
+ if (e.config.downsample === "none" && i <= Ae) {
2639
+ let i = e.visibleIndexRange(t);
2640
+ for (let a = i.start; a < i.end; a += K) {
2641
+ let o = e.copyScatterRange(a, Math.min(i.end, a + K), t, this.rawLineData, K, this.currentXOrigin, this.canvas.height, r);
2642
+ o <= 0 || (this.uploadRawLineData(o), this.renderer.drawPoints(this.rawLineBuffer, o, e.style, n, this.canvas.width, this.canvas.height), this.recordDraw("points", o));
2643
+ }
2644
+ return;
2645
+ }
2646
+ let a = e.copyScatterVisible(t, this.rawLineData, K, this.canvas.width, this.canvas.height, r, this.currentXOrigin);
2647
+ a <= 0 || (this.uploadRawLineData(a), this.renderer.drawPoints(this.rawLineBuffer, a, e.style, n, this.canvas.width, this.canvas.height), this.recordDraw("points", a));
2648
+ }
2649
+ drawBarSeries(e, t, n) {
2650
+ let r = e.visibleSampleCount(t), i = this.maxRawBarInstances();
2651
+ if (e.hasLOD && r > i) {
2652
+ let r = e.copyMinMaxInstanced(t, this.minMaxInstanceData, this.maxBarTriangleBars(), this.currentXOrigin);
2653
+ if (r <= 0) return;
2654
+ this.includeBaselineInBarRanges(r, e.style.baseline ?? 0);
2655
+ let i = this.writeBarBucketTriangles(r, t);
2656
+ this.drawBarTriangles(i, e.style, n);
2657
+ return;
2658
+ }
2659
+ let a = e.visibleIndexRange(t, 1), o = e.copyRawRange(a.start, a.end, this.rawLineData, i, this.currentXOrigin);
2660
+ if (o <= 0) return;
2661
+ if (this.renderer.supportsInstancedBars) {
2662
+ this.uploadRawLineData(o), this.renderer.drawBarsInstanced(this.rawLineBuffer, o, e.style, n), this.recordDraw("bars", o);
2663
+ return;
2664
+ }
2665
+ let s = this.writeBarTriangles(o, e.style.baseline ?? 0, e.style.barWidth ?? .8);
2666
+ this.drawBarTriangles(s, e.style, n);
2667
+ }
2668
+ uploadRawLineData(e) {
2669
+ this.uploadFloatData(this.rawLineBuffer, this.rawLineData, e * 2);
2670
+ }
2671
+ uploadMinMaxInstanceData(e) {
2672
+ this.uploadFloatData(this.minMaxInstanceBuffer, this.minMaxInstanceData, e * J);
2673
+ }
2674
+ uploadBarTriangleData(e) {
2675
+ this.uploadFloatData(this.barTriangleBuffer, this.barTriangleData, e * 2);
2676
+ }
2677
+ uploadGridData(e) {
2678
+ this.uploadFloatData(this.gridBuffer, this.gridData, e * 2);
2679
+ }
2680
+ uploadFloatData(e, t, n) {
2681
+ let r = Math.max(0, Math.min(n, t.length));
2682
+ this.renderer.updateFloatBuffer(e, t, r), this.stats.uploadBytes += r * Float32Array.BYTES_PER_ELEMENT;
2683
+ }
2684
+ includeBaselineInBarRanges(e, t) {
2685
+ for (let n = 0; n < e; n++) {
2686
+ let e = n * J, r = this.minMaxInstanceData[e + 1], i = this.minMaxInstanceData[e + 2];
2687
+ this.minMaxInstanceData[e + 1] = Math.min(t, r), this.minMaxInstanceData[e + 2] = Math.max(t, i);
2688
+ }
2689
+ }
2690
+ writeBarTriangles(e, t, n) {
2691
+ let r = Math.min(e, this.maxBarTriangleBars());
2692
+ for (let e = 0; e < r; e++) {
2693
+ let r = this.rawLineData[e * 2], i = this.rawLineData[e * 2 + 1];
2694
+ this.writeBarTriangle(e, r - n * .5, r + n * .5, t, i);
2695
+ }
2696
+ return r * 6;
2697
+ }
2698
+ writeBarBucketTriangles(e, t) {
2699
+ let n = Math.min(e, this.maxBarTriangleBars());
2700
+ for (let e = 0; e < n; e++) {
2701
+ let r = this.minMaxInstanceData[e * 3 + 1], i = this.minMaxInstanceData[e * 3 + 2], [a, o] = this.barBucketBounds(e, n, t);
2702
+ this.writeBarTriangle(e, a, o, r, i);
2703
+ }
2704
+ return n * 6;
2705
+ }
2706
+ barBucketBounds(e, t, n) {
2707
+ let r = this.minMaxInstanceData[e * 3], i = n.xMin - this.currentXOrigin, a = n.xMax - this.currentXOrigin, o = a - i;
2708
+ if (t <= 1) {
2709
+ let e = Math.max(0, o * .5);
2710
+ return [Math.max(i, r - e), Math.min(a, r + e)];
2711
+ }
2712
+ let s = e > 0 ? this.minMaxInstanceData[(e - 1) * 3] : NaN, c = e + 1 < t ? this.minMaxInstanceData[(e + 1) * 3] : NaN, l = e === 0 ? r - (c - r) * .5 : (s + r) * .5, u = e + 1 === t ? r + (r - s) * .5 : (r + c) * .5;
2713
+ if (!Number.isFinite(l) || !Number.isFinite(u) || u <= l) {
2714
+ let n = o / Math.max(1, t);
2715
+ l = i + e * n, u = e + 1 === t ? a : l + n;
2716
+ }
2717
+ return [Math.max(i, l), Math.min(a, u)];
2718
+ }
2719
+ writeCandlestickWicks(e) {
2720
+ for (let t = 0; t < e; t++) {
2721
+ let e = t * Y, n = t * 4, r = this.rawLineData[e], i = this.rawLineData[e + 2], a = this.rawLineData[e + 3];
2722
+ this.barTriangleData[n] = r, this.barTriangleData[n + 1] = a, this.barTriangleData[n + 2] = r, this.barTriangleData[n + 3] = i;
2723
+ }
2724
+ return e * 2;
2725
+ }
2726
+ drawCandlestickBodies(e, t, n, r, i) {
2727
+ let a = t * .5, o = 0;
2728
+ for (let t = 0; t < e && o < this.maxBarTriangleBars(); t++) {
2729
+ let e = t * Y, r = this.rawLineData[e], i = this.rawLineData[e + 1], s = this.rawLineData[e + 4];
2730
+ n === "up" == s >= i && (this.writeBarTriangle(o, r - a, r + a, Math.min(i, s), Math.max(i, s)), o++);
2731
+ }
2732
+ this.drawBarTriangles(o * 6, r, i);
2733
+ }
2734
+ writeBarTriangle(e, t, n, r, i) {
2735
+ let a = e * De;
2736
+ this.barTriangleData[a] = t, this.barTriangleData[a + 1] = r, this.barTriangleData[a + 2] = n, this.barTriangleData[a + 3] = r, this.barTriangleData[a + 4] = t, this.barTriangleData[a + 5] = i, this.barTriangleData[a + 6] = t, this.barTriangleData[a + 7] = i, this.barTriangleData[a + 8] = n, this.barTriangleData[a + 9] = r, this.barTriangleData[a + 10] = n, this.barTriangleData[a + 11] = i;
2737
+ }
2738
+ drawBarTriangles(e, t, n, r = "bars") {
2739
+ e <= 0 || (this.uploadBarTriangleData(e), this.renderer.drawBarTriangles(this.barTriangleBuffer, e, t, n), this.recordDraw(r, e));
2740
+ }
2741
+ recordDraw(e, t, n = 1) {
2742
+ this.recordRenderMode(e), this.stats.pointsRendered += t, this.stats.drawCalls += n;
2743
+ }
2744
+ findNearestXCandidate(e, t, n) {
2745
+ let r = null, i = Infinity;
2746
+ for (let n = 0; n < this.series.length; n++) {
2747
+ let a = this.series[n];
2748
+ if (!a.visible) continue;
2749
+ let o = this.cameraForSeries(a).viewport, s = t / (o.xMax - o.xMin), c = a.nearestSampleByX(e, o);
2750
+ if (!c) continue;
2751
+ let l = Math.abs(c.x - e) * s;
2752
+ l < i && (r = {
2753
+ sample: c,
2754
+ series: a,
2755
+ seriesIndex: n
2756
+ }, i = l);
2757
+ }
2758
+ return r && i <= n ? r : null;
2759
+ }
2760
+ findNearestPointCandidate(e, t, n, r, i) {
2761
+ let a = null;
2762
+ for (let o = 0; o < this.series.length; o++) {
2763
+ let s = this.series[o];
2764
+ if (!s.visible) continue;
2765
+ let c = this.cameraForSeries(s).viewport, l = c.yMax - t / r * (c.yMax - c.yMin), u = s.nearestSampleByPoint(e, l, c, n, r, i);
2766
+ u && (!a || (u.distancePx ?? Infinity) < (a.sample.distancePx ?? Infinity)) && (a = {
2767
+ sample: u,
2768
+ series: s,
2769
+ seriesIndex: o
2770
+ });
2771
+ }
2772
+ return a && (a.sample.distancePx ?? Infinity) <= i ? a : null;
2773
+ }
2774
+ collectPickItems(e, t, n, r) {
2775
+ let i = [];
2776
+ for (let a = 0; a < this.series.length; a++) {
2777
+ let o = this.series[a];
2778
+ if (!o.visible) continue;
2779
+ let s = o.nearestSampleByX(e, this.cameraForSeries(o).viewport);
2780
+ s && i.push(this.createPickItem(s, o, a, t, n, r));
2781
+ }
2782
+ return i;
2783
+ }
2784
+ createPickItem(e, t, n, r, i, a) {
2785
+ let o = this.cameraForSeries(t), [s, c] = o.toClip(e.x, e.y), [l, u] = o.toScreen(s, c, a.width, a.height), d = a.left + l, f = a.top + u, p = d - r, m = f - i;
2786
+ return {
2787
+ ...e,
2788
+ distancePx: Math.hypot(p, m),
2789
+ series: t,
2790
+ seriesIndex: n,
2791
+ id: t.config.id,
2792
+ name: t.config.name,
2793
+ mode: t.config.mode,
2794
+ plotX: l,
2795
+ plotY: u,
2796
+ clientX: d,
2797
+ clientY: f
2798
+ };
2799
+ }
2800
+ scheduleHoverRefresh() {
2801
+ this._hoverRafId === 0 && (this._hoverRafId = requestAnimationFrame(() => {
2802
+ this._hoverRafId = 0, this.refreshHover();
2803
+ }));
2804
+ }
2805
+ refreshHover() {
2806
+ this.pointerInPlot && this.emitHover(this.pick(this.lastPointerClientX, this.lastPointerClientY));
2807
+ }
2808
+ emitHover(e) {
2809
+ this.currentHover = e;
2810
+ for (let t of this.hoverSubscribers) t(e);
2811
+ }
2812
+ emitPointerEvent(e, t) {
2813
+ let n = this.canvas.getBoundingClientRect();
2814
+ if (n.width <= 0 || n.height <= 0) return null;
2815
+ let r = t.clientX - n.left, i = t.clientY - n.top;
2816
+ if (r < 0 || i < 0 || r > n.width || i > n.height) return null;
2817
+ let a = this.camera.viewport, o = a.xMin + r / n.width * (a.xMax - a.xMin), s = a.yMax - i / n.height * (a.yMax - a.yMin), c = this.pick(t.clientX, t.clientY, this.options.hover), l = {
2818
+ type: e,
2819
+ clientX: t.clientX,
2820
+ clientY: t.clientY,
2821
+ plotX: r,
2822
+ plotY: i,
2823
+ dataX: o,
2824
+ dataY: s,
2825
+ button: t.button,
2826
+ buttons: t.buttons,
2827
+ altKey: t.altKey,
2828
+ ctrlKey: t.ctrlKey,
2829
+ metaKey: t.metaKey,
2830
+ shiftKey: t.shiftKey,
2831
+ items: c?.items ?? []
2832
+ };
2833
+ for (let t of this.pointerSubscribers[e]) t(l);
2834
+ return l;
2835
+ }
2836
+ emitSeriesClick(e) {
2837
+ for (let t of this.seriesClickSubscribers) t(e);
2838
+ }
2839
+ emitViewportChange() {
2840
+ let e = {
2841
+ viewport: this.camera.viewport,
2842
+ rightViewport: this.rightCamera.viewport
2843
+ };
2844
+ for (let t of this.viewportSubscribers) t(e);
2845
+ }
2846
+ emitSeriesChange() {
2847
+ for (let e of this.seriesSubscribers) e();
2848
+ this.refreshHover();
2849
+ }
2850
+ emitThemeChange() {
2851
+ for (let e of this.themeSubscribers) e();
2852
+ }
2853
+ emitRender() {
2854
+ for (let e of this.renderSubscribers) e(this);
2855
+ }
2856
+ drawDomTextForScreenshot(e, t, n) {
2857
+ let r = this.layout.root.querySelectorAll("div");
2858
+ for (let i of r) {
2859
+ let r = i.textContent;
2860
+ if (!r || i.children.length > 0) continue;
2861
+ let a = getComputedStyle(i);
2862
+ if (a.display === "none" || a.visibility === "hidden" || a.opacity === "0") continue;
2863
+ let o = i.getBoundingClientRect();
2864
+ o.width <= 0 || o.height <= 0 || (e.save(), e.scale(n, n), e.font = a.font, e.fillStyle = a.color, e.textBaseline = "top", e.textAlign = "left", e.fillText(r, o.left - t.left, o.top - t.top), e.restore());
2865
+ }
2866
+ }
2867
+ maxMinMaxSegments() {
2868
+ return Math.min(this.canvas.width, Te);
2869
+ }
2870
+ maxBarTriangleBars() {
2871
+ return Math.min(Ee, K);
2872
+ }
2873
+ maxRawBarInstances() {
2874
+ return this.renderer.supportsInstancedBars ? K : this.maxBarTriangleBars();
2875
+ }
2876
+ writeGridVertices(e) {
2877
+ let t = Math.max(1, this.canvas.clientWidth), n = Math.max(1, this.canvas.clientHeight);
2878
+ this.axis.getXTickValues(t, 12, this.xTicks), this.axis.getYTickValues(n, 8, this.yTicks);
2879
+ let r = 0;
2880
+ for (let t of this.xTicks) {
2881
+ if (r + 2 > X) return r;
2882
+ this.gridData[r * 2] = this.xToClip(t, e), this.gridData[r * 2 + 1] = -1, r++, this.gridData[r * 2] = this.xToClip(t, e), this.gridData[r * 2 + 1] = 1, r++;
2883
+ }
2884
+ for (let t of this.yTicks) {
2885
+ if (r + 2 > X) return r;
2886
+ this.gridData[r * 2] = -1, this.gridData[r * 2 + 1] = this.yToClip(t, e), r++, this.gridData[r * 2] = 1, this.gridData[r * 2 + 1] = this.yToClip(t, e), r++;
2887
+ }
2888
+ return r;
2889
+ }
2890
+ xToClip(e, t) {
2891
+ return (e - t.xMin) / (t.xMax - t.xMin) * 2 - 1;
2892
+ }
2893
+ yToClip(e, t) {
2894
+ return (e - t.yMin) / (t.yMax - t.yMin) * 2 - 1;
2895
+ }
2896
+ recordRenderMode(e) {
2897
+ this.stats.renderMode === "none" ? this.stats.renderMode = e : this.stats.renderMode !== e && (this.stats.renderMode = "mixed");
2898
+ }
2899
+ };
2900
+ //#endregion
2901
+ export { _ as a, m as c, O as i, n as l, L as n, h as o, F as r, g as s, Pe as t };
2902
+
2903
+ //# sourceMappingURL=Chart-BW9JaHs6.js.map