[英]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 algorithm 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 . 这是用SQL实现的算法 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.