-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
61 lines (53 loc) · 1.93 KB
/
index.html
File metadata and controls
61 lines (53 loc) · 1.93 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
<!DOCTYPE html>
<html>
<head>
<title>fyp try</title>
<style>
body {
margin: 0;
overflow: hidden;
}
canvas {
background: red;
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div>
<label for="input_file">Specify a file:</label><br>
<input type="file" id="input_file">
</div>
<script src="three.js"></script>
<!--<script src="screenrenderer.js"></script>-->
<textarea id="content-target"></textarea>
<div>
<label>only accepts csv files that have the graph starting in the top most cell</label>
<label>results will appear in console</label>
</div>
<script src="classes.js"></script>
<script>
document.getElementById('input_file').addEventListener('change', getFile)
var inputManager = grapher.GetInputManager();
function getFile(event) {
const input = event.target
if ('files' in input && input.files.length > 0) {//works with repeat changes to file importing
placeFileContent(document.getElementById('content-target'),input.files[0]);//uses only the first file if multiple are chosen
}
}
function placeFileContent(target, file) {
//readFileContent(file).then(content => {target.value = content}).catch(error => console.log(error));
readFileContent(file).then(content => {inputManager.MakeNewBarGraph(content);target.value = content}).catch(error => console.log(error));
}
function readFileContent(file) {
const reader = new FileReader()
return new Promise((resolve, reject) => {
reader.onload = event => resolve(event.target.result);
reader.onerror = error => reject(error);
reader.readAsText(file);
})
}
</script>
</body>
</html>