From d02f4041b28460d4f4d21973a249c4385c7ec008 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Thu, 2 Jun 2016 15:34:32 -0700 Subject: [PATCH] [Timeline] Update scroll position on timeout Fixes #817 --- platform/features/timeline/bundle.js | 1 + .../src/controllers/TimelineZoomController.js | 12 ++++++++++-- .../test/controllers/TimelineZoomControllerSpec.js | 3 +++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/platform/features/timeline/bundle.js b/platform/features/timeline/bundle.js index ae7a283fc5..782918e545 100644 --- a/platform/features/timeline/bundle.js +++ b/platform/features/timeline/bundle.js @@ -472,6 +472,7 @@ define([ "implementation": TimelineZoomController, "depends": [ "$scope", + "$timeout", "TIMELINE_ZOOM_CONFIGURATION" ] }, diff --git a/platform/features/timeline/src/controllers/TimelineZoomController.js b/platform/features/timeline/src/controllers/TimelineZoomController.js index 6e97f0bd0e..8e1c440ce3 100644 --- a/platform/features/timeline/src/controllers/TimelineZoomController.js +++ b/platform/features/timeline/src/controllers/TimelineZoomController.js @@ -28,11 +28,12 @@ define( * Controls the pan-zoom state of a timeline view. * @constructor */ - function TimelineZoomController($scope, ZOOM_CONFIGURATION) { + function TimelineZoomController($scope, $timeout, ZOOM_CONFIGURATION) { // Prefer to start with the middle index var zoomLevels = ZOOM_CONFIGURATION.levels || [1000], zoomIndex = Math.floor(zoomLevels.length / 2), tickWidth = ZOOM_CONFIGURATION.width || 200, + width = tickWidth, bounds = { x: 0, width: tickWidth }; // Default duration in view function toMillis(pixels) { @@ -62,6 +63,12 @@ define( zoomIndex += 1; } bounds.x = toPixels(timespan.getStart()); + + // 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() { @@ -122,7 +129,8 @@ define( */ width: function (timestamp) { var pixels = Math.ceil(toPixels(timestamp * (1 + PADDING))); - return Math.max(bounds.width * 2, pixels); + width = Math.max(bounds.width, pixels); + return width; } }; } diff --git a/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js b/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js index bf2bc03180..e037c689d4 100644 --- a/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js +++ b/platform/features/timeline/test/controllers/TimelineZoomControllerSpec.js @@ -28,6 +28,7 @@ define( describe("The timeline zoom state controller", function () { var testConfiguration, mockScope, + mockTimeout, controller; beforeEach(function () { @@ -37,8 +38,10 @@ define( }; mockScope = jasmine.createSpyObj("$scope", ['$watch']); mockScope.commit = jasmine.createSpy('commit'); + mockTimeout = jasmine.createSpy('$timeout'); controller = new TimelineZoomController( mockScope, + mockTimeout, testConfiguration ); });