@tradecanvas/core 1.0.0 → 1.0.2

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
@@ -415,6 +415,24 @@ var ee = class {
415
415
  scrollBy(e) {
416
416
  this.state.offset += e, this.clampOffset(), this.updateVisibleRange();
417
417
  }
418
+ panPriceRange(e) {
419
+ let t = this.state.chartRect.height;
420
+ if (t <= 0 || e === 0) return;
421
+ let { min: n, max: r } = this.state.priceRange, i = e / t;
422
+ if (this.isLogScale() && n > 0 && r > 0) {
423
+ let e = Math.log(n), t = Math.log(r), a = (t - e) * i;
424
+ this.state.priceRange = {
425
+ min: Math.exp(e - a),
426
+ max: Math.exp(t - a)
427
+ };
428
+ return;
429
+ }
430
+ let a = (r - n) * i;
431
+ this.state.priceRange = {
432
+ min: n - a,
433
+ max: r - a
434
+ };
435
+ }
418
436
  isAtEnd() {
419
437
  let e = this.state.barWidth + this.state.barSpacing, t = this.rightMarginBars * e, n = this.dataLength * e - this.state.chartRect.width + t;
420
438
  return this.state.offset >= n - e * 2;
@@ -434,7 +452,12 @@ var ee = class {
434
452
  clampOffset() {
435
453
  if (this.state.chartRect.width <= 0) return;
436
454
  let e = this.state.barWidth + this.state.barSpacing, t = this.dataLength * e, n = this.rightMarginBars * e, r = t - this.state.chartRect.width + n, i, a;
437
- r > 0 ? (i = -(this.state.chartRect.width * .5), a = r) : (i = r, a = r), this.state.offset = f(this.state.offset, i, a);
455
+ if (r > 0) i = -(this.state.chartRect.width * .5), a = r;
456
+ else {
457
+ let e = this.state.chartRect.width * .5;
458
+ i = r - e, a = r + e;
459
+ }
460
+ this.state.offset = f(this.state.offset, i, a);
438
461
  }
439
462
  updateVisibleRange() {
440
463
  let e = this.state.barWidth + this.state.barSpacing;
@@ -5718,7 +5741,10 @@ var Dn = class {
5718
5741
  this.zoomHandler?.onWheel(-t * 100, n);
5719
5742
  }
5720
5743
  let r = this.lastTouchMid.x - n.x;
5721
- Math.abs(r) > 1 && (this.panHandler?.onPointerDown(this.lastTouchMid), this.panHandler?.onPointerMove(n)), this.lastTouchDist = e, this.lastTouchMid = n;
5744
+ Math.abs(r) > 1 && (this.panHandler?.onPointerDown(this.lastTouchMid), this.panHandler?.onPointerMove({
5745
+ x: n.x,
5746
+ y: this.lastTouchMid.y
5747
+ })), this.lastTouchDist = e, this.lastTouchMid = n;
5722
5748
  }
5723
5749
  this.onOverlayDirty?.();
5724
5750
  }, f = (e) => {
@@ -5770,35 +5796,38 @@ var Dn = class {
5770
5796
  }, Nn = class {
5771
5797
  dragging = !1;
5772
5798
  lastX = 0;
5799
+ lastY = 0;
5773
5800
  lastTime = 0;
5774
- velocity = 0;
5801
+ velocityX = 0;
5802
+ velocityY = 0;
5775
5803
  momentumId = 0;
5776
5804
  callback;
5805
+ onStart;
5777
5806
  friction = .92;
5778
- constructor(e) {
5779
- this.callback = e;
5807
+ constructor(e, t) {
5808
+ this.callback = e, this.onStart = t;
5780
5809
  }
5781
5810
  onPointerDown(e) {
5782
- this.dragging = !0, this.lastX = e.x, this.lastTime = Date.now(), this.velocity = 0, this.stopMomentum();
5811
+ this.dragging = !0, this.lastX = e.x, this.lastY = e.y, this.lastTime = Date.now(), this.velocityX = 0, this.velocityY = 0, this.stopMomentum(), this.onStart?.();
5783
5812
  }
5784
5813
  onPointerMove(e) {
5785
5814
  if (!this.dragging) return;
5786
- let t = Date.now(), n = this.lastX - e.x, r = t - this.lastTime;
5787
- r > 0 && (this.velocity = n / r), this.lastX = e.x, this.lastTime = t, this.callback(n);
5815
+ let t = Date.now(), n = this.lastX - e.x, r = this.lastY - e.y, i = t - this.lastTime;
5816
+ i > 0 && (this.velocityX = n / i, this.velocityY = r / i), this.lastX = e.x, this.lastY = e.y, this.lastTime = t, this.callback(n, r);
5788
5817
  }
5789
5818
  onPointerUp() {
5790
- this.dragging && (this.dragging = !1, Math.abs(this.velocity) > .1 && this.startMomentum());
5819
+ this.dragging && (this.dragging = !1, Math.hypot(this.velocityX, this.velocityY) > .1 && this.startMomentum());
5791
5820
  }
5792
5821
  startMomentum() {
5793
5822
  this.stopMomentum();
5794
- let e = this.velocity * 16, t = () => {
5795
- if (e *= this.friction, Math.abs(e) < .5) {
5823
+ let e = this.velocityX * 16, t = this.velocityY * 16, n = () => {
5824
+ if (e *= this.friction, t *= this.friction, Math.hypot(e, t) < .5) {
5796
5825
  this.momentumId = 0;
5797
5826
  return;
5798
5827
  }
5799
- this.callback(e), this.momentumId = requestAnimationFrame(t);
5828
+ this.callback(e, t), this.momentumId = requestAnimationFrame(n);
5800
5829
  };
5801
- this.momentumId = requestAnimationFrame(t);
5830
+ this.momentumId = requestAnimationFrame(n);
5802
5831
  }
5803
5832
  stopMomentum() {
5804
5833
  this.momentumId &&= (cancelAnimationFrame(this.momentumId), 0);