From fd294736642717d869c9d056311880a5d4330673 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 12 Jul 2016 15:02:39 -0700 Subject: [PATCH] Support resize --- .../conductor-v2/src/MctConductorAxis.js | 13 ++++++--- .../src/TimeConductorController.js | 27 +++++++++++++------ 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/platform/features/conductor-v2/src/MctConductorAxis.js b/platform/features/conductor-v2/src/MctConductorAxis.js index e12903f77e..e9c2fe61ad 100644 --- a/platform/features/conductor-v2/src/MctConductorAxis.js +++ b/platform/features/conductor-v2/src/MctConductorAxis.js @@ -54,7 +54,7 @@ define( var axisElement = vis.append("g") .attr("transform", "translate(0," + (height - padding) + ")"); - function setBounds(start, end) { + function setScale(start, end) { var width = target.offsetWidth; xScale.domain([new Date(start), new Date(end)]) .range([padding, width - padding * 2]); @@ -62,16 +62,23 @@ define( axisElement.call(xAxis); } + scope.resize = function () { + setScale(conductor.bounds().start, conductor.bounds().end); + }; + conductor.on('bounds', function (bounds) { - setBounds(bounds.start, bounds.end); + setScale(bounds.start, bounds.end); }); + + //Set initial scale. + setScale(conductor.bounds().start, conductor.bounds().end); } return { // Only show at the element level restrict: "E", - template: "
", + template: "
", // ngOptions is terminal, so we need to be higher priority priority: 1000, diff --git a/platform/features/conductor-v2/src/TimeConductorController.js b/platform/features/conductor-v2/src/TimeConductorController.js index 3e151d9414..50667cf031 100644 --- a/platform/features/conductor-v2/src/TimeConductorController.js +++ b/platform/features/conductor-v2/src/TimeConductorController.js @@ -69,9 +69,6 @@ define( self[key] = self[key].bind(self); }); - //Temporary workaround for resizing issue - $timeout(self.initialize, 1000); - $scope.$watch('modeModel.selected', this.switchMode); $scope.modeModel = { @@ -97,6 +94,14 @@ define( } } } + + $scope.$on('$destroy', function() { + if (self.mode) { + self.mode(); + } + }); + + self.initialize(); } TimeConductorController.prototype.initialize = function () { @@ -167,15 +172,21 @@ define( var tickInterval = 1000; var conductor = this.conductor; var $timeout = this.$timeout; - var timeoutPromise = $timeout(tick, tickInterval); conductor.follow(true); + setToNowMinus(FIFTEEN_MINUTES); + + var timeoutPromise = $timeout(tick, tickInterval); + + function setToNowMinus(delta) { + var now = Math.ceil(Date.now() / 1000) * 1000; + conductor.bounds({start: now - delta, end: now}); + } function tick() { var bounds = conductor.bounds(); - var interval = bounds.end - bounds.start; - var now = Math.ceil(Date.now() / 1000) * 1000; - conductor.bounds({start: now - interval, end: now}); + var delta = bounds.end - bounds.start; + setToNowMinus(delta); timeoutPromise = $timeout(tick, tickInterval) } @@ -184,7 +195,7 @@ define( $timeout.cancel(timeoutPromise); } }, - 'latest': function (conductor) { + 'latest': function () { //Don't know what to do here yet... this.conductor.follow(true); }