2
votes

I'm using the TreeLayout in JUNG for my graph. The user is able to make changes to the graph and it should then update and show the changes.

To enable a update, I create the graph again and set the layout using it:

graph = new DelegateForest<String, Integer>(
          new DirectedOrderedSparseMultigraph<String, Integer>());
createGraph()    //adds the vertices and edges to the graph
layout.setGraph(graph);
vv.repaint();

This does update the tree to what it should be, but the tree layout is lost.

Most of the nodes do appear in the right place, but the leaf nodes appear in random places. Is it possible to get back the tree structure that you get the first time you create the graph?

1
I believe the reason they are out of order is because JUNG's TreeLayout stores the vertices in a HashMap (where order is not guaranteed). I believe it would work if you copied JUNG's TreeLayout code and replaced it with TreeHashMaps. - sdasdadas
sdasdadas, that's incorrect. See below. - Joshua O'Madadhain

1 Answers

1
votes

You need to create a new TreeLayout instance with the updated graph, and update the visualization with the new TreeLayout instance. You're getting the new nodes in random places because the TreeLayout instance you have hasn't calculated positions for them.

This could be made more efficient for some types of graph updates (additions only). But it's not high on our list right now.