|
@@ -10,8 +10,9 @@
|
10
|
10
|
// in return. Thomas Buck & Christian Högerle
|
11
|
11
|
// ----------------------------------------------------------------------------
|
12
|
12
|
|
13
|
|
-var arrSensor = Array();
|
|
13
|
+var arrSensor = Array(); // Data received from Websockets
|
14
|
14
|
|
|
15
|
+// Text Strings. Change these to translate.
|
15
|
16
|
textAvailableSensors = "Available Sensors";
|
16
|
17
|
textButtonNext = "Continue";
|
17
|
18
|
homeTabName = "Home";
|
|
@@ -23,28 +24,36 @@ humidityLabel = 'Humidity [%RH]';
|
23
|
24
|
temperatureHeading = "Temperature";
|
24
|
25
|
humidityHeading = "Humidity";
|
25
|
26
|
|
26
|
|
-$(document).ready(function() {
|
27
|
|
- $('#main-part').append(`
|
28
|
|
- <div class="row" id="contentDiv">
|
29
|
|
- <div class="col-md-5 col-lg-5">
|
30
|
|
- <div class="panel panel-primary">
|
31
|
|
- <div class="panel-heading" id="listSensorsHeading">
|
32
|
|
- ` + textAvailableSensors + ` (0/0)
|
33
|
|
- </div>
|
34
|
|
- <div class="panel-body">
|
35
|
|
- <ul class="list-group" id="listSensors"></ul>
|
36
|
|
- <div id="alertDiv"></div>
|
37
|
|
- <button class="btn btn-primary" disabled="" id="btnSubmit">
|
38
|
|
- ` + textButtonNext + `
|
39
|
|
- </button>
|
40
|
|
- </div>
|
41
|
|
- </div>
|
42
|
|
- </div>
|
43
|
|
- </div>`);
|
|
27
|
+// Colors
|
|
28
|
+singleChartTempColor = "#337ab7";
|
|
29
|
+singleChartHumidColor = "#337ab7";
|
|
30
|
+preDefinedColors = Array(
|
|
31
|
+ "#337ab7", "#ff0000", "#00ff00"
|
|
32
|
+);
|
|
33
|
+
|
|
34
|
+// Get current client-time for the graph X-axis labels
|
|
35
|
+var actTime = new Date();
|
|
36
|
+actTime = actTime.getHours() + ":" + (actTime.getMinutes() < 10 ? '0':'') + actTime.getMinutes();
|
44
|
37
|
|
45
|
|
- // Get current client-time for the graph X-axis labels
|
46
|
|
- var actTime = new Date();
|
47
|
|
- actTime = actTime.getHours() + ":" + (actTime.getMinutes() < 10 ? '0':'') + actTime.getMinutes();
|
|
38
|
+// Draw initial view when the page has been loaded
|
|
39
|
+$(document).ready(initialView);
|
|
40
|
+
|
|
41
|
+function initialView() {
|
|
42
|
+ $('#contentDiv').empty();
|
|
43
|
+ $('#contentDiv').append(`<div class="col-sm-12 col-md-12 col-lg-12">
|
|
44
|
+ <div class="panel panel-primary">
|
|
45
|
+ <div class="panel-heading" id="listSensorsHeading">
|
|
46
|
+ ` + textAvailableSensors + ` (0/0)
|
|
47
|
+ </div>
|
|
48
|
+ <div class="panel-body">
|
|
49
|
+ <ul class="list-group" id="listSensors"></ul>
|
|
50
|
+ <div id="alertDiv"></div>
|
|
51
|
+ <button class="btn btn-primary" disabled="" id="btnSubmit">
|
|
52
|
+ ` + textButtonNext + `
|
|
53
|
+ </button>
|
|
54
|
+ </div>
|
|
55
|
+ </div>
|
|
56
|
+ </div>`);
|
48
|
57
|
|
49
|
58
|
$('#listSensorsHeading').empty();
|
50
|
59
|
$('#listSensorsHeading').html(textAvailableSensors + " (0/" + clients.length + ")");
|
|
@@ -58,9 +67,9 @@ $(document).ready(function() {
|
58
|
67
|
// Button to continue to graph view
|
59
|
68
|
$("#btnSubmit").click(function(event) {
|
60
|
69
|
$('#contentDiv').empty();
|
61
|
|
- generateView(arrSensor, actTime);
|
|
70
|
+ generateView(arrSensor);
|
62
|
71
|
});
|
63
|
|
-});
|
|
72
|
+}
|
64
|
73
|
|
65
|
74
|
function webSocket(wsUri, wsPort, count, clientsCount) {
|
66
|
75
|
websocket = new WebSocket("ws://" + wsUri + ":" + wsPort + "/");
|
|
@@ -102,8 +111,8 @@ function webSocket(wsUri, wsPort, count, clientsCount) {
|
102
|
111
|
};
|
103
|
112
|
}
|
104
|
113
|
|
105
|
|
-function generateView(arrSensor, actTime) {
|
106
|
|
- $('#contentDiv').append(`<div class="col-md-12 col-lg-12">
|
|
114
|
+function generateView(arrSensor) {
|
|
115
|
+ $('#contentDiv').append(`<div class="col-sm-12 col-md-12 col-lg-12">
|
107
|
116
|
<div class="panel panel-primary">
|
108
|
117
|
<ul class="nav nav-pills">
|
109
|
118
|
<li class="active"><a class="navtab" data-toggle="tab" href="#home">` + homeTabName + `</a></li>
|
|
@@ -120,26 +129,30 @@ function generateView(arrSensor, actTime) {
|
120
|
129
|
});
|
121
|
130
|
|
122
|
131
|
// flag for combined plot -> true
|
123
|
|
- generateGraph(true, arrSensor, actTime);
|
|
132
|
+ generateGraph(true, arrSensor);
|
124
|
133
|
|
125
|
134
|
$(".navtab").click(function(event) {
|
126
|
135
|
$('#contentPanel').empty();
|
127
|
136
|
if(event.target.text == homeTabName) {
|
128
|
137
|
// flag for combined plot -> true
|
129
|
|
- generateGraph(true, arrSensor, actTime);
|
|
138
|
+ generateGraph(true, arrSensor);
|
130
|
139
|
} else {
|
131
|
|
- generateGraph(false, arrSensor[(event.target.text.split(" ")[1] - 1)], actTime);
|
|
140
|
+ generateGraph(false, arrSensor[(event.target.text.split(" ")[1] - 1)]);
|
132
|
141
|
}
|
133
|
142
|
});
|
134
|
143
|
}
|
135
|
144
|
|
136
|
|
-function generateGraph(flag, sensor, actTime) {
|
|
145
|
+function generateGraph(flag, sensor) {
|
137
|
146
|
$('#contentPanel').append(`<div class="row">
|
138
|
147
|
<div class="col-sm-12 col-md-12 col-lg-6">
|
139
|
|
- <canvas id="temperaturChart"></canvas>
|
|
148
|
+ <div id="temperatureDiv" class="embed-responsive embed-responsive-4by3">
|
|
149
|
+ <canvas id="temperatureChart"></canvas>
|
|
150
|
+ </div>
|
140
|
151
|
</div>
|
141
|
152
|
<div class="col-sm-12 col-md-12 col-lg-6">
|
142
|
|
- <canvas id="humidityChart"></canvas>
|
|
153
|
+ <div id="humidityDiv" class="embed-responsive embed-responsive-4by3">
|
|
154
|
+ <canvas id="humidityChart"></canvas>
|
|
155
|
+ </div>
|
143
|
156
|
</div>
|
144
|
157
|
</div>`);
|
145
|
158
|
if (flag) {
|
|
@@ -176,7 +189,7 @@ function generateGraph(flag, sensor, actTime) {
|
176
|
189
|
tmpDataTemperature.push(tmp.currentTemp);
|
177
|
190
|
tmpDataHumidity.push(tmp.currentHum);
|
178
|
191
|
|
179
|
|
- var lineColor = getRandomColor();
|
|
192
|
+ var lineColor = getColor(index);
|
180
|
193
|
dataTemperature.push({label: sensorTabName + " " + tmp.id, data: tmpDataTemperature, fill: false,
|
181
|
194
|
borderWidth: 3, borderColor : lineColor,});
|
182
|
195
|
dataHumidity.push({label: sensorTabName + " " + tmp.id, data: tmpDataHumidity, fill: false,
|
|
@@ -205,14 +218,19 @@ function generateGraph(flag, sensor, actTime) {
|
205
|
218
|
tmpDataHumidity.push(sensor.currentHum);
|
206
|
219
|
|
207
|
220
|
var dataTemperature = [{label: temperatureLabel, data: tmpDataTemperature,
|
208
|
|
- fill: false, borderWidth: 3, borderColor: '#337ab7',}];
|
|
221
|
+ fill: false, borderWidth: 3, borderColor: singleChartTempColor,}];
|
209
|
222
|
var dataHumidity = [{label: humidityLabel, data: tmpDataHumidity,
|
210
|
|
- fill: false, borderWidth: 3, borderColor: '#337ab7',}];
|
|
223
|
+ fill: false, borderWidth: 3, borderColor: singleChartHumidColor,}];
|
211
|
224
|
}
|
212
|
225
|
|
213
|
|
- var tempCtx = $('#temperaturChart');
|
|
226
|
+ var tempCtx = $('#temperatureChart');
|
214
|
227
|
var humCtx = $('#humidityChart');
|
215
|
228
|
|
|
229
|
+ //tempCtx.attr('width', $('#temperatureDiv').width());
|
|
230
|
+ //tempCtx.attr('height', $('#temperatureDiv').height());
|
|
231
|
+ //humCtx.attr('width', $('#humidityDiv').width());
|
|
232
|
+ //humCtx.attr('height', $('#humidityDiv').height());
|
|
233
|
+
|
216
|
234
|
var tempChart = new Chart(tempCtx, {
|
217
|
235
|
type: 'line',
|
218
|
236
|
data: {
|
|
@@ -223,7 +241,10 @@ function generateGraph(flag, sensor, actTime) {
|
223
|
241
|
title: {
|
224
|
242
|
display: true,
|
225
|
243
|
text: temperatureHeading
|
226
|
|
- }
|
|
244
|
+ },
|
|
245
|
+ responsive: true,
|
|
246
|
+ maintainAspectRatio: true,
|
|
247
|
+ scaleOverride: true
|
227
|
248
|
}
|
228
|
249
|
});
|
229
|
250
|
|
|
@@ -237,7 +258,10 @@ function generateGraph(flag, sensor, actTime) {
|
237
|
258
|
title: {
|
238
|
259
|
display: true,
|
239
|
260
|
text: humidityHeading
|
240
|
|
- }
|
|
261
|
+ },
|
|
262
|
+ responsive: true,
|
|
263
|
+ maintainAspectRatio: true,
|
|
264
|
+ scaleOverride: true
|
241
|
265
|
}
|
242
|
266
|
});
|
243
|
267
|
}
|
|
@@ -247,6 +271,14 @@ Number.prototype.mod = function(n) {
|
247
|
271
|
return ((this%n)+n)%n;
|
248
|
272
|
}
|
249
|
273
|
|
|
274
|
+function getColor(index) {
|
|
275
|
+ if (index < preDefinedColors.length) {
|
|
276
|
+ return preDefinedColors[index];
|
|
277
|
+ } else {
|
|
278
|
+ return getRandomColor();
|
|
279
|
+ }
|
|
280
|
+}
|
|
281
|
+
|
250
|
282
|
function getRandomColor() {
|
251
|
283
|
var letters = '0123456789ABCDEF'.split('');
|
252
|
284
|
var color = '#';
|