Skip to content

Commit

Permalink
Support resize
Browse files Browse the repository at this point in the history
  • Loading branch information
akhenry committed Jul 12, 2016
1 parent 97f3fd5 commit fd29473
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
13 changes: 10 additions & 3 deletions platform/features/conductor-v2/src/MctConductorAxis.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,31 @@ 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]);
xAxis.scale(xScale);
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,
Expand Down
27 changes: 19 additions & 8 deletions platform/features/conductor-v2/src/TimeConductorController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -97,6 +94,14 @@ define(
}
}
}

$scope.$on('$destroy', function() {
if (self.mode) {
self.mode();
}
});

self.initialize();
}

TimeConductorController.prototype.initialize = function () {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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);
}
Expand Down

0 comments on commit fd29473

Please sign in to comment.