Commit 69d5d279 authored by gsavin's avatar gsavin

Add methods to compute layout easily

parent 0dd009c3
...@@ -32,6 +32,9 @@ package org.graphstream.algorithm; ...@@ -32,6 +32,9 @@ package org.graphstream.algorithm;
import java.util.*; import java.util.*;
import org.graphstream.graph.*; import org.graphstream.graph.*;
import org.graphstream.stream.GraphReplay;
import org.graphstream.ui.layout.Layout;
import org.graphstream.ui.layout.springbox.SpringBox;
/** /**
* Lots of small often used algorithms on graphs. * Lots of small often used algorithms on graphs.
...@@ -1472,4 +1475,52 @@ public class Toolkit extends ...@@ -1472,4 +1475,52 @@ public class Toolkit extends
fillIncidenceMatrix(graph, matrix); fillIncidenceMatrix(graph, matrix);
return matrix; return matrix;
} }
/**
* Compute coordinates of nodes using a layout algorithm.
*
* @param g
* the graph
* @param layout
* layout algorithm to use for computing coordinates
* @param stab
* stabilization limit
*/
public static void computeLayout(Graph g, Layout layout, double stab) {
GraphReplay r = new GraphReplay(g.getId());
stab = Math.min(stab, 1);
r.addSink(layout);
r.replay(g);
layout.shake();
layout.compute();
while (layout.getStabilization() < stab)
layout.compute();
}
/**
* Compute coordinates of nodes using default layout algorithm (SpringBox).
*
* @param g
* the graph
* @param stab
* stabilization limit
*/
public static void computeLayout(Graph g, double stab) {
computeLayout(g, new SpringBox(), stab);
}
/**
* Compute coordinates of nodes using default layout algorithm and default
* stabilization limit.
*
* @param g
* the graph
*/
public static void computeLayout(Graph g) {
computeLayout(g, new SpringBox(), 0.99);
}
} }
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