树可视化算法 [英] Tree visualization algorithm

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

问题描述

有一些算法树数据结构的可视化?我尝试使用Google,但无法找到任何。我是pretty的肯定,必须有一些算法,这不是简单的任务。或者有人有一些想法?

解决方案

假设:要被显示的每个节点,使得其高于其子节点为中心的

要实现这一点,计算每个节点,其中我定义为水平空间显示这些节点的整个子树所需的时间量,以使得它不与它的左或右的兄弟姐妹子树重叠的宽度。

这会导致:

 宽度= 1 + SUM(宽度儿童的节点)
 

所以,做一个深度优先遍历通过树来计算每个节点的宽度。要显示,做一个广度优先遍历绘制由水平的树级别。

这是如何去了解它的大概的了解。您可能需要调整的宽度计算取决于您希望如何渲染树的细节。

Is there some algorithm for tree data structure visualization? I tried googling, but couldnt find any. I'm pretty sure there has to be some algorithm for this not that simple task. Or anyone has some ideas?

解决方案

Assumption: you want each node to be displayed such that it is centered above its child nodes.

To achieve this, calculate the width of each node, which I define as the amount of horizontal space required to display this node's entire subtree, such that it doesn't overlap with its left or right siblings' subtrees.

This leads to:

width = 1 + sum(widths of children's nodes)

So, do a depth-first traversal through the tree to calculate each node's width. To display, do a breadth-first traversal to draw the tree level by level.

This is the rough idea of how to go about it. You might want to tweak the width calculation depending on the details of how you would like to render the tree.

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

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