From d2a1f38f1202187f42d4927977fe1af6c92d15a7 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sun, 2 Jul 2017 20:28:54 +0200 Subject: [PATCH] src/plugin/regions.js: fix regions on zoom by merging 4ee2b29 in next branch (see #825) (#1158) --- src/plugin/regions.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/plugin/regions.js b/src/plugin/regions.js index 1c798ec27..5faef88ef 100644 --- a/src/plugin/regions.js +++ b/src/plugin/regions.js @@ -30,7 +30,8 @@ class Region { this.bindInOut(); this.render(); - this.wavesurfer.on('zoom', () => this.updateRender()); + this.onZoom = this.updateRender.bind(this); + this.wavesurfer.on('zoom', this.onZoom); this.wavesurfer.fireEvent('region-created', this); } @@ -79,7 +80,7 @@ class Region { this.wrapper.removeChild(this.element); this.element = null; this.fireEvent('remove'); - this.wavesurfer.un('zoom', pxPerSec => this.updateRender(pxPerSec)); + this.wavesurfer.un('zoom', this.onZoom); this.wavesurfer.fireEvent('region-removed', this); } } @@ -150,15 +151,14 @@ class Region { ].join(':')).join('-'); } + getWidth() { + return this.wavesurfer.drawer.width / this.wavesurfer.params.pixelRatio; + } + /* Update element's position, width, color. */ - updateRender(pxPerSec) { + updateRender() { const dur = this.wavesurfer.getDuration(); - let width; - if (pxPerSec) { - width = Math.round(this.wavesurfer.getDuration() * pxPerSec); - } else { - width = this.wrapper.scrollWidth; - } + const width = this.getWidth(); if (this.start < 0) { this.start = 0;