Thanks a lot for this answer, it helps me to understand some concepts and I made some tries by myself but actually It would have been more a question about the option 1 : "obtaining a picture without opening a window" so we can use/export our generated graph the way we want after that..Sorry for the misunderstanding, I hope you could help me again.Nicolas2011/7/7 Antoine Dutot <antoine.dutot AT gmail.com>
I am not sure to understand. Do you want to obtain a picture without opening a window or only get the nodes position from the layout ?I assume it's the second option. The Layouts in GraphStream are made to run continuously (for dynamic graphs), and we lack layout algorithms. However it is possible to use the only layout available in GraphStream (SpringBox) in this way. Under is an example of this.Basically, you create the layout object, make it sink of the graph, and make the graph sink of the layout. This way the layout receives graph events (new nodes, new edges) and the graph receives position attributes ("xyz" attributes stored on nodes). The result is a graph with the correct positioning attributes (you can display this graph with a viewer where the automatic layout is disabled).To compute the layout with the SpringBox, you only have to call repeatedly layout.compute(), until the layout.getStabilization() method returns a number close to 1. Naturally, force-directed layouts may never reach 1, therefore you must fix a threshold, for example 0.9. The example under, displays the graph, but the viewer, here, is not related to the layout, and no automatic layout takes place. You can remove the code related to the viewer to obtain only a layout of the graph.The graph being directly modified by the layout, you can write it directly, and the "xyz" attributes will be stored with it.Hope this answers the question, else do not hesitate to repost,Regards,Antoineimport org.graphstream.algorithm.generator.DorogovtsevMendesGenerator;import org.graphstream.algorithm.generator.Generator;import org.graphstream.graph.Graph;import org.graphstream.graph.implementations.MultiGraph;import org.graphstream.stream.ProxyPipe;import org.graphstream.stream.thread.ThreadProxyPipe;import org.graphstream.ui.layout.Layout;import org.graphstream.ui.layout.springbox.SpringBox;import org.graphstream.ui.swingViewer.Viewer;public class TestLayoutAndViewer {public static void main(String args[]) {new TestLayoutAndViewer();}public TestLayoutAndViewer() {boolean loop = true;Graph graph = new MultiGraph("g1");Viewer viewer = new Viewer(new ThreadProxyPipe(graph));ProxyPipe fromViewer = viewer.newThreadProxyOnGraphicGraph();Layout layout = new SpringBox(false);graph.addAttribute("ui.antialias");graph.addAttribute("ui.stylesheet", styleSheet);fromViewer.addSink(graph);viewer.addDefaultView(true);// We make a loop between the layout and the graph.// Both listen at the other, however the graph// can listen only at attributes of the graph since// only the "xyz" positions are needed. GraphStream// handles such loops gracefully (this is called// graph synchronization).graph.addSink(layout);layout.addAttributeSink(graph);// Generate a graph.Generator gen = new DorogovtsevMendesGenerator();gen.addSink(graph);gen.begin();for (int i = 0; i < 500; i++)gen.nextEvents();gen.end();while (loop) {// Get the events from the viewer (is the view// closed, is the mouse pressed). This comes// under the form of attributes.fromViewer.pump();if (graph.hasAttribute("ui.viewClosed")) {loop = false;} else {try { Thread.sleep(20); } catch (Exception e) {}// We compute one step of the layout.// The more the layout is iterated, better// is the layout. Note that at the contrary// of automatic layout, the algorithm will// never end. You must stop it by yourself,// by observing the layout.getStabilization()// value (0 not stable, 1 fully stable).layout.compute();}}System.exit(0);}protected static String styleSheet ="node { size: 3px; fill-color: rgb(150,150,150); }"+ "edge { fill-color: rgb(100,100,100); }";}2011/7/7 Nicolas Quattropani <nicolas.quattropani AT gmail.com>
Hi,I would like to know if it's possible to dissociate the automatic calculation of the elements' placement and the display of the graph (ie get the viewer without displaying the swing windows).Indeed, we would like to set up our graph without displaying it it in a swing window in order to export it in an another format afterwards.We didn't found how to do that, is it possible ?Thanks for your time,Regards.Nicolas
Archives gérées par MHonArc 2.6.16.