blazeplot 0.1.5 → 0.1.7

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
@@ -122,7 +122,7 @@ var t = 16, n = class {
122
122
  _dirty = !1;
123
123
  _visible = !0;
124
124
  constructor(e, t, r) {
125
- this.dataset = e, this.config = t, this.pyramid = t.downsample === "none" ? null : new n(), this.style = r, this.pyramid && e.length > 0 && this.pyramid.build(e);
125
+ this.dataset = e, this.config = t, this.pyramid = t.mode === "line" && t.downsample !== "none" ? new n() : null, this.style = r, this.pyramid && e.length > 0 && this.pyramid.build(e);
126
126
  }
127
127
  get hasLOD() {
128
128
  return this.pyramid !== null;
@@ -168,28 +168,58 @@ var t = 16, n = class {
168
168
  return Math.max(0, n - t);
169
169
  }
170
170
  copyRawVisible(e, t, n) {
171
- if (n <= 0 || t.length < n * 2) return 0;
172
- let r = this.dataset.lowerBoundX(e.xMin), i = this.dataset.upperBoundX(e.xMax), a = i - r;
173
- if (a <= 0) return 0;
174
- let o = Math.max(1, Math.ceil(a / n)), s = 0;
175
- 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++;
176
- return s;
171
+ return this.copyVisibleSamples(e, t, n, "points", 0);
172
+ }
173
+ copyAreaVisible(e, t, n, r = 0) {
174
+ return this.copyVisibleSamples(e, t, n, "area", r) * 2;
177
175
  }
178
176
  copyMinMaxVisible(e, t, n) {
179
- if (!this.pyramid || n <= 0 || t.length < n * 4) return 0;
180
- let r = this.dataset.lowerBoundX(e.xMin), i = this.dataset.upperBoundX(e.xMax), a = i - r;
181
- if (a <= 0) return 0;
182
- let o = Math.min(n, a), s = 0;
183
- for (let e = 0; e < o; e++) {
184
- 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;
177
+ return this.copyMinMaxSegments(e, t, n, "line-list") * 2;
178
+ }
179
+ copyMinMaxInstanced(e, t, n) {
180
+ return this.copyMinMaxSegments(e, t, n, "instanced");
181
+ }
182
+ copyVisibleSamples(e, t, n, r, i) {
183
+ let a = r === "points" ? 2 : 4;
184
+ if (n <= 0 || t.length < n * a) return 0;
185
+ let o = this.dataset.lowerBoundX(e.xMin), s = this.dataset.upperBoundX(e.xMax), c = s - o;
186
+ if (c <= 0) return 0;
187
+ let l = Math.max(1, Math.ceil(c / n)), u = 0;
188
+ for (let e = o; e < s && u < n; e += l) {
189
+ let n = this.dataset.getX(e), a = this.dataset.getY(e);
190
+ if (r === "points") {
191
+ let e = u * 2;
192
+ t[e] = n, t[e + 1] = a;
193
+ } else {
194
+ let e = u * 4;
195
+ t[e] = n, t[e + 1] = i, t[e + 2] = n, t[e + 3] = a;
196
+ }
197
+ u++;
198
+ }
199
+ return u;
200
+ }
201
+ copyMinMaxSegments(e, t, n, r) {
202
+ let i = r === "line-list" ? 4 : 3;
203
+ if (!this.pyramid || n <= 0 || t.length < n * i) return 0;
204
+ let a = this.dataset.lowerBoundX(e.xMin), o = this.dataset.upperBoundX(e.xMax), s = o - a;
205
+ if (s <= 0) return 0;
206
+ let c = Math.min(n, s);
207
+ for (let e = 0; e < c; e++) {
208
+ let n = a + Math.floor(e * s / c), i = a + Math.max(Math.floor((e + 1) * s / c), Math.floor(e * s / c) + 1), l = Math.min(o, i), u = Infinity, d = -Infinity;
185
209
  for (let e = n; e < l; e++) {
186
210
  let t = this.dataset.getY(e);
187
211
  t < u && (u = t), t > d && (d = t);
188
212
  }
189
213
  let f = this.dataset.getX(n + (l - n >> 1));
190
- t[s * 2] = f, t[s * 2 + 1] = u, s++, t[s * 2] = f, t[s * 2 + 1] = d, s++;
214
+ if (r === "line-list") {
215
+ let n = e * 4;
216
+ t[n] = f, t[n + 1] = u, t[n + 2] = f, t[n + 3] = d;
217
+ } else {
218
+ let n = e * 3;
219
+ t[n] = f, t[n + 1] = u, t[n + 2] = d;
220
+ }
191
221
  }
192
- return s;
222
+ return c;
193
223
  }
194
224
  }, i = class {
195
225
  capacity;
@@ -260,16 +290,70 @@ var t = 16, n = class {
260
290
  frag: "precision mediump float;\n\nuniform vec4 uColor;\n\nvoid main() {\n gl_FragColor = uColor;\n}\n"
261
291
  },
262
292
  segment: {
263
- vert: "attribute float aX;\nattribute float aMinY;\nattribute float aMaxY;\n\nuniform vec2 uScale;\nuniform vec2 uOffset;\n\nvoid main() {\n float y = (gl_VertexID == 0) ? aMinY : aMaxY;\n vec2 position = vec2(aX, y);\n vec2 clipSpace = position * uScale + uOffset;\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n}\n",
293
+ vert: "attribute float aX;\nattribute float aMinY;\nattribute float aMaxY;\nattribute float aSelect;\n\nuniform vec2 uScale;\nuniform vec2 uOffset;\n\nvoid main() {\n float y = (aSelect < 0.5) ? aMinY : aMaxY;\n vec2 position = vec2(aX, y);\n vec2 clipSpace = position * uScale + uOffset;\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n}\n",
294
+ frag: "precision mediump float;\n\nuniform vec4 uColor;\n\nvoid main() {\n gl_FragColor = uColor;\n}\n"
295
+ },
296
+ point: {
297
+ vert: "attribute vec2 aPosition;\nattribute vec2 aCorner;\n\nuniform vec2 uScale;\nuniform vec2 uOffset;\nuniform vec2 uCanvasSize;\nuniform float uPointSize;\n\nvoid main() {\n vec2 centerClip = aPosition * uScale + uOffset;\n vec2 pointSizeClip = vec2(2.0 / uCanvasSize.x, 2.0 / uCanvasSize.y) * uPointSize * 0.5;\n vec2 clipSpace = centerClip + aCorner * pointSizeClip;\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n}\n",
298
+ frag: "precision mediump float;\n\nuniform vec4 uColor;\n\nvoid main() {\n gl_FragColor = uColor;\n}\n"
299
+ },
300
+ bar: {
301
+ vert: "attribute vec2 aPosition;\nattribute vec2 aCorner;\n\nuniform vec2 uScale;\nuniform vec2 uOffset;\nuniform float uBarWidth;\nuniform float uBaseline;\n\nvoid main() {\n float x = aPosition.x + aCorner.x * uBarWidth;\n float y = mix(uBaseline, aPosition.y, aCorner.y);\n vec2 clipSpace = vec2(x, y) * uScale + uOffset;\n gl_Position = vec4(clipSpace, 0.0, 1.0);\n}\n",
264
302
  frag: "precision mediump float;\n\nuniform vec4 uColor;\n\nvoid main() {\n gl_FragColor = uColor;\n}\n"
265
303
  }
266
- }, o = class {
304
+ }, o = 3, s = 2, c = 4, l = 4, u = .8, d = 0, f = class {
267
305
  backend;
268
306
  lineProgram;
307
+ segmentProgram;
308
+ pointProgram;
309
+ barProgram;
310
+ segmentSelectBuffer;
311
+ pointCornerBuffer;
312
+ barCornerBuffer;
269
313
  scaleUniform = new Float32Array(2);
270
314
  offsetUniform = new Float32Array(2);
315
+ canvasSizeUniform = new Float32Array(2);
271
316
  constructor(e) {
272
- this.backend = e, this.lineProgram = this.backend.createProgram(a.line.vert, a.line.frag);
317
+ this.backend = e, this.lineProgram = this.backend.createProgram(a.line.vert, a.line.frag), this.segmentProgram = this.backend.createProgram(a.segment.vert, a.segment.frag), this.pointProgram = this.backend.createProgram(a.point.vert, a.point.frag), this.barProgram = this.backend.createProgram(a.bar.vert, a.bar.frag), this.segmentSelectBuffer = this.backend.createBuffer({
318
+ usage: "static",
319
+ type: "float",
320
+ length: 2
321
+ }), this.backend.updateBuffer(this.segmentSelectBuffer, new Float32Array([0, 1])), this.pointCornerBuffer = this.backend.createBuffer({
322
+ usage: "static",
323
+ type: "float",
324
+ length: 8
325
+ }), this.backend.updateBuffer(this.pointCornerBuffer, new Float32Array([
326
+ -1,
327
+ -1,
328
+ 1,
329
+ -1,
330
+ -1,
331
+ 1,
332
+ 1,
333
+ 1
334
+ ])), this.barCornerBuffer = this.backend.createBuffer({
335
+ usage: "static",
336
+ type: "float",
337
+ length: 8
338
+ }), this.backend.updateBuffer(this.barCornerBuffer, new Float32Array([
339
+ -.5,
340
+ 0,
341
+ .5,
342
+ 0,
343
+ -.5,
344
+ 1,
345
+ .5,
346
+ 1
347
+ ]));
348
+ }
349
+ get supportsInstancedSegments() {
350
+ return this.backend.capabilities.instancing;
351
+ }
352
+ get supportsInstancedPoints() {
353
+ return this.backend.capabilities.instancing;
354
+ }
355
+ get supportsInstancedBars() {
356
+ return this.backend.capabilities.instancing;
273
357
  }
274
358
  clear(e, t, n, r) {
275
359
  this.backend.clear(e, t, n, r);
@@ -293,8 +377,131 @@ var t = 16, n = class {
293
377
  drawLineStrip(e, t, n, r) {
294
378
  this.drawLinePrimitive("line_strip", e, t, n, r);
295
379
  }
380
+ drawMinMaxSegments(e, t, n, r) {
381
+ this.drawLines(e, t, n, r);
382
+ }
383
+ drawMinMaxSegmentsInstanced(e, t, n, r) {
384
+ this.writeCameraUniforms(r);
385
+ let i = o * c, a = {
386
+ buffer: e,
387
+ divisor: 1,
388
+ stride: i,
389
+ offset: 0
390
+ }, s = {
391
+ buffer: e,
392
+ divisor: 1,
393
+ stride: i,
394
+ offset: c
395
+ }, l = {
396
+ buffer: e,
397
+ divisor: 1,
398
+ stride: i,
399
+ offset: c * 2
400
+ }, u = {
401
+ buffer: this.segmentSelectBuffer,
402
+ divisor: 0,
403
+ stride: c,
404
+ offset: 0
405
+ };
406
+ this.backend.draw({
407
+ program: this.segmentProgram,
408
+ primitive: "lines",
409
+ count: 2,
410
+ instances: t,
411
+ attributes: {
412
+ aMaxY: l,
413
+ aMinY: s,
414
+ aSelect: u,
415
+ aX: a
416
+ },
417
+ uniforms: {
418
+ uScale: this.scaleUniform,
419
+ uOffset: this.offsetUniform,
420
+ uColor: n.color
421
+ }
422
+ });
423
+ }
424
+ drawPointsInstanced(e, t, n, r, i, a) {
425
+ this.writeCameraUniforms(r), this.canvasSizeUniform[0] = Math.max(1, i), this.canvasSizeUniform[1] = Math.max(1, a);
426
+ let o = {
427
+ buffer: e,
428
+ divisor: 1,
429
+ stride: s * c,
430
+ offset: 0,
431
+ size: 2
432
+ }, u = {
433
+ buffer: this.pointCornerBuffer,
434
+ divisor: 0,
435
+ stride: s * c,
436
+ offset: 0,
437
+ size: 2
438
+ };
439
+ this.backend.draw({
440
+ program: this.pointProgram,
441
+ primitive: "triangle_strip",
442
+ count: 4,
443
+ instances: t,
444
+ attributes: {
445
+ aCorner: u,
446
+ aPosition: o
447
+ },
448
+ uniforms: {
449
+ uScale: this.scaleUniform,
450
+ uOffset: this.offsetUniform,
451
+ uCanvasSize: this.canvasSizeUniform,
452
+ uPointSize: n.pointSize ?? l,
453
+ uColor: n.color
454
+ }
455
+ });
456
+ }
457
+ drawAreaStrip(e, t, n, r) {
458
+ this.writeCameraUniforms(r), this.backend.draw({
459
+ program: this.lineProgram,
460
+ primitive: "triangle_strip",
461
+ count: t,
462
+ attributes: { position: e },
463
+ uniforms: {
464
+ uScale: this.scaleUniform,
465
+ uOffset: this.offsetUniform,
466
+ uColor: n.fillColor ?? n.color
467
+ }
468
+ });
469
+ }
470
+ drawBarsInstanced(e, t, n, r) {
471
+ this.writeCameraUniforms(r);
472
+ let i = {
473
+ buffer: e,
474
+ divisor: 1,
475
+ stride: s * c,
476
+ offset: 0,
477
+ size: 2
478
+ }, a = {
479
+ buffer: this.barCornerBuffer,
480
+ divisor: 0,
481
+ stride: s * c,
482
+ offset: 0,
483
+ size: 2
484
+ };
485
+ this.backend.draw({
486
+ program: this.barProgram,
487
+ primitive: "triangle_strip",
488
+ count: 4,
489
+ instances: t,
490
+ attributes: {
491
+ aCorner: a,
492
+ aPosition: i
493
+ },
494
+ uniforms: {
495
+ uScale: this.scaleUniform,
496
+ uOffset: this.offsetUniform,
497
+ uBarWidth: n.barWidth ?? u,
498
+ uBaseline: n.baseline ?? d,
499
+ uColor: n.color
500
+ }
501
+ });
502
+ }
296
503
  drawLinePrimitive(e, t, n, r, i) {
297
- this.scaleUniform[0] = i.xScale, this.scaleUniform[1] = i.yScale, this.offsetUniform[0] = i.xOffset, this.offsetUniform[1] = i.yOffset, this.backend.draw({
504
+ this.writeCameraUniforms(i), this.backend.draw({
298
505
  program: this.lineProgram,
299
506
  primitive: e,
300
507
  count: n,
@@ -306,19 +513,19 @@ var t = 16, n = class {
306
513
  }
307
514
  });
308
515
  }
309
- drawMinMaxSegments(e, t, n, r) {
310
- this.drawLines(e, t, n, r);
516
+ writeCameraUniforms(e) {
517
+ this.scaleUniform[0] = e.xScale, this.scaleUniform[1] = e.yScale, this.offsetUniform[0] = e.xOffset, this.offsetUniform[1] = e.yOffset;
311
518
  }
312
519
  dispose() {
313
520
  this.backend.destroy();
314
521
  }
315
- }, s = [
522
+ }, p = [
316
523
  1024,
317
524
  4096,
318
525
  16384,
319
526
  32768,
320
527
  131072
321
- ], c = class {
528
+ ], m = class {
322
529
  regl;
323
530
  pool = [];
324
531
  preAllocated = !1;
@@ -331,7 +538,7 @@ var t = 16, n = class {
331
538
  preAllocate() {
332
539
  if (!this.preAllocated) {
333
540
  this.preAllocated = !0;
334
- for (let e of s) this.pool.push(this.createEntry(e, "stream"));
541
+ for (let e of p) this.pool.push(this.createEntry(e, "stream"));
335
542
  }
336
543
  }
337
544
  acquire(e, t = "stream") {
@@ -371,23 +578,24 @@ var t = 16, n = class {
371
578
  return this.pool.find((t) => !t.inUse && t.floatCapacity >= e);
372
579
  }
373
580
  roundUp(e) {
374
- for (let t of s) if (t >= e) return t;
375
- let t = s[s.length - 1], n = 1 << 32 - Math.clz32(e - 1);
581
+ for (let t of p) if (t >= e) return t;
582
+ let t = p[p.length - 1], n = 1 << 32 - Math.clz32(e - 1);
376
583
  return Math.max(t * 2, n);
377
584
  }
378
585
  };
379
586
  //#endregion
380
587
  //#region src/render/ReglBackend.ts
381
- function l(e) {
588
+ function h(e) {
382
589
  return e;
383
590
  }
384
- var u = class {
591
+ var g = class {
385
592
  gl;
386
593
  regl;
387
594
  resources;
388
595
  nextProgramId = 1;
389
596
  commandCache = /* @__PURE__ */ new Map();
390
597
  scissorBox = null;
598
+ capabilities;
391
599
  constructor(t) {
392
600
  let n = t.getContext("webgl2", {
393
601
  alpha: !0,
@@ -400,10 +608,10 @@ var u = class {
400
608
  });
401
609
  if (!n) throw Error("BlazePlot requires WebGL2, but this browser/context does not support it.");
402
610
  this.gl = n, this.regl = e({
403
- gl: l(this.gl),
611
+ gl: h(this.gl),
404
612
  extensions: [],
405
- optionalExtensions: ["ext_disjoint_timer_query_webgl2"]
406
- }), this.resources = new c(this.regl), this.resources.preAllocate();
613
+ optionalExtensions: ["angle_instanced_arrays", "ext_disjoint_timer_query_webgl2"]
614
+ }), this.capabilities = { instancing: this.regl.hasExtension("angle_instanced_arrays") }, this.resources = new m(this.regl), this.resources.preAllocate();
407
615
  }
408
616
  createBuffer(e) {
409
617
  let { buffer: t } = this.resources.acquire(e.length, e.usage);
@@ -436,7 +644,7 @@ var u = class {
436
644
  ].join("|"), a = this.commandCache.get(i);
437
645
  a || (a = this.createDrawCommand(t, e.primitive, n, r, e.instances !== void 0), this.commandCache.set(i, a));
438
646
  let o = {};
439
- for (let t of n) o[t] = this.asReglBuffer(e.attributes[t]).buffer;
647
+ for (let t of n) o[t] = this.resolveAttribute(e.attributes[t]);
440
648
  let s = {
441
649
  count: e.count,
442
650
  instances: e.instances ?? 0,
@@ -497,6 +705,15 @@ var u = class {
497
705
  }
498
706
  });
499
707
  }
708
+ resolveAttribute(e) {
709
+ return "divisor" in e ? {
710
+ buffer: this.asReglBuffer(e.buffer).buffer,
711
+ divisor: e.divisor,
712
+ stride: e.stride,
713
+ offset: e.offset,
714
+ size: e.size
715
+ } : this.asReglBuffer(e).buffer;
716
+ }
500
717
  asReglBuffer(e) {
501
718
  return e;
502
719
  }
@@ -513,7 +730,7 @@ var u = class {
513
730
  default: return e;
514
731
  }
515
732
  }
516
- }, d = class {
733
+ }, _ = class {
517
734
  canvas;
518
735
  camera;
519
736
  policy;
@@ -567,7 +784,7 @@ var u = class {
567
784
  dispose() {
568
785
  this.canvas.removeEventListener("pointerdown", this.onPointerDown), this.canvas.removeEventListener("pointermove", this.onPointerMove), this.canvas.removeEventListener("pointerup", this.onPointerUp), this.canvas.removeEventListener("pointercancel", this.onPointerUp), this.canvas.removeEventListener("wheel", this.onWheel);
569
786
  }
570
- }, f = class e {
787
+ }, v = class e {
571
788
  _xMin = 0;
572
789
  _xMax = 1;
573
790
  _yMin = 0;
@@ -652,7 +869,7 @@ var u = class {
652
869
  static assertFinite(e, t) {
653
870
  if (!Number.isFinite(t)) throw RangeError(`Camera2D ${e} must be finite.`);
654
871
  }
655
- }, p = class {
872
+ }, y = class {
656
873
  camera;
657
874
  constructor(e) {
658
875
  this.camera = e;
@@ -684,53 +901,77 @@ var u = class {
684
901
  let n = Math.max(0, -Math.floor(Math.log10(t)) + 2), r = Number(e.toFixed(n));
685
902
  return Object.is(r, -0) ? 0 : r;
686
903
  }
687
- }, m = class {
688
- canvas;
904
+ }, b = class {
905
+ layout;
689
906
  config;
690
907
  options;
691
- container;
692
908
  xPool = [];
693
909
  yPool = [];
694
910
  xTicks = [];
695
911
  yTicks = [];
696
912
  constructor(e, t, n = {}) {
697
- this.canvas = e, this.config = t, this.options = n, this.container = document.createElement("div"), this.container.style.position = "absolute", this.container.style.pointerEvents = "none", this.container.style.overflow = "hidden";
698
- let r = e.parentElement;
699
- r && getComputedStyle(r).position === "static" && (r.style.position = "relative"), this.syncPosition(), r?.appendChild(this.container);
913
+ this.layout = e, this.config = t, this.options = n;
700
914
  }
701
- update(e, t, n, r) {
702
- this.syncPosition();
703
- let i = this.canvas.clientWidth, a = this.canvas.clientHeight, o = Math.max(1, i - n), s = Math.max(1, a - r);
704
- this.config.x.visible ? t.getXTickValues(o, 12, this.xTicks) : this.xTicks.length = 0, this.config.y.visible ? t.getYTickValues(s, 8, this.yTicks) : this.yTicks.length = 0, this.updateAxis(this.xPool, this.xTicks, "x", e, i, a, t, n, r), this.updateAxis(this.yPool, this.yTicks, "y", e, i, a, t, n, r);
915
+ update(e, t) {
916
+ let n = Math.max(1, this.layout.plot.clientWidth), r = Math.max(1, this.layout.plot.clientHeight);
917
+ this.config.x.visible ? t.getXTickValues(n, 12, this.xTicks) : this.xTicks.length = 0, this.config.y.visible ? t.getYTickValues(r, 8, this.yTicks) : this.yTicks.length = 0, this.updateAxis(this.xPool, this.xTicks, "x", e, n, r, t), this.updateAxis(this.yPool, this.yTicks, "y", e, n, r, t);
705
918
  }
706
919
  dispose() {
707
- this.container.remove();
708
- }
709
- syncPosition() {
710
- let e = this.canvas.parentElement;
711
- if (!e) return;
712
- let t = this.canvas.getBoundingClientRect(), n = e.getBoundingClientRect();
713
- this.container.style.top = `${Math.round(t.top - n.top)}px`, this.container.style.left = `${Math.round(t.left - n.left)}px`, this.container.style.width = `${this.canvas.clientWidth}px`, this.container.style.height = `${this.canvas.clientHeight}px`;
920
+ for (let e of this.xPool) e.remove();
921
+ for (let e of this.yPool) e.remove();
922
+ this.xPool = [], this.yPool = [];
714
923
  }
715
- toCssScreen(e, t, n, r, i, a) {
716
- let o = Math.max(1, n - i), s = Math.max(1, r - a);
717
- return [(e + 1) * .5 * o + i, (1 - t) * .5 * s];
924
+ parentForAxis(e) {
925
+ return e === "x" ? this.config.x.position === "outside" ? this.layout.xAxis : this.layout.plot : this.config.y.position === "outside" ? this.layout.yAxis : this.layout.plot;
718
926
  }
719
- updateAxis(e, t, n, r, i, a, o, s, c) {
927
+ updateAxis(e, t, n, r, i, a, o) {
928
+ let s = this.parentForAxis(n);
720
929
  for (; e.length < t.length;) {
721
930
  let t = document.createElement("div");
722
- 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", this.container.appendChild(t), e.push(t);
931
+ 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);
723
932
  }
933
+ for (let t of e) t.parentElement !== s && s.appendChild(t);
724
934
  for (let n = t.length; n < e.length; n++) e[n].style.display = "none";
725
- for (let l = 0; l < t.length; l++) {
726
- let u = e[l], d = t[l], f = o.formatValue(d);
727
- u.textContent !== f && (u.textContent = f), u.style.display = "block";
728
- let [p, m] = n === "x" ? r.toClip(d, r.yMin) : r.toClip(r.xMin, d), [h, g] = this.toCssScreen(p, m, i, a, s, c);
729
- n === "x" ? (u.style.left = `${h}px`, u.style.transform = "translateX(-50%)", this.config.x.position === "outside" ? (u.style.top = `${g + 4}px`, u.style.bottom = "auto") : (u.style.top = "auto", u.style.bottom = `${a - g + 4}px`)) : (u.style.top = `${g}px`, u.style.transform = "translateY(-50%)", this.config.y.position === "outside" ? (u.style.left = "auto", u.style.right = `${i - h + 4}px`) : (u.style.left = `${h + 4}px`, u.style.right = "auto"));
935
+ for (let s = 0; s < t.length; s++) {
936
+ let c = e[s], l = t[s], u = o.formatValue(l);
937
+ if (c.textContent !== u && (c.textContent = u), c.style.display = "block", n === "x") {
938
+ let [e] = r.toClip(l, r.yMin), t = (e + 1) * .5 * i;
939
+ 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");
940
+ } else {
941
+ let [, e] = r.toClip(r.xMin, l), t = (1 - e) * .5 * a;
942
+ c.style.top = `${t}px`, c.style.bottom = "auto", c.style.transform = "translateY(-50%)", this.config.y.position === "outside" ? (c.style.left = "auto", c.style.right = "4px") : (c.style.left = "4px", c.style.right = "auto");
943
+ }
730
944
  }
731
945
  }
732
- }, h = 16384, g = 64, _ = 52, v = 28;
733
- function y(e) {
946
+ }, x = class {
947
+ root;
948
+ plot;
949
+ canvas;
950
+ xAxis;
951
+ yAxis;
952
+ corner;
953
+ externalCanvas;
954
+ originalCanvasCssText;
955
+ originalCanvasParent;
956
+ constructor(e, t) {
957
+ let n = e instanceof HTMLCanvasElement ? e : null;
958
+ 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.corner = 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.corner.className = "blazeplot-axis-corner", this.applyBaseStyles(), this.mount(e), this.update(t);
959
+ }
960
+ update(e) {
961
+ let t = e.y.visible && e.y.position === "outside", n = e.x.visible && e.x.position === "outside";
962
+ this.root.style.gridTemplateColumns = `${t ? 52 : 0}px minmax(0, 1fr)`, this.root.style.gridTemplateRows = `minmax(0, 1fr) ${n ? 28 : 0}px`, this.yAxis.style.display = t ? "block" : "none", this.xAxis.style.display = n ? "block" : "none", this.corner.style.display = n && t ? "block" : "none";
963
+ }
964
+ dispose() {
965
+ this.externalCanvas && this.originalCanvasParent && (this.canvas.style.cssText = this.originalCanvasCssText, this.originalCanvasParent.insertBefore(this.canvas, this.root)), this.root.remove();
966
+ }
967
+ mount(e) {
968
+ 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.corner), this.root.appendChild(this.xAxis), this.plot.appendChild(this.canvas);
969
+ }
970
+ applyBaseStyles() {
971
+ 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.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";
972
+ }
973
+ }, S = 16384, C = S >> 1, w = S >> 1, T = 3, E = 64;
974
+ function D(e) {
734
975
  return e === !1 ? {
735
976
  visible: !1,
736
977
  position: "inside"
@@ -742,8 +983,7 @@ function y(e) {
742
983
  position: e.position ?? "inside"
743
984
  };
744
985
  }
745
- var b = class {
746
- canvas;
986
+ var O = class {
747
987
  options;
748
988
  series = [];
749
989
  camera;
@@ -752,6 +992,8 @@ var b = class {
752
992
  input;
753
993
  rawLineBuffer;
754
994
  rawLineData;
995
+ minMaxInstanceBuffer;
996
+ minMaxInstanceData;
755
997
  gridBuffer;
756
998
  gridData;
757
999
  gridStyle;
@@ -759,6 +1001,7 @@ var b = class {
759
1001
  yTicks = [];
760
1002
  axisOverlay = null;
761
1003
  normalizedAxes;
1004
+ layout;
762
1005
  stats = {
763
1006
  fps: 0,
764
1007
  frameMs: 0,
@@ -771,15 +1014,7 @@ var b = class {
771
1014
  lastFrameAt = 0;
772
1015
  _rafId = 0;
773
1016
  constructor(e, t = {}) {
774
- this.canvas = e, this.options = t, this.applyCanvasSize(), this.camera = new f(), this.axis = new p(this.camera), this.renderer = new o(new u(e)), this.input = new d(e, this.camera, t.viewportPolicy), this.rawLineData = new Float32Array(h * 2), this.rawLineBuffer = this.renderer.createFloatBuffer(this.rawLineData.length), this.gridData = new Float32Array(g * 2), this.gridBuffer = this.renderer.createFloatBuffer(this.gridData.length), this.gridStyle = {
775
- color: t.gridStyle?.color ?? [
776
- .22,
777
- .3,
778
- .44,
779
- .45
780
- ],
781
- lineWidth: t.gridStyle?.lineWidth ?? 1
782
- };
1017
+ this.options = t;
783
1018
  let n = t.axes;
784
1019
  n === !1 ? this.normalizedAxes = {
785
1020
  x: {
@@ -800,21 +1035,41 @@ var b = class {
800
1035
  position: "inside"
801
1036
  }
802
1037
  } : this.normalizedAxes = {
803
- x: y(n.x),
804
- y: y(n.y)
805
- }, (this.normalizedAxes.x.visible || this.normalizedAxes.y.visible) && (this.axisOverlay = new m(e, this.normalizedAxes)), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(this.canvas));
806
- }
807
- addSeries(e, t) {
808
- let n = new r(e.dataset ?? new i(e.capacity), e, {
809
- color: t?.color ?? [
1038
+ x: D(n.x),
1039
+ y: D(n.y)
1040
+ }, this.layout = new x(e, this.normalizedAxes), this.applyCanvasSize(), this.camera = new v(), this.axis = new y(this.camera), this.renderer = new f(new g(this.layout.canvas)), this.input = new _(this.layout.canvas, this.camera, t.viewportPolicy), this.rawLineData = new Float32Array(S * 2), this.rawLineBuffer = this.renderer.createFloatBuffer(this.rawLineData.length), this.minMaxInstanceData = new Float32Array(w * T), this.minMaxInstanceBuffer = this.renderer.createFloatBuffer(this.minMaxInstanceData.length), this.gridData = new Float32Array(E * 2), this.gridBuffer = this.renderer.createFloatBuffer(this.gridData.length), this.gridStyle = {
1041
+ color: t.gridStyle?.color ?? [
1042
+ .22,
810
1043
  .3,
811
- .6,
812
- 1,
813
- 1
1044
+ .44,
1045
+ .45
814
1046
  ],
815
- lineWidth: t?.lineWidth ?? 1
1047
+ lineWidth: t.gridStyle?.lineWidth ?? 1
1048
+ }, (this.normalizedAxes.x.visible || this.normalizedAxes.y.visible) && (this.axisOverlay = new b(this.layout, this.normalizedAxes)), typeof ResizeObserver < "u" && (this.resizeObserver = new ResizeObserver(() => this.resize()), this.resizeObserver.observe(this.layout.plot));
1049
+ }
1050
+ get canvas() {
1051
+ return this.layout.canvas;
1052
+ }
1053
+ addSeries(e, t) {
1054
+ let n = e.dataset ?? new i(e.capacity), a = t?.color ?? [
1055
+ .3,
1056
+ .6,
1057
+ 1,
1058
+ 1
1059
+ ], o = new r(n, e, {
1060
+ color: a,
1061
+ lineWidth: t?.lineWidth ?? 1,
1062
+ pointSize: t?.pointSize ?? 4,
1063
+ barWidth: t?.barWidth ?? .8,
1064
+ baseline: t?.baseline ?? 0,
1065
+ fillColor: t?.fillColor ?? [
1066
+ a[0],
1067
+ a[1],
1068
+ a[2],
1069
+ a[3] * .25
1070
+ ]
816
1071
  });
817
- return this.series.push(n), n;
1072
+ return this.series.push(o), o;
818
1073
  }
819
1074
  removeSeries(e) {
820
1075
  let t = this.series.indexOf(e);
@@ -845,54 +1100,92 @@ var b = class {
845
1100
  stop() {
846
1101
  cancelAnimationFrame(this._rafId);
847
1102
  }
848
- getMargins() {
849
- return {
850
- left: this.normalizedAxes.y.visible && this.normalizedAxes.y.position === "outside" ? _ : 0,
851
- bottom: this.normalizedAxes.x.visible && this.normalizedAxes.x.position === "outside" ? v : 0
852
- };
853
- }
854
1103
  render() {
855
1104
  let e = performance.now();
856
- 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";
857
- let t = this.getMargins(), n = this.canvas.width / Math.max(1, this.canvas.clientWidth), r = Math.floor(t.left * n), i = Math.floor(t.bottom * n);
858
- this.options.viewportPolicy?.beforeRender?.(this.camera), this.renderer.viewport(0, 0, this.canvas.width, this.canvas.height), this.renderer.clear(.08, .1, .16, 1), this.renderer.viewport(r, i, this.canvas.width - r, this.canvas.height - i);
859
- let a = this.camera.viewport;
1105
+ 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.renderer.viewport(0, 0, this.canvas.width, this.canvas.height), this.renderer.clear(.08, .1, .16, 1);
1106
+ let t = this.camera.viewport;
860
1107
  if (this.options.grid !== !1) {
861
- let e = this.writeGridVertices(a, t);
1108
+ let e = this.writeGridVertices(t);
862
1109
  e > 0 && (this.renderer.updateFloatBuffer(this.gridBuffer, this.gridData), this.renderer.drawLines(this.gridBuffer, e, this.gridStyle, this.camera), this.stats.drawCalls++, this.stats.uploadBytes += this.gridData.byteLength);
863
1110
  }
864
1111
  for (let e of this.series) {
865
1112
  if (!e.visible) continue;
866
- let t = e.visibleSampleCount(a), n = e.hasLOD && t > h, r = n ? e.copyMinMaxVisible(a, this.rawLineData, Math.min(this.canvas.width, h >> 1)) : e.copyRawVisible(a, this.rawLineData, h);
867
- r < 2 || (this.renderer.updateFloatBuffer(this.rawLineBuffer, this.rawLineData), n ? (this.renderer.drawMinMaxSegments(this.rawLineBuffer, r, e.style, this.camera), this.recordRenderMode("minmax")) : (this.renderer.drawLineStrip(this.rawLineBuffer, r, e.style, this.camera), this.recordRenderMode("raw")), this.stats.pointsRendered += r, this.stats.drawCalls++, this.stats.uploadBytes += this.rawLineData.byteLength);
1113
+ if (e.config.mode === "scatter") {
1114
+ this.drawScatterSeries(e, t);
1115
+ continue;
1116
+ }
1117
+ if (e.config.mode === "bar") {
1118
+ this.drawBarSeries(e, t);
1119
+ continue;
1120
+ }
1121
+ if (e.config.mode === "area") {
1122
+ this.drawAreaSeries(e, t);
1123
+ continue;
1124
+ }
1125
+ let n = e.visibleSampleCount(t), r = e.hasLOD && n > S;
1126
+ if (r && this.renderer.supportsInstancedSegments) {
1127
+ let n = e.copyMinMaxInstanced(t, this.minMaxInstanceData, this.maxMinMaxSegments());
1128
+ if (n <= 0) continue;
1129
+ this.renderer.updateFloatBuffer(this.minMaxInstanceBuffer, this.minMaxInstanceData), this.renderer.drawMinMaxSegmentsInstanced(this.minMaxInstanceBuffer, n, e.style, this.camera), this.recordRenderMode("minmax"), this.stats.pointsRendered += n * 2, this.stats.drawCalls++, this.stats.uploadBytes += this.minMaxInstanceData.byteLength;
1130
+ continue;
1131
+ }
1132
+ let i = r ? e.copyMinMaxVisible(t, this.rawLineData, this.maxMinMaxSegments()) : e.copyRawVisible(t, this.rawLineData, S);
1133
+ i < 2 || (this.renderer.updateFloatBuffer(this.rawLineBuffer, this.rawLineData), r ? (this.renderer.drawMinMaxSegments(this.rawLineBuffer, i, e.style, this.camera), this.recordRenderMode("minmax")) : (this.renderer.drawLineStrip(this.rawLineBuffer, i, e.style, this.camera), this.recordRenderMode("raw")), this.stats.pointsRendered += i, this.stats.drawCalls++, this.stats.uploadBytes += this.rawLineData.byteLength);
868
1134
  }
869
- this.axisOverlay?.update(this.camera, this.axis, t.left, t.bottom), this.stats.frameMs = performance.now() - e;
1135
+ this.axisOverlay?.update(this.camera, this.axis), this.stats.frameMs = performance.now() - e;
870
1136
  }
871
1137
  dispose() {
872
- this.stop(), this.resizeObserver?.disconnect(), this.input.dispose(), this.axisOverlay?.dispose(), this.renderer.dispose();
1138
+ this.stop(), this.resizeObserver?.disconnect(), this.input.dispose(), this.axisOverlay?.dispose(), this.renderer.dispose(), this.layout.dispose();
873
1139
  }
874
1140
  applyCanvasSize(e = globalThis.devicePixelRatio) {
875
1141
  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));
876
1142
  return this.canvas.width === n && this.canvas.height === r ? !1 : (this.canvas.width = n, this.canvas.height = r, !0);
877
1143
  }
878
- writeGridVertices(e, t) {
879
- let n = Math.max(1, this.canvas.clientWidth - t.left), r = Math.max(1, this.canvas.clientHeight - t.bottom);
880
- this.axis.getXTickValues(n, 12, this.xTicks), this.axis.getYTickValues(r, 8, this.yTicks);
881
- let i = 0;
1144
+ drawAreaSeries(e, t) {
1145
+ let n = e.style.baseline ?? 0, r = e.copyAreaVisible(t, this.rawLineData, C, n);
1146
+ if (r < 4) return;
1147
+ this.renderer.updateFloatBuffer(this.rawLineBuffer, this.rawLineData), this.renderer.drawAreaStrip(this.rawLineBuffer, r, e.style, this.camera), this.stats.pointsRendered += r, this.stats.drawCalls++, this.stats.uploadBytes += this.rawLineData.byteLength;
1148
+ let i = this.uploadRawInstances(e, t, C);
1149
+ i >= 2 && (this.renderer.drawLineStrip(this.rawLineBuffer, i, e.style, this.camera), this.stats.pointsRendered += i, this.stats.drawCalls++), this.recordRenderMode("area");
1150
+ }
1151
+ drawScatterSeries(e, t) {
1152
+ if (!this.renderer.supportsInstancedPoints) return;
1153
+ let n = this.uploadRawInstances(e, t, S);
1154
+ n <= 0 || (this.renderer.drawPointsInstanced(this.rawLineBuffer, n, e.style, this.camera, this.canvas.width, this.canvas.height), this.recordInstancedDraw("points", n));
1155
+ }
1156
+ drawBarSeries(e, t) {
1157
+ if (!this.renderer.supportsInstancedBars) return;
1158
+ let n = this.uploadRawInstances(e, t, S);
1159
+ n <= 0 || (this.renderer.drawBarsInstanced(this.rawLineBuffer, n, e.style, this.camera), this.recordInstancedDraw("bars", n));
1160
+ }
1161
+ uploadRawInstances(e, t, n) {
1162
+ let r = e.copyRawVisible(t, this.rawLineData, n);
1163
+ return r <= 0 ? 0 : (this.renderer.updateFloatBuffer(this.rawLineBuffer, this.rawLineData), this.stats.uploadBytes += this.rawLineData.byteLength, r);
1164
+ }
1165
+ recordInstancedDraw(e, t) {
1166
+ this.recordRenderMode(e), this.stats.pointsRendered += t, this.stats.drawCalls++;
1167
+ }
1168
+ maxMinMaxSegments() {
1169
+ return Math.min(this.canvas.width, w);
1170
+ }
1171
+ writeGridVertices(e) {
1172
+ let t = Math.max(1, this.canvas.clientWidth), n = Math.max(1, this.canvas.clientHeight);
1173
+ this.axis.getXTickValues(t, 12, this.xTicks), this.axis.getYTickValues(n, 8, this.yTicks);
1174
+ let r = 0;
882
1175
  for (let t of this.xTicks) {
883
- if (i + 2 > g) return i;
884
- this.gridData[i * 2] = t, this.gridData[i * 2 + 1] = e.yMin, i++, this.gridData[i * 2] = t, this.gridData[i * 2 + 1] = e.yMax, i++;
1176
+ if (r + 2 > E) return r;
1177
+ this.gridData[r * 2] = t, this.gridData[r * 2 + 1] = e.yMin, r++, this.gridData[r * 2] = t, this.gridData[r * 2 + 1] = e.yMax, r++;
885
1178
  }
886
1179
  for (let t of this.yTicks) {
887
- if (i + 2 > g) return i;
888
- this.gridData[i * 2] = e.xMin, this.gridData[i * 2 + 1] = t, i++, this.gridData[i * 2] = e.xMax, this.gridData[i * 2 + 1] = t, i++;
1180
+ if (r + 2 > E) return r;
1181
+ this.gridData[r * 2] = e.xMin, this.gridData[r * 2 + 1] = t, r++, this.gridData[r * 2] = e.xMax, this.gridData[r * 2 + 1] = t, r++;
889
1182
  }
890
- return i;
1183
+ return r;
891
1184
  }
892
1185
  recordRenderMode(e) {
893
1186
  this.stats.renderMode === "none" ? this.stats.renderMode = e : this.stats.renderMode !== e && (this.stats.renderMode = "mixed");
894
1187
  }
895
- }, x = class {
1188
+ }, k = class {
896
1189
  xData;
897
1190
  yData;
898
1191
  constructor(e, t) {
@@ -934,6 +1227,6 @@ var b = class {
934
1227
  }
935
1228
  };
936
1229
  //#endregion
937
- export { p as AxisController, f as Camera2D, b as Chart, n as MinMaxPyramid, i as RingBuffer, r as SeriesStore, x as StaticDataset };
1230
+ export { y as AxisController, v as Camera2D, O as Chart, n as MinMaxPyramid, i as RingBuffer, r as SeriesStore, k as StaticDataset };
938
1231
 
939
1232
  //# sourceMappingURL=index.js.map