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")
.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: "<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
priority: 1000,

View File

@ -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);
}