문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top