I’m using JUNG ( http://jung.sourceforge.net/index.html ) to draw graphics in java. The software is great but I have a small question. How can I be sure that the displayed graph is each time the same (no changes is architecture or position)?
To be more specific: the graph model (data to be represented) doesn’t change but its representation changes each time I hit the “View graph” button 🙂 [some vertices are in other places, for example: sometimes in the upper part of the window, sometimes in the lower part ]
Thank you,
Iulian
A StaticLayout lets you specify a vertex to Point2D transformer. This will allow you to control where the vertices are placed and should do what you want to do. You should use the following constructor:
You’ll need to implement your own transformer that takes in a vertex and returns the location where the vertex should appear. An example of its in use:
Added 20 Feb 2010:
An alternative is to use a PersistentLayoutImpl to save the locations of the vertices to a file. However, you need to also somehow persist the graph to get which vertices and vertices were on there (this needs to persisted separately). There are number of classes for persisting the graph in edu.uci.ics.jung.io. This is an example that uses just PersistentLayoutImpl:
Note that the example does not persist the vertices and edges yet, as I haven’t had the time to figure out how use the classes in edu.uci.ics.jung.io yet.