算法有效地绘制树? [英] Algorithm for efficiently drawing trees?

查看:113
本文介绍了算法有效地绘制树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要画一个企业结构树(排序像一个族谱)在C#中。所有附属code是存在的。它是彩色的,互动的,和花式。唯一的麻烦是,居然决定在何处放置每个节点的算法是给我很多痛苦。

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 algorithm that actually decides where to put each node is giving me a lot of grief.

目前,盒子的尺寸100x50,我有一类叫做 StaffNode 从而重新presents在特定的X的一名工作人员,Y合作纵坐标。

For the moment, boxes are 100x50 in size, and I have a class called StaffNode which represents a staff member at a particular x,y co-ordinate.

该算法只需要创建一个名单,其中,StaffNode> 与相应的X和Y的

The algorithm just needs to create a List<StaffNode> with the appropriate x's and y's.

这是令人难以置信的棘手。

This is incredibly tricky.

基本上算法是沿着企业结构递归,所以左>对的,那么顶级>沿树上下来。显然,这是不好的,如果两个节点都在彼此的顶部上。

Basically the algorithm is recursive along the corporate structure, so left->right, then top->down along the tree. Obviously it is bad if two nodes are on top of one another.

我能想到的,可能会产生这样的一些算法:

I can think of a few algorithms that might produce something like this:

          *
    o         O
o o o o o     O
o         O O O O O
                O

而这样的事情会比较好,因为树是非常大的空间是非常有限的:

Whereas something like this would be better, since the tree is very large and space is very limited:

       *
    o     O
o o o o o O
o     O O O O O
            O

你们中有前画一棵树这样吗?如果你有我敢肯定你已经遇到了许多障碍我已经得到了。任何提示吗?到目前为止,我已经在上面花费了整整一天。

Have any of you had to draw a tree like this before? If you have I'm sure you've come across the many hurdles I've got. Any tips? So far I've spent an entire day on it.

推荐答案

有许多很好的算法,绘制树,其中每个展示了树木的某些不同的属性。如果你想炫耀层次,有这个code为WPF绘制层次。对于如何绘制图形和树木,考虑看<一个更广泛的讨论href="http://graphics.stanford.edu/courses/cs448b-02-winter/lectures/treesgraphs/tree.graph.pdf">these演讲稿的细节很多这样的算法。还有这些优秀的幻灯片涵盖类似的材料。

There are many good algorithms for drawing trees, each of which shows off some different property of trees. If you want to show off a hierarchy, there is this code for WPF that draws hierarchies. For a more general discussion of how to draw graphs and trees, considering looking at these lecture slides detailing many such algorithms. There's also these excellent slides covering similar material.

希望这有助于!

这篇关于算法有效地绘制树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆