JUNG树布局动态更新 [英] JUNG Tree Layout dynamic update

查看:102
本文介绍了JUNG树布局动态更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JUNG中的TreeLayout作为图形.用户可以对图形进行更改,然后它应该更新并显示更改.

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?

推荐答案

您需要使用更新后的图形创建新的TreeLayout实例,并使用新的TreeLayout实例更新可视化效果.您将新节点放置在随机位置,因为您尚未为它们的TreeLayout实例计算位置.

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.

这篇关于JUNG树布局动态更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆