Skip to content

Commit

Permalink
Fixed waveform view initialisation if playhead time is not zero
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisn committed Nov 30, 2024
1 parent 9416162 commit fcfa24d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ Peaks.init = function(opts, callback) {
const zoomviewContainer = instance.options.zoomview.container;
const overviewContainer = instance.options.overview.container;

if (overviewContainer) {
instance.views.createOverview(overviewContainer);
}

if (zoomviewContainer) {
instance.views.createZoomview(zoomviewContainer);
}

if (overviewContainer) {
instance.views.createOverview(overviewContainer);
}

if (scrollbarContainer) {
instance.views.createScrollbar(scrollbarContainer);
}
Expand Down
3 changes: 2 additions & 1 deletion src/scrollbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ function Scrollbar(container, peaks) {
this._scrollbox.on('dragend', this._onScrollboxDragEnd);

this._layer.add(this._scrollbox);
this._layer.draw();

this._updateScrollbarWidthAndPosition();
}

Scrollbar.prototype.setZoomview = function(zoomview) {
Expand Down
6 changes: 6 additions & 0 deletions src/waveform-overview.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ function WaveformOverview(waveformData, container, peaks) {
self._playheadLayer.updatePlayheadTime(time);

self._mouseDragHandler = new SeekMouseDragHandler(peaks, self);

const zoomview = peaks.views.getView('zoomview');

if (zoomview) {
self._highlightLayer.showHighlight(zoomview.getStartTime(), zoomview.getEndTime());
}
}

WaveformOverview.prototype = Object.create(WaveformView.prototype);
Expand Down
37 changes: 32 additions & 5 deletions test/segment-shape-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,51 @@ describe('SegmentShape', function() {
expect(call.args[0].segment.endTime).to.equal(10);
expect(call.args[0].segment.editable).to.equal(test.editable);
expect(call.args[0].segment.id).to.equal('segment1');
expect(call.args[0].editable).to.equal(false);
expect(call.args[0]).to.have.property('startMarker');
expect(call.args[0].editable).to.equal(test.editable);
expect(call.args[0].startMarker).to.equal(true);
expect(call.args[0].color).to.equal('#aaaaaa');
expect(call.args[0]).to.have.property('layer');
expect(call.args[0].view).to.equal('overview');
expect(call.args[0].view).to.equal('zoomview');

call = spy.getCall(2);
call = spy.getCall(1);

expect(call.args).to.have.lengthOf(1);
expect(call.args[0].segment.startTime).to.equal(0);
expect(call.args[0].segment.endTime).to.equal(10);
expect(call.args[0].segment.editable).to.equal(test.editable);
expect(call.args[0].segment.id).to.equal('segment1');
expect(call.args[0].editable).to.equal(test.editable);
expect(call.args[0]).to.have.property('startMarker');
expect(call.args[0].startMarker).to.equal(false);
expect(call.args[0].color).to.equal('#aaaaaa');
expect(call.args[0]).to.have.property('layer');
expect(call.args[0].view).to.equal('zoomview');

call = spy.getCall(2);

expect(call.args).to.have.lengthOf(1);
expect(call.args[0].segment.startTime).to.equal(0);
expect(call.args[0].segment.endTime).to.equal(10);
expect(call.args[0].segment.editable).to.equal(test.editable);
expect(call.args[0].segment.id).to.equal('segment1');
expect(call.args[0].editable).to.equal(false);
expect(call.args[0].startMarker).to.equal(true);
expect(call.args[0].color).to.equal('#aaaaaa');
expect(call.args[0]).to.have.property('layer');
expect(call.args[0].view).to.equal('overview');

call = spy.getCall(3);

expect(call.args).to.have.lengthOf(1);
expect(call.args[0].segment.startTime).to.equal(0);
expect(call.args[0].segment.endTime).to.equal(10);
expect(call.args[0].segment.editable).to.equal(test.editable);
expect(call.args[0].segment.id).to.equal('segment1');
expect(call.args[0].editable).to.equal(false);
expect(call.args[0].startMarker).to.equal(false);
expect(call.args[0].color).to.equal('#aaaaaa');
expect(call.args[0]).to.have.property('layer');
expect(call.args[0].view).to.equal('overview');

done();
});
});
Expand Down

0 comments on commit fcfa24d

Please sign in to comment.