Support resize

This commit is contained in:
Henry 2016-07-12 15:02:39 -07:00
parent 97f3fd516b
commit fd29473664
2 changed files with 29 additions and 11 deletions

View File

@ -54,7 +54,7 @@ define(
var axisElement = vis.append("g") var axisElement = vis.append("g")
.attr("transform", "translate(0," + (height - padding) + ")"); .attr("transform", "translate(0," + (height - padding) + ")");
function setBounds(start, end) { function setScale(start, end) {
var width = target.offsetWidth; var width = target.offsetWidth;
xScale.domain([new Date(start), new Date(end)]) xScale.domain([new Date(start), new Date(end)])
.range([padding, width - padding * 2]); .range([padding, width - padding * 2]);
@ -62,16 +62,23 @@ define(
axisElement.call(xAxis); axisElement.call(xAxis);
} }
scope.resize = function () {
setScale(conductor.bounds().start, conductor.bounds().end);
};
conductor.on('bounds', function (bounds) { 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 { return {
// Only show at the element level // Only show at the element level
restrict: "E", restrict: "E",
template: "<div class=\"l-axis-holder\"></div>", template: "<div class=\"l-axis-holder\" mct-resize=\"resize()\"></div>",
// ngOptions is terminal, so we need to be higher priority // ngOptions is terminal, so we need to be higher priority
priority: 1000, priority: 1000,

View File

@ -69,9 +69,6 @@ define(
self[key] = self[key].bind(self); self[key] = self[key].bind(self);
}); });
//Temporary workaround for resizing issue
$timeout(self.initialize, 1000);
$scope.$watch('modeModel.selected', this.switchMode); $scope.$watch('modeModel.selected', this.switchMode);
$scope.modeModel = { $scope.modeModel = {
@ -97,6 +94,14 @@ define(
} }
} }
} }
$scope.$on('$destroy', function() {
if (self.mode) {
self.mode();
}
});
self.initialize();
} }
TimeConductorController.prototype.initialize = function () { TimeConductorController.prototype.initialize = function () {
@ -167,15 +172,21 @@ define(
var tickInterval = 1000; var tickInterval = 1000;
var conductor = this.conductor; var conductor = this.conductor;
var $timeout = this.$timeout; var $timeout = this.$timeout;
var timeoutPromise = $timeout(tick, tickInterval);
conductor.follow(true); 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() { function tick() {
var bounds = conductor.bounds(); var bounds = conductor.bounds();
var interval = bounds.end - bounds.start; var delta = bounds.end - bounds.start;
var now = Math.ceil(Date.now() / 1000) * 1000; setToNowMinus(delta);
conductor.bounds({start: now - interval, end: now});
timeoutPromise = $timeout(tick, tickInterval) timeoutPromise = $timeout(tick, tickInterval)
} }
@ -184,7 +195,7 @@ define(
$timeout.cancel(timeoutPromise); $timeout.cancel(timeoutPromise);
} }
}, },
'latest': function (conductor) { 'latest': function () {
//Don't know what to do here yet... //Don't know what to do here yet...
this.conductor.follow(true); this.conductor.follow(true);
} }