[Timeline] Always set scroll on timeout

...to allow time for width to increase.
This commit is contained in:
Victor Woeltjen
2016-06-02 16:36:09 -07:00
parent 44d6456de1
commit d52bfed1df

View File

@@ -33,8 +33,8 @@ define(
var zoomLevels = ZOOM_CONFIGURATION.levels || [1000], var zoomLevels = ZOOM_CONFIGURATION.levels || [1000],
zoomIndex = Math.floor(zoomLevels.length / 2), zoomIndex = Math.floor(zoomLevels.length / 2),
tickWidth = ZOOM_CONFIGURATION.width || 200, tickWidth = ZOOM_CONFIGURATION.width || 200,
width = tickWidth,
desiredScroll = 0, desiredScroll = 0,
achievedDesiredScroll,
bounds = { x: 0, width: tickWidth }; // Default duration in view bounds = { x: 0, width: tickWidth }; // Default duration in view
function toMillis(pixels) { function toMillis(pixels) {
@@ -56,13 +56,13 @@ define(
} }
} }
function setScroll() { function setScroll(x) {
bounds.x = desiredScroll; desiredScroll = x;
// Physical width may be insufficient for scroll; achievedDesiredScroll = false;
// if so, try again on a timeout! $timeout(function () {
if (bounds.x + bounds.width > width) { $scope.scroll.x = desiredScroll;
$timeout(setScroll, 0); achievedDesiredScroll = true;
} }, 0);
} }
function initializeZoomFromTimespan(timespan) { function initializeZoomFromTimespan(timespan) {
@@ -72,8 +72,7 @@ define(
zoomIndex < zoomLevels.length - 1) { zoomIndex < zoomLevels.length - 1) {
zoomIndex += 1; zoomIndex += 1;
} }
desiredScroll = toPixels(timespan.getStart()); setScroll(toPixels(timespan.getStart()));
setScroll();
} }
function initializeZoom() { function initializeZoom() {
@@ -103,11 +102,11 @@ define(
zoom: function (amount) { zoom: function (amount) {
// Update the zoom level if called with an argument // Update the zoom level if called with an argument
if (arguments.length > 0 && !isNaN(amount)) { if (arguments.length > 0 && !isNaN(amount)) {
//var x = achievedDesiredScroll ?
// bounds.x : desiredScroll;
var center = this.toMillis(bounds.x + bounds.width / 2); var center = this.toMillis(bounds.x + bounds.width / 2);
setZoomLevel(zoomIndex + amount); setZoomLevel(zoomIndex + amount);
desiredScroll = setScroll(this.toPixels(center) - bounds.width / 2);
this.toPixels(center) - bounds.width / 2;
setScroll();
} }
return zoomLevels[zoomIndex]; return zoomLevels[zoomIndex];
}, },
@@ -136,8 +135,7 @@ define(
*/ */
width: function (timestamp) { width: function (timestamp) {
var pixels = Math.ceil(toPixels(timestamp * (1 + PADDING))); var pixels = Math.ceil(toPixels(timestamp * (1 + PADDING)));
width = Math.max(bounds.width, pixels); return Math.max(bounds.width, pixels);
return width;
} }
}; };
} }