-
Notifications
You must be signed in to change notification settings - Fork 0
/
nwb.js
58 lines (49 loc) · 1.45 KB
/
nwb.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
export default {
template: `
<canvas ref="canvas" width="800" height="400"></canvas>`,
props: {
url: String,
path: String,
},
data() {
return {
canvas: null,
ctx: null,
};
},
mounted() {
console.log("Mounted");
this.canvas = this.$el;
this.ctx = this.canvas.getContext('2d');
},
delete() {
console.log("Unmounted");
},
methods: {
display(channels, start, duration) {
console.log("nwb params:", channels, start, duration);
const worker = new Worker("/static/worker.js", { type: "module" });
worker.postMessage([this.url, this.path, channels, start, duration]);
worker.onmessage = (e) => {
console.log("Result:", e.data);
const { width, height } = this.canvas;
const channelHeight = height / channels.length;
this.ctx.clearRect(0, 0, width, height);
for (let c = 0; c < channels.length; c++) {
const channelTop = c * channelHeight;
this.ctx.beginPath();
this.ctx.moveTo(0, channelTop + channelHeight / 2);
// var scale = 65535;
var scale = 16384;
for (let t = 0; t < duration; t++) {
const x = (t / duration) * width;
const y = channelTop + channelHeight / 2 - ((e.data[c * channels.length + t] / scale) * channelHeight) / 2;
this.ctx.lineTo(x, y);
console.log(x, y);
}
this.ctx.stroke();
}
}
}
}
}