如何使用 JUNG 绘制树层次结构?

发布于 2024-08-28 04:16:28 字数 167 浏览 7 评论 0原文

我是 JUNG 的新手。我尝试使用 TreeLayout 绘制树图,但树永远不会像真正的树一样出现。每次树看起来都不一样。我怎样才能让这棵树看起来像一棵普通的树,根在顶部,根在顶部?从它下降的其余节点?

I'm new to JUNG. I tried to draw a graph of a tree using the TreeLayout but the tree never comes out like a real tree. Every time the tree looks different. How can I make the tree look like a normal tree with the root on top & the rest of the nodes descending from it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

金橙橙 2024-09-04 04:16:28

将顶点添加到图形后,您必须初始化 TreeLayout ,我尝试过,它对我有用。

你必须做如下的事情:(请注意,这是我的 1 年前的代码,你可能会发现它有点过时)

Layout<GraphVertex, GraphEdge> layout; //create a layout
layout = new TreeLayout<GraphVertex, GraphEdge>((Forest<GraphVertex, GraphEdge>) g); 
// initialize your layout using the graph you created, which has to be of type forest
vv.setGraphLayout(layout); 
// set the layout of the visualization viewer you are using to be the layout you just created (the tree layout)

GraphVertex 是表示顶点的类在图中,GraphEdge 表示图中的边。

You have to Initialize the TreeLayout after adding the Vertexes to the graph, I tried that and it worked for me.

You have to do something like the following: (please note that this is a 1 year old code that i had, you might find it to be a little out dated)

Layout<GraphVertex, GraphEdge> layout; //create a layout
layout = new TreeLayout<GraphVertex, GraphEdge>((Forest<GraphVertex, GraphEdge>) g); 
// initialize your layout using the graph you created, which has to be of type forest
vv.setGraphLayout(layout); 
// set the layout of the visualization viewer you are using to be the layout you just created (the tree layout)

GraphVertex Is the class which represents a vertex in the graph, GraphEdge represents the edges in your graph.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文