开发者

Java Library or algorithm for calculating coordinates of tree nodes / drawing

I am looking for a library which would give me the exact coordinates of each node in a tree (any tree, not just binary trees).

Let's say I define the tree in the following notation

(() (() (() () ())) 

And some library gives me the coordinates like this:

[500 0]([200 50]() [600 50]([500 100]() [750 100]([600 150]() [700 150]() [800 150]())) 

or any other notation which uniquely represents a tree.

This kind of library would enable a space-efficient drawing of trees and would also solve the problem of overlapping nodes and links. For example, if a tree is a list infact, I would like that library to take that into account and arrange nodes in a single column or row, to save space.

If nothing similar exists, an alg开发者_如何学Pythonorithm would also come in handy, provided that it can be implemented relatively easily.


I think the Nested Set model may help you.

The algorithm is fairly simple, and very efficient for reads, although updates to the tree are a little more expensive, because the boundaries of the nodes have to be updated in a cascading fashion. Here is the algorithm implemented in SQL.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜