simonalexander2005
simonalexander2005

Reputation: 4577

How to partially auto-layout a graphstream graph

If I have some fixed co-ordinates for some nodes in a Graphstream graph, can I get Graphstream to "fill in the gaps" and auto-layout those nodes that don't have a manually specified location?

for example:

Node n1 = graph.addNode("n1");
n1.setAttribute("xy",-0.1,53.35);
Node n2 = graph.addNode("n2");
graph.addEdge("n1n2",n1,n2);
Node n3 = graph.addNode("n3");
n3.setAttribute("xy",-0.4,56.35);
graph.addEdge("n2n3",n2,n3);

Given the above, n2 doesn't have a location specified. Is it possible to ask GraphStream to infer it, rather than just not displaying it because it doesn't know where it is?

If I use viewer.disableAutoLayout();, it won't display unlocated nodes; and if I use viewer.enableAutoLayout(); then it ignores my manual node locations.

Upvotes: 0

Views: 761

Answers (1)

simonalexander2005
simonalexander2005

Reputation: 4577

There are some settings that can be used to (sort-of) do this, although the inferred locations aren't averages of the known ones.

Adapting the above code:

Node n1 = graph.addNode("n1");
n1.setAttribute("xy",-0.1,53.35);
n1.addAttribute("layout.frozen");
Node n2 = graph.addNode("n2");
graph.addEdge("n1n2",n1,n2);
Node n3 = graph.addNode("n3");
n3.setAttribute("xy",-0.4,56.35);
n3.addAttribute("layout.frozen");
graph.addEdge("n2n3",n2,n3);

SpringBox layout = new SpringBox(false,new Random(0));
viewer.enableAutoLayout(layout);

Adding the layout.frozen attributes to those nodes with known locations, will prevent them from being moved by the layout manager.

The inferred locations / edge lengths, however, aren't necessarily on the same scale as those known ones. This can be adjusted by setting a layout.weight attribute on each node and each edge - as a number above 0. On the nodes, this sets how much each node repulses the adjacent nodes; and on edges it's a multiplier for the target edge length. See The Documentation for more details.

Upvotes: 1

Related Questions