driverMatrix.js
2.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// js for driver view
(function () {
'use strict';
// injected refs
var $log, $scope, fs, wss, mast;
// constants
var detailsReq = 'driverDataRequest',
detailsResp = 'driverDataResponse',
topPad = 13,
labelFudge = 14;
// d3 selections
var tabular, dMatrix, tabHdRot, tabGrid, first;
function fixSizes() {
var dy = fs.noPxStyle(tabular, 'height') +
fs.noPxStyle(tabHdRot, 'height') + mast.mastHeight() + topPad,
tHeight = fs.windowSize(dy).height + 'px',
rowHdr = tabGrid.select('.row-header'),
w;
tabGrid.style('height', tHeight);
if (!rowHdr.empty()) {
w = fs.noPxStyle(rowHdr, 'width') + labelFudge;
first.style('width', w + 'px');
}
}
function respDetailsCb(data) {
$scope.behaviours = data.behaviours;
$scope.drivers = data.drivers;
$scope.matrix = data.matrix;
$scope.$apply();
fixSizes();
}
angular.module('ovDriverMatrix', [])
.run(['IconService', function (is) {
// Create our icon-to-glyph binding here:
is.registerIconMapping('nav_drivers', 'cog');
}])
.controller('OvDriverMatrixCtrl',
['$rootScope', '$window', '$log', '$scope', '$sce',
'FnService', 'WebSocketService', 'MastService',
function ($rootScope, $window, _$log_, _$scope_, $sce,
_fs_, _wss_, _mast_) {
$log = _$log_;
$scope = _$scope_;
fs = _fs_;
wss = _wss_;
mast = _mast_;
var handlers = {},
unbindWatch;
tabular = d3.select('.tabular-header');
dMatrix = d3.select('.driver-matrix');
tabHdRot = d3.select('.table-header-rotated');
tabGrid = d3.select('.table-grid');
first = tabHdRot.select('.first');
unbindWatch = $rootScope.$watchCollection(
function () {
return {
h: $window.innerHeight,
w: $window.innerWidth
};
}, fixSizes
);
$scope.behaviours = [];
$scope.drivers = [];
$scope.matrix = {};
handlers[detailsResp] = respDetailsCb;
wss.bindHandlers(handlers);
wss.sendEvent(detailsReq);
function cellHit(d, b) {
var drec = $scope.matrix[d],
brec = drec && drec[b];
return !!brec;
}
$scope.cellMarked = cellHit;
$scope.checkmark = $sce.trustAsHtml("✓");
// cleanup
$scope.$on('$destroy', function () {
unbindWatch();
wss.unbindHandlers(handlers);
$log.log('OvDriverMatrixCtrl has been destroyed');
});
$log.log('OvDriverMatrixCtrl has been created');
}]);
}());