JUNG Tree Layout dynamic update

荒凉一梦 提交于 2019-12-11 01:47:33

问题


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:


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.



来源:https://stackoverflow.com/questions/17254673/jung-tree-layout-dynamic-update

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!