diff --git a/src/waveform-zoomview.js b/src/waveform-zoomview.js index 01c0065a..5231b586 100644 --- a/src/waveform-zoomview.js +++ b/src/waveform-zoomview.js @@ -305,7 +305,7 @@ WaveformZoomView.prototype._syncPlayhead = function(time) { }; WaveformZoomView.prototype._getScale = function(duration) { - return duration * this._data.sample_rate / this._width; + return Math.floor(duration * this._data.sample_rate / this._width); }; function isAutoScale(options) { @@ -348,7 +348,7 @@ WaveformZoomView.prototype.setZoom = function(options) { else { if (objectHasProperty(options, 'scale')) { this._zoomLevelSeconds = null; - scale = options.scale; + scale = Math.floor(options.scale); } else if (objectHasProperty(options, 'seconds')) { if (!isValidTime(options.seconds)) { diff --git a/test/api-view-spec.js b/test/api-view-spec.js index e82e00cf..ae22bdc6 100644 --- a/test/api-view-spec.js +++ b/test/api-view-spec.js @@ -210,6 +210,24 @@ describe('WaveformView', function() { }); }); + context('with non-integer scale', function() { + it('should round the scale down to an integer value', function() { + const view = p.views.getView('zoomview'); + + const resampleData = sinon.spy(view, '_resampleData'); + + view.setZoom({ scale: 500.5 }); + + expect(resampleData.callCount).to.equal(1); + + // width is here because WaveformData.resample modifies + // its options parameter + expect(resampleData).calledWithExactly({ scale: 500, width: null }); + + expect(view._scale).to.equal(500); + }); + }); + context('with auto option', function() { it('should fit the waveform to the width of the view', function() { const view = p.views.getView('zoomview');