-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfileImpExp.js
38 lines (33 loc) · 1.08 KB
/
fileImpExp.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
function jsonifyGraph(){
graph = {nodes,adjList};
console.log(graph);
}
function showUploadButton(){document.getElementById('openFile').style.visibility = 'visible';}
function genTextFile() {
jsonifyGraph();
var blob = new Blob([JSON.stringify(graph)], {
type: "text/plain;charset=utf-8"
});
saveAs(blob, "graph.txt");
}
//TO DO
function impTextFile() {
while (graphEl.hasChildNodes()){graphEl.removeChild(graphEl.lastChild)}
var fr = new FileReader();
fr.onload = function () {
graph = null;
nodes = JSON.parse(this.result.split(',"adjList":')[0].substring(9,this.result.split(',"adjList":')[0].length-1)+"}");
adjList = JSON.parse(this.result.split(',"adjList":')[1].substring(0,this.result.split(',"adjList":')[1].length-1));
processGraph();
}
fr.readAsText(document.getElementById('openFile').files[0]);
document.getElementById('openFile').style.visibility = 'hidden';
}
function processGraph(){
for (n in nodes){
addN0de(n);
for (var g = 0; g<adjList[n].length;g++){
addEdge(n,adjList[n][g],false,true);
}
}
}