diff --git a/static/chart.js b/static/chart.js index b89f508..a4907d1 100644 --- a/static/chart.js +++ b/static/chart.js @@ -723,13 +723,16 @@ class ConfluenceChart { distance: Math.max(distances[distances.x >= distances.y ? 'x' : 'y'], 1), startGap: Math.max(gap(touches), 1), startMid: mid, - startPrice: this.candles.coordinateToPrice(centerY), anchor, minValue: Math.min(top, bottom), maxValue: Math.max(top, bottom), timeRange, timeAnchor: timeRange.from + (timeRange.to - timeRange.from) * centerX / plot.width, plotWidth: plot.width, + pricePerPx: (Math.max(top, bottom) - Math.min(top, bottom)) + / Math.max(plot.height * (1 - margins.top - margins.bottom), 1), + frame: null, + latest: null, }; event.preventDefault(); }; @@ -742,9 +745,16 @@ class ConfluenceChart { } if (!this.touchTwo || event.touches.length !== 2) return; event.preventDefault(); - const touches = [...event.touches]; - const mid = midpoint(touches); + this.touchTwo.latest = [...event.touches]; + if (this.touchTwo.frame) return; + this.touchTwo.frame = requestAnimationFrame(() => this.applyTouchTwo()); + }; + this.applyTouchTwo = () => { const gesture = this.touchTwo; + if (!gesture?.latest) return; + gesture.frame = null; + const touches = gesture.latest; + const mid = midpoint(touches); if (!gesture.kind) { const midDelta = Math.hypot(mid.x - gesture.startMid.x, mid.y - gesture.startMid.y); const gapDelta = Math.abs(gap(touches) - gesture.startGap); @@ -758,14 +768,10 @@ class ConfluenceChart { from: gesture.timeRange.from + shift, to: gesture.timeRange.to + shift, }); - const nowPrice = this.candles.coordinateToPrice( - mid.y - this.plotCanvas().getBoundingClientRect().top, - ); - const dPrice = nowPrice == null || gesture.startPrice == null - ? 0 : nowPrice - gesture.startPrice; + const dPrice = (mid.y - gesture.startMid.y) * gesture.pricePerPx; this.manualPriceRange = { - minValue: gesture.minValue - dPrice, - maxValue: gesture.maxValue - dPrice, + minValue: gesture.minValue + dPrice, + maxValue: gesture.maxValue + dPrice, }; this.candles.applyOptions({ autoscaleInfoProvider: this.candleAutoscaleProvider }); } else { @@ -792,7 +798,10 @@ class ConfluenceChart { this.renderContextLabels(); }; this.touchEndListener = event => { - if (event.touches.length < 2) this.touchTwo = null; + if (event.touches.length < 2 && this.touchTwo) { + if (this.touchTwo.frame) cancelAnimationFrame(this.touchTwo.frame); + this.touchTwo = null; + } if (event.touches.length || !this.touchTap || this.armedTool) return; const tap = this.touchTap; this.touchTap = null;