-
Notifications
You must be signed in to change notification settings - Fork 1
/
plots_page.html
269 lines (248 loc) · 8.28 KB
/
plots_page.html
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Plots</title>
<!-- <link rel="stylesheet" type="text/css" href="style.css"> -->
<link rel="stylesheet" type="text/css" href="plot-style.css">
<!-- <script type="text/javascript" language="javascript"></script> -->
<script src="socket.io.js"></script>
<script src="jquery-3.5.1.js"></script>
<script src="canvasjs.min.js"></script>
</script>
</head>
<script>
function display_c() {
var refresh = 1000; // Refresh rate in milli seconds
mytime = setTimeout('display_ct()', refresh)
}
function display_ct() {
var x = new Date()
var x1 = x.getMonth() + 1 + "/" + x.getDate() + "/" + x.getYear();
x1 = x1 + " - " + x.getHours() + ":" + x.getMinutes() + ":" + x.getSeconds();
document.getElementById('ct').innerHTML = x1;
display_c();
}
</script>
<body onload=display_ct();>
<div>
<div class="vl"></div>
<div>
<p><span id="name"></span> <span id="ct"></span>
<button id='clear' class="btn-link" onclick="clearPlots()">Clear</button>
<button id='release' class="btn-link" onclick="saveEvent('release')">Cuff Release</button>
<button id='occlusion' class="btn-link" onclick="saveEvent('occlusion')">Occlusion</button>
<button id='baseline' class="btn-link" onclick="saveEvent('baseline')">Baseline</button>
</p>
</div>
<div class="chartBlock">
<h6>Fingertip Pressure</h6>
<div>
<button id="zi1">+</button>
<button id="zo1">-</button>
</div>
<div id="chartContainer1" class="chartArea"></div><br>
<br>
<input type="checkbox" id="filtered1">
<label for="filtered1" class="checkBox"> Show Filtered</label><br>
<hr style="border-color: gray; width:120%; border-style:solid;margin-top: 15px;">
<h6>Fingertip Temperature</h6>
<div>
<button id="zi2">+</button>
<button id="zo2">-</button>
</div>
<div id="chartContainer2" class="chartArea"></div>
<input type="checkbox" id="filtered2">
<label for="filtered2" class="checkBox"> Show Filtered</label>
</div>
<div class="chartBlock">
<h6>SPO2</h6>
<div>
<button id="zi3">+</button>
<button id="zo3">-</button>
</div>
<div id="chartContainer3" class="chartArea"></div><br>
<br>
<input type="checkbox" id="filtered3">
<label for="filtered3" class="checkBox"> Show Filtered</label><br>
<hr style="border-color: gray;border-style: solid;margin-top: 15px;">
<h6>Bioimpedance</h6>
<div>
<button id="zi4">+</button>
<button id="zo4">-</button>
</div>
<div id="chartContainer4" class="chartArea"></div>
<br>
<input type="checkbox" id="filtered4">
<label for="filtered4" class="checkBox"> Show Filtered</label>
</div>
</div>
<script>
//defining variables
var socket = io('http://localhost:9090');//socket connection
// const DATA_LENGTH = 1000;
function saveEvent(msg) {
socket.emit('event', msg)
console.log(msg)
}
function clearPlots() {
socket.emit('clear')
console.log("Clear Plots");
charts = newCharts();
}
class DataChart {
DATA_LENGTH = 1000;
dataPoints = [];
chart = null;
chartOptions = {};
axisXMin = 0;
axisXMax = 0;
axisYMin = 0;
axisYMax = 0;
resetFlag = false;
updateRange = 0;
updateInterval = 500;
zoomInButton;
zoomOutButton;
zoomed = false;
constructor(chartId, noOfSignals, zoomInBtn, zoomOutBtn) {
this.zoomInButton = document.getElementById(zoomInBtn);
this.zoomInButton.addEventListener('click', this.zoomIn.bind(this));
this.zoomOutButton = document.getElementById(zoomOutBtn);
this.zoomOutButton.addEventListener('click', this.zoomOut.bind(this));
for (let i = 0; i < noOfSignals; i++) {
this.dataPoints.push({
type: 'line',
dataPoints: [],
});
}
let chartOptions = {
zoomEnabled: true,
exportEnabled: true,
zoomType: 'xy',
rangeChanged: function (e1) {
if (e1.trigger === 'zoom') {
this.axisXMax = e1.axisX[0].viewportMaximum;
this.axisXMin = e1.axisX[0].viewportMinimum;
this.axisYMax = e1.axisY[0].viewportMaximum;
this.axisYMin = e1.axisY[0].viewportMinimum;
this.resetFlag = false;
this.zoomed = true;
if (this.updateRange > 0) clearInterval(this.updateRange);
} else if (e1.trigger == 'reset') {
this.resetFlag = true;
clearInterval(this.updateRange);
}
}.bind(this),
axisX: {
// {},
stripLines: [
{
startValue: 100,
endValue: 250,
color: '#d8d8d8',
},
],
},
axisY: {},
data: this.dataPoints,
};
this.chart = new CanvasJS.Chart(chartId, chartOptions);
this.chart.render();
}
updateChart(upd, dps) {
// console.log(this.zoomed);
let count = upd.time.length;
for (var j = 0; j < count; j++) {
this.dataPoints[dps].dataPoints.push({
// x: upd.time[j],
x: upd.time[j],
y: upd.data[j],
});
}
if (this.zoomed){
this.updateAxisRange(count);
}
if (this.resetFlag) {
this.chart.options.axisX.viewportMinimum = null;
this.chart.options.axisX.viewportMaximum = null;
this.chart.options.axisY.viewportMinimum = null;
this.chart.options.axisY.viewportMaximum = null;
}
if (this.dataPoints[dps].dataPoints.length > this.DATA_LENGTH){
this.dataPoints[dps].dataPoints.splice(0,count)
}
this.chart.render();
}
//define updateAxisRange: function to update the axis X range on zooming
updateAxisRange(increment) {
this.axisXMax += increment;
this.axisXMin += increment;
this.chart.options.axisX.viewportMaximum = this.axisXMax;
this.chart.options.axisX.viewportMinimum = this.axisXMin;
}
//Function for zooming out
zoomOut() {
this.axisXMax += 1;
this.axisXMin -= 5;
this.axisYMax += 0.5;
this.axisYMin -= 0.5;
this.chart.options.axisX.viewportMaximum = this.axisXMax;
this.chart.options.axisX.viewportMinimum = this.axisXMin;
this.chart.options.axisY.viewportMaximum = this.axisYMax;
this.chart.options.axisY.viewportMinimum = this.axisYMin;
this.chart.render();
}
//Function for zooming in
zoomIn() {
this.axisXMax -= 1;
this.axisXMin += 5;
this.axisYMax -= 0.5;
this.axisYMin += 0.5;
this.chart.options.axisX.viewportMaximum = this.axisXMax;
this.chart.options.axisX.viewportMinimum = this.axisXMin;
this.chart.options.axisY.viewportMaximum = this.axisYMax;
this.chart.options.axisY.viewportMinimum = this.axisYMin;
this.chart.render();
}
}
function newCharts(){
let chart1 = new DataChart("chartContainer1", 2, "zi1", "zo1")
let chart2 = new DataChart("chartContainer2", 3, "zi2", "zo2")
let chart3 = new DataChart("chartContainer3", 2, "zi3", "zo3")
let chart4 = new DataChart("chartContainer4", 4, "zi4", "zo4")
console.log("New charts");
return [chart1, chart2, chart3, chart4];
}
let charts = newCharts();
console.log(charts);
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const uid = urlParams.get('id') ? urlParams.get('id') :'defaultCollection'
//console.log(uid)
socket.emit('db', uid)
// obtaining data from socket io to plot the data
socket.on('signals', (message) => {
// console.log(message);
let time = message.time;
let data = message.data;
if (message.data) {
switch (message.type) {
case "PData": charts[0].updateChart({ time: time, data: data }, 0); break;
case "TData": charts[1].updateChart({ time: time, data: data }, 0); break;
case "SData": charts[2].updateChart({ time: time, data: data }, 0); break;
case "WData": charts[3].updateChart({ time: time, data: data }, 0); break;
case "EData": charts[1].updateChart({ time: time, data: data }, 2); break;
case "PCData": charts[0].updateChart({ time: time, data: data }, 1); break;
case "TCData": charts[1].updateChart({ time: time, data: data }, 1); break;
case "SCData": charts[2].updateChart({ time: time, data: data }, 1); break;
case "WCData": charts[3].updateChart({ time: time, data: data }, 1); break;
case "YCData": charts[3].updateChart({ time: time, data: data }, 2); break;
case "YData": charts[3].updateChart({ time: time, data: data }, 3); break;
}
}
});
</script>
</body>
</html>