-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (71 loc) · 1.8 KB
/
script.js
File metadata and controls
78 lines (71 loc) · 1.8 KB
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
let input = document.querySelector('input');
//let textarea = document.querySelector('textarea');
let lines = [];
let line = -5;
let data = [];
function updateData() {
line += 5;
var string = lines[line].split(" ");
data = [string[5], string[6], string[7]];
}
function getX() {
return data[0];
}
function getY() {
return data[1];
}
function getZ() {
return data[2];
}
input.addEventListener('change', () => {
let files = input.files;
if(files.length == 0) return;
const file = files[0];
let reader = new FileReader();
reader.onload = (e) => {
const file = e.target.result;
lines = file.split(/\r\n|\n/);
updateData();
Plotly.newPlot('all',[{
y:[getX()],
type:'line',
name:'X acceleration',
line: {
color: 'rgb(255, 0, 0)',
width:1
}
}, {
y:[getY()],
type:'line',
name:'Y acceleration',
line: {
color: 'rgb(0, 255, 0)',
width:1
}
}, {
y:[getZ()],
type:'line',
name:'Z acceleration',
line: {
color: 'rgb(0, 0, 255)',
width:1
}
}], {
title:'Acceleration vs. Time',
xaxis: {
title:'Time'
},
yaxis: {
title:'Meters/Seconds^2'
}
}, {
responsive: true
});
setInterval(function() {
updateData();
Plotly.extendTraces('all', { y: [[getX()],[getY()],[getZ()]]}, [0, 1, 2])
}, 2);
};
reader.onerror = (e) => alert(e.target.error.name);
reader.readAsText(file);
});