@tradecanvas/core 1.0.1 → 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.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +36 -12
- package/dist/index.js.map +1 -1
- package/dist/interaction/InteractionManager.d.ts.map +1 -1
- package/dist/interaction/PanHandler.d.ts +15 -4
- package/dist/interaction/PanHandler.d.ts.map +1 -1
- package/dist/viewport/Viewport.d.ts +11 -0
- package/dist/viewport/Viewport.d.ts.map +1 -1
- package/package.json +2 -2
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;
|
|
@@ -5723,7 +5741,10 @@ var Dn = class {
|
|
|
5723
5741
|
this.zoomHandler?.onWheel(-t * 100, n);
|
|
5724
5742
|
}
|
|
5725
5743
|
let r = this.lastTouchMid.x - n.x;
|
|
5726
|
-
Math.abs(r) > 1 && (this.panHandler?.onPointerDown(this.lastTouchMid), this.panHandler?.onPointerMove(
|
|
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;
|
|
5727
5748
|
}
|
|
5728
5749
|
this.onOverlayDirty?.();
|
|
5729
5750
|
}, f = (e) => {
|
|
@@ -5775,35 +5796,38 @@ var Dn = class {
|
|
|
5775
5796
|
}, Nn = class {
|
|
5776
5797
|
dragging = !1;
|
|
5777
5798
|
lastX = 0;
|
|
5799
|
+
lastY = 0;
|
|
5778
5800
|
lastTime = 0;
|
|
5779
|
-
|
|
5801
|
+
velocityX = 0;
|
|
5802
|
+
velocityY = 0;
|
|
5780
5803
|
momentumId = 0;
|
|
5781
5804
|
callback;
|
|
5805
|
+
onStart;
|
|
5782
5806
|
friction = .92;
|
|
5783
|
-
constructor(e) {
|
|
5784
|
-
this.callback = e;
|
|
5807
|
+
constructor(e, t) {
|
|
5808
|
+
this.callback = e, this.onStart = t;
|
|
5785
5809
|
}
|
|
5786
5810
|
onPointerDown(e) {
|
|
5787
|
-
this.dragging = !0, this.lastX = e.x, this.lastTime = Date.now(), this.
|
|
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?.();
|
|
5788
5812
|
}
|
|
5789
5813
|
onPointerMove(e) {
|
|
5790
5814
|
if (!this.dragging) return;
|
|
5791
|
-
let t = Date.now(), n = this.lastX - e.x, r = t - this.lastTime;
|
|
5792
|
-
|
|
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);
|
|
5793
5817
|
}
|
|
5794
5818
|
onPointerUp() {
|
|
5795
|
-
this.dragging && (this.dragging = !1, Math.
|
|
5819
|
+
this.dragging && (this.dragging = !1, Math.hypot(this.velocityX, this.velocityY) > .1 && this.startMomentum());
|
|
5796
5820
|
}
|
|
5797
5821
|
startMomentum() {
|
|
5798
5822
|
this.stopMomentum();
|
|
5799
|
-
let e = this.
|
|
5800
|
-
if (e *= this.friction, Math.
|
|
5823
|
+
let e = this.velocityX * 16, t = this.velocityY * 16, n = () => {
|
|
5824
|
+
if (e *= this.friction, t *= this.friction, Math.hypot(e, t) < .5) {
|
|
5801
5825
|
this.momentumId = 0;
|
|
5802
5826
|
return;
|
|
5803
5827
|
}
|
|
5804
|
-
this.callback(e), this.momentumId = requestAnimationFrame(
|
|
5828
|
+
this.callback(e, t), this.momentumId = requestAnimationFrame(n);
|
|
5805
5829
|
};
|
|
5806
|
-
this.momentumId = requestAnimationFrame(
|
|
5830
|
+
this.momentumId = requestAnimationFrame(n);
|
|
5807
5831
|
}
|
|
5808
5832
|
stopMomentum() {
|
|
5809
5833
|
this.momentumId &&= (cancelAnimationFrame(this.momentumId), 0);
|