Algorithm for efficiently drawing trees?

前端 未结 2 586
温柔的废话
温柔的废话 2021-02-04 11:58

I need to draw a corporate structure tree (sort-of like a family tree) in C#. All the ancillary code is there. It is colored, interactive, and fancy. The only trouble is the alg

2条回答
  •  花落未央
    2021-02-04 12:32

    You could use an iterative approach. Lay out the tree using something like the first example you used above. Then move nodes or subtrees closer to each other, while making sure no constraints are violated (eg: Nodes cannot overlap, child nodes must be below parent nodes).

    Pros:

    • Simple algorithm.
    • Gets a good-enough solution.
    • Can be applied continuously to a changing tree.
    • Can be made to look cool.

    Cons:

    • May need many iterations to look good.
    • May not find optimal solution (gets caught in a local maximum)

提交回复
热议问题