Skip to content

Commit

Permalink
src/plugin/regions.js: fix regions on zoom by merging 4ee2b29 in next…
Browse files Browse the repository at this point in the history
… branch (see #825) (#1158)
  • Loading branch information
piem authored and katspaugh committed Jul 2, 2017
1 parent 1a1358c commit d2a1f38
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/plugin/regions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

}
Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d2a1f38

Please sign in to comment.