SimulationVue/graphUtils.js
2021-08-10 17:32:42 +02:00

27 lines
614 B
JavaScript

function edgelistToDot(name, inp){
var output = "strict graph \"" + name + "\" {\n";
for(e in inp){
e = inp[e];
output += e[0] + " -- " + e[1] + ";\n";
}
output += "}";
return output;
}
function dotToEdgelist(graph){
var outList = [];
graph = graph.split("\n");
//var name = graph[0].split(" ")[2];
//name = name.slice(1, name.length - 1);
for (var i = 0; i < graph.length - 1; i++){
if(i == 0){
continue;
}
var nodes = graph[i].split("--");
var node1 = Number(nodes[0]);
var node2 = Number(nodes[1].slice(0, nodes[1].length - 1));
outList.push([node1, node2]);
}
return outList;
}