Skip to content

Commit e65c334

Browse files
committed
Fixed point/segment display on resize
1 parent 474daac commit e65c334

File tree

5 files changed

+48
-15
lines changed

5 files changed

+48
-15
lines changed

demo/custom-markers/index.html

+7-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ <h2>Demo: Custom Point and Segment Markers</h2>
6565
<input type="range" id="amplitude-scale" min="0" max="10" step="1">
6666
<input type="checkbox" id="auto-scroll" checked>
6767
<label for="auto-scroll">Auto-scroll</label>
68-
<button data-action="resize">Resize</button>
69-
<button data-action="destroy">Destroy</button>
7068
</div>
7169
<div>
7270
<input type="checkbox" id="enable-seek" checked>
@@ -87,6 +85,13 @@ <h2>Demo: Custom Point and Segment Markers</h2>
8785
<option value="compress">Compress</option>
8886
</select>
8987
</div>
88+
<div>
89+
<button data-action="resize-width">Resize width</button>
90+
<button data-action="resize-height">Resize height</button>
91+
</div>
92+
<div>
93+
<button data-action="destroy">Destroy</button>
94+
</div>
9095
</div>
9196
</div>
9297

demo/custom-markers/main.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,31 @@ Peaks.init(options, function(err, peaksInstance) {
286286
peaksInstance.views.getView('overview').setAmplitudeScale(scale);
287287
});
288288

289-
document.querySelector('button[data-action="resize"]').addEventListener('click', function(event) {
289+
document.querySelector('button[data-action="resize-width"]').addEventListener('click', function(event) {
290+
document.querySelectorAll('.waveform-container').forEach(function(container) {
291+
container.style.width = container.offsetWidth === 1000 ? "700px" : "1000px";
292+
});
293+
294+
const zoomview = peaksInstance.views.getView('zoomview');
295+
296+
if (zoomview) {
297+
zoomview.fitToContainer();
298+
}
299+
300+
const scrollbar = peaksInstance.views.getScrollbar();
301+
302+
if (scrollbar) {
303+
scrollbar.fitToContainer();
304+
}
305+
306+
const overview = peaksInstance.views.getView('overview');
307+
308+
if (overview) {
309+
overview.fitToContainer();
310+
}
311+
});
312+
313+
document.querySelector('button[data-action="resize-height"]').addEventListener('click', function(event) {
290314
const zoomviewContainer = document.getElementById('zoomview-container');
291315
const overviewContainer = document.getElementById('overview-container');
292316

src/waveform-overview.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ WaveformOverview.prototype.removeHighlightRect = function() {
121121
this._highlightLayer.removeHighlight();
122122
};
123123

124-
WaveformOverview.prototype.updateWaveform = function() {
124+
WaveformOverview.prototype.updateWaveform = function(/* frameOffset, forceUpdate */) {
125125
this._waveformLayer.draw();
126126
this._axisLayer.draw();
127127

src/waveform-view.js

+12-7
Original file line numberDiff line numberDiff line change
@@ -444,26 +444,31 @@ WaveformView.prototype.fitToContainer = function() {
444444
updateWaveform = this.containerWidthChange();
445445
}
446446

447+
let heightChanged = false;
448+
447449
if (this._container.clientHeight !== this._height) {
448450
this._height = this._container.clientHeight;
449-
this._stage.height(this._height);
451+
this._stage.setHeight(this._height);
450452

451453
this._waveformShape.fitToView();
452454
this._playheadLayer.fitToView();
453455

456+
this.containerHeightChange();
457+
458+
heightChanged = true;
459+
}
460+
461+
if (updateWaveform) {
462+
this.updateWaveform(this._frameOffset, true);
463+
}
464+
else if (heightChanged) {
454465
if (this._segmentsLayer) {
455466
this._segmentsLayer.fitToView();
456467
}
457468

458469
if (this._pointsLayer) {
459470
this._pointsLayer.fitToView();
460471
}
461-
462-
this.containerHeightChange();
463-
}
464-
465-
if (updateWaveform) {
466-
this.updateWaveform(this._frameOffset);
467472
}
468473
};
469474

src/waveform-zoomview.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ WaveformZoomView.prototype.scrollWaveform = function(options) {
495495
* Updates the region of waveform shown in the view.
496496
*
497497
* @param {Number} frameOffset The new frame offset, in pixels.
498+
* @param {Boolean} forceUpdate Forces the waveform view to be redrawn, if the
499+
* frameOffset is unchanged.
498500
*/
499501

500502
WaveformZoomView.prototype.updateWaveform = function(frameOffset, forceUpdate) {
@@ -564,8 +566,6 @@ WaveformZoomView.prototype.setMinSegmentDragWidth = function(width) {
564566
};
565567

566568
WaveformZoomView.prototype.containerWidthChange = function() {
567-
let updateWaveform = false;
568-
569569
let resample = false;
570570
let resampleOptions;
571571

@@ -581,14 +581,13 @@ WaveformZoomView.prototype.containerWidthChange = function() {
581581
if (resample) {
582582
try {
583583
this._resampleData(resampleOptions);
584-
updateWaveform = true;
585584
}
586585
catch (error) {
587586
// Ignore, and leave this._data as it was
588587
}
589588
}
590589

591-
return updateWaveform;
590+
return true;
592591
};
593592

594593
WaveformZoomView.prototype.containerHeightChange = function() {

0 commit comments

Comments
 (0)