-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.js
32 lines (32 loc) · 1.07 KB
/
export.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
function d3graph_to_gml(){
var gml_string = "graph\n[\n"
var options = Object.keys(data.nodes[0])
for (var i = 0; i < n; ++i){
node = nodes[i]
gml_string += "node\n"
gml_string += "[\n"
for (option of options){
if (node[option].constructor !== Array || typeof node[option] !== 'object') {
if (typeof node[option] === 'string' || node[option] instanceof String){
gml_string += option + " " + '"' + node[option] + '"' + "\n"
}
else {
gml_string += option + " " + node[option] + "\n"
}}}
gml_string += "alpha " + nodes[i+n].x + "\n"
gml_string += "beta " + nodes[i+n].y + "\n"
gml_string += "]\n"
}
for (var i = 0; i < data.links.length; ++i){
link = data.links[i], source = link.source, target = link.target;
gml_string += "edge\n"
gml_string += "[\n"
gml_string += "source " + source.id + "\n"
gml_string += "target " + target.id + "\n"
gml_string += "]\n"
}
gml_string += "]"
var blob = new Blob([gml_string],
{ type: "text/plain;charset=utf-8" });
saveAs(blob, "graph.gml");
}