开发者

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.

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 a开发者_StackOverflownd clean way.

Can someone help me?


You may want to look at GraphViz, which is a program to do exactly this (render graphs). 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!)

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. Disclaimer - I do contribute to the project.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜