-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
108 lines (96 loc) · 3.87 KB
/
app.js
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
102
103
104
105
106
107
108
var app;
(function(){
app = angular.module('cypressWSN', ['ngMaterial', 'nvd3'])
.config(function($mdThemingProvider) {
$mdThemingProvider.theme('default')
.primaryPalette('blue')
.accentPalette('blue-grey');
$mdThemingProvider.theme('success-toast');
$mdThemingProvider.theme('error-toast');
$mdThemingProvider.alwaysWatchTheme(true);
})
})();
app.controller('mainController', function($scope, $mdToast){
$scope.cypressWSN = cypressWSN;
// Disabling the mouse right click event
document.addEventListener('contextmenu', function(event) { event.preventDefault();});
// ---------- Graph Code START -----------
$scope.options = {
chart: {
type: 'lineChart',
height: 250,
width: 380,
margin : {
top: 20,
right: 20,
bottom: 40,
left: 55
},
x: function(d){ return d.x; },
y: function(d){ return d.y; },
useInteractiveGuideline: true,
duration: 0,
yAxis: {
tickFormat: function(d){
return d3.format('.01f')(d);
}
},
xAxis: {
axisLabel:'Time',
tickFormat: function(d){
for(var uuid in $scope.cypressWSN.peripherals){
if($scope.cypressWSN.peripherals[uuid].tempGraphData[0].values[d]){
var label = $scope.cypressWSN.peripherals[uuid].tempGraphData[0].values[d].label;
return label;
}
}
}
}
}
};
$scope.tempOptions = angular.copy($scope.options);
$scope.humidityOptions = angular.copy($scope.options);
var x = 0;
setInterval(function(){
for(var uuid in $scope.cypressWSN.peripherals){
if(!isNaN($scope.cypressWSN.peripherals[uuid].tempData.timeNum) && !isNaN($scope.cypressWSN.peripherals[uuid].tempData.temp)){
$scope.cypressWSN.peripherals[uuid].tempGraphData[0].values.push(
{ x: $scope.cypressWSN.peripherals[uuid].tempData.timeNum,
y: $scope.cypressWSN.peripherals[uuid].tempData.temp,
label:$scope.cypressWSN.peripherals[uuid].tempData.date});
}
if ($scope.cypressWSN.peripherals[uuid].tempGraphData[0].values.length > 100) $scope.cypressWSN.peripherals[uuid].tempGraphData[0].values.shift();
if(!isNaN($scope.cypressWSN.peripherals[uuid].humidityData.timeNum) && !isNaN($scope.cypressWSN.peripherals[uuid].humidityData.temp)){
$scope.cypressWSN.peripherals[uuid].humidityGraphData[0].values.push(
{ x: $scope.cypressWSN.peripherals[uuid].humidityData.timeNum,
y: $scope.cypressWSN.peripherals[uuid].humidityData.temp,
label:$scope.cypressWSN.peripherals[uuid].tempData.date});
}
if ($scope.cypressWSN.peripherals[uuid].humidityGraphData[0].values.length > 100) $scope.cypressWSN.peripherals[uuid].humidityGraphData[0].values.shift();
}
x++;
}, 1000);
// ---------- Graph Code END -----------
$scope.cypressWSN.onSuccess = function(message){
$mdToast.show(
$mdToast.simple()
.content(message)
.position('top right')
.hideDelay(4000)
.theme("success-toast")
);
};
$scope.cypressWSN.onError = function(message){
$mdToast.show(
$mdToast.simple()
.content(message)
.position('top right')
.hideDelay(2500)
.theme("error-toast")
);
};
$scope.cypressWSN.updateUI = function(){
$scope.$apply();
};
$scope.cypressWSN.onSuccess('Scanning ....');
});