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.
- package/dist/Chart-BW9JaHs6.js +2903 -0
- package/dist/Chart-BW9JaHs6.js.map +1 -0
- package/dist/OverlayUtils-Cw1o8UH-.js +35 -0
- package/dist/OverlayUtils-Cw1o8UH-.js.map +1 -0
- package/dist/core/SeriesStore.d.ts +2 -0
- package/dist/core/SeriesStore.d.ts.map +1 -1
- package/dist/core/UniformRingBuffer.d.ts +67 -0
- package/dist/core/UniformRingBuffer.d.ts.map +1 -0
- package/dist/core/index.d.ts +3 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/types.d.ts +5 -1
- package/dist/core/types.d.ts.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +153 -2304
- package/dist/index.js.map +1 -1
- package/dist/interaction/AxisController.d.ts +45 -3
- package/dist/interaction/AxisController.d.ts.map +1 -1
- package/dist/interaction/index.d.ts +1 -0
- package/dist/interaction/index.d.ts.map +1 -1
- package/dist/linked.d.ts +3 -0
- package/dist/linked.d.ts.map +1 -0
- package/dist/linked.js +64 -0
- package/dist/linked.js.map +1 -0
- package/dist/plugins/crosshair.d.ts +3 -0
- package/dist/plugins/crosshair.d.ts.map +1 -0
- package/dist/plugins/crosshair.js +192 -0
- package/dist/plugins/crosshair.js.map +1 -0
- package/dist/plugins/interactions.js +87 -65
- package/dist/plugins/interactions.js.map +1 -1
- package/dist/plugins/navigator.d.ts +3 -0
- package/dist/plugins/navigator.d.ts.map +1 -0
- package/dist/plugins/navigator.js +147 -0
- package/dist/plugins/navigator.js.map +1 -0
- package/dist/plugins/selection.d.ts +3 -0
- package/dist/plugins/selection.d.ts.map +1 -0
- package/dist/plugins/selection.js +144 -0
- package/dist/plugins/selection.js.map +1 -0
- package/dist/plugins/tooltip.js +29 -45
- package/dist/plugins/tooltip.js.map +1 -1
- package/dist/react.d.ts +14 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +30 -0
- package/dist/react.js.map +1 -0
- package/dist/ui/Chart.d.ts +79 -1
- package/dist/ui/Chart.d.ts.map +1 -1
- package/dist/ui/ChartLayout.d.ts +10 -0
- package/dist/ui/ChartLayout.d.ts.map +1 -1
- package/dist/ui/Crosshair.d.ts +60 -0
- package/dist/ui/Crosshair.d.ts.map +1 -0
- package/dist/ui/Interactions.d.ts.map +1 -1
- package/dist/ui/LinkedCharts.d.ts +23 -0
- package/dist/ui/LinkedCharts.d.ts.map +1 -0
- package/dist/ui/Navigator.d.ts +32 -0
- package/dist/ui/Navigator.d.ts.map +1 -0
- package/dist/ui/OverlayUtils.d.ts +17 -0
- package/dist/ui/OverlayUtils.d.ts.map +1 -0
- package/dist/ui/Selection.d.ts +64 -0
- package/dist/ui/Selection.d.ts.map +1 -0
- package/dist/ui/Tooltip.d.ts.map +1 -1
- package/dist/ui/theme.d.ts +12 -0
- package/dist/ui/theme.d.ts.map +1 -1
- package/package.json +29 -1
package/dist/index.js
CHANGED
|
@@ -1,680 +1,82 @@
|
|
|
1
|
-
import e from "
|
|
2
|
-
//#region src/core/
|
|
3
|
-
|
|
4
|
-
|
|
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 "copySamplesRange" in e;
|
|
157
|
-
}
|
|
158
|
-
function o(e) {
|
|
159
|
-
return "copyMinMaxSegments" in e;
|
|
160
|
-
}
|
|
161
|
-
function s(e) {
|
|
162
|
-
return "copyVisibleSamples" in e;
|
|
1
|
+
import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c } from "./Chart-BW9JaHs6.js";
|
|
2
|
+
//#region src/core/UniformRingBuffer.ts
|
|
3
|
+
function l(e, t) {
|
|
4
|
+
return (e % t + t) % t;
|
|
163
5
|
}
|
|
164
|
-
|
|
165
|
-
return "copyVisiblePoints" in e;
|
|
166
|
-
}
|
|
167
|
-
var l = 64, u = 64, d = 1024;
|
|
168
|
-
function f(e, t, n, r, i) {
|
|
169
|
-
if (n === e) return t;
|
|
170
|
-
let a = (i - e) / (n - e);
|
|
171
|
-
return t + (r - t) * a;
|
|
172
|
-
}
|
|
173
|
-
var p = class {
|
|
174
|
-
config;
|
|
175
|
-
style;
|
|
176
|
-
dataset;
|
|
177
|
-
pyramid;
|
|
178
|
-
_dirty = !1;
|
|
179
|
-
_useDatasetRangeMinMax = !1;
|
|
180
|
-
_useRawMinMaxScan = !1;
|
|
181
|
-
_lastBuildLength = 0;
|
|
182
|
-
_lastBuildRangeStart = NaN;
|
|
183
|
-
_visible = !0;
|
|
184
|
-
constructor(e, t, i) {
|
|
185
|
-
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;
|
|
186
|
-
}
|
|
187
|
-
get hasLOD() {
|
|
188
|
-
return this.pyramid !== null;
|
|
189
|
-
}
|
|
190
|
-
get dirty() {
|
|
191
|
-
return this._dirty;
|
|
192
|
-
}
|
|
193
|
-
get length() {
|
|
194
|
-
return this.dataset.length;
|
|
195
|
-
}
|
|
196
|
-
get visible() {
|
|
197
|
-
return this._visible;
|
|
198
|
-
}
|
|
199
|
-
setVisible(e) {
|
|
200
|
-
this._visible = e;
|
|
201
|
-
}
|
|
202
|
-
append(e, t) {
|
|
203
|
-
if (!("push" in this.dataset)) throw TypeError("SeriesStore dataset is not appendable.");
|
|
204
|
-
this.dataset.append(e, t), this._dirty = !0;
|
|
205
|
-
}
|
|
206
|
-
clear() {
|
|
207
|
-
if (!("clear" in this.dataset)) throw TypeError("SeriesStore dataset is not clearable.");
|
|
208
|
-
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;
|
|
209
|
-
}
|
|
210
|
-
rebuildPyramid() {
|
|
211
|
-
if (this._dirty) {
|
|
212
|
-
if (this.pyramid) {
|
|
213
|
-
let e = this.dataset.length, t = this.dataset.range?.start ?? NaN, n = e === this._lastBuildLength && t !== this._lastBuildRangeStart;
|
|
214
|
-
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;
|
|
215
|
-
}
|
|
216
|
-
this._dirty = !1;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
query(e, t) {
|
|
220
|
-
if (!this.pyramid || !this.dataset.range) return {
|
|
221
|
-
buckets: new Float32Array(),
|
|
222
|
-
bucketCount: 0,
|
|
223
|
-
level: 0,
|
|
224
|
-
samplesPerPixel: 0
|
|
225
|
-
};
|
|
226
|
-
let n = this.dataset.lowerBoundX(e.xMin), r = this.dataset.upperBoundX(e.xMax), i = Math.max(0, r - n);
|
|
227
|
-
return this._useDatasetRangeMinMax ? this.queryRangeMinMax(n, i, t) : this.pyramid.query(e, t, {
|
|
228
|
-
start: n,
|
|
229
|
-
length: i
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
visibleSampleCount(e) {
|
|
233
|
-
let t = this.dataset.lowerBoundX(e.xMin), n = this.dataset.upperBoundX(e.xMax);
|
|
234
|
-
return Math.max(0, n - t);
|
|
235
|
-
}
|
|
236
|
-
sampleAt(e) {
|
|
237
|
-
return e < 0 || e >= this.dataset.length ? null : {
|
|
238
|
-
index: e,
|
|
239
|
-
x: this.dataset.getX(e),
|
|
240
|
-
y: this.dataset.getY(e)
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
nearestSampleByX(e, t) {
|
|
244
|
-
let n = this.visibleIndexRange(t);
|
|
245
|
-
if (n.start >= n.end) return null;
|
|
246
|
-
let r = this.dataset.lowerBoundX(e), i = Math.min(Math.max(r, n.start), n.end - 1), a = i - 1;
|
|
247
|
-
if (a >= n.start) {
|
|
248
|
-
let t = Math.abs(this.dataset.getX(i) - e);
|
|
249
|
-
Math.abs(this.dataset.getX(a) - e) <= t && (i = a);
|
|
250
|
-
}
|
|
251
|
-
return this.sampleAt(i);
|
|
252
|
-
}
|
|
253
|
-
nearestSampleByPoint(e, t, n, r, i, a = Infinity) {
|
|
254
|
-
let o = this.visibleIndexRange(n), s = n.xMax - n.xMin, c = n.yMax - n.yMin;
|
|
255
|
-
if (o.start >= o.end || r <= 0 || i <= 0 || s <= 0 || c <= 0) return null;
|
|
256
|
-
let u = r / s, d = i / c, f = -1, p = a < 0 ? -1 : Number.isFinite(a) ? a * a : Infinity, m = (n) => {
|
|
257
|
-
let r = (this.dataset.getX(n) - e) * u, i = (this.dataset.getY(n) - t) * d, a = r * r + i * i;
|
|
258
|
-
(a < p || f < 0 && a <= p) && (p = a, f = n);
|
|
259
|
-
}, h = this.dataset.lowerBoundX(e), g = Math.min(Math.max(h, o.start), o.end - 1);
|
|
260
|
-
if (m(g), g > o.start && m(g - 1), g + 1 < o.end && m(g + 1), this.hasPointIntervalBounds() && o.end - o.start > l) {
|
|
261
|
-
let n = this.pointIntervalDistanceSq(o.start, o.end, e, t, u, d), r = n <= p ? [{
|
|
262
|
-
start: o.start,
|
|
263
|
-
end: o.end,
|
|
264
|
-
lowerBoundSq: n
|
|
265
|
-
}] : [];
|
|
266
|
-
for (; r.length > 0;) {
|
|
267
|
-
let n = r.pop();
|
|
268
|
-
if (n.lowerBoundSq > p) continue;
|
|
269
|
-
let i = n.end - n.start;
|
|
270
|
-
if (i <= l) {
|
|
271
|
-
for (let e = n.start; e < n.end; e++) m(e);
|
|
272
|
-
continue;
|
|
273
|
-
}
|
|
274
|
-
let a = n.start + (i >> 1), o = this.pointIntervalDistanceSq(n.start, a, e, t, u, d), s = this.pointIntervalDistanceSq(a, n.end, e, t, u, d), c = {
|
|
275
|
-
start: n.start,
|
|
276
|
-
end: a,
|
|
277
|
-
lowerBoundSq: o
|
|
278
|
-
}, f = {
|
|
279
|
-
start: a,
|
|
280
|
-
end: n.end,
|
|
281
|
-
lowerBoundSq: s
|
|
282
|
-
};
|
|
283
|
-
o < s ? (s <= p && r.push(f), o <= p && r.push(c)) : (o <= p && r.push(c), s <= p && r.push(f));
|
|
284
|
-
}
|
|
285
|
-
} else {
|
|
286
|
-
let t = Math.min(h - 1, o.end - 1), n = Math.max(h, o.start);
|
|
287
|
-
for (; t >= o.start || n < o.end;) {
|
|
288
|
-
let r = t >= o.start ? this.pointXDistanceSq(t, e, u) : Infinity, i = n < o.end ? this.pointXDistanceSq(n, e, u) : Infinity;
|
|
289
|
-
if (r > p && i > p) break;
|
|
290
|
-
r <= i ? (r <= p && m(t), t--) : (i <= p && m(n), n++);
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
if (f < 0) return null;
|
|
294
|
-
let _ = this.sampleAt(f);
|
|
295
|
-
return _ ? {
|
|
296
|
-
..._,
|
|
297
|
-
distancePx: Math.sqrt(p)
|
|
298
|
-
} : null;
|
|
299
|
-
}
|
|
300
|
-
copyRawVisible(e, t, n, r = 0) {
|
|
301
|
-
return this.copyVisibleSamples(e, t, n, "points", 0, r);
|
|
302
|
-
}
|
|
303
|
-
copyScatterVisible(e, t, n, r, i, a, o = 0) {
|
|
304
|
-
return this.copyVisiblePoints(e, t, n, r, i, a, o);
|
|
305
|
-
}
|
|
306
|
-
copyScatterRange(e, t, n, r, i, a = 0, o = 0, s = 0) {
|
|
307
|
-
if (i <= 0 || r.length < i * 2) return 0;
|
|
308
|
-
let c = Math.max(0, Math.floor(e)), l = Math.min(this.dataset.length, Math.ceil(t));
|
|
309
|
-
if (l <= c) return 0;
|
|
310
|
-
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;
|
|
311
|
-
for (let e = c; e < l && h < i; e++) {
|
|
312
|
-
let t = this.dataset.getY(e);
|
|
313
|
-
if (t < p || t > m) continue;
|
|
314
|
-
let n = h * 2;
|
|
315
|
-
r[n] = this.dataset.getX(e) - a, r[n + 1] = t, h++;
|
|
316
|
-
}
|
|
317
|
-
return h;
|
|
318
|
-
}
|
|
319
|
-
copyRawVisibleClipped(e, t, n, r = 0) {
|
|
320
|
-
return this.copyClippedVisibleLine(e, t, n, r, "data");
|
|
321
|
-
}
|
|
322
|
-
copyRawVisibleClipSpace(e, t, n) {
|
|
323
|
-
return this.copyClippedVisibleLine(e, t, n, 0, "clip");
|
|
324
|
-
}
|
|
325
|
-
copyRawRange(e, t, n, r, i = 0) {
|
|
326
|
-
return this.copySampleRange(e, t, n, r, "points", 0, i);
|
|
327
|
-
}
|
|
328
|
-
copyAreaVisible(e, t, n, r = 0, i = 0) {
|
|
329
|
-
return this.copyVisibleSamples(e, t, n, "area", r, i) * 2;
|
|
330
|
-
}
|
|
331
|
-
copyAreaRange(e, t, n, r, i = 0, a = 0) {
|
|
332
|
-
return this.copySampleRange(e, t, n, r, "area", i, a) * 2;
|
|
333
|
-
}
|
|
334
|
-
copyMinMaxVisible(e, t, n, r = 0) {
|
|
335
|
-
return this.copyMinMaxSegments(e, t, n, "line-list", r) * 2;
|
|
336
|
-
}
|
|
337
|
-
copyMinMaxInstanced(e, t, n, r = 0) {
|
|
338
|
-
return this.copyMinMaxSegments(e, t, n, "instanced", r);
|
|
339
|
-
}
|
|
340
|
-
copyOhlcRange(e, t, n, r, a, o = 0) {
|
|
341
|
-
if (!i(this.dataset) || r <= 0 || n.length < r * 12) return 0;
|
|
342
|
-
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;
|
|
343
|
-
for (let e = 0; e < l; e++) {
|
|
344
|
-
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;
|
|
345
|
-
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;
|
|
346
|
-
}
|
|
347
|
-
return l;
|
|
348
|
-
}
|
|
349
|
-
copyOhlcTuplesRange(e, t, n, r, a = 0) {
|
|
350
|
-
if (!i(this.dataset) || r <= 0 || n.length < r * 5) return 0;
|
|
351
|
-
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));
|
|
352
|
-
for (let e = 0; e < c; e++) {
|
|
353
|
-
let t = o + e, r = e * 5;
|
|
354
|
-
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);
|
|
355
|
-
}
|
|
356
|
-
return c;
|
|
357
|
-
}
|
|
358
|
-
visibleIndexRange(e, t = 0) {
|
|
359
|
-
if (!e) return {
|
|
360
|
-
start: 0,
|
|
361
|
-
end: this.dataset.length
|
|
362
|
-
};
|
|
363
|
-
let n = Math.max(0, Math.floor(t));
|
|
364
|
-
return {
|
|
365
|
-
start: Math.max(0, this.dataset.lowerBoundX(e.xMin) - n),
|
|
366
|
-
end: Math.min(this.dataset.length, this.dataset.upperBoundX(e.xMax) + n)
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
pointXDistanceSq(e, t, n) {
|
|
370
|
-
let r = (this.dataset.getX(e) - t) * n;
|
|
371
|
-
return r * r;
|
|
372
|
-
}
|
|
373
|
-
pointIntervalDistanceSq(e, t, n, r, i, a) {
|
|
374
|
-
if (t <= e) return Infinity;
|
|
375
|
-
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);
|
|
376
|
-
if (!l) return Infinity;
|
|
377
|
-
let u = r < l.minY ? (l.minY - r) * a : r > l.maxY ? (r - l.maxY) * a : 0;
|
|
378
|
-
return c * c + u * u;
|
|
379
|
-
}
|
|
380
|
-
hasPointIntervalBounds() {
|
|
381
|
-
return r(this.dataset) || this.pyramid !== null && !this._dirty && !this._useRawMinMaxScan;
|
|
382
|
-
}
|
|
383
|
-
pointIntervalMinMaxY(e, t) {
|
|
384
|
-
return r(this.dataset) ? this.dataset.rangeMinMaxY(e, t) : this.pyramid && !this._dirty && !this._useRawMinMaxScan ? this.pyramid.rangeMinMax(this.dataset, e, t) : null;
|
|
385
|
-
}
|
|
386
|
-
copyClippedVisibleLine(e, t, n, r, i) {
|
|
387
|
-
if (n <= 0 || t.length < n * 2) return 0;
|
|
388
|
-
let a = e.xMax - e.xMin, o = e.yMax - e.yMin;
|
|
389
|
-
if (i === "clip" && (a <= 0 || o <= 0)) return 0;
|
|
390
|
-
let s = Math.max(0, this.dataset.lowerBoundX(e.xMin) - 1), c = Math.min(this.dataset.length, this.dataset.upperBoundX(e.xMax) + 1);
|
|
391
|
-
if (c - s <= 0) return 0;
|
|
392
|
-
let l = 0, u = NaN, d = NaN, p = (s, c) => {
|
|
393
|
-
let f = i === "clip" ? (s - e.xMin) / a * 2 - 1 : s - r, p = i === "clip" ? (c - e.yMin) / o * 2 - 1 : c;
|
|
394
|
-
if (l > 0 && f === u && p === d) return !0;
|
|
395
|
-
if (l >= n) return !1;
|
|
396
|
-
let m = l * 2;
|
|
397
|
-
return t[m] = f, t[m + 1] = p, l++, u = f, d = p, !0;
|
|
398
|
-
};
|
|
399
|
-
if (c - s === 1) {
|
|
400
|
-
let t = this.dataset.getX(s);
|
|
401
|
-
return t < e.xMin || t > e.xMax ? 0 : p(t, this.dataset.getY(s)) ? l : 0;
|
|
402
|
-
}
|
|
403
|
-
for (let t = s; t + 1 < c; t++) {
|
|
404
|
-
let n = this.dataset.getX(t), r = this.dataset.getY(t), i = this.dataset.getX(t + 1), a = this.dataset.getY(t + 1);
|
|
405
|
-
if (i < e.xMin || n > e.xMax) continue;
|
|
406
|
-
let o = Math.max(n, e.xMin), s = Math.min(i, e.xMax);
|
|
407
|
-
if (s < o) continue;
|
|
408
|
-
let c = f(n, r, i, a, o), l = f(n, r, i, a, s);
|
|
409
|
-
if (!p(o, c) || !p(s, l)) break;
|
|
410
|
-
}
|
|
411
|
-
return l;
|
|
412
|
-
}
|
|
413
|
-
copyVisiblePoints(e, t, n, r, i, a, o) {
|
|
414
|
-
if (c(this.dataset)) return this.dataset.copyVisiblePoints(e, t, n, o, r, i, a);
|
|
415
|
-
if (n <= 0 || t.length < n * 2) return 0;
|
|
416
|
-
let s = e.xMax - e.xMin, l = e.yMax - e.yMin, u = Math.max(1, Math.floor(r)), d = Math.max(1, Math.floor(i));
|
|
417
|
-
if (s <= 0 || l <= 0) return 0;
|
|
418
|
-
let f = (Number.isFinite(a) ? Math.max(0, a) : 0) * .5, p = f / u * s, m = f / d * l, 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);
|
|
419
|
-
if (b <= y) return 0;
|
|
420
|
-
if (b - y <= n) return this.copyVisiblePointRange(y, b, _, v, t, n, o);
|
|
421
|
-
let x = this.hasPointIntervalBounds(), S = x ? this.pointIntervalMinMaxY(y, b) : null;
|
|
422
|
-
if (S && (S.maxY < _ || S.minY > v)) return 0;
|
|
423
|
-
if (b - y <= n * 4) {
|
|
424
|
-
let e = this.copyVisiblePointsExact(y, b, _, v, t, n, o);
|
|
425
|
-
if (!e.overflow) return e.count;
|
|
426
|
-
}
|
|
427
|
-
let C = S !== null && S.minY >= _ && S.maxY <= v;
|
|
428
|
-
return this.copyVisiblePointBuckets(y, b, _, v, t, n, o, C, x);
|
|
429
|
-
}
|
|
430
|
-
copyVisiblePointRange(e, t, n, r, i, a, o) {
|
|
431
|
-
let s = 0;
|
|
432
|
-
for (let c = e; c < t && s < a; c++) {
|
|
433
|
-
let e = this.dataset.getY(c);
|
|
434
|
-
if (e < n || e > r) continue;
|
|
435
|
-
let t = s * 2;
|
|
436
|
-
i[t] = this.dataset.getX(c) - o, i[t + 1] = e, s++;
|
|
437
|
-
}
|
|
438
|
-
return s;
|
|
439
|
-
}
|
|
440
|
-
copyVisiblePointBuckets(e, t, n, r, i, a, o, s, c) {
|
|
441
|
-
let l = t - e, u = this.stableScatterBucketWidth(l, a), f = Math.floor(e / u) * u, p = 0, m = (e) => {
|
|
442
|
-
let t = p * 2;
|
|
443
|
-
i[t] = this.dataset.getX(e) - o, i[t + 1] = this.dataset.getY(e), p++;
|
|
444
|
-
};
|
|
445
|
-
for (let l = f; l < t && p < a; l += u) {
|
|
446
|
-
let a = Math.min(t, l + u), f = Math.max(e, l);
|
|
447
|
-
if (a <= f) continue;
|
|
448
|
-
let h = Math.max(f, Math.min(a - 1, l + (u >> 1)));
|
|
449
|
-
if (s) {
|
|
450
|
-
m(h);
|
|
451
|
-
continue;
|
|
452
|
-
}
|
|
453
|
-
let g = c && a - f >= d ? this.pointIntervalMinMaxY(f, a) : null;
|
|
454
|
-
if (!(g && (g.maxY < n || g.minY > r))) {
|
|
455
|
-
if (g && g.minY >= n && g.maxY <= r) {
|
|
456
|
-
m(h);
|
|
457
|
-
continue;
|
|
458
|
-
}
|
|
459
|
-
for (let e = f; e < a; e++) {
|
|
460
|
-
let t = this.dataset.getY(e);
|
|
461
|
-
if (t < n || t > r) continue;
|
|
462
|
-
let a = p * 2;
|
|
463
|
-
i[a] = this.dataset.getX(e) - o, i[a + 1] = t, p++;
|
|
464
|
-
break;
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
return p;
|
|
469
|
-
}
|
|
470
|
-
stableScatterBucketWidth(e, t) {
|
|
471
|
-
let n = Math.max(1, Math.ceil(e / Math.max(1, t)));
|
|
472
|
-
return n <= 8 ? n : Math.ceil(n / 8) * 8;
|
|
473
|
-
}
|
|
474
|
-
copyVisiblePointsExact(e, t, n, r, i, a, o) {
|
|
475
|
-
let s = 0, c = !1, l = this.hasPointIntervalBounds(), d = (e) => {
|
|
476
|
-
let t = this.dataset.getY(e);
|
|
477
|
-
if (t < n || t > r) return !0;
|
|
478
|
-
if (s >= a) return c = !0, !1;
|
|
479
|
-
let l = s * 2;
|
|
480
|
-
return i[l] = this.dataset.getX(e) - o, i[l + 1] = t, s++, !0;
|
|
481
|
-
}, f = (e, t) => {
|
|
482
|
-
for (let n = e; n < t; n++) if (!d(n)) return !1;
|
|
483
|
-
return !0;
|
|
484
|
-
}, p = (e, t) => {
|
|
485
|
-
if (t <= e) return !0;
|
|
486
|
-
let i = l ? this.pointIntervalMinMaxY(e, t) : null;
|
|
487
|
-
if (i && (i.maxY < n || i.minY > r)) return !0;
|
|
488
|
-
if (t - e <= u || !l) return f(e, t);
|
|
489
|
-
let a = e + (t - e >> 1);
|
|
490
|
-
return p(e, a) && p(a, t);
|
|
491
|
-
};
|
|
492
|
-
return p(e, t), {
|
|
493
|
-
count: s,
|
|
494
|
-
overflow: c
|
|
495
|
-
};
|
|
496
|
-
}
|
|
497
|
-
copyVisibleSamples(e, t, n, r, i, a) {
|
|
498
|
-
if (s(this.dataset)) return this.dataset.copyVisibleSamples(e, t, n, r, i, a);
|
|
499
|
-
let o = r === "points" ? 2 : 4;
|
|
500
|
-
if (n <= 0 || t.length < n * o) return 0;
|
|
501
|
-
let c = this.dataset.lowerBoundX(e.xMin), l = this.dataset.upperBoundX(e.xMax), u = l - c;
|
|
502
|
-
if (u <= 0) return 0;
|
|
503
|
-
let d = Math.max(1, Math.ceil(u / n)), f = 0;
|
|
504
|
-
for (let e = c; e < l && f < n; e += d) {
|
|
505
|
-
let n = this.dataset.getX(e) - a, o = this.dataset.getY(e);
|
|
506
|
-
if (r === "points") {
|
|
507
|
-
let e = f * 2;
|
|
508
|
-
t[e] = n, t[e + 1] = o;
|
|
509
|
-
} else {
|
|
510
|
-
let e = f * 4;
|
|
511
|
-
t[e] = n, t[e + 1] = i, t[e + 2] = n, t[e + 3] = o;
|
|
512
|
-
}
|
|
513
|
-
f++;
|
|
514
|
-
}
|
|
515
|
-
return f;
|
|
516
|
-
}
|
|
517
|
-
copySampleRange(e, t, n, r, i, o, s) {
|
|
518
|
-
if (a(this.dataset)) return this.dataset.copySamplesRange(e, t, n, r, i, o, s);
|
|
519
|
-
let c = i === "points" ? 2 : 4;
|
|
520
|
-
if (r <= 0 || n.length < r * c) return 0;
|
|
521
|
-
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));
|
|
522
|
-
for (let e = 0; e < d; e++) {
|
|
523
|
-
let t = l + e, r = this.dataset.getX(t) - s, a = this.dataset.getY(t);
|
|
524
|
-
if (i === "points") {
|
|
525
|
-
let t = e * 2;
|
|
526
|
-
n[t] = r, n[t + 1] = a;
|
|
527
|
-
} else {
|
|
528
|
-
let t = e * 4;
|
|
529
|
-
n[t] = r, n[t + 1] = o, n[t + 2] = r, n[t + 3] = a;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
return d;
|
|
533
|
-
}
|
|
534
|
-
copyMinMaxSegments(e, t, n, r, i) {
|
|
535
|
-
if (o(this.dataset)) return this.dataset.copyMinMaxSegments(e, t, n, r, i);
|
|
536
|
-
let a = r === "line-list" ? 4 : 3;
|
|
537
|
-
if (!this.pyramid || n <= 0 || t.length < n * a) return 0;
|
|
538
|
-
let s = this.dataset.lowerBoundX(e.xMin), c = this.dataset.upperBoundX(e.xMax), l = c - s;
|
|
539
|
-
if (l <= 0) return 0;
|
|
540
|
-
let u = Math.min(n, l);
|
|
541
|
-
for (let e = 0; e < u; e++) {
|
|
542
|
-
let n = s + Math.floor(e * l / u), a = s + Math.max(Math.floor((e + 1) * l / u), Math.floor(e * l / u) + 1), o = Math.min(c, a), d = this.minMaxForRange(n, o);
|
|
543
|
-
if (!d) continue;
|
|
544
|
-
let f = this.dataset.getX(n + (o - n >> 1)) - i, { minY: p, maxY: m } = d;
|
|
545
|
-
if (r === "line-list") {
|
|
546
|
-
let n = e * 4;
|
|
547
|
-
t[n] = f, t[n + 1] = p, t[n + 2] = f, t[n + 3] = m;
|
|
548
|
-
} else {
|
|
549
|
-
let n = e * 3;
|
|
550
|
-
t[n] = f, t[n + 1] = p, t[n + 2] = m;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
return u;
|
|
554
|
-
}
|
|
555
|
-
minMaxForRange(e, t) {
|
|
556
|
-
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);
|
|
557
|
-
}
|
|
558
|
-
queryRangeMinMax(e, t, n) {
|
|
559
|
-
if (n <= 0 || t <= 0 || !r(this.dataset)) return {
|
|
560
|
-
buckets: new Float32Array(),
|
|
561
|
-
bucketCount: 0,
|
|
562
|
-
level: 0,
|
|
563
|
-
samplesPerPixel: 0
|
|
564
|
-
};
|
|
565
|
-
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);
|
|
566
|
-
for (let e = 0; e < f; e++) {
|
|
567
|
-
let t = (u + e) * o, n = Math.min(this.dataset.length, t + o), r = this.dataset.rangeMinMaxY(t, n);
|
|
568
|
-
r && (p[e * 2] = r.minY, p[e * 2 + 1] = r.maxY);
|
|
569
|
-
}
|
|
570
|
-
return {
|
|
571
|
-
buckets: p,
|
|
572
|
-
bucketCount: f,
|
|
573
|
-
level: a,
|
|
574
|
-
samplesPerPixel: i
|
|
575
|
-
};
|
|
576
|
-
}
|
|
577
|
-
rawMinMaxForRange(e, t) {
|
|
578
|
-
if (r(this.dataset)) return this.dataset.rangeMinMaxY(e, t);
|
|
579
|
-
let n = Math.max(0, Math.floor(e)), i = Math.min(this.dataset.length, Math.ceil(t));
|
|
580
|
-
if (i <= n) return null;
|
|
581
|
-
let a = Infinity, o = -Infinity;
|
|
582
|
-
for (let e = n; e < i; e++) {
|
|
583
|
-
let t = this.dataset.getY(e);
|
|
584
|
-
t < a && (a = t), t > o && (o = t);
|
|
585
|
-
}
|
|
586
|
-
return {
|
|
587
|
-
minY: a,
|
|
588
|
-
maxY: o
|
|
589
|
-
};
|
|
590
|
-
}
|
|
591
|
-
};
|
|
592
|
-
//#endregion
|
|
593
|
-
//#region src/core/search.ts
|
|
594
|
-
function m(e, t, n) {
|
|
595
|
-
let r = 0, i = e;
|
|
596
|
-
for (; r < i;) {
|
|
597
|
-
let e = r + (i - r >> 1);
|
|
598
|
-
t(e) < n ? r = e + 1 : i = e;
|
|
599
|
-
}
|
|
600
|
-
return r;
|
|
601
|
-
}
|
|
602
|
-
function h(e, t, n) {
|
|
603
|
-
let r = 0, i = e;
|
|
604
|
-
for (; r < i;) {
|
|
605
|
-
let e = r + (i - r >> 1);
|
|
606
|
-
t(e) <= n ? r = e + 1 : i = e;
|
|
607
|
-
}
|
|
608
|
-
return r;
|
|
609
|
-
}
|
|
610
|
-
//#endregion
|
|
611
|
-
//#region src/core/RingBuffer.ts
|
|
612
|
-
var g = class e {
|
|
6
|
+
var u = class e {
|
|
613
7
|
capacity;
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
xData;
|
|
8
|
+
xStep;
|
|
9
|
+
blockSize;
|
|
617
10
|
yData;
|
|
618
|
-
|
|
11
|
+
blockMin;
|
|
12
|
+
blockMax;
|
|
13
|
+
blockTreeBase;
|
|
619
14
|
minTree;
|
|
620
15
|
maxTree;
|
|
621
|
-
|
|
16
|
+
_length = 0;
|
|
17
|
+
_head = 0;
|
|
18
|
+
_nextX;
|
|
622
19
|
constructor(t, n = {}) {
|
|
623
|
-
if (!Number.isInteger(t) || t <= 0) throw RangeError("
|
|
624
|
-
|
|
20
|
+
if (!Number.isInteger(t) || t <= 0) throw RangeError("UniformRingBuffer capacity must be a positive integer.");
|
|
21
|
+
let r = n.xStep ?? 1;
|
|
22
|
+
if (!Number.isFinite(r) || r <= 0) throw RangeError("UniformRingBuffer xStep must be a positive finite number.");
|
|
23
|
+
let i = n.blockSize ?? 64;
|
|
24
|
+
if (!Number.isInteger(i) || i <= 0) throw RangeError("UniformRingBuffer blockSize must be a positive integer.");
|
|
25
|
+
this.capacity = t, this.xStep = r, this.blockSize = i, this._nextX = n.xStart ?? 0, this.yData = new Float32Array(t);
|
|
26
|
+
let a = Math.ceil(t / this.blockSize);
|
|
27
|
+
this.blockMin = new Float32Array(a), this.blockMax = new Float32Array(a), this.blockTreeBase = e.nextPowerOfTwo(a), this.minTree = new Float32Array(this.blockTreeBase * 2), this.maxTree = new Float32Array(this.blockTreeBase * 2), this.blockMin.fill(Infinity), this.blockMax.fill(-Infinity), this.minTree.fill(Infinity), this.maxTree.fill(-Infinity);
|
|
625
28
|
}
|
|
626
29
|
get length() {
|
|
627
30
|
return this._length;
|
|
628
31
|
}
|
|
629
32
|
get range() {
|
|
630
33
|
return this._length === 0 ? null : {
|
|
631
|
-
start: this.
|
|
34
|
+
start: this.firstX(),
|
|
632
35
|
end: this.getX(this._length - 1)
|
|
633
36
|
};
|
|
634
37
|
}
|
|
635
38
|
push(e, t) {
|
|
636
|
-
|
|
637
|
-
if (this.overflow === "drop-new") return;
|
|
638
|
-
if (this.overflow === "error") throw RangeError("RingBuffer capacity exceeded.");
|
|
639
|
-
}
|
|
640
|
-
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++;
|
|
39
|
+
this._length === 0 && Number.isFinite(e) && (this._nextX = e), this.appendY([t]);
|
|
641
40
|
}
|
|
642
41
|
append(e, t) {
|
|
643
42
|
let n = Math.min(e.length, t.length);
|
|
644
43
|
if (!(n <= 0)) {
|
|
645
|
-
if (this.
|
|
646
|
-
let
|
|
647
|
-
|
|
648
|
-
let i = Math.min(n, r);
|
|
649
|
-
if (i <= 0) return;
|
|
650
|
-
this.appendNoWrap(e, t, 0, i);
|
|
651
|
-
return;
|
|
44
|
+
if (this._length === 0) {
|
|
45
|
+
let t = e[0];
|
|
46
|
+
Number.isFinite(t) && (this._nextX = t);
|
|
652
47
|
}
|
|
653
48
|
if (n >= this.capacity) {
|
|
654
|
-
let r = n - this.capacity;
|
|
655
|
-
|
|
49
|
+
let r = n - this.capacity, i = e[r], a = Number.isFinite(i);
|
|
50
|
+
a && (this._nextX = i), this.replaceAll(t, r, a ? this.capacity : n);
|
|
656
51
|
return;
|
|
657
52
|
}
|
|
658
|
-
this.
|
|
53
|
+
this.appendValues(t, 0, n);
|
|
659
54
|
}
|
|
660
55
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
56
|
+
appendY(e) {
|
|
57
|
+
let t = e.length;
|
|
58
|
+
if (!(t <= 0)) {
|
|
59
|
+
if (t >= this.capacity) {
|
|
60
|
+
this.replaceAll(e, t - this.capacity, t);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this.appendValues(e, 0, t);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
clear() {
|
|
67
|
+
this._length = 0, this._head = 0, this.blockMin.fill(Infinity), this.blockMax.fill(-Infinity), this.minTree.fill(Infinity), this.maxTree.fill(-Infinity);
|
|
666
68
|
}
|
|
667
69
|
getX(e) {
|
|
668
|
-
return this.assertValidIndex(e), this.
|
|
70
|
+
return this.assertValidIndex(e), this.firstX() + e * this.xStep;
|
|
669
71
|
}
|
|
670
72
|
getY(e) {
|
|
671
73
|
return this.assertValidIndex(e), this.yData[this.logicalToPhysical(e)];
|
|
672
74
|
}
|
|
673
75
|
lowerBoundX(e) {
|
|
674
|
-
return
|
|
76
|
+
return this._length === 0 ? 0 : Math.max(0, Math.min(this._length, Math.ceil((e - this.firstX()) / this.xStep)));
|
|
675
77
|
}
|
|
676
78
|
upperBoundX(e) {
|
|
677
|
-
return
|
|
79
|
+
return this._length === 0 ? 0 : Math.max(0, Math.min(this._length, Math.floor((e - this.firstX()) / this.xStep) + 1));
|
|
678
80
|
}
|
|
679
81
|
rangeMinMaxY(e, t) {
|
|
680
82
|
let n = Math.max(0, Math.floor(e)), r = Math.min(this._length, Math.ceil(t));
|
|
@@ -687,44 +89,100 @@ var g = class e {
|
|
|
687
89
|
maxY: Math.max(o.maxY, s.maxY)
|
|
688
90
|
} : o : s;
|
|
689
91
|
}
|
|
690
|
-
|
|
691
|
-
|
|
92
|
+
copyVisibleSamples(e, t, n, r, i, a) {
|
|
93
|
+
let o = this.lowerBoundX(e.xMin), s = this.upperBoundX(e.xMax);
|
|
94
|
+
if (s <= o) return 0;
|
|
95
|
+
let c = Math.max(1, Math.ceil((e.xMax - e.xMin) / this.xStep)), u = Math.max(1, Math.ceil(c / n)), d = o + l(-l(Math.round(this.firstX() / this.xStep) + o, u), u);
|
|
96
|
+
return this.copyStridedSamples(d, s, u, t, n, r, i, a);
|
|
692
97
|
}
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
for (; a > 0;) {
|
|
696
|
-
let n = Math.min(a, this.capacity - this._head);
|
|
697
|
-
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;
|
|
698
|
-
}
|
|
98
|
+
copySamplesRange(e, t, n, r, i, a, o) {
|
|
99
|
+
return this.copyStridedSamples(Math.max(0, Math.floor(e)), Math.min(this._length, Math.ceil(t)), 1, n, r, i, a, o);
|
|
699
100
|
}
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
101
|
+
copyMinMaxSegments(e, t, n, r, i) {
|
|
102
|
+
let a = r === "line-list" ? 4 : 3;
|
|
103
|
+
if (n <= 0 || t.length < n * a) return 0;
|
|
104
|
+
let o = this.lowerBoundX(e.xMin), s = this.upperBoundX(e.xMax), c = s - o;
|
|
105
|
+
if (c <= 0) return 0;
|
|
106
|
+
let l = Math.min(n, c);
|
|
107
|
+
for (let e = 0; e < l; e++) {
|
|
108
|
+
let n = o + Math.floor(e * c / l), a = Math.min(s, o + Math.max(Math.floor((e + 1) * c / l), Math.floor(e * c / l) + 1)), u = this.rangeMinMaxY(n, a);
|
|
109
|
+
if (!u) continue;
|
|
110
|
+
let d = this.firstX() + (n + (a - n >> 1)) * this.xStep - i;
|
|
111
|
+
if (r === "line-list") {
|
|
112
|
+
let n = e * 4;
|
|
113
|
+
t[n] = d, t[n + 1] = u.minY, t[n + 2] = d, t[n + 3] = u.maxY;
|
|
114
|
+
} else {
|
|
115
|
+
let n = e * 3;
|
|
116
|
+
t[n] = d, t[n + 1] = u.minY, t[n + 2] = u.maxY;
|
|
117
|
+
}
|
|
706
118
|
}
|
|
707
|
-
|
|
119
|
+
return l;
|
|
708
120
|
}
|
|
709
|
-
|
|
710
|
-
let n = this.
|
|
711
|
-
|
|
121
|
+
replaceAll(e, t, n) {
|
|
122
|
+
for (let n = 0; n < this.capacity; n++) this.yData[n] = e[t + n];
|
|
123
|
+
this._head = 0, this._length = this.capacity, this._nextX += n * this.xStep, this.recomputeAllBlocks();
|
|
712
124
|
}
|
|
713
|
-
|
|
714
|
-
let
|
|
715
|
-
for (;
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
125
|
+
appendValues(e, t, n) {
|
|
126
|
+
let r = t, i = n;
|
|
127
|
+
for (; i > 0;) {
|
|
128
|
+
let t = Math.min(i, this.capacity - this._head);
|
|
129
|
+
for (let n = 0; n < t; n++) this.yData[this._head + n] = e[r + n];
|
|
130
|
+
this._length = Math.min(this.capacity, this._length + t), this.recomputePhysicalBlockRange(this._head, this._head + t), this._head = (this._head + t) % this.capacity, r += t, i -= t;
|
|
719
131
|
}
|
|
132
|
+
this._nextX += n * this.xStep;
|
|
720
133
|
}
|
|
721
|
-
|
|
722
|
-
let
|
|
723
|
-
|
|
134
|
+
copyStridedSamples(e, t, n, r, i, a, o, s) {
|
|
135
|
+
let c = a === "points" ? 2 : 4;
|
|
136
|
+
if (i <= 0 || r.length < i * c) return 0;
|
|
137
|
+
let l = Math.min(i, Math.max(0, Math.ceil((t - e) / n))), u = this.firstX();
|
|
138
|
+
if (a === "points") for (let t = 0, i = e; t < l; t++, i += n) {
|
|
139
|
+
let e = t * 2;
|
|
140
|
+
r[e] = u + i * this.xStep - s, r[e + 1] = this.yData[this.logicalToPhysical(i)];
|
|
141
|
+
}
|
|
142
|
+
else for (let t = 0, i = e; t < l; t++, i += n) {
|
|
143
|
+
let e = t * 4, n = u + i * this.xStep - s;
|
|
144
|
+
r[e] = n, r[e + 1] = o, r[e + 2] = n, r[e + 3] = this.yData[this.logicalToPhysical(i)];
|
|
145
|
+
}
|
|
146
|
+
return l;
|
|
724
147
|
}
|
|
725
148
|
queryPhysicalMinMax(e, t) {
|
|
726
|
-
|
|
727
|
-
|
|
149
|
+
let n = Infinity, r = -Infinity, i = e;
|
|
150
|
+
for (; i < t && i % this.blockSize !== 0;) {
|
|
151
|
+
let e = this.yData[i];
|
|
152
|
+
e < n && (n = e), e > r && (r = e), i++;
|
|
153
|
+
}
|
|
154
|
+
let a = i / this.blockSize, o = Math.floor(t / this.blockSize);
|
|
155
|
+
if (o > a) {
|
|
156
|
+
let e = this.queryBlockMinMax(a, o);
|
|
157
|
+
e && (e.minY < n && (n = e.minY), e.maxY > r && (r = e.maxY)), i = o * this.blockSize;
|
|
158
|
+
}
|
|
159
|
+
for (; i < t;) {
|
|
160
|
+
let e = this.yData[i];
|
|
161
|
+
e < n && (n = e), e > r && (r = e), i++;
|
|
162
|
+
}
|
|
163
|
+
return Number.isFinite(n) && Number.isFinite(r) ? {
|
|
164
|
+
minY: n,
|
|
165
|
+
maxY: r
|
|
166
|
+
} : null;
|
|
167
|
+
}
|
|
168
|
+
recomputePhysicalBlockRange(e, t) {
|
|
169
|
+
let n = Math.floor(e / this.blockSize), r = Math.floor((t - 1) / this.blockSize);
|
|
170
|
+
for (let e = n; e <= r; e++) this.recomputeBlock(e);
|
|
171
|
+
}
|
|
172
|
+
recomputeAllBlocks() {
|
|
173
|
+
for (let e = 0; e < this.blockMin.length; e++) this.recomputeBlock(e);
|
|
174
|
+
}
|
|
175
|
+
recomputeBlock(e) {
|
|
176
|
+
let t = e * this.blockSize, n = Math.min(this.capacity, t + this.blockSize), r = Infinity, i = -Infinity;
|
|
177
|
+
for (let e = t; e < n; e++) {
|
|
178
|
+
if (!this.isPhysicalValid(e)) continue;
|
|
179
|
+
let t = this.yData[e];
|
|
180
|
+
t < r && (r = t), t > i && (i = t);
|
|
181
|
+
}
|
|
182
|
+
this.blockMin[e] = r, this.blockMax[e] = i, this.updateBlockTreeLeaf(e, r, i);
|
|
183
|
+
}
|
|
184
|
+
queryBlockMinMax(e, t) {
|
|
185
|
+
let n = this.blockTreeBase + e, r = this.blockTreeBase + t, i = Infinity, a = -Infinity;
|
|
728
186
|
for (; n < r;) {
|
|
729
187
|
if (n & 1) {
|
|
730
188
|
let e = this.minTree[n], t = this.maxTree[n];
|
|
@@ -742,1638 +200,29 @@ var g = class e {
|
|
|
742
200
|
maxY: a
|
|
743
201
|
} : null;
|
|
744
202
|
}
|
|
203
|
+
updateBlockTreeLeaf(e, t, n) {
|
|
204
|
+
let r = this.blockTreeBase + e;
|
|
205
|
+
for (this.minTree[r] = t, this.maxTree[r] = n, r >>= 1; r >= 1;) {
|
|
206
|
+
let e = r << 1, t = e + 1, n = this.minTree[e], i = this.minTree[t], a = this.maxTree[e], o = this.maxTree[t];
|
|
207
|
+
this.minTree[r] = n < i ? n : i, this.maxTree[r] = a > o ? a : o, r >>= 1;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
isPhysicalValid(e) {
|
|
211
|
+
return this._length === this.capacity || e < this._length;
|
|
212
|
+
}
|
|
213
|
+
firstX() {
|
|
214
|
+
return this._nextX - this._length * this.xStep;
|
|
215
|
+
}
|
|
745
216
|
logicalToPhysical(e) {
|
|
746
217
|
return (this._head - this._length + e + this.capacity) % this.capacity;
|
|
747
218
|
}
|
|
748
219
|
assertValidIndex(e) {
|
|
749
|
-
if (!Number.isInteger(e) || e < 0 || e >= this._length) throw RangeError(`
|
|
220
|
+
if (!Number.isInteger(e) || e < 0 || e >= this._length) throw RangeError(`UniformRingBuffer index out of range: ${e}`);
|
|
750
221
|
}
|
|
751
222
|
static nextPowerOfTwo(e) {
|
|
752
223
|
return 2 ** Math.ceil(Math.log2(e));
|
|
753
224
|
}
|
|
754
|
-
},
|
|
755
|
-
line: {
|
|
756
|
-
vert: _,
|
|
757
|
-
frag: v
|
|
758
|
-
},
|
|
759
|
-
segment: {
|
|
760
|
-
vert: y,
|
|
761
|
-
frag: b
|
|
762
|
-
},
|
|
763
|
-
point: {
|
|
764
|
-
vert: x,
|
|
765
|
-
frag: S
|
|
766
|
-
},
|
|
767
|
-
pointSprite: {
|
|
768
|
-
vert: C,
|
|
769
|
-
frag: ee
|
|
770
|
-
},
|
|
771
|
-
bar: {
|
|
772
|
-
vert: te,
|
|
773
|
-
frag: w
|
|
774
|
-
},
|
|
775
|
-
barRange: {
|
|
776
|
-
vert: ne,
|
|
777
|
-
frag: w
|
|
778
|
-
}
|
|
779
|
-
}, E = 3, D = 2, O = 4, k = 4, A = .8, re = 0, ie = class {
|
|
780
|
-
backend;
|
|
781
|
-
lineProgram;
|
|
782
|
-
segmentProgram;
|
|
783
|
-
pointProgram;
|
|
784
|
-
pointSpriteProgram;
|
|
785
|
-
barProgram;
|
|
786
|
-
barRangeProgram;
|
|
787
|
-
segmentSelectBuffer;
|
|
788
|
-
pointCornerBuffer;
|
|
789
|
-
barCornerBuffer;
|
|
790
|
-
scaleUniform = new Float32Array(2);
|
|
791
|
-
offsetUniform = new Float32Array(2);
|
|
792
|
-
canvasSizeUniform = new Float32Array(2);
|
|
793
|
-
xOrigin = 0;
|
|
794
|
-
constructor(e) {
|
|
795
|
-
this.backend = e, this.lineProgram = this.backend.createProgram(T.line.vert, T.line.frag), this.segmentProgram = this.backend.createProgram(T.segment.vert, T.segment.frag), this.pointProgram = this.backend.createProgram(T.point.vert, T.point.frag), this.pointSpriteProgram = this.backend.createProgram(T.pointSprite.vert, T.pointSprite.frag), this.barProgram = this.backend.createProgram(T.bar.vert, T.bar.frag), this.barRangeProgram = this.backend.createProgram(T.barRange.vert, T.barRange.frag), this.segmentSelectBuffer = this.backend.createBuffer({
|
|
796
|
-
usage: "static",
|
|
797
|
-
type: "float",
|
|
798
|
-
length: 2
|
|
799
|
-
}), this.backend.updateBuffer(this.segmentSelectBuffer, new Float32Array([0, 1])), this.pointCornerBuffer = this.backend.createBuffer({
|
|
800
|
-
usage: "static",
|
|
801
|
-
type: "float",
|
|
802
|
-
length: 8
|
|
803
|
-
}), this.backend.updateBuffer(this.pointCornerBuffer, new Float32Array([
|
|
804
|
-
-1,
|
|
805
|
-
-1,
|
|
806
|
-
1,
|
|
807
|
-
-1,
|
|
808
|
-
-1,
|
|
809
|
-
1,
|
|
810
|
-
1,
|
|
811
|
-
1
|
|
812
|
-
])), this.barCornerBuffer = this.backend.createBuffer({
|
|
813
|
-
usage: "static",
|
|
814
|
-
type: "float",
|
|
815
|
-
length: 8
|
|
816
|
-
}), this.backend.updateBuffer(this.barCornerBuffer, new Float32Array([
|
|
817
|
-
-.5,
|
|
818
|
-
0,
|
|
819
|
-
.5,
|
|
820
|
-
0,
|
|
821
|
-
-.5,
|
|
822
|
-
1,
|
|
823
|
-
.5,
|
|
824
|
-
1
|
|
825
|
-
]));
|
|
826
|
-
}
|
|
827
|
-
get supportsInstancedSegments() {
|
|
828
|
-
return this.backend.capabilities.instancing;
|
|
829
|
-
}
|
|
830
|
-
get supportsInstancedPoints() {
|
|
831
|
-
return this.backend.capabilities.instancing;
|
|
832
|
-
}
|
|
833
|
-
get supportsInstancedBars() {
|
|
834
|
-
return this.backend.capabilities.instancing;
|
|
835
|
-
}
|
|
836
|
-
clear(e, t, n, r) {
|
|
837
|
-
this.backend.clear(e, t, n, r);
|
|
838
|
-
}
|
|
839
|
-
createFloatBuffer(e) {
|
|
840
|
-
return this.backend.createBuffer({
|
|
841
|
-
usage: "stream",
|
|
842
|
-
type: "float",
|
|
843
|
-
length: e
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
updateFloatBuffer(e, t, n = t.length) {
|
|
847
|
-
let r = Math.max(0, Math.min(n, t.length));
|
|
848
|
-
this.backend.updateBuffer(e, r === t.length ? t : t.subarray(0, r));
|
|
849
|
-
}
|
|
850
|
-
viewport(e, t, n, r) {
|
|
851
|
-
this.backend.viewport(e, t, n, r);
|
|
852
|
-
}
|
|
853
|
-
setXOrigin(e) {
|
|
854
|
-
this.xOrigin = Number.isFinite(e) ? e : 0;
|
|
855
|
-
}
|
|
856
|
-
getWebGLContext() {
|
|
857
|
-
return this.backend.getContext?.() ?? null;
|
|
858
|
-
}
|
|
859
|
-
drawLines(e, t, n, r) {
|
|
860
|
-
this.drawLinePrimitive("lines", e, t, n, r);
|
|
861
|
-
}
|
|
862
|
-
drawLineStrip(e, t, n, r) {
|
|
863
|
-
this.drawLinePrimitive("line_strip", e, t, n, r);
|
|
864
|
-
}
|
|
865
|
-
drawClipLineStrip(e, t, n) {
|
|
866
|
-
this.drawClipPrimitive("line_strip", e, t, n);
|
|
867
|
-
}
|
|
868
|
-
drawClipLines(e, t, n) {
|
|
869
|
-
this.drawClipPrimitive("lines", e, t, n);
|
|
870
|
-
}
|
|
871
|
-
drawMinMaxSegments(e, t, n, r) {
|
|
872
|
-
this.drawLines(e, t, n, r);
|
|
873
|
-
}
|
|
874
|
-
drawMinMaxSegmentsInstanced(e, t, n, r) {
|
|
875
|
-
this.writeCameraUniforms(r);
|
|
876
|
-
let i = E * O, a = {
|
|
877
|
-
buffer: e,
|
|
878
|
-
divisor: 1,
|
|
879
|
-
stride: i,
|
|
880
|
-
offset: 0
|
|
881
|
-
}, o = {
|
|
882
|
-
buffer: e,
|
|
883
|
-
divisor: 1,
|
|
884
|
-
stride: i,
|
|
885
|
-
offset: O
|
|
886
|
-
}, s = {
|
|
887
|
-
buffer: e,
|
|
888
|
-
divisor: 1,
|
|
889
|
-
stride: i,
|
|
890
|
-
offset: O * 2
|
|
891
|
-
}, c = {
|
|
892
|
-
buffer: this.segmentSelectBuffer,
|
|
893
|
-
divisor: 0,
|
|
894
|
-
stride: O,
|
|
895
|
-
offset: 0
|
|
896
|
-
};
|
|
897
|
-
this.backend.draw({
|
|
898
|
-
program: this.segmentProgram,
|
|
899
|
-
primitive: "lines",
|
|
900
|
-
count: 2,
|
|
901
|
-
instances: t,
|
|
902
|
-
attributes: {
|
|
903
|
-
aMaxY: s,
|
|
904
|
-
aMinY: o,
|
|
905
|
-
aSelect: c,
|
|
906
|
-
aX: a
|
|
907
|
-
},
|
|
908
|
-
uniforms: {
|
|
909
|
-
uScale: this.scaleUniform,
|
|
910
|
-
uOffset: this.offsetUniform,
|
|
911
|
-
uColor: n.color
|
|
912
|
-
}
|
|
913
|
-
});
|
|
914
|
-
}
|
|
915
|
-
drawPoints(e, t, n, r, i, a) {
|
|
916
|
-
this.supportsInstancedPoints ? this.drawPointsInstanced(e, t, n, r, i, a) : this.drawPointSprites(e, t, n, r);
|
|
917
|
-
}
|
|
918
|
-
drawPointsInstanced(e, t, n, r, i, a) {
|
|
919
|
-
this.writeCameraUniforms(r), this.canvasSizeUniform[0] = Math.max(1, i), this.canvasSizeUniform[1] = Math.max(1, a);
|
|
920
|
-
let o = {
|
|
921
|
-
buffer: e,
|
|
922
|
-
divisor: 1,
|
|
923
|
-
stride: D * O,
|
|
924
|
-
offset: 0,
|
|
925
|
-
size: 2
|
|
926
|
-
}, s = {
|
|
927
|
-
buffer: this.pointCornerBuffer,
|
|
928
|
-
divisor: 0,
|
|
929
|
-
stride: D * O,
|
|
930
|
-
offset: 0,
|
|
931
|
-
size: 2
|
|
932
|
-
};
|
|
933
|
-
this.backend.draw({
|
|
934
|
-
program: this.pointProgram,
|
|
935
|
-
primitive: "triangle_strip",
|
|
936
|
-
count: 4,
|
|
937
|
-
instances: t,
|
|
938
|
-
attributes: {
|
|
939
|
-
aCorner: s,
|
|
940
|
-
aPosition: o
|
|
941
|
-
},
|
|
942
|
-
uniforms: {
|
|
943
|
-
uScale: this.scaleUniform,
|
|
944
|
-
uOffset: this.offsetUniform,
|
|
945
|
-
uCanvasSize: this.canvasSizeUniform,
|
|
946
|
-
uPointSize: n.pointSize ?? k,
|
|
947
|
-
uColor: n.color
|
|
948
|
-
}
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
drawPointSprites(e, t, n, r) {
|
|
952
|
-
this.writeCameraUniforms(r), this.backend.draw({
|
|
953
|
-
program: this.pointSpriteProgram,
|
|
954
|
-
primitive: "points",
|
|
955
|
-
count: t,
|
|
956
|
-
attributes: { aPosition: e },
|
|
957
|
-
uniforms: {
|
|
958
|
-
uScale: this.scaleUniform,
|
|
959
|
-
uOffset: this.offsetUniform,
|
|
960
|
-
uPointSize: n.pointSize ?? k,
|
|
961
|
-
uColor: n.color
|
|
962
|
-
}
|
|
963
|
-
});
|
|
964
|
-
}
|
|
965
|
-
drawAreaStrip(e, t, n, r) {
|
|
966
|
-
this.writeCameraUniforms(r), this.backend.draw({
|
|
967
|
-
program: this.lineProgram,
|
|
968
|
-
primitive: "triangle_strip",
|
|
969
|
-
count: t,
|
|
970
|
-
attributes: { position: e },
|
|
971
|
-
uniforms: {
|
|
972
|
-
uScale: this.scaleUniform,
|
|
973
|
-
uOffset: this.offsetUniform,
|
|
974
|
-
uColor: n.fillColor ?? n.color
|
|
975
|
-
}
|
|
976
|
-
});
|
|
977
|
-
}
|
|
978
|
-
drawBarsInstanced(e, t, n, r) {
|
|
979
|
-
this.writeCameraUniforms(r);
|
|
980
|
-
let i = {
|
|
981
|
-
buffer: e,
|
|
982
|
-
divisor: 1,
|
|
983
|
-
stride: D * O,
|
|
984
|
-
offset: 0,
|
|
985
|
-
size: 2
|
|
986
|
-
}, a = {
|
|
987
|
-
buffer: this.barCornerBuffer,
|
|
988
|
-
divisor: 0,
|
|
989
|
-
stride: D * O,
|
|
990
|
-
offset: 0,
|
|
991
|
-
size: 2
|
|
992
|
-
};
|
|
993
|
-
this.backend.draw({
|
|
994
|
-
program: this.barProgram,
|
|
995
|
-
primitive: "triangle_strip",
|
|
996
|
-
count: 4,
|
|
997
|
-
instances: t,
|
|
998
|
-
attributes: {
|
|
999
|
-
aCorner: a,
|
|
1000
|
-
aPosition: i
|
|
1001
|
-
},
|
|
1002
|
-
uniforms: {
|
|
1003
|
-
uScale: this.scaleUniform,
|
|
1004
|
-
uOffset: this.offsetUniform,
|
|
1005
|
-
uBarWidth: n.barWidth ?? A,
|
|
1006
|
-
uBaseline: n.baseline ?? re,
|
|
1007
|
-
uColor: n.color
|
|
1008
|
-
}
|
|
1009
|
-
});
|
|
1010
|
-
}
|
|
1011
|
-
drawBarRangesInstanced(e, t, n, r) {
|
|
1012
|
-
this.writeCameraUniforms(r);
|
|
1013
|
-
let i = E * O, a = {
|
|
1014
|
-
buffer: e,
|
|
1015
|
-
divisor: 1,
|
|
1016
|
-
stride: i,
|
|
1017
|
-
offset: 0
|
|
1018
|
-
}, o = {
|
|
1019
|
-
buffer: e,
|
|
1020
|
-
divisor: 1,
|
|
1021
|
-
stride: i,
|
|
1022
|
-
offset: O
|
|
1023
|
-
}, s = {
|
|
1024
|
-
buffer: e,
|
|
1025
|
-
divisor: 1,
|
|
1026
|
-
stride: i,
|
|
1027
|
-
offset: O * 2
|
|
1028
|
-
}, c = {
|
|
1029
|
-
buffer: this.barCornerBuffer,
|
|
1030
|
-
divisor: 0,
|
|
1031
|
-
stride: D * O,
|
|
1032
|
-
offset: 0,
|
|
1033
|
-
size: 2
|
|
1034
|
-
};
|
|
1035
|
-
this.backend.draw({
|
|
1036
|
-
program: this.barRangeProgram,
|
|
1037
|
-
primitive: "triangle_strip",
|
|
1038
|
-
count: 4,
|
|
1039
|
-
instances: t,
|
|
1040
|
-
attributes: {
|
|
1041
|
-
aCorner: c,
|
|
1042
|
-
aMaxY: s,
|
|
1043
|
-
aMinY: o,
|
|
1044
|
-
aX: a
|
|
1045
|
-
},
|
|
1046
|
-
uniforms: {
|
|
1047
|
-
uScale: this.scaleUniform,
|
|
1048
|
-
uOffset: this.offsetUniform,
|
|
1049
|
-
uBarWidth: n.barWidth ?? A,
|
|
1050
|
-
uColor: n.color
|
|
1051
|
-
}
|
|
1052
|
-
});
|
|
1053
|
-
}
|
|
1054
|
-
drawBarTriangles(e, t, n, r) {
|
|
1055
|
-
this.drawTrianglePrimitive(e, t, n, r);
|
|
1056
|
-
}
|
|
1057
|
-
drawLinePrimitive(e, t, n, r, i) {
|
|
1058
|
-
this.writeCameraUniforms(i), this.backend.draw({
|
|
1059
|
-
program: this.lineProgram,
|
|
1060
|
-
primitive: e,
|
|
1061
|
-
count: n,
|
|
1062
|
-
attributes: { position: t },
|
|
1063
|
-
uniforms: {
|
|
1064
|
-
uScale: this.scaleUniform,
|
|
1065
|
-
uOffset: this.offsetUniform,
|
|
1066
|
-
uColor: r.color
|
|
1067
|
-
}
|
|
1068
|
-
});
|
|
1069
|
-
}
|
|
1070
|
-
drawTrianglePrimitive(e, t, n, r) {
|
|
1071
|
-
this.writeCameraUniforms(r), this.backend.draw({
|
|
1072
|
-
program: this.lineProgram,
|
|
1073
|
-
primitive: "triangles",
|
|
1074
|
-
count: t,
|
|
1075
|
-
attributes: { position: e },
|
|
1076
|
-
uniforms: {
|
|
1077
|
-
uScale: this.scaleUniform,
|
|
1078
|
-
uOffset: this.offsetUniform,
|
|
1079
|
-
uColor: n.color
|
|
1080
|
-
}
|
|
1081
|
-
});
|
|
1082
|
-
}
|
|
1083
|
-
drawClipPrimitive(e, t, n, r) {
|
|
1084
|
-
this.scaleUniform[0] = 1, this.scaleUniform[1] = 1, this.offsetUniform[0] = 0, this.offsetUniform[1] = 0, this.backend.draw({
|
|
1085
|
-
program: this.lineProgram,
|
|
1086
|
-
primitive: e,
|
|
1087
|
-
count: n,
|
|
1088
|
-
attributes: { position: t },
|
|
1089
|
-
uniforms: {
|
|
1090
|
-
uScale: this.scaleUniform,
|
|
1091
|
-
uOffset: this.offsetUniform,
|
|
1092
|
-
uColor: r.color
|
|
1093
|
-
}
|
|
1094
|
-
});
|
|
1095
|
-
}
|
|
1096
|
-
writeCameraUniforms(e) {
|
|
1097
|
-
let t = e.xMin - this.xOrigin, n = e.xMax - this.xOrigin;
|
|
1098
|
-
this.scaleUniform[0] = e.xScale, this.scaleUniform[1] = e.yScale, this.offsetUniform[0] = -(t + n) / (n - t), this.offsetUniform[1] = e.yOffset;
|
|
1099
|
-
}
|
|
1100
|
-
dispose() {
|
|
1101
|
-
this.backend.destroy();
|
|
1102
|
-
}
|
|
1103
|
-
}, j = [
|
|
1104
|
-
1024,
|
|
1105
|
-
4096,
|
|
1106
|
-
16384,
|
|
1107
|
-
32768,
|
|
1108
|
-
131072
|
|
1109
|
-
], ae = class {
|
|
1110
|
-
regl;
|
|
1111
|
-
pool = [];
|
|
1112
|
-
preAllocated = !1;
|
|
1113
|
-
constructor(e) {
|
|
1114
|
-
this.regl = e;
|
|
1115
|
-
}
|
|
1116
|
-
get reglInstance() {
|
|
1117
|
-
return this.regl;
|
|
1118
|
-
}
|
|
1119
|
-
preAllocate() {
|
|
1120
|
-
if (!this.preAllocated) {
|
|
1121
|
-
this.preAllocated = !0;
|
|
1122
|
-
for (let e of j) this.pool.push(this.createEntry(e, "stream"));
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
acquire(e, t = "stream") {
|
|
1126
|
-
let n = e, r = this.findFree(n);
|
|
1127
|
-
if (!r) {
|
|
1128
|
-
let e = this.roundUp(n);
|
|
1129
|
-
r = this.createEntry(e, t), this.pool.push(r);
|
|
1130
|
-
}
|
|
1131
|
-
return r.inUse = !0, {
|
|
1132
|
-
buffer: r.buffer,
|
|
1133
|
-
array: r.floatArray
|
|
1134
|
-
};
|
|
1135
|
-
}
|
|
1136
|
-
release(e) {
|
|
1137
|
-
for (let t of this.pool) if (t.buffer === e) {
|
|
1138
|
-
t.inUse = !1;
|
|
1139
|
-
return;
|
|
1140
|
-
}
|
|
1141
|
-
}
|
|
1142
|
-
destroy() {
|
|
1143
|
-
for (let e of this.pool) e.buffer.destroy();
|
|
1144
|
-
this.pool.length = 0, this.preAllocated = !1;
|
|
1145
|
-
}
|
|
1146
|
-
createEntry(e, t) {
|
|
1147
|
-
return {
|
|
1148
|
-
buffer: this.regl.buffer({
|
|
1149
|
-
length: e * 4,
|
|
1150
|
-
usage: t,
|
|
1151
|
-
type: "float"
|
|
1152
|
-
}),
|
|
1153
|
-
floatArray: new Float32Array(e),
|
|
1154
|
-
floatCapacity: e,
|
|
1155
|
-
inUse: !1
|
|
1156
|
-
};
|
|
1157
|
-
}
|
|
1158
|
-
findFree(e) {
|
|
1159
|
-
return this.pool.find((t) => !t.inUse && t.floatCapacity >= e);
|
|
1160
|
-
}
|
|
1161
|
-
roundUp(e) {
|
|
1162
|
-
for (let t of j) if (t >= e) return t;
|
|
1163
|
-
let t = j[j.length - 1], n = 1 << 32 - Math.clz32(e - 1);
|
|
1164
|
-
return Math.max(t * 2, n);
|
|
1165
|
-
}
|
|
1166
|
-
};
|
|
1167
|
-
//#endregion
|
|
1168
|
-
//#region src/render/ReglBackend.ts
|
|
1169
|
-
function oe(e) {
|
|
1170
|
-
return e;
|
|
1171
|
-
}
|
|
1172
|
-
var se = class {
|
|
1173
|
-
gl;
|
|
1174
|
-
regl;
|
|
1175
|
-
resources;
|
|
1176
|
-
nextProgramId = 1;
|
|
1177
|
-
commandCache = /* @__PURE__ */ new Map();
|
|
1178
|
-
scissorBox = null;
|
|
1179
|
-
capabilities;
|
|
1180
|
-
constructor(t) {
|
|
1181
|
-
let n = t.getContext("webgl2", {
|
|
1182
|
-
alpha: !0,
|
|
1183
|
-
antialias: !1,
|
|
1184
|
-
depth: !1,
|
|
1185
|
-
stencil: !1,
|
|
1186
|
-
premultipliedAlpha: !1,
|
|
1187
|
-
preserveDrawingBuffer: !1,
|
|
1188
|
-
powerPreference: "high-performance"
|
|
1189
|
-
});
|
|
1190
|
-
if (!n) throw Error("BlazePlot requires WebGL2, but this browser/context does not support it.");
|
|
1191
|
-
this.gl = n, this.regl = e({
|
|
1192
|
-
gl: oe(this.gl),
|
|
1193
|
-
extensions: [],
|
|
1194
|
-
optionalExtensions: ["angle_instanced_arrays", "ext_disjoint_timer_query_webgl2"]
|
|
1195
|
-
}), this.capabilities = { instancing: this.regl.hasExtension("angle_instanced_arrays") }, this.resources = new ae(this.regl), this.resources.preAllocate();
|
|
1196
|
-
}
|
|
1197
|
-
createBuffer(e) {
|
|
1198
|
-
let { buffer: t } = this.resources.acquire(e.length, e.usage);
|
|
1199
|
-
return {
|
|
1200
|
-
length: e.length,
|
|
1201
|
-
type: e.type,
|
|
1202
|
-
buffer: t
|
|
1203
|
-
};
|
|
1204
|
-
}
|
|
1205
|
-
updateBuffer(e, t, n = 0) {
|
|
1206
|
-
if (t.length + n > e.length) throw RangeError("GPU buffer update exceeds allocated buffer length.");
|
|
1207
|
-
let r = e.type === "float" ? 4 : 2;
|
|
1208
|
-
this.asReglBuffer(e).buffer.subdata(t, n * r);
|
|
1209
|
-
}
|
|
1210
|
-
createProgram(e, t) {
|
|
1211
|
-
return {
|
|
1212
|
-
id: this.nextProgramId++,
|
|
1213
|
-
vert: e,
|
|
1214
|
-
frag: t
|
|
1215
|
-
};
|
|
1216
|
-
}
|
|
1217
|
-
draw(e) {
|
|
1218
|
-
if (e.count <= 0) return;
|
|
1219
|
-
let t = this.asReglProgram(e.program), n = Object.keys(e.attributes).sort(), r = Object.keys(e.uniforms).sort(), i = [
|
|
1220
|
-
t.id,
|
|
1221
|
-
e.primitive,
|
|
1222
|
-
n.join(","),
|
|
1223
|
-
r.join(","),
|
|
1224
|
-
e.instances === void 0 ? 0 : 1
|
|
1225
|
-
].join("|"), a = this.commandCache.get(i);
|
|
1226
|
-
a || (a = this.createDrawCommand(t, e.primitive, n, r, e.instances !== void 0), this.commandCache.set(i, a));
|
|
1227
|
-
let o = {};
|
|
1228
|
-
for (let t of n) o[t] = this.resolveAttribute(e.attributes[t]);
|
|
1229
|
-
let s = {
|
|
1230
|
-
count: e.count,
|
|
1231
|
-
instances: e.instances ?? 0,
|
|
1232
|
-
attributes: o,
|
|
1233
|
-
uniforms: e.uniforms
|
|
1234
|
-
};
|
|
1235
|
-
this.scissorBox && (s.scissorEnable = !0, s.scissorBox = {
|
|
1236
|
-
x: this.scissorBox.x,
|
|
1237
|
-
y: this.scissorBox.y,
|
|
1238
|
-
width: this.scissorBox.w,
|
|
1239
|
-
height: this.scissorBox.h
|
|
1240
|
-
}), a(s);
|
|
1241
|
-
}
|
|
1242
|
-
dispose(e) {
|
|
1243
|
-
this.isReglBuffer(e) && this.resources.release(e.buffer);
|
|
1244
|
-
}
|
|
1245
|
-
clear(e, t, n, r) {
|
|
1246
|
-
this.regl.clear({ color: [
|
|
1247
|
-
e,
|
|
1248
|
-
t,
|
|
1249
|
-
n,
|
|
1250
|
-
r
|
|
1251
|
-
] });
|
|
1252
|
-
}
|
|
1253
|
-
viewport(e, t, n, r) {
|
|
1254
|
-
this.regl.poll(), this.scissorBox = {
|
|
1255
|
-
x: e,
|
|
1256
|
-
y: t,
|
|
1257
|
-
w: n,
|
|
1258
|
-
h: r
|
|
1259
|
-
};
|
|
1260
|
-
}
|
|
1261
|
-
getContext() {
|
|
1262
|
-
return this.gl;
|
|
1263
|
-
}
|
|
1264
|
-
destroy() {
|
|
1265
|
-
this.resources.destroy(), this.regl.destroy();
|
|
1266
|
-
}
|
|
1267
|
-
createDrawCommand(e, t, n, r, i) {
|
|
1268
|
-
let a = {};
|
|
1269
|
-
for (let e of n) a[e] = (t, n) => n.attributes[e];
|
|
1270
|
-
let o = {};
|
|
1271
|
-
for (let e of r) o[e] = (t, n) => n.uniforms[e];
|
|
1272
|
-
return this.regl({
|
|
1273
|
-
vert: e.vert,
|
|
1274
|
-
frag: e.frag,
|
|
1275
|
-
attributes: a,
|
|
1276
|
-
uniforms: o,
|
|
1277
|
-
primitive: this.toReglPrimitive(t),
|
|
1278
|
-
count: (e, t) => t.count,
|
|
1279
|
-
instances: i ? (e, t) => t.instances : void 0,
|
|
1280
|
-
depth: { enable: !1 },
|
|
1281
|
-
scissor: {
|
|
1282
|
-
enable: (e, t) => t.scissorEnable ?? !1,
|
|
1283
|
-
box: (e, t) => t.scissorBox ?? {
|
|
1284
|
-
x: 0,
|
|
1285
|
-
y: 0,
|
|
1286
|
-
width: 0,
|
|
1287
|
-
height: 0
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
});
|
|
1291
|
-
}
|
|
1292
|
-
resolveAttribute(e) {
|
|
1293
|
-
return "divisor" in e ? {
|
|
1294
|
-
buffer: this.asReglBuffer(e.buffer).buffer,
|
|
1295
|
-
divisor: e.divisor,
|
|
1296
|
-
stride: e.stride,
|
|
1297
|
-
offset: e.offset,
|
|
1298
|
-
size: e.size
|
|
1299
|
-
} : this.asReglBuffer(e).buffer;
|
|
1300
|
-
}
|
|
1301
|
-
asReglBuffer(e) {
|
|
1302
|
-
return e;
|
|
1303
|
-
}
|
|
1304
|
-
asReglProgram(e) {
|
|
1305
|
-
return e;
|
|
1306
|
-
}
|
|
1307
|
-
isReglBuffer(e) {
|
|
1308
|
-
return "length" in e && "type" in e && "buffer" in e;
|
|
1309
|
-
}
|
|
1310
|
-
toReglPrimitive(e) {
|
|
1311
|
-
switch (e) {
|
|
1312
|
-
case "line_strip": return "line strip";
|
|
1313
|
-
case "triangle_strip": return "triangle strip";
|
|
1314
|
-
default: return e;
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
}, M = class e {
|
|
1318
|
-
_xMin = 0;
|
|
1319
|
-
_xMax = 1;
|
|
1320
|
-
_yMin = 0;
|
|
1321
|
-
_yMax = 1;
|
|
1322
|
-
get xMin() {
|
|
1323
|
-
return this._xMin;
|
|
1324
|
-
}
|
|
1325
|
-
get xMax() {
|
|
1326
|
-
return this._xMax;
|
|
1327
|
-
}
|
|
1328
|
-
get yMin() {
|
|
1329
|
-
return this._yMin;
|
|
1330
|
-
}
|
|
1331
|
-
get yMax() {
|
|
1332
|
-
return this._yMax;
|
|
1333
|
-
}
|
|
1334
|
-
get viewport() {
|
|
1335
|
-
return {
|
|
1336
|
-
xMin: this._xMin,
|
|
1337
|
-
xMax: this._xMax,
|
|
1338
|
-
yMin: this._yMin,
|
|
1339
|
-
yMax: this._yMax
|
|
1340
|
-
};
|
|
1341
|
-
}
|
|
1342
|
-
get xScale() {
|
|
1343
|
-
return 2 / (this._xMax - this._xMin);
|
|
1344
|
-
}
|
|
1345
|
-
get xOffset() {
|
|
1346
|
-
return -(this._xMin + this._xMax) / (this._xMax - this._xMin);
|
|
1347
|
-
}
|
|
1348
|
-
get yScale() {
|
|
1349
|
-
return 2 / (this._yMax - this._yMin);
|
|
1350
|
-
}
|
|
1351
|
-
get yOffset() {
|
|
1352
|
-
return -(this._yMin + this._yMax) / (this._yMax - this._yMin);
|
|
1353
|
-
}
|
|
1354
|
-
setViewport(t) {
|
|
1355
|
-
let n = {
|
|
1356
|
-
xMin: t.xMin ?? this._xMin,
|
|
1357
|
-
xMax: t.xMax ?? this._xMax,
|
|
1358
|
-
yMin: t.yMin ?? this._yMin,
|
|
1359
|
-
yMax: t.yMax ?? this._yMax
|
|
1360
|
-
};
|
|
1361
|
-
e.assertValidViewport(n), this._xMin = n.xMin, this._xMax = n.xMax, this._yMin = n.yMin, this._yMax = n.yMax;
|
|
1362
|
-
}
|
|
1363
|
-
pan(t) {
|
|
1364
|
-
let { dx: n, dy: r } = t;
|
|
1365
|
-
e.assertFinite("dx", n), e.assertFinite("dy", r);
|
|
1366
|
-
let i = this._xMax - this._xMin, a = this._yMax - this._yMin;
|
|
1367
|
-
this.setViewport({
|
|
1368
|
-
xMin: this._xMin + n * i,
|
|
1369
|
-
xMax: this._xMax + n * i,
|
|
1370
|
-
yMin: this._yMin + r * a,
|
|
1371
|
-
yMax: this._yMax + r * a
|
|
1372
|
-
});
|
|
1373
|
-
}
|
|
1374
|
-
zoom(t) {
|
|
1375
|
-
let { factor: n, cx: r, cy: i, axis: a } = t;
|
|
1376
|
-
if (e.assertFinite("factor", n), e.assertFinite("cx", r), e.assertFinite("cy", i), n <= 0) throw RangeError("Camera2D zoom factor must be > 0.");
|
|
1377
|
-
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;
|
|
1378
|
-
this.setViewport({
|
|
1379
|
-
xMin: c - u * r,
|
|
1380
|
-
xMax: c + u * (1 - r),
|
|
1381
|
-
yMin: l - d * i,
|
|
1382
|
-
yMax: l + d * (1 - i)
|
|
1383
|
-
});
|
|
1384
|
-
}
|
|
1385
|
-
toClip(e, t) {
|
|
1386
|
-
return [e * this.xScale + this.xOffset, t * this.yScale + this.yOffset];
|
|
1387
|
-
}
|
|
1388
|
-
toScreen(e, t, n, r) {
|
|
1389
|
-
return [(e + 1) * .5 * n, (1 - t) * .5 * r];
|
|
1390
|
-
}
|
|
1391
|
-
clone() {
|
|
1392
|
-
let t = new e();
|
|
1393
|
-
return t.setViewport(this.viewport), t;
|
|
1394
|
-
}
|
|
1395
|
-
static assertValidViewport(t) {
|
|
1396
|
-
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.");
|
|
1397
|
-
if (t.yMax <= t.yMin) throw RangeError("Camera2D requires yMax > yMin.");
|
|
1398
|
-
}
|
|
1399
|
-
static assertFinite(e, t) {
|
|
1400
|
-
if (!Number.isFinite(t)) throw RangeError(`Camera2D ${e} must be finite.`);
|
|
1401
|
-
}
|
|
1402
|
-
}, N = class {
|
|
1403
|
-
camera;
|
|
1404
|
-
constructor(e) {
|
|
1405
|
-
this.camera = e;
|
|
1406
|
-
}
|
|
1407
|
-
getXTickValues(e, t = 10, n = []) {
|
|
1408
|
-
return this.getTickValues(this.camera.xMin, this.camera.xMax, e, t, 80, n);
|
|
1409
|
-
}
|
|
1410
|
-
getYTickValues(e, t = 10, n = []) {
|
|
1411
|
-
return this.getTickValues(this.camera.yMin, this.camera.yMax, e, t, 48, n);
|
|
1412
|
-
}
|
|
1413
|
-
formatValue(e) {
|
|
1414
|
-
if (Math.abs(e) < 1e-12) return "0";
|
|
1415
|
-
let t = Math.abs(e);
|
|
1416
|
-
return t >= 1e6 || t < .001 ? e.toExponential(2) : t >= 100 ? e.toFixed(0) : t >= 10 ? e.toFixed(1) : e.toFixed(2);
|
|
1417
|
-
}
|
|
1418
|
-
getTickValues(e, t, n, r, i, a) {
|
|
1419
|
-
if (a.length = 0, n <= 0 || r <= 0) return a;
|
|
1420
|
-
let o = t - e;
|
|
1421
|
-
if (!Number.isFinite(o) || o <= 0) return a;
|
|
1422
|
-
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);
|
|
1423
|
-
for (let e = l; e <= u && a.length < r + 2; e++) a.push(this.normalizeTick(e * c, c));
|
|
1424
|
-
return a;
|
|
1425
|
-
}
|
|
1426
|
-
niceStep(e) {
|
|
1427
|
-
let t = 10 ** Math.floor(Math.log10(e)), n = e / t;
|
|
1428
|
-
return n <= 1.5 ? t : n <= 3 ? 2 * t : n <= 7 ? 5 * t : 10 * t;
|
|
1429
|
-
}
|
|
1430
|
-
normalizeTick(e, t) {
|
|
1431
|
-
let n = Math.max(0, -Math.floor(Math.log10(t)) + 2), r = Number(e.toFixed(n));
|
|
1432
|
-
return Object.is(r, -0) ? 0 : r;
|
|
1433
|
-
}
|
|
1434
|
-
}, P = class {
|
|
1435
|
-
layout;
|
|
1436
|
-
config;
|
|
1437
|
-
options;
|
|
1438
|
-
xPool = [];
|
|
1439
|
-
yPool = [];
|
|
1440
|
-
y2Pool = [];
|
|
1441
|
-
xTicks = [];
|
|
1442
|
-
yTicks = [];
|
|
1443
|
-
y2Ticks = [];
|
|
1444
|
-
constructor(e, t, n = {}) {
|
|
1445
|
-
this.layout = e, this.config = t, this.options = n;
|
|
1446
|
-
}
|
|
1447
|
-
setOptions(e) {
|
|
1448
|
-
this.options = e;
|
|
1449
|
-
for (let e of [
|
|
1450
|
-
...this.xPool,
|
|
1451
|
-
...this.yPool,
|
|
1452
|
-
...this.y2Pool
|
|
1453
|
-
]) e.style.font = this.options.font ?? "11px ui-monospace, monospace, sans-serif", e.style.color = this.options.color ?? "#bfd6ff";
|
|
1454
|
-
}
|
|
1455
|
-
update(e, t, n = e, r = t) {
|
|
1456
|
-
let i = Math.max(1, this.layout.plot.clientWidth), a = Math.max(1, this.layout.plot.clientHeight);
|
|
1457
|
-
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);
|
|
1458
|
-
}
|
|
1459
|
-
dispose() {
|
|
1460
|
-
for (let e of this.xPool) e.remove();
|
|
1461
|
-
for (let e of this.yPool) e.remove();
|
|
1462
|
-
for (let e of this.y2Pool) e.remove();
|
|
1463
|
-
this.xPool = [], this.yPool = [], this.y2Pool = [];
|
|
1464
|
-
}
|
|
1465
|
-
parentForAxis(e) {
|
|
1466
|
-
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;
|
|
1467
|
-
}
|
|
1468
|
-
updateAxis(e, t, n, r, i, a, o) {
|
|
1469
|
-
let s = this.parentForAxis(n);
|
|
1470
|
-
for (; e.length < t.length;) {
|
|
1471
|
-
let t = document.createElement("div");
|
|
1472
|
-
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);
|
|
1473
|
-
}
|
|
1474
|
-
for (let t of e) t.parentElement !== s && s.appendChild(t);
|
|
1475
|
-
for (let n = t.length; n < e.length; n++) e[n].style.display = "none";
|
|
1476
|
-
for (let s = 0; s < t.length; s++) {
|
|
1477
|
-
let c = e[s], l = t[s], u = o.formatValue(l);
|
|
1478
|
-
if (c.textContent !== u && (c.textContent = u), c.style.display = "block", n === "x") {
|
|
1479
|
-
let [e] = r.toClip(l, r.yMin), t = (e + 1) * .5 * i;
|
|
1480
|
-
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");
|
|
1481
|
-
} else {
|
|
1482
|
-
let e = n === "y2", t = e ? this.config.y2 : this.config.y, [, i] = r.toClip(r.xMin, l), o = (1 - i) * .5 * a;
|
|
1483
|
-
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");
|
|
1484
|
-
}
|
|
1485
|
-
}
|
|
1486
|
-
}
|
|
1487
|
-
}, ce = class {
|
|
1488
|
-
root;
|
|
1489
|
-
plot;
|
|
1490
|
-
canvas;
|
|
1491
|
-
xAxis;
|
|
1492
|
-
yAxis;
|
|
1493
|
-
y2Axis;
|
|
1494
|
-
corner;
|
|
1495
|
-
cornerRight;
|
|
1496
|
-
externalCanvas;
|
|
1497
|
-
originalCanvasCssText;
|
|
1498
|
-
originalCanvasParent;
|
|
1499
|
-
constructor(e, t) {
|
|
1500
|
-
let n = e instanceof HTMLCanvasElement ? e : null;
|
|
1501
|
-
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.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.applyBaseStyles(), this.mount(e), this.update(t);
|
|
1502
|
-
}
|
|
1503
|
-
update(e) {
|
|
1504
|
-
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";
|
|
1505
|
-
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";
|
|
1506
|
-
}
|
|
1507
|
-
dispose() {
|
|
1508
|
-
this.externalCanvas && this.originalCanvasParent && (this.canvas.style.cssText = this.originalCanvasCssText, this.originalCanvasParent.insertBefore(this.canvas, this.root)), this.root.remove();
|
|
1509
|
-
}
|
|
1510
|
-
mount(e) {
|
|
1511
|
-
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.plot.appendChild(this.canvas);
|
|
1512
|
-
}
|
|
1513
|
-
applyBaseStyles() {
|
|
1514
|
-
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.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";
|
|
1515
|
-
}
|
|
1516
|
-
}, F = {
|
|
1517
|
-
backgroundColor: [
|
|
1518
|
-
.02,
|
|
1519
|
-
.02,
|
|
1520
|
-
.02,
|
|
1521
|
-
1
|
|
1522
|
-
],
|
|
1523
|
-
backgroundCssColor: "rgba(5, 5, 5, 1)",
|
|
1524
|
-
gridColor: [
|
|
1525
|
-
.22,
|
|
1526
|
-
.22,
|
|
1527
|
-
.22,
|
|
1528
|
-
.45
|
|
1529
|
-
],
|
|
1530
|
-
axisColor: "#d4d4d4",
|
|
1531
|
-
axisFont: "11px ui-monospace, monospace, sans-serif",
|
|
1532
|
-
seriesColors: [
|
|
1533
|
-
[
|
|
1534
|
-
.3,
|
|
1535
|
-
.6,
|
|
1536
|
-
1,
|
|
1537
|
-
1
|
|
1538
|
-
],
|
|
1539
|
-
[
|
|
1540
|
-
.95,
|
|
1541
|
-
.35,
|
|
1542
|
-
.35,
|
|
1543
|
-
1
|
|
1544
|
-
],
|
|
1545
|
-
[
|
|
1546
|
-
.2,
|
|
1547
|
-
.8,
|
|
1548
|
-
.4,
|
|
1549
|
-
.9
|
|
1550
|
-
],
|
|
1551
|
-
[
|
|
1552
|
-
.95,
|
|
1553
|
-
.72,
|
|
1554
|
-
.25,
|
|
1555
|
-
1
|
|
1556
|
-
],
|
|
1557
|
-
[
|
|
1558
|
-
.72,
|
|
1559
|
-
.45,
|
|
1560
|
-
.95,
|
|
1561
|
-
1
|
|
1562
|
-
],
|
|
1563
|
-
[
|
|
1564
|
-
.25,
|
|
1565
|
-
.85,
|
|
1566
|
-
.95,
|
|
1567
|
-
1
|
|
1568
|
-
]
|
|
1569
|
-
],
|
|
1570
|
-
tooltipBackgroundColor: "rgba(10, 10, 10, 0.88)",
|
|
1571
|
-
tooltipTextColor: "#e5e5e5",
|
|
1572
|
-
tooltipFont: "11px/1.35 ui-monospace, monospace",
|
|
1573
|
-
legendBackgroundColor: "rgba(10, 10, 10, 0.88)",
|
|
1574
|
-
legendBorderColor: "transparent",
|
|
1575
|
-
legendTextColor: "#e5e5e5",
|
|
1576
|
-
legendMutedTextColor: "#888",
|
|
1577
|
-
legendFont: "11px/1.35 ui-monospace, monospace"
|
|
1578
|
-
};
|
|
1579
|
-
function I(e, t) {
|
|
1580
|
-
if (!e) return F;
|
|
1581
|
-
let n = L(e.backgroundColor, F.backgroundColor, t), r = e.seriesColors?.length ? e.seriesColors.map((e, n) => L(e, F.seriesColors[n % F.seriesColors.length], t)) : F.seriesColors;
|
|
1582
|
-
return {
|
|
1583
|
-
backgroundColor: n,
|
|
1584
|
-
backgroundCssColor: le(e.backgroundColor, F.backgroundCssColor),
|
|
1585
|
-
gridColor: L(e.gridColor, F.gridColor, t),
|
|
1586
|
-
axisColor: e.axisColor ?? F.axisColor,
|
|
1587
|
-
axisFont: e.axisFont ?? F.axisFont,
|
|
1588
|
-
seriesColors: r,
|
|
1589
|
-
tooltipBackgroundColor: e.tooltipBackgroundColor ?? F.tooltipBackgroundColor,
|
|
1590
|
-
tooltipTextColor: e.tooltipTextColor ?? F.tooltipTextColor,
|
|
1591
|
-
tooltipFont: e.tooltipFont ?? F.tooltipFont,
|
|
1592
|
-
legendBackgroundColor: e.legendBackgroundColor ?? F.legendBackgroundColor,
|
|
1593
|
-
legendBorderColor: e.legendBorderColor ?? F.legendBorderColor,
|
|
1594
|
-
legendTextColor: e.legendTextColor ?? F.legendTextColor,
|
|
1595
|
-
legendMutedTextColor: e.legendMutedTextColor ?? F.legendMutedTextColor,
|
|
1596
|
-
legendFont: e.legendFont ?? F.legendFont
|
|
1597
|
-
};
|
|
1598
|
-
}
|
|
1599
|
-
function L(e, t, n) {
|
|
1600
|
-
if (!e) return t;
|
|
1601
|
-
if (typeof e != "string") return e;
|
|
1602
|
-
let r = ue(e, n), i = de(r ?? e, n);
|
|
1603
|
-
return z(r ?? e) ?? z(i ?? "") ?? t;
|
|
1604
|
-
}
|
|
1605
|
-
function le(e, t) {
|
|
1606
|
-
return e ? typeof e == "string" ? e : R(e) : t;
|
|
1607
|
-
}
|
|
1608
|
-
function R(e) {
|
|
1609
|
-
return `rgba(${Math.round(e[0] * 255)}, ${Math.round(e[1] * 255)}, ${Math.round(e[2] * 255)}, ${e[3]})`;
|
|
1610
|
-
}
|
|
1611
|
-
function ue(e, t) {
|
|
1612
|
-
let n = t?.ownerDocument ?? globalThis.document;
|
|
1613
|
-
if (!n?.documentElement || typeof getComputedStyle > "u") return null;
|
|
1614
|
-
let r = t instanceof HTMLElement ? t : n.documentElement, i = n.createElement("span");
|
|
1615
|
-
i.style.position = "absolute", i.style.visibility = "hidden", i.style.pointerEvents = "none", i.style.color = e, r.appendChild(i);
|
|
1616
|
-
let a = getComputedStyle(i).color;
|
|
1617
|
-
return i.remove(), a || null;
|
|
1618
|
-
}
|
|
1619
|
-
function z(e) {
|
|
1620
|
-
let t = e.trim();
|
|
1621
|
-
return fe(t) ?? pe(t) ?? me(t);
|
|
1622
|
-
}
|
|
1623
|
-
function de(e, t) {
|
|
1624
|
-
let n = t?.ownerDocument ?? globalThis.document;
|
|
1625
|
-
if (!n?.createElement) return null;
|
|
1626
|
-
let r = n.createElement("canvas").getContext("2d");
|
|
1627
|
-
if (!r) return null;
|
|
1628
|
-
let i = "#010203";
|
|
1629
|
-
r.fillStyle = i, r.fillStyle = e;
|
|
1630
|
-
let a = String(r.fillStyle);
|
|
1631
|
-
return a === i ? null : a;
|
|
1632
|
-
}
|
|
1633
|
-
function fe(e) {
|
|
1634
|
-
let t = e.match(/^rgba?\((.*)\)$/i);
|
|
1635
|
-
if (!t) return null;
|
|
1636
|
-
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);
|
|
1637
|
-
if (a.length < 3) return null;
|
|
1638
|
-
let o = B(a[0]), s = B(a[1]), c = B(a[2]), l = H(i ?? (a.length > 3 ? a[3] : void 0));
|
|
1639
|
-
return o === null || s === null || c === null || l === null ? null : [
|
|
1640
|
-
o,
|
|
1641
|
-
s,
|
|
1642
|
-
c,
|
|
1643
|
-
l
|
|
1644
|
-
];
|
|
1645
|
-
}
|
|
1646
|
-
function pe(e) {
|
|
1647
|
-
let t = e.match(/^color\(\s*srgb\s+(.+)\)$/i);
|
|
1648
|
-
if (!t) return null;
|
|
1649
|
-
let n = t[1].split("/").map((e) => e.trim()), r = n[0].split(/\s+/).filter(Boolean);
|
|
1650
|
-
if (r.length < 3) return null;
|
|
1651
|
-
let i = V(r[0]), a = V(r[1]), o = V(r[2]), s = H(n[1]);
|
|
1652
|
-
return i === null || a === null || o === null || s === null ? null : [
|
|
1653
|
-
i,
|
|
1654
|
-
a,
|
|
1655
|
-
o,
|
|
1656
|
-
s
|
|
1657
|
-
];
|
|
1658
|
-
}
|
|
1659
|
-
function me(e) {
|
|
1660
|
-
let t = e.startsWith("#") ? e.slice(1) : "";
|
|
1661
|
-
if (![
|
|
1662
|
-
3,
|
|
1663
|
-
4,
|
|
1664
|
-
6,
|
|
1665
|
-
8
|
|
1666
|
-
].includes(t.length) || !/^[\da-f]+$/i.test(t)) return null;
|
|
1667
|
-
let n = t.length <= 4 ? [...t].map((e) => e + e).join("") : t, r = Number.parseInt(n, 16);
|
|
1668
|
-
return Number.isFinite(r) ? [
|
|
1669
|
-
(r >> (n.length === 8 ? 24 : 16) & 255) / 255,
|
|
1670
|
-
(r >> (n.length === 8 ? 16 : 8) & 255) / 255,
|
|
1671
|
-
(r >> (n.length === 8 ? 8 : 0) & 255) / 255,
|
|
1672
|
-
n.length === 8 ? (r & 255) / 255 : 1
|
|
1673
|
-
] : null;
|
|
1674
|
-
}
|
|
1675
|
-
function B(e) {
|
|
1676
|
-
return e.endsWith("%") ? U(Number.parseFloat(e) / 100) : U(Number.parseFloat(e) / 255);
|
|
1677
|
-
}
|
|
1678
|
-
function V(e) {
|
|
1679
|
-
return e.endsWith("%") ? U(Number.parseFloat(e) / 100) : U(Number.parseFloat(e));
|
|
1680
|
-
}
|
|
1681
|
-
function H(e) {
|
|
1682
|
-
return e ? e.endsWith("%") ? U(Number.parseFloat(e) / 100) : U(Number.parseFloat(e)) : 1;
|
|
1683
|
-
}
|
|
1684
|
-
function U(e) {
|
|
1685
|
-
return Number.isFinite(e) ? Math.min(1, Math.max(0, e)) : null;
|
|
1686
|
-
}
|
|
1687
|
-
//#endregion
|
|
1688
|
-
//#region src/ui/Chart.ts
|
|
1689
|
-
var W = 16384, G = W >> 1, K = W >> 1, q = 3, J = 4096, Y = 12, he = 12, X = 5, Z = 64, ge = 4, _e = W * 4;
|
|
1690
|
-
function Q(e) {
|
|
1691
|
-
return e === !1 ? {
|
|
1692
|
-
visible: !1,
|
|
1693
|
-
position: "inside"
|
|
1694
|
-
} : e === !0 || e === void 0 ? {
|
|
1695
|
-
visible: !0,
|
|
1696
|
-
position: "inside"
|
|
1697
|
-
} : {
|
|
1698
|
-
visible: e.visible !== !1,
|
|
1699
|
-
position: e.position ?? "inside"
|
|
1700
|
-
};
|
|
1701
|
-
}
|
|
1702
|
-
function $(e) {
|
|
1703
|
-
return e === !1 ? {
|
|
1704
|
-
x: {
|
|
1705
|
-
visible: !1,
|
|
1706
|
-
position: "inside"
|
|
1707
|
-
},
|
|
1708
|
-
y: {
|
|
1709
|
-
visible: !1,
|
|
1710
|
-
position: "inside"
|
|
1711
|
-
},
|
|
1712
|
-
y2: {
|
|
1713
|
-
visible: !1,
|
|
1714
|
-
position: "inside"
|
|
1715
|
-
}
|
|
1716
|
-
} : e === !0 || e === void 0 ? {
|
|
1717
|
-
x: {
|
|
1718
|
-
visible: !0,
|
|
1719
|
-
position: "inside"
|
|
1720
|
-
},
|
|
1721
|
-
y: {
|
|
1722
|
-
visible: !0,
|
|
1723
|
-
position: "inside"
|
|
1724
|
-
},
|
|
1725
|
-
y2: {
|
|
1726
|
-
visible: !1,
|
|
1727
|
-
position: "inside"
|
|
1728
|
-
}
|
|
1729
|
-
} : {
|
|
1730
|
-
x: Q(e.x),
|
|
1731
|
-
y: Q(e.y),
|
|
1732
|
-
y2: Q(e.y2 ?? !1)
|
|
1733
|
-
};
|
|
1734
|
-
}
|
|
1735
|
-
var ve = class {
|
|
1736
|
-
options;
|
|
1737
|
-
series = [];
|
|
1738
|
-
camera;
|
|
1739
|
-
rightCamera;
|
|
1740
|
-
axis;
|
|
1741
|
-
rightAxis;
|
|
1742
|
-
renderer;
|
|
1743
|
-
rawLineBuffer;
|
|
1744
|
-
rawLineData;
|
|
1745
|
-
minMaxInstanceBuffer;
|
|
1746
|
-
minMaxInstanceData;
|
|
1747
|
-
barTriangleBuffer;
|
|
1748
|
-
barTriangleData;
|
|
1749
|
-
gridBuffer;
|
|
1750
|
-
gridData;
|
|
1751
|
-
gridStyle;
|
|
1752
|
-
xTicks = [];
|
|
1753
|
-
yTicks = [];
|
|
1754
|
-
axisOverlay = null;
|
|
1755
|
-
normalizedAxes;
|
|
1756
|
-
resolvedTheme;
|
|
1757
|
-
_gridVisible;
|
|
1758
|
-
layout;
|
|
1759
|
-
stats = {
|
|
1760
|
-
fps: 0,
|
|
1761
|
-
frameMs: 0,
|
|
1762
|
-
pointsRendered: 0,
|
|
1763
|
-
drawCalls: 0,
|
|
1764
|
-
uploadBytes: 0,
|
|
1765
|
-
renderMode: "none"
|
|
1766
|
-
};
|
|
1767
|
-
resizeObserver = null;
|
|
1768
|
-
pluginDisposers = [];
|
|
1769
|
-
hoverSubscribers = /* @__PURE__ */ new Set();
|
|
1770
|
-
seriesSubscribers = /* @__PURE__ */ new Set();
|
|
1771
|
-
themeSubscribers = /* @__PURE__ */ new Set();
|
|
1772
|
-
renderSubscribers = /* @__PURE__ */ new Set();
|
|
1773
|
-
currentHover = null;
|
|
1774
|
-
lastPointerClientX = 0;
|
|
1775
|
-
lastPointerClientY = 0;
|
|
1776
|
-
pointerInPlot = !1;
|
|
1777
|
-
lastFrameAt = 0;
|
|
1778
|
-
currentXOrigin = 0;
|
|
1779
|
-
_rafId = 0;
|
|
1780
|
-
handlePointerMove = (e) => {
|
|
1781
|
-
this.pointerInPlot = !0, this.lastPointerClientX = e.clientX, this.lastPointerClientY = e.clientY, this.refreshHover();
|
|
1782
|
-
};
|
|
1783
|
-
handlePointerLeave = () => {
|
|
1784
|
-
this.pointerInPlot = !1, this.emitHover(null);
|
|
1785
|
-
};
|
|
1786
|
-
constructor(e, t = {}) {
|
|
1787
|
-
this.options = t, this.resolvedTheme = I(t.theme, e), this.normalizedAxes = $(t.axes), this._gridVisible = t.grid !== !1, this.layout = new ce(e, this.normalizedAxes), this.layout.root.style.background = this.resolvedTheme.backgroundCssColor, this.applyCanvasSize(), this.camera = new M(), this.rightCamera = new M(), this.axis = new N(this.camera), this.rightAxis = new N(this.rightCamera), this.renderer = new ie(new se(this.layout.canvas)), this.rawLineData = new Float32Array(W * 2), this.rawLineBuffer = this.renderer.createFloatBuffer(this.rawLineData.length), this.minMaxInstanceData = new Float32Array(K * q), this.minMaxInstanceBuffer = this.renderer.createFloatBuffer(this.minMaxInstanceData.length), this.barTriangleData = new Float32Array(J * Y), this.barTriangleBuffer = this.renderer.createFloatBuffer(this.barTriangleData.length), this.gridData = new Float32Array(Z * 2), this.gridBuffer = this.renderer.createFloatBuffer(this.gridData.length), this.gridStyle = {
|
|
1788
|
-
color: t.gridStyle?.color ?? this.resolvedTheme.gridColor,
|
|
1789
|
-
lineWidth: t.gridStyle?.lineWidth ?? 1
|
|
1790
|
-
}, (this.normalizedAxes.x.visible || this.normalizedAxes.y.visible || this.normalizedAxes.y2.visible) && (this.axisOverlay = new P(this.layout, this.normalizedAxes, {
|
|
1791
|
-
color: this.resolvedTheme.axisColor,
|
|
1792
|
-
font: this.resolvedTheme.axisFont
|
|
1793
|
-
})), this.canvas.addEventListener("pointermove", this.handlePointerMove), this.canvas.addEventListener("pointerleave", this.handlePointerLeave), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(this.layout.plot));
|
|
1794
|
-
for (let e of t.plugins ?? []) {
|
|
1795
|
-
let t = e.install(this);
|
|
1796
|
-
typeof t == "function" ? this.pluginDisposers.push(t) : t && this.pluginDisposers.push(() => t.dispose());
|
|
1797
|
-
}
|
|
1798
|
-
}
|
|
1799
|
-
get canvas() {
|
|
1800
|
-
return this.layout.canvas;
|
|
1801
|
-
}
|
|
1802
|
-
get rootElement() {
|
|
1803
|
-
return this.layout.root;
|
|
1804
|
-
}
|
|
1805
|
-
get plotElement() {
|
|
1806
|
-
return this.layout.plot;
|
|
1807
|
-
}
|
|
1808
|
-
get xAxisElement() {
|
|
1809
|
-
return this.layout.xAxis;
|
|
1810
|
-
}
|
|
1811
|
-
get yAxisElement() {
|
|
1812
|
-
return this.layout.yAxis;
|
|
1813
|
-
}
|
|
1814
|
-
get y2AxisElement() {
|
|
1815
|
-
return this.layout.y2Axis;
|
|
1816
|
-
}
|
|
1817
|
-
get theme() {
|
|
1818
|
-
return this.resolvedTheme;
|
|
1819
|
-
}
|
|
1820
|
-
getWebGLContext() {
|
|
1821
|
-
return this.renderer.getWebGLContext();
|
|
1822
|
-
}
|
|
1823
|
-
getCamera(e = "left") {
|
|
1824
|
-
return e === "right" ? this.rightCamera : this.camera;
|
|
1825
|
-
}
|
|
1826
|
-
dataToPlot(e, t, n = "left") {
|
|
1827
|
-
let r = this.getCamera(n), [i, a] = r.toClip(e, t);
|
|
1828
|
-
return r.toScreen(i, a, this.canvas.clientWidth, this.canvas.clientHeight);
|
|
1829
|
-
}
|
|
1830
|
-
clientToData(e, t, n = "left") {
|
|
1831
|
-
let r = this.canvas.getBoundingClientRect();
|
|
1832
|
-
if (r.width <= 0 || r.height <= 0) return null;
|
|
1833
|
-
let i = e - r.left, a = t - r.top;
|
|
1834
|
-
if (i < 0 || a < 0 || i > r.width || a > r.height) return null;
|
|
1835
|
-
let o = this.getCamera(n).viewport;
|
|
1836
|
-
return [o.xMin + i / r.width * (o.xMax - o.xMin), o.yMax - a / r.height * (o.yMax - o.yMin)];
|
|
1837
|
-
}
|
|
1838
|
-
getViewport(e = "left") {
|
|
1839
|
-
return this.getCamera(e).viewport;
|
|
1840
|
-
}
|
|
1841
|
-
pan(e) {
|
|
1842
|
-
this.camera.pan(e), this.syncRightCameraX(), this.refreshHover();
|
|
1843
|
-
}
|
|
1844
|
-
zoom(e) {
|
|
1845
|
-
this.camera.zoom(e), this.syncRightCameraX(), this.refreshHover();
|
|
1846
|
-
}
|
|
1847
|
-
addSeries(e, t) {
|
|
1848
|
-
if ((e.mode === "ohlc" || e.mode === "candlestick") && !e.dataset) throw TypeError("OHLC and candlestick series require an OhlcDataset.");
|
|
1849
|
-
let n = e.dataset ?? new g(e.capacity, { overflow: e.overflow }), r = this.resolvedTheme.seriesColors, i = r[this.series.length % r.length] ?? this.resolvedTheme.seriesColors[0], a = t?.color ?? i, o = new p(n, e, {
|
|
1850
|
-
color: a,
|
|
1851
|
-
lineWidth: t?.lineWidth ?? 1,
|
|
1852
|
-
pointSize: t?.pointSize ?? 4,
|
|
1853
|
-
barWidth: t?.barWidth ?? .8,
|
|
1854
|
-
baseline: t?.baseline ?? 0,
|
|
1855
|
-
fillColor: t?.fillColor ?? [
|
|
1856
|
-
a[0],
|
|
1857
|
-
a[1],
|
|
1858
|
-
a[2],
|
|
1859
|
-
a[3] * .25
|
|
1860
|
-
],
|
|
1861
|
-
tickWidth: t?.tickWidth ?? t?.barWidth ?? .8,
|
|
1862
|
-
upColor: t?.upColor ?? a,
|
|
1863
|
-
downColor: t?.downColor ?? t?.fillColor ?? [
|
|
1864
|
-
a[0],
|
|
1865
|
-
a[1],
|
|
1866
|
-
a[2],
|
|
1867
|
-
a[3] * .45
|
|
1868
|
-
],
|
|
1869
|
-
wickColor: t?.wickColor ?? a
|
|
1870
|
-
});
|
|
1871
|
-
return this.series.push(o), this.emitSeriesChange(), o;
|
|
1872
|
-
}
|
|
1873
|
-
addLine(e, t) {
|
|
1874
|
-
return this.addSeries({
|
|
1875
|
-
...e,
|
|
1876
|
-
mode: "line"
|
|
1877
|
-
}, t);
|
|
1878
|
-
}
|
|
1879
|
-
addArea(e, t) {
|
|
1880
|
-
return this.addSeries({
|
|
1881
|
-
...e,
|
|
1882
|
-
mode: "area"
|
|
1883
|
-
}, t);
|
|
1884
|
-
}
|
|
1885
|
-
addScatter(e, t) {
|
|
1886
|
-
return this.addSeries({
|
|
1887
|
-
...e,
|
|
1888
|
-
mode: "scatter"
|
|
1889
|
-
}, t);
|
|
1890
|
-
}
|
|
1891
|
-
addBar(e, t) {
|
|
1892
|
-
return this.addSeries({
|
|
1893
|
-
...e,
|
|
1894
|
-
mode: "bar"
|
|
1895
|
-
}, t);
|
|
1896
|
-
}
|
|
1897
|
-
addOhlc(e, t) {
|
|
1898
|
-
return this.addSeries({
|
|
1899
|
-
...e,
|
|
1900
|
-
mode: "ohlc"
|
|
1901
|
-
}, t);
|
|
1902
|
-
}
|
|
1903
|
-
addCandlestick(e, t) {
|
|
1904
|
-
return this.addSeries({
|
|
1905
|
-
...e,
|
|
1906
|
-
mode: "candlestick"
|
|
1907
|
-
}, t);
|
|
1908
|
-
}
|
|
1909
|
-
removeSeries(e) {
|
|
1910
|
-
let t = this.series.indexOf(e);
|
|
1911
|
-
return t === -1 ? !1 : (this.series.splice(t, 1), this.emitSeriesChange(), !0);
|
|
1912
|
-
}
|
|
1913
|
-
setSeriesVisible(e, t) {
|
|
1914
|
-
return this.series.includes(e) ? e.visible === t ? !0 : (e.setVisible(t), this.emitSeriesChange(), !0) : !1;
|
|
1915
|
-
}
|
|
1916
|
-
getSeriesState() {
|
|
1917
|
-
return this.series.map((e, t) => ({
|
|
1918
|
-
series: e,
|
|
1919
|
-
index: t,
|
|
1920
|
-
id: e.config.id,
|
|
1921
|
-
name: e.config.name,
|
|
1922
|
-
mode: e.config.mode,
|
|
1923
|
-
visible: e.visible,
|
|
1924
|
-
color: e.style.color,
|
|
1925
|
-
yAxis: e.config.yAxis ?? "left"
|
|
1926
|
-
}));
|
|
1927
|
-
}
|
|
1928
|
-
setViewport(e) {
|
|
1929
|
-
this.camera.setViewport(e), this.rightCamera.setViewport(e), this.refreshHover();
|
|
1930
|
-
}
|
|
1931
|
-
setYViewport(e, t) {
|
|
1932
|
-
this.getCamera(e).setViewport(t), this.refreshHover();
|
|
1933
|
-
}
|
|
1934
|
-
resize(e = globalThis.devicePixelRatio) {
|
|
1935
|
-
let t = this.applyCanvasSize(e);
|
|
1936
|
-
return t && this.refreshHover(), t;
|
|
1937
|
-
}
|
|
1938
|
-
getFrameStats(e = {
|
|
1939
|
-
fps: 0,
|
|
1940
|
-
frameMs: 0,
|
|
1941
|
-
pointsRendered: 0,
|
|
1942
|
-
drawCalls: 0,
|
|
1943
|
-
uploadBytes: 0,
|
|
1944
|
-
renderMode: "none"
|
|
1945
|
-
}) {
|
|
1946
|
-
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;
|
|
1947
|
-
}
|
|
1948
|
-
getHoverState() {
|
|
1949
|
-
return this.currentHover;
|
|
1950
|
-
}
|
|
1951
|
-
subscribe(e, t) {
|
|
1952
|
-
if (e === "hover") {
|
|
1953
|
-
let e = t;
|
|
1954
|
-
return this.hoverSubscribers.add(e), () => this.hoverSubscribers.delete(e);
|
|
1955
|
-
}
|
|
1956
|
-
if (e === "themechange") {
|
|
1957
|
-
let e = t;
|
|
1958
|
-
return this.themeSubscribers.add(e), () => this.themeSubscribers.delete(e);
|
|
1959
|
-
}
|
|
1960
|
-
if (e === "render") {
|
|
1961
|
-
let e = t;
|
|
1962
|
-
return this.renderSubscribers.add(e), () => this.renderSubscribers.delete(e);
|
|
1963
|
-
}
|
|
1964
|
-
let n = t;
|
|
1965
|
-
return this.seriesSubscribers.add(n), () => this.seriesSubscribers.delete(n);
|
|
1966
|
-
}
|
|
1967
|
-
setTheme(e) {
|
|
1968
|
-
this.resolvedTheme = I(e, this.layout.root), this.applyTheme(), this.emitThemeChange(), this.refreshHover();
|
|
1969
|
-
}
|
|
1970
|
-
setGridVisible(e) {
|
|
1971
|
-
this._gridVisible = e;
|
|
1972
|
-
}
|
|
1973
|
-
getGridVisible() {
|
|
1974
|
-
return this._gridVisible;
|
|
1975
|
-
}
|
|
1976
|
-
setAxes(e) {
|
|
1977
|
-
this.normalizedAxes = $(e), 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 P(this.layout, this.normalizedAxes, {
|
|
1978
|
-
color: this.resolvedTheme.axisColor,
|
|
1979
|
-
font: this.resolvedTheme.axisFont
|
|
1980
|
-
})), this.resize(), this.refreshHover();
|
|
1981
|
-
}
|
|
1982
|
-
pick(e, t, n = {}) {
|
|
1983
|
-
let r = this.canvas.getBoundingClientRect();
|
|
1984
|
-
if (r.width <= 0 || r.height <= 0) return null;
|
|
1985
|
-
let i = e - r.left, a = t - r.top;
|
|
1986
|
-
if (i < 0 || a < 0 || i > r.width || a > r.height) return null;
|
|
1987
|
-
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);
|
|
1988
|
-
if (!f) return null;
|
|
1989
|
-
let p = f.sample.x;
|
|
1990
|
-
return {
|
|
1991
|
-
clientX: e,
|
|
1992
|
-
clientY: t,
|
|
1993
|
-
plotX: i,
|
|
1994
|
-
plotY: a,
|
|
1995
|
-
dataX: s,
|
|
1996
|
-
dataY: c,
|
|
1997
|
-
anchorX: p,
|
|
1998
|
-
mode: l,
|
|
1999
|
-
group: u,
|
|
2000
|
-
maxDistancePx: d,
|
|
2001
|
-
items: u === "none" ? [this.createPickItem(f.sample, f.series, f.seriesIndex, e, t, r)] : this.collectPickItems(p, e, t, r)
|
|
2002
|
-
};
|
|
2003
|
-
}
|
|
2004
|
-
async screenshot(e = {}) {
|
|
2005
|
-
this.render();
|
|
2006
|
-
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");
|
|
2007
|
-
o.width = i, o.height = a;
|
|
2008
|
-
let s = o.getContext("2d");
|
|
2009
|
-
if (!s) throw Error("Unable to create a 2D canvas context for screenshot export.");
|
|
2010
|
-
return s.fillStyle = e.background ?? R(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) => {
|
|
2011
|
-
o.toBlob((e) => e ? t(e) : n(/* @__PURE__ */ Error("Unable to encode chart screenshot.")), e.type ?? "image/png", e.quality);
|
|
2012
|
-
});
|
|
2013
|
-
}
|
|
2014
|
-
start() {
|
|
2015
|
-
let e = () => {
|
|
2016
|
-
this._rafId = requestAnimationFrame(e), this.render();
|
|
2017
|
-
};
|
|
2018
|
-
this._rafId = requestAnimationFrame(e);
|
|
2019
|
-
}
|
|
2020
|
-
stop() {
|
|
2021
|
-
cancelAnimationFrame(this._rafId);
|
|
2022
|
-
}
|
|
2023
|
-
render() {
|
|
2024
|
-
let e = performance.now();
|
|
2025
|
-
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();
|
|
2026
|
-
let [t, n, r, i] = this.resolvedTheme.backgroundColor;
|
|
2027
|
-
this.renderer.viewport(0, 0, this.canvas.width, this.canvas.height), this.renderer.clear(t, n, r, i);
|
|
2028
|
-
let a = this.camera.viewport;
|
|
2029
|
-
if (this.currentXOrigin = a.xMin, this.renderer.setXOrigin(this.currentXOrigin), this._gridVisible) {
|
|
2030
|
-
let e = this.writeGridVertices(a);
|
|
2031
|
-
e > 0 && (this.uploadGridData(e), this.renderer.drawClipLines(this.gridBuffer, e, this.gridStyle), this.stats.drawCalls++);
|
|
2032
|
-
}
|
|
2033
|
-
for (let e of this.series) e.visible && (e.rebuildPyramid(), this.drawSeries(e));
|
|
2034
|
-
this.axisOverlay?.update(this.camera, this.axis, this.rightCamera, this.rightAxis), this.emitRender(), this.stats.frameMs = performance.now() - e, this.refreshHover();
|
|
2035
|
-
}
|
|
2036
|
-
dispose() {
|
|
2037
|
-
this.stop(), this.resizeObserver?.disconnect(), this.canvas.removeEventListener("pointermove", this.handlePointerMove), this.canvas.removeEventListener("pointerleave", this.handlePointerLeave);
|
|
2038
|
-
for (let e of this.pluginDisposers.splice(0)) e();
|
|
2039
|
-
this.axisOverlay?.dispose(), this.renderer.dispose(), this.layout.dispose();
|
|
2040
|
-
}
|
|
2041
|
-
applyTheme() {
|
|
2042
|
-
this.layout.root.style.background = this.resolvedTheme.backgroundCssColor, this.options.gridStyle?.color === void 0 && (this.gridStyle = {
|
|
2043
|
-
...this.gridStyle,
|
|
2044
|
-
color: this.resolvedTheme.gridColor
|
|
2045
|
-
}), this.axisOverlay?.setOptions({
|
|
2046
|
-
color: this.resolvedTheme.axisColor,
|
|
2047
|
-
font: this.resolvedTheme.axisFont
|
|
2048
|
-
});
|
|
2049
|
-
}
|
|
2050
|
-
applyCanvasSize(e = globalThis.devicePixelRatio) {
|
|
2051
|
-
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));
|
|
2052
|
-
return this.canvas.width === n && this.canvas.height === r ? !1 : (this.canvas.width = n, this.canvas.height = r, !0);
|
|
2053
|
-
}
|
|
2054
|
-
cameraForSeries(e) {
|
|
2055
|
-
return e.config.yAxis === "right" ? this.rightCamera : this.camera;
|
|
2056
|
-
}
|
|
2057
|
-
syncRightCameraX() {
|
|
2058
|
-
this.rightCamera.setViewport({
|
|
2059
|
-
xMin: this.camera.xMin,
|
|
2060
|
-
xMax: this.camera.xMax
|
|
2061
|
-
});
|
|
2062
|
-
}
|
|
2063
|
-
drawSeries(e) {
|
|
2064
|
-
let t = this.cameraForSeries(e), n = t.viewport;
|
|
2065
|
-
switch (e.config.mode) {
|
|
2066
|
-
case "area":
|
|
2067
|
-
this.drawAreaSeries(e, n, t);
|
|
2068
|
-
return;
|
|
2069
|
-
case "bar":
|
|
2070
|
-
this.drawBarSeries(e, n, t);
|
|
2071
|
-
return;
|
|
2072
|
-
case "ohlc":
|
|
2073
|
-
this.drawOhlcSeries(e, n, t);
|
|
2074
|
-
return;
|
|
2075
|
-
case "candlestick":
|
|
2076
|
-
this.drawCandlestickSeries(e, n, t);
|
|
2077
|
-
return;
|
|
2078
|
-
case "scatter":
|
|
2079
|
-
this.drawScatterSeries(e, n, t);
|
|
2080
|
-
return;
|
|
2081
|
-
default: this.drawLineSeries(e, n, t);
|
|
2082
|
-
}
|
|
2083
|
-
}
|
|
2084
|
-
drawLineSeries(e, t, n) {
|
|
2085
|
-
let r = e.visibleSampleCount(t), i = e.hasLOD && r > W - 2;
|
|
2086
|
-
if (i && this.renderer.supportsInstancedSegments) {
|
|
2087
|
-
let r = e.copyMinMaxInstanced(t, this.minMaxInstanceData, this.maxMinMaxSegments(), this.currentXOrigin);
|
|
2088
|
-
if (r <= 0) return;
|
|
2089
|
-
this.uploadMinMaxInstanceData(r), this.renderer.drawMinMaxSegmentsInstanced(this.minMaxInstanceBuffer, r, e.style, n), this.recordDraw("minmax", r * 2);
|
|
2090
|
-
return;
|
|
2091
|
-
}
|
|
2092
|
-
if (i) {
|
|
2093
|
-
let r = e.copyMinMaxVisible(t, this.rawLineData, this.maxMinMaxSegments(), this.currentXOrigin);
|
|
2094
|
-
if (r < 2) return;
|
|
2095
|
-
this.uploadRawLineData(r), this.renderer.drawMinMaxSegments(this.rawLineBuffer, r, e.style, n), this.recordDraw("minmax", r);
|
|
2096
|
-
return;
|
|
2097
|
-
}
|
|
2098
|
-
let a = e.copyRawVisibleClipSpace(t, this.rawLineData, W);
|
|
2099
|
-
a < 2 || (this.uploadRawLineData(a), this.renderer.drawClipLineStrip(this.rawLineBuffer, a, e.style), this.recordDraw("raw", a));
|
|
2100
|
-
}
|
|
2101
|
-
drawAreaSeries(e, t, n) {
|
|
2102
|
-
let r = e.visibleIndexRange(t, 1);
|
|
2103
|
-
if (r.end - r.start < 2) return;
|
|
2104
|
-
let i = e.style.baseline ?? 0;
|
|
2105
|
-
if (r.end - r.start > G) {
|
|
2106
|
-
let r = e.copyAreaVisible(t, this.rawLineData, G, i, this.currentXOrigin);
|
|
2107
|
-
r >= 4 && (this.uploadRawLineData(r), this.renderer.drawAreaStrip(this.rawLineBuffer, r, e.style, n), this.recordDraw("area", r));
|
|
2108
|
-
let a = e.copyRawVisible(t, this.rawLineData, G, this.currentXOrigin);
|
|
2109
|
-
a >= 2 && (this.uploadRawLineData(a), this.renderer.drawLineStrip(this.rawLineBuffer, a, e.style, n), this.recordDraw("area", a));
|
|
2110
|
-
return;
|
|
2111
|
-
}
|
|
2112
|
-
for (let t = r.start; t < r.end;) {
|
|
2113
|
-
let a = e.copyAreaRange(t, r.end, this.rawLineData, G, i, this.currentXOrigin);
|
|
2114
|
-
if (a < 4) break;
|
|
2115
|
-
this.uploadRawLineData(a), this.renderer.drawAreaStrip(this.rawLineBuffer, a, e.style, n), this.recordDraw("area", a), t += Math.max(1, (a >> 1) - 1);
|
|
2116
|
-
}
|
|
2117
|
-
for (let t = r.start; t < r.end;) {
|
|
2118
|
-
let i = e.copyRawRange(t, r.end, this.rawLineData, G, this.currentXOrigin);
|
|
2119
|
-
if (i < 2) break;
|
|
2120
|
-
this.uploadRawLineData(i), this.renderer.drawLineStrip(this.rawLineBuffer, i, e.style, n), this.recordDraw("area", i), t += Math.max(1, i - 1);
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
drawOhlcSeries(e, t, n) {
|
|
2124
|
-
let r = e.visibleIndexRange(t), i = Math.floor(this.rawLineData.length / he);
|
|
2125
|
-
for (let t = r.start; t < r.end;) {
|
|
2126
|
-
let a = e.copyOhlcRange(t, r.end, this.rawLineData, i, e.style.tickWidth ?? e.style.barWidth ?? .8, this.currentXOrigin);
|
|
2127
|
-
if (a <= 0) break;
|
|
2128
|
-
let o = a * 6;
|
|
2129
|
-
this.uploadRawLineData(o), this.renderer.drawLines(this.rawLineBuffer, o, e.style, n), this.recordDraw("raw", o), t += a;
|
|
2130
|
-
}
|
|
2131
|
-
}
|
|
2132
|
-
drawCandlestickSeries(e, t, n) {
|
|
2133
|
-
let r = e.visibleIndexRange(t, 1), i = Math.min(Math.floor(this.rawLineData.length / X), this.maxBarTriangleBars()), a = {
|
|
2134
|
-
...e.style,
|
|
2135
|
-
color: e.style.wickColor ?? e.style.color
|
|
2136
|
-
}, o = {
|
|
2137
|
-
...e.style,
|
|
2138
|
-
color: e.style.upColor ?? e.style.color
|
|
2139
|
-
}, s = {
|
|
2140
|
-
...e.style,
|
|
2141
|
-
color: e.style.downColor ?? e.style.fillColor ?? e.style.color
|
|
2142
|
-
};
|
|
2143
|
-
for (let t = r.start; t < r.end;) {
|
|
2144
|
-
let c = e.copyOhlcTuplesRange(t, r.end, this.rawLineData, i, this.currentXOrigin);
|
|
2145
|
-
if (c <= 0) break;
|
|
2146
|
-
let l = this.writeCandlestickWicks(c);
|
|
2147
|
-
l > 0 && (this.uploadBarTriangleData(l), this.renderer.drawLines(this.barTriangleBuffer, l, a, n), this.recordDraw("raw", l));
|
|
2148
|
-
let u = e.style.barWidth ?? e.style.tickWidth ?? .8;
|
|
2149
|
-
this.drawCandlestickBodies(c, u, "up", o, n), this.drawCandlestickBodies(c, u, "down", s, n), t += c;
|
|
2150
|
-
}
|
|
2151
|
-
}
|
|
2152
|
-
drawScatterSeries(e, t, n) {
|
|
2153
|
-
let r = e.style.pointSize ?? ge, i = e.visibleSampleCount(t);
|
|
2154
|
-
if (e.config.downsample === "none" && i <= _e) {
|
|
2155
|
-
let i = e.visibleIndexRange(t);
|
|
2156
|
-
for (let a = i.start; a < i.end; a += W) {
|
|
2157
|
-
let o = e.copyScatterRange(a, Math.min(i.end, a + W), t, this.rawLineData, W, this.currentXOrigin, this.canvas.height, r);
|
|
2158
|
-
o <= 0 || (this.uploadRawLineData(o), this.renderer.drawPoints(this.rawLineBuffer, o, e.style, n, this.canvas.width, this.canvas.height), this.recordDraw("points", o));
|
|
2159
|
-
}
|
|
2160
|
-
return;
|
|
2161
|
-
}
|
|
2162
|
-
let a = e.copyScatterVisible(t, this.rawLineData, W, this.canvas.width, this.canvas.height, r, this.currentXOrigin);
|
|
2163
|
-
a <= 0 || (this.uploadRawLineData(a), this.renderer.drawPoints(this.rawLineBuffer, a, e.style, n, this.canvas.width, this.canvas.height), this.recordDraw("points", a));
|
|
2164
|
-
}
|
|
2165
|
-
drawBarSeries(e, t, n) {
|
|
2166
|
-
let r = e.visibleSampleCount(t), i = this.maxRawBarInstances();
|
|
2167
|
-
if (e.hasLOD && r > i) {
|
|
2168
|
-
let r = e.copyMinMaxInstanced(t, this.minMaxInstanceData, this.maxBarTriangleBars(), this.currentXOrigin);
|
|
2169
|
-
if (r <= 0) return;
|
|
2170
|
-
this.includeBaselineInBarRanges(r, e.style.baseline ?? 0);
|
|
2171
|
-
let i = this.writeBarBucketTriangles(r, t);
|
|
2172
|
-
this.drawBarTriangles(i, e.style, n);
|
|
2173
|
-
return;
|
|
2174
|
-
}
|
|
2175
|
-
let a = e.visibleIndexRange(t, 1), o = e.copyRawRange(a.start, a.end, this.rawLineData, i, this.currentXOrigin);
|
|
2176
|
-
if (o <= 0) return;
|
|
2177
|
-
if (this.renderer.supportsInstancedBars) {
|
|
2178
|
-
this.uploadRawLineData(o), this.renderer.drawBarsInstanced(this.rawLineBuffer, o, e.style, n), this.recordDraw("bars", o);
|
|
2179
|
-
return;
|
|
2180
|
-
}
|
|
2181
|
-
let s = this.writeBarTriangles(o, e.style.baseline ?? 0, e.style.barWidth ?? .8);
|
|
2182
|
-
this.drawBarTriangles(s, e.style, n);
|
|
2183
|
-
}
|
|
2184
|
-
uploadRawLineData(e) {
|
|
2185
|
-
this.uploadFloatData(this.rawLineBuffer, this.rawLineData, e * 2);
|
|
2186
|
-
}
|
|
2187
|
-
uploadMinMaxInstanceData(e) {
|
|
2188
|
-
this.uploadFloatData(this.minMaxInstanceBuffer, this.minMaxInstanceData, e * q);
|
|
2189
|
-
}
|
|
2190
|
-
uploadBarTriangleData(e) {
|
|
2191
|
-
this.uploadFloatData(this.barTriangleBuffer, this.barTriangleData, e * 2);
|
|
2192
|
-
}
|
|
2193
|
-
uploadGridData(e) {
|
|
2194
|
-
this.uploadFloatData(this.gridBuffer, this.gridData, e * 2);
|
|
2195
|
-
}
|
|
2196
|
-
uploadFloatData(e, t, n) {
|
|
2197
|
-
let r = Math.max(0, Math.min(n, t.length));
|
|
2198
|
-
this.renderer.updateFloatBuffer(e, t, r), this.stats.uploadBytes += r * Float32Array.BYTES_PER_ELEMENT;
|
|
2199
|
-
}
|
|
2200
|
-
includeBaselineInBarRanges(e, t) {
|
|
2201
|
-
for (let n = 0; n < e; n++) {
|
|
2202
|
-
let e = n * q, r = this.minMaxInstanceData[e + 1], i = this.minMaxInstanceData[e + 2];
|
|
2203
|
-
this.minMaxInstanceData[e + 1] = Math.min(t, r), this.minMaxInstanceData[e + 2] = Math.max(t, i);
|
|
2204
|
-
}
|
|
2205
|
-
}
|
|
2206
|
-
writeBarTriangles(e, t, n) {
|
|
2207
|
-
let r = Math.min(e, this.maxBarTriangleBars());
|
|
2208
|
-
for (let e = 0; e < r; e++) {
|
|
2209
|
-
let r = this.rawLineData[e * 2], i = this.rawLineData[e * 2 + 1];
|
|
2210
|
-
this.writeBarTriangle(e, r - n * .5, r + n * .5, t, i);
|
|
2211
|
-
}
|
|
2212
|
-
return r * 6;
|
|
2213
|
-
}
|
|
2214
|
-
writeBarBucketTriangles(e, t) {
|
|
2215
|
-
let n = Math.min(e, this.maxBarTriangleBars());
|
|
2216
|
-
for (let e = 0; e < n; e++) {
|
|
2217
|
-
let r = this.minMaxInstanceData[e * 3 + 1], i = this.minMaxInstanceData[e * 3 + 2], [a, o] = this.barBucketBounds(e, n, t);
|
|
2218
|
-
this.writeBarTriangle(e, a, o, r, i);
|
|
2219
|
-
}
|
|
2220
|
-
return n * 6;
|
|
2221
|
-
}
|
|
2222
|
-
barBucketBounds(e, t, n) {
|
|
2223
|
-
let r = this.minMaxInstanceData[e * 3], i = n.xMin - this.currentXOrigin, a = n.xMax - this.currentXOrigin, o = a - i;
|
|
2224
|
-
if (t <= 1) {
|
|
2225
|
-
let e = Math.max(0, o * .5);
|
|
2226
|
-
return [Math.max(i, r - e), Math.min(a, r + e)];
|
|
2227
|
-
}
|
|
2228
|
-
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;
|
|
2229
|
-
if (!Number.isFinite(l) || !Number.isFinite(u) || u <= l) {
|
|
2230
|
-
let n = o / Math.max(1, t);
|
|
2231
|
-
l = i + e * n, u = e + 1 === t ? a : l + n;
|
|
2232
|
-
}
|
|
2233
|
-
return [Math.max(i, l), Math.min(a, u)];
|
|
2234
|
-
}
|
|
2235
|
-
writeCandlestickWicks(e) {
|
|
2236
|
-
for (let t = 0; t < e; t++) {
|
|
2237
|
-
let e = t * X, n = t * 4, r = this.rawLineData[e], i = this.rawLineData[e + 2], a = this.rawLineData[e + 3];
|
|
2238
|
-
this.barTriangleData[n] = r, this.barTriangleData[n + 1] = a, this.barTriangleData[n + 2] = r, this.barTriangleData[n + 3] = i;
|
|
2239
|
-
}
|
|
2240
|
-
return e * 2;
|
|
2241
|
-
}
|
|
2242
|
-
drawCandlestickBodies(e, t, n, r, i) {
|
|
2243
|
-
let a = t * .5, o = 0;
|
|
2244
|
-
for (let t = 0; t < e && o < this.maxBarTriangleBars(); t++) {
|
|
2245
|
-
let e = t * X, r = this.rawLineData[e], i = this.rawLineData[e + 1], s = this.rawLineData[e + 4];
|
|
2246
|
-
n === "up" == s >= i && (this.writeBarTriangle(o, r - a, r + a, Math.min(i, s), Math.max(i, s)), o++);
|
|
2247
|
-
}
|
|
2248
|
-
this.drawBarTriangles(o * 6, r, i);
|
|
2249
|
-
}
|
|
2250
|
-
writeBarTriangle(e, t, n, r, i) {
|
|
2251
|
-
let a = e * Y;
|
|
2252
|
-
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;
|
|
2253
|
-
}
|
|
2254
|
-
drawBarTriangles(e, t, n, r = "bars") {
|
|
2255
|
-
e <= 0 || (this.uploadBarTriangleData(e), this.renderer.drawBarTriangles(this.barTriangleBuffer, e, t, n), this.recordDraw(r, e));
|
|
2256
|
-
}
|
|
2257
|
-
recordDraw(e, t, n = 1) {
|
|
2258
|
-
this.recordRenderMode(e), this.stats.pointsRendered += t, this.stats.drawCalls += n;
|
|
2259
|
-
}
|
|
2260
|
-
findNearestXCandidate(e, t, n) {
|
|
2261
|
-
let r = null, i = Infinity;
|
|
2262
|
-
for (let n = 0; n < this.series.length; n++) {
|
|
2263
|
-
let a = this.series[n];
|
|
2264
|
-
if (!a.visible) continue;
|
|
2265
|
-
let o = this.cameraForSeries(a).viewport, s = t / (o.xMax - o.xMin), c = a.nearestSampleByX(e, o);
|
|
2266
|
-
if (!c) continue;
|
|
2267
|
-
let l = Math.abs(c.x - e) * s;
|
|
2268
|
-
l < i && (r = {
|
|
2269
|
-
sample: c,
|
|
2270
|
-
series: a,
|
|
2271
|
-
seriesIndex: n
|
|
2272
|
-
}, i = l);
|
|
2273
|
-
}
|
|
2274
|
-
return r && i <= n ? r : null;
|
|
2275
|
-
}
|
|
2276
|
-
findNearestPointCandidate(e, t, n, r, i) {
|
|
2277
|
-
let a = null;
|
|
2278
|
-
for (let o = 0; o < this.series.length; o++) {
|
|
2279
|
-
let s = this.series[o];
|
|
2280
|
-
if (!s.visible) continue;
|
|
2281
|
-
let c = this.cameraForSeries(s).viewport, l = c.yMax - t / r * (c.yMax - c.yMin), u = s.nearestSampleByPoint(e, l, c, n, r, i);
|
|
2282
|
-
u && (!a || (u.distancePx ?? Infinity) < (a.sample.distancePx ?? Infinity)) && (a = {
|
|
2283
|
-
sample: u,
|
|
2284
|
-
series: s,
|
|
2285
|
-
seriesIndex: o
|
|
2286
|
-
});
|
|
2287
|
-
}
|
|
2288
|
-
return a && (a.sample.distancePx ?? Infinity) <= i ? a : null;
|
|
2289
|
-
}
|
|
2290
|
-
collectPickItems(e, t, n, r) {
|
|
2291
|
-
let i = [];
|
|
2292
|
-
for (let a = 0; a < this.series.length; a++) {
|
|
2293
|
-
let o = this.series[a];
|
|
2294
|
-
if (!o.visible) continue;
|
|
2295
|
-
let s = o.nearestSampleByX(e, this.cameraForSeries(o).viewport);
|
|
2296
|
-
s && i.push(this.createPickItem(s, o, a, t, n, r));
|
|
2297
|
-
}
|
|
2298
|
-
return i;
|
|
2299
|
-
}
|
|
2300
|
-
createPickItem(e, t, n, r, i, a) {
|
|
2301
|
-
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;
|
|
2302
|
-
return {
|
|
2303
|
-
...e,
|
|
2304
|
-
distancePx: Math.hypot(p, m),
|
|
2305
|
-
series: t,
|
|
2306
|
-
seriesIndex: n,
|
|
2307
|
-
id: t.config.id,
|
|
2308
|
-
name: t.config.name,
|
|
2309
|
-
mode: t.config.mode,
|
|
2310
|
-
plotX: l,
|
|
2311
|
-
plotY: u,
|
|
2312
|
-
clientX: d,
|
|
2313
|
-
clientY: f
|
|
2314
|
-
};
|
|
2315
|
-
}
|
|
2316
|
-
refreshHover() {
|
|
2317
|
-
this.pointerInPlot && this.emitHover(this.pick(this.lastPointerClientX, this.lastPointerClientY));
|
|
2318
|
-
}
|
|
2319
|
-
emitHover(e) {
|
|
2320
|
-
this.currentHover = e;
|
|
2321
|
-
for (let t of this.hoverSubscribers) t(e);
|
|
2322
|
-
}
|
|
2323
|
-
emitSeriesChange() {
|
|
2324
|
-
for (let e of this.seriesSubscribers) e();
|
|
2325
|
-
this.refreshHover();
|
|
2326
|
-
}
|
|
2327
|
-
emitThemeChange() {
|
|
2328
|
-
for (let e of this.themeSubscribers) e();
|
|
2329
|
-
}
|
|
2330
|
-
emitRender() {
|
|
2331
|
-
for (let e of this.renderSubscribers) e(this);
|
|
2332
|
-
}
|
|
2333
|
-
drawDomTextForScreenshot(e, t, n) {
|
|
2334
|
-
let r = this.layout.root.querySelectorAll("div");
|
|
2335
|
-
for (let i of r) {
|
|
2336
|
-
let r = i.textContent;
|
|
2337
|
-
if (!r || i.children.length > 0) continue;
|
|
2338
|
-
let a = getComputedStyle(i);
|
|
2339
|
-
if (a.display === "none" || a.visibility === "hidden" || a.opacity === "0") continue;
|
|
2340
|
-
let o = i.getBoundingClientRect();
|
|
2341
|
-
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());
|
|
2342
|
-
}
|
|
2343
|
-
}
|
|
2344
|
-
maxMinMaxSegments() {
|
|
2345
|
-
return Math.min(this.canvas.width, K);
|
|
2346
|
-
}
|
|
2347
|
-
maxBarTriangleBars() {
|
|
2348
|
-
return Math.min(J, W);
|
|
2349
|
-
}
|
|
2350
|
-
maxRawBarInstances() {
|
|
2351
|
-
return this.renderer.supportsInstancedBars ? W : this.maxBarTriangleBars();
|
|
2352
|
-
}
|
|
2353
|
-
writeGridVertices(e) {
|
|
2354
|
-
let t = Math.max(1, this.canvas.clientWidth), n = Math.max(1, this.canvas.clientHeight);
|
|
2355
|
-
this.axis.getXTickValues(t, 12, this.xTicks), this.axis.getYTickValues(n, 8, this.yTicks);
|
|
2356
|
-
let r = 0;
|
|
2357
|
-
for (let t of this.xTicks) {
|
|
2358
|
-
if (r + 2 > Z) return r;
|
|
2359
|
-
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++;
|
|
2360
|
-
}
|
|
2361
|
-
for (let t of this.yTicks) {
|
|
2362
|
-
if (r + 2 > Z) return r;
|
|
2363
|
-
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++;
|
|
2364
|
-
}
|
|
2365
|
-
return r;
|
|
2366
|
-
}
|
|
2367
|
-
xToClip(e, t) {
|
|
2368
|
-
return (e - t.xMin) / (t.xMax - t.xMin) * 2 - 1;
|
|
2369
|
-
}
|
|
2370
|
-
yToClip(e, t) {
|
|
2371
|
-
return (e - t.yMin) / (t.yMax - t.yMin) * 2 - 1;
|
|
2372
|
-
}
|
|
2373
|
-
recordRenderMode(e) {
|
|
2374
|
-
this.stats.renderMode === "none" ? this.stats.renderMode = e : this.stats.renderMode !== e && (this.stats.renderMode = "mixed");
|
|
2375
|
-
}
|
|
2376
|
-
}, ye = class {
|
|
225
|
+
}, d = class {
|
|
2377
226
|
xData;
|
|
2378
227
|
yData;
|
|
2379
228
|
constructor(e, t) {
|
|
@@ -2395,15 +244,15 @@ var ve = class {
|
|
|
2395
244
|
return this.assertValidIndex(e), this.yData[e];
|
|
2396
245
|
}
|
|
2397
246
|
lowerBoundX(e) {
|
|
2398
|
-
return
|
|
247
|
+
return a(this.length, (e) => this.xData[e], e);
|
|
2399
248
|
}
|
|
2400
249
|
upperBoundX(e) {
|
|
2401
|
-
return
|
|
250
|
+
return s(this.length, (e) => this.xData[e], e);
|
|
2402
251
|
}
|
|
2403
252
|
assertValidIndex(e) {
|
|
2404
253
|
if (!Number.isInteger(e) || e < 0 || e >= this.length) throw RangeError(`StaticDataset index out of range: ${e}`);
|
|
2405
254
|
}
|
|
2406
|
-
},
|
|
255
|
+
}, f = class {
|
|
2407
256
|
length;
|
|
2408
257
|
xs;
|
|
2409
258
|
opens;
|
|
@@ -2438,15 +287,15 @@ var ve = class {
|
|
|
2438
287
|
return this.assertValidIndex(e), this.closes[e];
|
|
2439
288
|
}
|
|
2440
289
|
lowerBoundX(e) {
|
|
2441
|
-
return
|
|
290
|
+
return a(this.length, (e) => this.xs[e], e);
|
|
2442
291
|
}
|
|
2443
292
|
upperBoundX(e) {
|
|
2444
|
-
return
|
|
293
|
+
return s(this.length, (e) => this.xs[e], e);
|
|
2445
294
|
}
|
|
2446
295
|
assertValidIndex(e) {
|
|
2447
296
|
if (!Number.isInteger(e) || e < 0 || e >= this.length) throw RangeError(`StaticOhlcDataset index out of range: ${e}`);
|
|
2448
297
|
}
|
|
2449
|
-
},
|
|
298
|
+
}, p = class {
|
|
2450
299
|
capacity;
|
|
2451
300
|
overflow;
|
|
2452
301
|
xData;
|
|
@@ -2511,10 +360,10 @@ var ve = class {
|
|
|
2511
360
|
return this.assertValidIndex(e), this.closeData[this.logicalToPhysical(e)];
|
|
2512
361
|
}
|
|
2513
362
|
lowerBoundX(e) {
|
|
2514
|
-
return
|
|
363
|
+
return a(this._length, (e) => this.getX(e), e);
|
|
2515
364
|
}
|
|
2516
365
|
upperBoundX(e) {
|
|
2517
|
-
return
|
|
366
|
+
return s(this._length, (e) => this.getX(e), e);
|
|
2518
367
|
}
|
|
2519
368
|
logicalToPhysical(e) {
|
|
2520
369
|
return (this._head - this._length + e + this.capacity) % this.capacity;
|
|
@@ -2524,6 +373,6 @@ var ve = class {
|
|
|
2524
373
|
}
|
|
2525
374
|
};
|
|
2526
375
|
//#endregion
|
|
2527
|
-
export {
|
|
376
|
+
export { o as AxisController, n as Camera2D, c as Chart, i as DEFAULT_CHART_THEME, r as MinMaxPyramid, p as OhlcRingBuffer, e as RingBuffer, t as SeriesStore, d as StaticDataset, f as StaticOhlcDataset, u as UniformRingBuffer };
|
|
2528
377
|
|
|
2529
378
|
//# sourceMappingURL=index.js.map
|