-
Notifications
You must be signed in to change notification settings - Fork 6
/
demo.html
362 lines (292 loc) · 13.1 KB
/
demo.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" value="Dmitry Konyshev, [email protected]">
<title>Neurobotics jsEDF online viewer</title>
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAyZpVFh0WE1MOmNvbS5hZG9i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KTVwuccVyh0ozvXgy/vBSZhyZXYbz5QeQTqpK9f0CVcdmqo5HIIiXsPODfCIeZzF6cEz1IUwG6spvqDq2cir+Tu0G7Wkji25TP/Vky3PdMnUctNRGz28/BRgAg5JcyEt6pdYAAAAASUVORK5CYII=">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="edf.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap" rel="stylesheet">
<link rel>
<style>
* { font-family: 'Roboto Mono', monospace; box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: #FFF; overflow: hidden; }
body {
height: 100%;
min-height: 100vh;
}
</style>
</head>
<body >
<div style="height: 80px; background: #CCC; padding: 10px;">
<input type="file" name="file" id="file" onchange="openFile(this.files)">
<img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTYuNDUsMTcuNDVMMSwxMkw2LjQ1LDYuNTVMNy44Niw3Ljk2TDQuODMsMTFIMTkuMTdMMTYuMTQsNy45NkwxNy41NSw2LjU1TDIzLDEyTDE3LjU1LDE3LjQ1TDE2LjE0LDE2LjA0TDE5LjE3LDEzSDQuODNMNy44NiwxNi4wNEw2LjQ1LDE3LjQ1WiIgLz48L3N2Zz4=" width="16" height="16" style="vertical-align: middle;">
<select id="select-scaleY">
<option value="0.001">0.001 μV/px</option>
<option value="0.01">0.01 μV/px</option>
<option value="0.1" selected>0.1 μV/px</option>
<option value="1">1 μV/px</option>
<option value="10">10 μV/px</option>
<option value="100">100 μV/px</option>
</select>
<span style="display: inline-block; width: 20px;"></span>
<img src="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz48IURPQ1RZUEUgc3ZnIFBVQkxJQyAiLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4iICJodHRwOi8vd3d3LnczLm9yZy9HcmFwaGljcy9TVkcvMS4xL0RURC9zdmcxMS5kdGQiPjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB4bWxuczp4bGluaz0iaHR0cDovL3d3dy53My5vcmcvMTk5OS94bGluayIgdmVyc2lvbj0iMS4xIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiIHZpZXdCb3g9IjAgMCAyNCAyNCI+PHBhdGggZD0iTTYuNDUsMTcuNDVMMSwxMkw2LjQ1LDYuNTVMNy44Niw3Ljk2TDQuODMsMTFIMTkuMTdMMTYuMTQsNy45NkwxNy41NSw2LjU1TDIzLDEyTDE3LjU1LDE3LjQ1TDE2LjE0LDE2LjA0TDE5LjE3LDEzSDQuODNMNy44NiwxNi4wNEw2LjQ1LDE3LjQ1WiIgLz48L3N2Zz4=" width="16" height="16" style="vertical-align: middle">
<select id="select-visualSeconds">
<option value="1">1 s/screen</option>
<option value="10">5 s/screen</option>
<option value="10" selected>10 s/screen</option>
<option value="15">15 s/screen</option>
<option value="30">30 s/screen</option>
<option value="60">60 s/screen</option>
<option value="100">100 s/screen</option>
</select>
<br/>
<input id="scroll" type="range" min="0" max="0" value="0" style="width: calc(100% - 20px); margin-top: 10px;">
</div>
<div style="position: absolute; top: 80px; height: calc(100vh - 80px); width: 100%; " id="canvasSignalholder">
<canvas id="canvasSignal" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></canvas>
<canvas id="canvasSignalLine" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></canvas>
<canvas id="canvasSignalNow" style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></canvas>
<script>
var signalPoints = [];
var samplingRate = 120;
var visualSeconds = 10;
var scaleY = 0.1;
var offsetSeconds = 0;
var maxSeconds = 0;
var channelsCount = 0;
var fontFamily = 'Roboto Mono';
var fontSize = 12;
function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}
function timeToText(seconds)
{
var s = seconds%60;
var m = Math.floor(seconds/60)%60;
var h = Math.floor((seconds/60)/60);
return (h>0?(pad(h,2)+":"):"")+pad(m,2) +":"+pad(s,2);
}
function updateScrollBar()
{
var secs = visualSeconds;
var max = maxSeconds;
var maxScroll = Math.ceil(max - secs);
$("#scroll").attr("max", maxScroll);
$("#scroll").val(offsetSeconds);
}
function resizeCanvasEEG()
{
var parent = $("#canvasSignalholder");
var canvas = document.getElementById('canvasSignal');
canvas.width = parent.width();
canvas.height = parent.height();
canvas.style.width = parent.width();
canvas.style.height = parent.height();
canvas = document.getElementById('canvasSignalLine');
canvas.width = parent.width();
canvas.height = parent.height();
canvas.style.width = parent.width();
canvas.style.height = parent.height();
canvas = document.getElementById('canvasSignalNow');
canvas.width = parent.width();
canvas.height = parent.height();
canvas.style.width = parent.width();
canvas.style.height = parent.height();
drawEEGGrid();
}
function drawEEGGrid()
{
var canvas = document.getElementById('canvasSignal');
var w = canvas.width;
var h = canvas.height;
var context = canvas.getContext('2d');
context.width = w;
context.height = h;
context.fillStyle = "#FFF";
context.fillRect(0, 0, w, h);
context.translate(0.5, 0.5);
var offset = 10;
var vh = h - offset*2;
var vw = w - offset*2;
var pixelsPerSecond = vw/visualSeconds;
context.strokeWidth = 1;
for (var i = 1; i<=visualSeconds; i++)
{
context.lineWidth = 1;
context.strokeStyle = '#DDD';
context.beginPath();
context.moveTo(offset+pixelsPerSecond*(i-0.5), offset);
context.lineTo(offset+pixelsPerSecond*(i-0.5), offset+vh);
context.stroke();
context.lineWidth = 1;
context.strokeStyle = '#999';
context.beginPath();
context.moveTo(offset+pixelsPerSecond*i, offset);
context.lineTo(offset+pixelsPerSecond*i, offset+vh);
context.stroke();
}
context.strokeStyle = '#999';
context.lineWidth = 1;
context.strokeRect(offset, offset, vw, vh);
}
function redrawSignals()
{
var canvas = document.getElementById('canvasSignalLine');
var context = canvas.getContext('2d');
var w = canvas.width;
var h = canvas.height;
context.width = w;
context.height = h;
context.clearRect(0, 0, w, h);
var offset = 10;
var vh = h - offset*2;
var vw = w - offset*2;
var pixelsPerSecond = vw/visualSeconds;
var pixelsPerSample = 1.0*pixelsPerSecond/samplingRate;
context.font = fontSize+"px '" + fontFamily+"'";
context.fillStyle = "#333";
context.textAlign = "left";
for (var i =0; i<visualSeconds; i++)
{
context.fillText(timeToText(offsetSeconds+i), offset + 1 + i*pixelsPerSecond, offset + vh -2);
}
var channelCount = signalPoints.length;
var channelOffset = vh/(channelCount);
for (var i =0; i<channelCount; i++)
{
var d = signalPoints[i];
//console.log(d);
var x = offset;
var y = offset+(i+0.5)*(channelOffset);
context.lineWidth = 1;
context.strokeStyle = '#999';
context.beginPath();
context.moveTo(x, y);
context.lineTo(x+vw, y);
context.stroke();
context.lineWidth = 2;
context.strokeStyle = '#159';
context.beginPath();
context.moveTo(x, y);
for (var j = 0; j<d.length; j++)
{
context.lineTo(x, y - d[j]*scaleY);
//console.log(signalPoints[i]);
x+=pixelsPerSample;
}
context.stroke();
}
}
function setScaleY(scale)
{
scaleY = scale;
redrawSignals();
}
function setVisualSeconds(seconds)
{
visualSeconds = seconds;
drawEEGGrid();
updateData();
}
function setOffsetSeconds(offset)
{
offsetSeconds = offset;
updateData();
}
function updateData()
{
if (edf)
{
signalPoints = edf.read(offsetSeconds, visualSeconds);
}
redrawSignals();
}
var mouseX = 0;
var mouseY = 0;
function limitToBounds(value, min, max)
{
if (value < min) return min;
if (value > max) return max;
}
$(function()
{
$(window).resize(function() { resizeCanvasEEG(); redrawSignals(); });
resizeCanvasEEG();
$("body").mousemove(function(e)
{
mouseX = e.pageX;
mouseY = e.pageY;
});
})
</script>
</div>
<script>
var edf = null;
function base64ToBufferAsync(base64)
{
var dataUrl = "data:application/octet-binary;base64," + base64;
fetch(dataUrl)
.then(res => res.arrayBuffer())
.then(buffer =>
{
var buf = new Uint8Array(buffer);
edf = new EDF(buf);
offsetSeconds = 0;
maxSeconds = edf.duration;
updateScrollBar();
//console.log(edf);
samplingRate = edf.sampling_rate;
//signalPoints = edf.read(0, visualSeconds);
updateData();
//console.log("base64 to buffer: " + buf);
})
}
// buffer to base64
function bufferToBase64Async( buffer )
{
var blob = new Blob([buffer], {type:'application/octet-binary'});
console.log("buffer to blob:" + blob)
var fileReader = new FileReader();
fileReader.onload = function() {
var dataUrl = fileReader.result;
console.log("blob to dataUrl: " + dataUrl);
var base64 = dataUrl.substr(dataUrl.indexOf(',')+1)
console.log("dataUrl to base64: " + base64);
};
fileReader.readAsDataURL(blob);
}
function openFile(files)
{
console.log(files);
var reader = new FileReader();
reader.onload = function(e)
{
// The file's text will be printed here
var base64 = e.target.result;
base64 = base64.replace("data:application/octet-stream;base64,", "");
base64ToBufferAsync(base64);
};
reader.readAsDataURL(files[0]);
}
$(function() {
$("#select-visualSeconds").change(function()
{
setVisualSeconds(parseFloat($(this).val()));
});
$("#select-scaleY").change(function()
{
setScaleY(parseFloat($(this).val()));
});
$("#scroll").on('input', function()
{
setOffsetSeconds(parseFloat($(this).val()));
});
});
</script>
</body>
</html>