[Timeline] Update scroll position on timeout

Fixes #817
This commit is contained in:
Victor Woeltjen 2016-06-02 15:34:32 -07:00
parent 026ece3956
commit d02f4041b2
3 changed files with 14 additions and 2 deletions

View File

@ -472,6 +472,7 @@ define([
"implementation": TimelineZoomController, "implementation": TimelineZoomController,
"depends": [ "depends": [
"$scope", "$scope",
"$timeout",
"TIMELINE_ZOOM_CONFIGURATION" "TIMELINE_ZOOM_CONFIGURATION"
] ]
}, },

View File

@ -28,11 +28,12 @@ define(
* Controls the pan-zoom state of a timeline view. * Controls the pan-zoom state of a timeline view.
* @constructor * @constructor
*/ */
function TimelineZoomController($scope, ZOOM_CONFIGURATION) { function TimelineZoomController($scope, $timeout, ZOOM_CONFIGURATION) {
// Prefer to start with the middle index // Prefer to start with the middle index
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,
bounds = { x: 0, width: tickWidth }; // Default duration in view bounds = { x: 0, width: tickWidth }; // Default duration in view
function toMillis(pixels) { function toMillis(pixels) {
@ -62,6 +63,12 @@ define(
zoomIndex += 1; zoomIndex += 1;
} }
bounds.x = toPixels(timespan.getStart()); 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() { function initializeZoom() {
@ -122,7 +129,8 @@ define(
*/ */
width: function (timestamp) { width: function (timestamp) {
var pixels = Math.ceil(toPixels(timestamp * (1 + PADDING))); var pixels = Math.ceil(toPixels(timestamp * (1 + PADDING)));
return Math.max(bounds.width * 2, pixels); width = Math.max(bounds.width, pixels);
return width;
} }
}; };
} }

View File

@ -28,6 +28,7 @@ define(
describe("The timeline zoom state controller", function () { describe("The timeline zoom state controller", function () {
var testConfiguration, var testConfiguration,
mockScope, mockScope,
mockTimeout,
controller; controller;
beforeEach(function () { beforeEach(function () {
@ -37,8 +38,10 @@ define(
}; };
mockScope = jasmine.createSpyObj("$scope", ['$watch']); mockScope = jasmine.createSpyObj("$scope", ['$watch']);
mockScope.commit = jasmine.createSpy('commit'); mockScope.commit = jasmine.createSpy('commit');
mockTimeout = jasmine.createSpy('$timeout');
controller = new TimelineZoomController( controller = new TimelineZoomController(
mockScope, mockScope,
mockTimeout,
testConfiguration testConfiguration
); );
}); });