Commit 7f8708ff authored by Jérome Perrin's avatar Jérome Perrin

graph_editor: Fix condition to trigger graph layout

 * a graph which nodes have an empty coordinate Object should be auto layout
 * our approach cannot layout a graph without edges
parent 47eba793
...@@ -47,16 +47,22 @@ ...@@ -47,16 +47,22 @@
springy_nodes = {}, springy_nodes = {},
drawn_nodes = {}, drawn_nodes = {},
min_x=100, max_x=0, min_y=100, max_y=0; min_x=100, max_x=0, min_y=100, max_y=0;
// if graph is empty, no need to layout
if (Object.keys(graph_data.edge).length === 0) {
return resolve(graph_data);
}
// make a Springy graph with our graph // make a Springy graph with our graph
$.each(graph_data.node, function(key, value) { $.each(graph_data.node, function(key, value) {
if (value.coordinate) { if (value.coordinate && value.coordinate.top && value.coordinate.left) {
// graph already has a layout, no need to layout again // graph already has a layout, no need to layout again
return resolve(graph_data); return resolve(graph_data);
} }
springy_nodes[key] = springy_graph.newNode({node_id: key}); springy_nodes[key] = springy_graph.newNode({node_id: key});
}); });
$.each(graph_data.edge, function(key, value) { $.each(graph_data.edge, function(key, value) {
springy_graph.newEdge(springy_nodes[value.source], springy_nodes[value.destination]); springy_graph.newEdge(
springy_nodes[value.source],
springy_nodes[value.destination]);
}); });
var layout = new Springy.Layout.ForceDirected(springy_graph, 400.0, 400.0, 0.5); var layout = new Springy.Layout.ForceDirected(springy_graph, 400.0, 400.0, 0.5);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment