blazeplot 0.1.1 → 0.1.3

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/index.js CHANGED
@@ -1,95 +1,85 @@
1
1
  import e from "regl";
2
- //#region src/core/RingBuffer.ts
3
- var t = class {
4
- capacity;
5
- _length = 0;
6
- _head = 0;
7
- xData;
8
- yData;
9
- constructor(e) {
10
- if (!Number.isInteger(e) || e <= 0) throw RangeError("RingBuffer capacity must be a positive integer.");
11
- this.capacity = e, this.xData = new Float64Array(e), this.yData = new Float32Array(e);
12
- }
13
- get length() {
14
- return this._length;
15
- }
16
- get range() {
17
- return this._length === 0 ? null : {
18
- start: this.getX(0),
19
- end: this.getX(this._length - 1)
20
- };
21
- }
22
- push(e, t) {
23
- this.xData[this._head] = e, this.yData[this._head] = t, this._head = (this._head + 1) % this.capacity, this._length < this.capacity && this._length++;
24
- }
25
- get(e) {
26
- return e < 0 || e >= this._length ? null : {
27
- x: this.getX(e),
28
- y: this.getY(e)
29
- };
30
- }
31
- getX(e) {
32
- return this.assertValidIndex(e), this.xData[this.logicalToPhysical(e)];
33
- }
34
- getY(e) {
35
- return this.assertValidIndex(e), this.yData[this.logicalToPhysical(e)];
36
- }
37
- lowerBoundX(e) {
38
- let t = 0, n = this._length;
39
- for (; t < n;) {
40
- let r = t + (n - t >> 1);
41
- this.getX(r) < e ? t = r + 1 : n = r;
42
- }
43
- return t;
44
- }
45
- upperBoundX(e) {
46
- let t = 0, n = this._length;
47
- for (; t < n;) {
48
- let r = t + (n - t >> 1);
49
- this.getX(r) <= e ? t = r + 1 : n = r;
50
- }
51
- return t;
52
- }
53
- clear() {
54
- this._length = 0, this._head = 0;
55
- }
56
- logicalToPhysical(e) {
57
- return (this._head - this._length + e + this.capacity) % this.capacity;
58
- }
59
- assertValidIndex(e) {
60
- if (!Number.isInteger(e) || e < 0 || e >= this._length) throw RangeError(`RingBuffer index out of range: ${e}`);
61
- }
62
- }, n = 16, r = class {
2
+ //#region src/core/MinMaxPyramid.ts
3
+ var t = 16, n = class {
63
4
  bucketSize;
64
5
  levels = [];
65
6
  levelLengths;
66
7
  levelSampleWidths;
8
+ _builtLen = 0;
9
+ _lastRangeStart = NaN;
67
10
  constructor(e = 2) {
68
11
  if (this.bucketSize = e, !Number.isInteger(e) || e < 2) throw RangeError("MinMaxPyramid bucketSize must be an integer >= 2.");
69
- this.levelLengths = new Uint32Array(n), this.levelSampleWidths = new Uint32Array(n);
12
+ this.levelLengths = new Uint32Array(t), this.levelSampleWidths = new Uint32Array(t);
70
13
  }
71
14
  build(e) {
72
15
  this.levels = [], this.levelLengths.fill(0), this.levelSampleWidths.fill(0);
73
- let t = e.length;
74
- if (t === 0) return;
16
+ let n = e.length;
17
+ if (n === 0) {
18
+ this._builtLen = 0, this._lastRangeStart = NaN;
19
+ return;
20
+ }
75
21
  let r = null, i = 0;
76
- for (; t > 0 && i < n;) {
77
- let n = Math.ceil(t / this.bucketSize), a = new Float32Array(n * 2);
78
- for (let n = 0; n < t; n += this.bucketSize) {
79
- let i = Infinity, o = -Infinity, s = Math.min(n + this.bucketSize, t);
80
- for (let t = n; t < s; t++) if (r) {
81
- let e = r[t * 2], n = r[t * 2 + 1];
82
- e < i && (i = e), n > o && (o = n);
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);
83
29
  } else {
84
- let n = e.getY(t);
85
- n < i && (i = n), n > o && (o = n);
30
+ let t = e.getY(n);
31
+ t < i && (i = t), t > o && (o = t);
86
32
  }
87
- let c = Math.floor(n / this.bucketSize);
33
+ let c = Math.floor(t / this.bucketSize);
88
34
  a[c * 2] = i, a[c * 2 + 1] = o;
89
35
  }
90
- if (this.levels[i] = a, this.levelLengths[i] = n, this.levelSampleWidths[i] = this.bucketSize ** (i + 1), n === 1) break;
91
- r = a, t = n, i++;
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++;
92
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 = new Float32Array(n);
82
+ r && i.set(r.subarray(0, Math.min(r.length, n))), this.levels[e] = i;
93
83
  }
94
84
  query(e, t, n) {
95
85
  if (t <= 0 || n.length <= 0) return {
@@ -124,21 +114,21 @@ var t = class {
124
114
  samplesPerPixel: i
125
115
  };
126
116
  }
127
- }, i = class {
117
+ }, r = class {
128
118
  config;
129
119
  style;
130
- buffer;
120
+ dataset;
131
121
  pyramid;
132
122
  _dirty = !1;
133
123
  _visible = !0;
134
- constructor(e, n) {
135
- this.config = e, this.buffer = new t(e.capacity), this.pyramid = new r(), this.style = n;
124
+ constructor(e, t, r) {
125
+ this.dataset = e, this.config = t, this.pyramid = new n(), this.style = r, e.length > 0 && this.pyramid.build(e);
136
126
  }
137
127
  get dirty() {
138
128
  return this._dirty;
139
129
  }
140
130
  get length() {
141
- return this.buffer.length;
131
+ return this.dataset.length;
142
132
  }
143
133
  get visible() {
144
134
  return this._visible;
@@ -147,57 +137,120 @@ var t = class {
147
137
  this._visible = e;
148
138
  }
149
139
  append(e, t) {
150
- let n = Math.min(e.length, t.length);
151
- for (let r = 0; r < n; r++) this.buffer.push(e[r], t[r]);
152
- this._dirty = !0;
140
+ if (!("push" in this.dataset)) throw TypeError("SeriesStore dataset is not appendable.");
141
+ this.dataset.append(e, t), this._dirty = !0;
153
142
  }
154
143
  clear() {
155
- this.buffer.clear(), this.pyramid.build(this.buffer), this._dirty = !1;
144
+ if (!("clear" in this.dataset)) throw TypeError("SeriesStore dataset is not clearable.");
145
+ this.dataset.clear(), this.pyramid.build(this.dataset), this._dirty = !1;
156
146
  }
157
147
  rebuildPyramid() {
158
- this._dirty &&= (this.pyramid.build(this.buffer), !1);
148
+ this._dirty &&= (this.pyramid.incrementalBuild(this.dataset), !1);
159
149
  }
160
150
  query(e, t) {
161
- if (!this.buffer.range) return {
151
+ if (!this.dataset.range) return {
162
152
  buckets: new Float32Array(),
163
153
  bucketCount: 0,
164
154
  level: 0,
165
155
  samplesPerPixel: 0
166
156
  };
167
- let n = this.buffer.lowerBoundX(e.xMin), r = this.buffer.upperBoundX(e.xMax);
157
+ let n = this.dataset.lowerBoundX(e.xMin), r = this.dataset.upperBoundX(e.xMax);
168
158
  return this.pyramid.query(e, t, {
169
159
  start: n,
170
160
  length: Math.max(0, r - n)
171
161
  });
172
162
  }
173
163
  visibleSampleCount(e) {
174
- let t = this.buffer.lowerBoundX(e.xMin), n = this.buffer.upperBoundX(e.xMax);
164
+ let t = this.dataset.lowerBoundX(e.xMin), n = this.dataset.upperBoundX(e.xMax);
175
165
  return Math.max(0, n - t);
176
166
  }
177
167
  copyRawVisible(e, t, n) {
178
168
  if (n <= 0 || t.length < n * 2) return 0;
179
- let r = this.buffer.lowerBoundX(e.xMin), i = this.buffer.upperBoundX(e.xMax), a = i - r;
169
+ let r = this.dataset.lowerBoundX(e.xMin), i = this.dataset.upperBoundX(e.xMax), a = i - r;
180
170
  if (a <= 0) return 0;
181
171
  let o = Math.max(1, Math.ceil(a / n)), s = 0;
182
- for (let e = r; e < i && s < n; e += o) t[s * 2] = this.buffer.getX(e), t[s * 2 + 1] = this.buffer.getY(e), s++;
172
+ for (let e = r; e < i && s < n; e += o) t[s * 2] = this.dataset.getX(e), t[s * 2 + 1] = this.dataset.getY(e), s++;
183
173
  return s;
184
174
  }
185
175
  copyMinMaxVisible(e, t, n) {
186
176
  if (n <= 0 || t.length < n * 4) return 0;
187
- let r = this.buffer.lowerBoundX(e.xMin), i = this.buffer.upperBoundX(e.xMax), a = i - r;
177
+ let r = this.dataset.lowerBoundX(e.xMin), i = this.dataset.upperBoundX(e.xMax), a = i - r;
188
178
  if (a <= 0) return 0;
189
179
  let o = Math.min(n, a), s = 0;
190
180
  for (let e = 0; e < o; e++) {
191
181
  let n = r + Math.floor(e * a / o), c = r + Math.max(Math.floor((e + 1) * a / o), Math.floor(e * a / o) + 1), l = Math.min(i, c), u = Infinity, d = -Infinity;
192
182
  for (let e = n; e < l; e++) {
193
- let t = this.buffer.getY(e);
183
+ let t = this.dataset.getY(e);
194
184
  t < u && (u = t), t > d && (d = t);
195
185
  }
196
- let f = this.buffer.getX(n + (l - n >> 1));
186
+ let f = this.dataset.getX(n + (l - n >> 1));
197
187
  t[s * 2] = f, t[s * 2 + 1] = u, s++, t[s * 2] = f, t[s * 2 + 1] = d, s++;
198
188
  }
199
189
  return s;
200
190
  }
191
+ }, i = class {
192
+ capacity;
193
+ _length = 0;
194
+ _head = 0;
195
+ xData;
196
+ yData;
197
+ constructor(e) {
198
+ if (!Number.isInteger(e) || e <= 0) throw RangeError("RingBuffer capacity must be a positive integer.");
199
+ this.capacity = e, this.xData = new Float64Array(e), this.yData = new Float32Array(e);
200
+ }
201
+ get length() {
202
+ return this._length;
203
+ }
204
+ get range() {
205
+ return this._length === 0 ? null : {
206
+ start: this.getX(0),
207
+ end: this.getX(this._length - 1)
208
+ };
209
+ }
210
+ push(e, t) {
211
+ this.xData[this._head] = e, this.yData[this._head] = t, this._head = (this._head + 1) % this.capacity, this._length < this.capacity && this._length++;
212
+ }
213
+ append(e, t) {
214
+ let n = Math.min(e.length, t.length);
215
+ for (let r = 0; r < n; r++) this.push(e[r], t[r]);
216
+ }
217
+ get(e) {
218
+ return e < 0 || e >= this._length ? null : {
219
+ x: this.getX(e),
220
+ y: this.getY(e)
221
+ };
222
+ }
223
+ getX(e) {
224
+ return this.assertValidIndex(e), this.xData[this.logicalToPhysical(e)];
225
+ }
226
+ getY(e) {
227
+ return this.assertValidIndex(e), this.yData[this.logicalToPhysical(e)];
228
+ }
229
+ lowerBoundX(e) {
230
+ let t = 0, n = this._length;
231
+ for (; t < n;) {
232
+ let r = t + (n - t >> 1);
233
+ this.getX(r) < e ? t = r + 1 : n = r;
234
+ }
235
+ return t;
236
+ }
237
+ upperBoundX(e) {
238
+ let t = 0, n = this._length;
239
+ for (; t < n;) {
240
+ let r = t + (n - t >> 1);
241
+ this.getX(r) <= e ? t = r + 1 : n = r;
242
+ }
243
+ return t;
244
+ }
245
+ clear() {
246
+ this._length = 0, this._head = 0;
247
+ }
248
+ logicalToPhysical(e) {
249
+ return (this._head - this._length + e + this.capacity) % this.capacity;
250
+ }
251
+ assertValidIndex(e) {
252
+ if (!Number.isInteger(e) || e < 0 || e >= this._length) throw RangeError(`RingBuffer index out of range: ${e}`);
253
+ }
201
254
  }, a = {
202
255
  line: {
203
256
  vert: "attribute vec2 position;\n\nuniform vec2 uScale;\nuniform vec2 uOffset;\n\nvoid main() {\n vec2 clipSpace = position * uScale + uOffset;\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n}\n",
@@ -583,7 +636,7 @@ var c = class {
583
636
  }, typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(this.canvas));
584
637
  }
585
638
  addSeries(e, t) {
586
- let n = new i(e, {
639
+ let n = new r(e.dataset ?? new i(e.capacity), e, {
587
640
  color: t?.color ?? [
588
641
  .3,
589
642
  .6,
@@ -662,8 +715,48 @@ var c = class {
662
715
  recordRenderMode(e) {
663
716
  this.stats.renderMode === "none" ? this.stats.renderMode = e : this.stats.renderMode !== e && (this.stats.renderMode = "mixed");
664
717
  }
718
+ }, h = class {
719
+ xData;
720
+ yData;
721
+ constructor(e, t) {
722
+ this.xData = e, this.yData = t;
723
+ }
724
+ get length() {
725
+ return Math.min(this.xData.length, this.yData.length);
726
+ }
727
+ get range() {
728
+ return this.length === 0 ? null : {
729
+ start: this.xData[0],
730
+ end: this.xData[this.length - 1]
731
+ };
732
+ }
733
+ getX(e) {
734
+ return this.assertValidIndex(e), this.xData[e];
735
+ }
736
+ getY(e) {
737
+ return this.assertValidIndex(e), this.yData[e];
738
+ }
739
+ lowerBoundX(e) {
740
+ let t = 0, n = this.length;
741
+ for (; t < n;) {
742
+ let r = t + (n - t >> 1);
743
+ this.xData[r] < e ? t = r + 1 : n = r;
744
+ }
745
+ return t;
746
+ }
747
+ upperBoundX(e) {
748
+ let t = 0, n = this.length;
749
+ for (; t < n;) {
750
+ let r = t + (n - t >> 1);
751
+ this.xData[r] <= e ? t = r + 1 : n = r;
752
+ }
753
+ return t;
754
+ }
755
+ assertValidIndex(e) {
756
+ if (!Number.isInteger(e) || e < 0 || e >= this.length) throw RangeError(`StaticDataset index out of range: ${e}`);
757
+ }
665
758
  };
666
759
  //#endregion
667
- export { d as AxisController, u as Camera2D, m as Chart, r as MinMaxPyramid, t as RingBuffer, i as SeriesStore };
760
+ export { d as AxisController, u as Camera2D, m as Chart, n as MinMaxPyramid, i as RingBuffer, r as SeriesStore, h as StaticDataset };
668
761
 
669
762
  //# sourceMappingURL=index.js.map