[Timeline] Set scroll on timeout

Whenever timeline zoom controller sets scroll, check to see if
there may be a width violation that causes scroll to be reset,
and retry on a timeout if so. Fixes #936.
This commit is contained in:
Victor Woeltjen 2016-06-02 16:00:09 -07:00
parent beeefe517a
commit 44d6456de1

View File

@ -34,6 +34,7 @@ define(
zoomIndex = Math.floor(zoomLevels.length / 2), zoomIndex = Math.floor(zoomLevels.length / 2),
tickWidth = ZOOM_CONFIGURATION.width || 200, tickWidth = ZOOM_CONFIGURATION.width || 200,
width = tickWidth, width = tickWidth,
desiredScroll = 0,
bounds = { x: 0, width: tickWidth }; // Default duration in view bounds = { x: 0, width: tickWidth }; // Default duration in view
function toMillis(pixels) { function toMillis(pixels) {
@ -55,6 +56,15 @@ define(
} }
} }
function setScroll() {
bounds.x = desiredScroll;
// Physical width may be insufficient for scroll;
// if so, try again on a timeout!
if (bounds.x + bounds.width > width) {
$timeout(setScroll, 0);
}
}
function initializeZoomFromTimespan(timespan) { function initializeZoomFromTimespan(timespan) {
var timelineDuration = timespan.getDuration(); var timelineDuration = timespan.getDuration();
zoomIndex = 0; zoomIndex = 0;
@ -62,13 +72,8 @@ define(
zoomIndex < zoomLevels.length - 1) { zoomIndex < zoomLevels.length - 1) {
zoomIndex += 1; zoomIndex += 1;
} }
bounds.x = toPixels(timespan.getStart()); desiredScroll = toPixels(timespan.getStart());
setScroll();
// Physical width may be insufficient for scroll;
// if so, try again on a timeout!
if (bounds.x + bounds.width > width) {
$timeout(initializeZoomFromTimespan.bind(null, timespan));
}
} }
function initializeZoom() { function initializeZoom() {
@ -100,7 +105,9 @@ define(
if (arguments.length > 0 && !isNaN(amount)) { if (arguments.length > 0 && !isNaN(amount)) {
var center = this.toMillis(bounds.x + bounds.width / 2); var center = this.toMillis(bounds.x + bounds.width / 2);
setZoomLevel(zoomIndex + amount); setZoomLevel(zoomIndex + amount);
bounds.x = this.toPixels(center) - bounds.width / 2; desiredScroll =
this.toPixels(center) - bounds.width / 2;
setScroll();
} }
return zoomLevels[zoomIndex]; return zoomLevels[zoomIndex];
}, },