-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
epsChart.js
53 lines (49 loc) · 1.72 KB
/
epsChart.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
class EPSChart {
constructor(elementId, label, color, hasFileUpload, eps){
this.wavesample = []
this.eps = eps
this.label = label
this.chart = new Chart(
document.getElementById(elementId + "_chart"),
{
type: 'line',
data: {
labels:[0,1],
datasets: [{
data: [0,0],
label: label,
fill: false,
borderColor: color,
tension: 0.1,
pointRadius: 0,
borderWidth: 1
}]
}
}
);
if(hasFileUpload){
let self = this;
document.getElementById(elementId).addEventListener('change', function(){
let reader = new FileReader();
reader.onload = function() {
let arrayBuffer = this.result;
self.wavesample = self.eps.parseWavFile(arrayBuffer)
self.chart.data.labels = Array.from( {length: self.wavesample.length}, (value, index) => index),
self.chart.data.datasets = [
{
data: self.wavesample.map( a => a/32767),
label: label,
fill: false,
borderColor: color,
tension: 0.1,
pointRadius: 0,
borderWidth: 1
}
]
self.chart.update()
}
reader.readAsArrayBuffer(this.files[0]);
}, false);
}
}
}