如何在DOT中将节点放置在同一级别上? [英] How do I place nodes on the same level in DOT?

查看:90
本文介绍了如何在DOT中将节点放置在同一级别上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想同时渲染几棵树,并将所有根节点和所有叶节点置于同一级别.

I want to render several trees simultaneously and place all root nodes and all leaf nodes on the same level.

这是我正在尝试做的一个例子.根节点A和X处于同一级别,叶节点B,D和Z也在同一级别.

Here's an example of what I'm trying to do. Root nodes A and X are on the same level, and so are leaf nodes B, D, and Z.

我尝试如下将根部置于一个等级,然后将其置于另一个等级,但未成功:

I unsuccessfully tried putting roots in one rank and leaves in another as follows:

digraph G { 
rankdir = TB;
subgraph {
A -> B
A -> C
C -> D
X -> Y
rank = same; A; X;
rank = same; B; D; Y;
} /* closing subgraph */
}

得到了所有结果都在同一等级上的结果.

And got this outcome where everything is on the same rank.

关于我应该尝试什么的任何建议?我已经确定了根和叶.

Any suggestions about what I should be trying? I've already got roots and leaves identified.

推荐答案

rank = same; ...语句放在花括号中,例如:

Putting the rank = same; ... statements in braces, e.g.:

digraph G { 
  rankdir = TB;
  subgraph {
    A -> B
    A -> C
    C -> D
    X -> Y
    // note that rank is used in the subgraph
    {rank = same; A; X;}
    {rank = same; B; D; Y;}
  } /* closing subgraph */
}

...给出期望的结果:

... gives the desired result:

这篇关于如何在DOT中将节点放置在同一级别上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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