Skip to content

Commit 58ed500

Browse files
committed
Time sync via conductor
1 parent bca5eb0 commit 58ed500

File tree

4 files changed

+65
-49
lines changed

4 files changed

+65
-49
lines changed

platform/features/conductor-v2/bundle.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ define([
5252
"implementation": TimeConductorController,
5353
"depends": [
5454
"$scope",
55+
"$timeout",
5556
"timeConductor"
5657
]
5758
}
@@ -60,7 +61,9 @@ define([
6061
{
6162
"key": "mctConductorAxis",
6263
"implementation": MCTConductorAxis,
63-
"depends": ["$timeout"]
64+
"depends": [
65+
"timeConductor"
66+
]
6467
}
6568
],
6669
"representations": [

platform/features/conductor-v2/res/templates/time-conductor.html

+2-4
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
stroke: #A0A0A0;
2626
}
2727

28-
.l-axis-holder svg>g
29-
3028
</style>
3129
<!-- Parent holder for time conductor. follow-mode | fixed-mode -->
3230
<div class="follow-mode"
@@ -43,7 +41,7 @@
4341
validate: tcController.validateStart
4442
}"
4543
ng-model="formModel"
46-
ng-blur="tcController.updateBoundsFromForm()"
44+
ng-blur="tcController.updateBoundsFromForm(formModel)"
4745
field="'start'"
4846
class="time-range-start">
4947
</mct-control>
@@ -56,7 +54,7 @@
5654
validate: tcController.validateEnd
5755
}"
5856
ng-model="formModel"
59-
ng-blur="trCtrl.updateBoundsFromForm()"
57+
ng-blur="tcController.updateBoundsFromForm(formModel)"
6058
field="'end'"
6159
class="time-range-end">
6260
</mct-control>

platform/features/conductor-v2/src/MctConductorAxis.js

+22-29
Original file line numberDiff line numberDiff line change
@@ -37,41 +37,34 @@ define(
3737
* @constructor
3838
* @memberof platform/forms
3939
*/
40-
function MCTConductorAxis($timeout) {
40+
function MCTConductorAxis(conductor) {
4141

4242
function link(scope, element, attrs, ngModelController) {
43-
$timeout(function () {
44-
var target = element[0].firstChild,
45-
width = target.offsetWidth,
46-
height = target.offsetHeight,
47-
padding = 1;
43+
var target = element[0].firstChild,
44+
height = target.offsetHeight,
45+
padding = 1;
4846

49-
var vis = d3.select(target)
50-
.append('svg:svg')
51-
//.attr('viewBox', '0 0 ' + width + ' ' +
52-
// height)
53-
.attr('width', '100%')
54-
.attr('height', height);
55-
//.attr('preserveAspectRatio', 'xMidYMid meet');
47+
var vis = d3.select(target)
48+
.append('svg:svg')
49+
.attr('width', '100%')
50+
.attr('height', height);
51+
var xScale = d3.scaleTime();
52+
var xAxis = d3.axisTop();
53+
// draw x axis with labels and move to the bottom of the chart area
54+
var axisElement = vis.append("g")
55+
.attr("transform", "translate(0," + (height - padding) + ")");
5656

57-
// define the x scale (horizontal)
58-
var mindate = new Date(2012,0,1),
59-
maxdate = new Date(2016,0,1);
60-
61-
var xScale = d3.scaleTime()
62-
.domain([mindate, maxdate])
57+
function setBounds(start, end) {
58+
var width = target.offsetWidth;
59+
xScale.domain([new Date(start), new Date(end)])
6360
.range([padding, width - padding * 2]);
64-
65-
var xAxis = d3.axisTop()
66-
.scale(xScale);
67-
68-
// draw x axis with labels and move to the bottom of the chart area
69-
var axisElement = vis.append("g")
70-
.attr("class", "xaxis") // give it a class so it can be used to select only xaxis labels below
71-
.attr("transform", "translate(0," + (height - padding) + ")");
72-
61+
xAxis.scale(xScale);
7362
axisElement.call(xAxis);
74-
}, 1000);
63+
}
64+
65+
conductor.on('bounds', function (bounds) {
66+
setBounds(bounds.start, bounds.end);
67+
});
7568
}
7669

7770
return {

platform/features/conductor-v2/src/TimeConductorController.js

+37-15
Original file line numberDiff line numberDiff line change
@@ -24,31 +24,53 @@ define(
2424
[],
2525
function () {
2626

27-
function TimeConductorController($scope, conductor) {
27+
var SIX_HOURS = 6 * 60 * 60 * 1000;
28+
29+
function TimeConductorController($scope, $timeout, conductor) {
30+
var now = Date.now();
31+
var self = this;
32+
2833
this.$scope = $scope;
2934
this.conductor = conductor;
3035

31-
/*
32-
Stuff to put on scope
33-
- parameters
34-
- formModel
35-
*/
36-
this.$scope.formModel = {
37-
start: '2012-01-01 00:00:00.000Z',
38-
end: '2016-01-01 00:00:00.000Z'
39-
};
36+
$scope.formModel = {};
37+
38+
conductor.on('bounds', function (bounds) {
39+
$scope.formModel = {
40+
start: bounds.start,
41+
end: bounds.end
42+
};
43+
});
44+
45+
//Temporary workaround for resizing issue
46+
$timeout(function() {
47+
//Set the time conductor to some default
48+
conductor.bounds({start: now - SIX_HOURS, end: now});
49+
}, 1000);
50+
51+
Object.keys(TimeConductorController.prototype).filter(function (key){
52+
return typeof TimeConductorController.prototype[key] === 'function';
53+
}).forEach(function (key) {
54+
self[key] = self[key].bind(self);
55+
});
4056
}
4157

42-
TimeConductorController.prototype.validateStart = function () {
43-
return true;
58+
TimeConductorController.prototype.validateStart = function (start) {
59+
var bounds = this.conductor.bounds();
60+
return this.conductor.validateBounds({start: start, end: bounds.end}) === true;
4461
};
4562

46-
TimeConductorController.prototype.validateEnd = function () {
47-
return true;
63+
TimeConductorController.prototype.validateEnd = function (end) {
64+
var bounds = this.conductor.bounds();
65+
return this.conductor.validateBounds({start: bounds.start, end: end}) === true;
4866
};
4967

50-
TimeConductorController.prototype.updateBoundsFromForm = function () {
68+
TimeConductorController.prototype.updateBoundsFromForm = function (formModel) {
69+
var newBounds = {start: formModel.start, end: formModel.end};
5170

71+
if (this.conductor.validateBounds(newBounds) === true) {
72+
this.conductor.bounds(newBounds);
73+
}
5274
};
5375

5476
return TimeConductorController;

0 commit comments

Comments
 (0)