简体   繁体   English

如何使用Java 2D组织图节点进行绘制

[英]how to organize graph nodes to draw using java 2d

I created a program that builds and draw nested cyclic graphs (with undirected edges) in a JFrame using java awt. 我创建了一个程序,该程序使用java awt在JFrame中构建和绘制嵌套的循环图(具有无方向的边)。

The problem is that if the position of the nodes is not explicitly specified, or created at random, the graph becomes very messy, with edges crossing and vertex colliding. 问题在于,如果未明确指定或随机创建节点的位置,则图将变得非常混乱,边缘交叉且顶点碰撞。

I would like to implement an algorithm for repositioning to better distribute the nodes, in a more homogeneous and clean way. 我想实现一种用于重新定位的算法,以更均匀和整洁的方式更好地分配节点。

Can someone help me? 有人能帮我吗?

You may want to look at GraphViz , which is a program to do exactly this (render graphs). 您可能想看看GraphViz ,这是一个可以完全做到这一点的程序(渲染图)。 It has a Java API, so you could integrate it into your program, and it's open-source, so if you'd rather implement a solution yourself, perhaps their code could provide some inspiration (just remember to check the license!) 它具有Java API,因此您可以将其集成到您的程序中,并且它是开源的,因此,如果您希望自己实施解决方案,则也许它们的代码可以提供一些启发(请记住要检查许可证!)

In addition, their website has a list of resources pertaining to graph drawing theory , which sounds exactly like what you need. 此外,他们的网站上还列出了与图形绘制理论有关的资源 ,这听起来很像您所需要的。

JGraphX is native Java and includes automatic layouting options. JGraphX是本机Java,并且包含自动布局选项。 Disclaimer - I do contribute to the project. 免责声明-我确实为该项目做出了贡献。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM