[Timeline] Simplify bounds-tracking

This commit is contained in:
Victor Woeltjen
2016-06-02 16:40:07 -07:00
parent 86b31bc040
commit 99590d18f7

View File

@@ -32,8 +32,7 @@ define(
// 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;
bounds = { x: 0, width: tickWidth }; // Default duration in view
function toMillis(pixels) { function toMillis(pixels) {
return (pixels / tickWidth) * zoomLevels[zoomIndex]; return (pixels / tickWidth) * zoomLevels[zoomIndex];
@@ -63,7 +62,7 @@ define(
function initializeZoomFromTimespan(timespan) { function initializeZoomFromTimespan(timespan) {
var timelineDuration = timespan.getDuration(); var timelineDuration = timespan.getDuration();
zoomIndex = 0; zoomIndex = 0;
while (toMillis(bounds.width) < timelineDuration && while (toMillis($scope.scroll.width) < timelineDuration &&
zoomIndex < zoomLevels.length - 1) { zoomIndex < zoomLevels.length - 1) {
zoomIndex += 1; zoomIndex += 1;
} }
@@ -77,9 +76,6 @@ define(
} }
} }
$scope.$watch("scroll", function (scroll) {
bounds = scroll;
});
$scope.$watch("domainObject", initializeZoom); $scope.$watch("domainObject", initializeZoom);
return { return {
@@ -97,8 +93,7 @@ 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 ? var bounds = $scope.scroll;
// 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);
setScroll(this.toPixels(center) - bounds.width / 2); setScroll(this.toPixels(center) - bounds.width / 2);
@@ -130,7 +125,7 @@ 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, pixels); return Math.max($scope.scroll.width, pixels);
} }
}; };
} }