-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathio.js
More file actions
58 lines (48 loc) · 1.31 KB
/
io.js
File metadata and controls
58 lines (48 loc) · 1.31 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
async function uploadNodesEdges(json)
{
var file = new File([json], "foo.txt", {
type: "text/plain",
});
var data = new FormData();
data.append('file', file, "json.txt");
fetch('upload.php', {
method: 'POST',
body: data
})
}
function saveNetwork()
{
let jsonNodes = JSON.stringify(nodes);
let jsonEdges = JSON.stringify(edges);
var myjson = '{"nodes":' + jsonNodes + ', "edges":'+ jsonEdges +'}';
let myObject = JSON.stringify(myjson);
uploadNodesEdges(myObject);
console.log(nodes.length + " nodes & " + edges.length + " edges saved.");
}
async function loadNetwork()
{
const response = await fetch('dump/json.txt');
var data = await response.json();
if (response)
{
let str = JSON.parse(data);
populateNodeEdgeArray(str)
}
}
function populateNodeEdgeArray(json)
{
nodes = [], edges = [];
let edge, node;
for (let i = 0; i < json.nodes.length; i++)
{
node = json.nodes[i];
nodes.push(new Node(node.number, new Point (node.location.x, node.location.y),
new Vector(node.velocity.i, node.velocity.j), node.label, node.visibility ));
}
for (let i = 0; i < json.edges.length; i++)
{
edge = json.edges[i];
edges.push(new Edge(edge.source, edge.target));
}
console.log(nodes.length + " nodes & " + edges.length + " edges loaded.");
}