如何在graphviz的点中控制级别节点顺序?

Rob*_*man 16 dot graphviz graph-layout

我有一个以树为主干的图表.所以我有,例如一个带有子B,C和D的节点A.假设图形是自上而下绘制的,A将在一个级别上,然后是B,C和D.我想强制graphviz到在他们的等级内按B,C,D顺序排列.这可能吗?如果是这样,怎么样?

如果只有A,B,C和D,我可以通过在输入点文件中按顺序放入B,C和D来获得此效果.但是如果B,C和/或D中有其他边缘,有时订单会被扰乱.这就是我想要避免的.

Tom*_*rvo 18

这可以通过所示的"不可见"边缘来实现.请注意描述其工作原理的评论.

digraph test{

// make invisible ranks
rank1 [style=invisible];
rank2 [style=invisible];

// make "invisible" (white) link between them
rank1 -> rank2 [color=white];

// declare nodes all out of desired order
A -> D;
A -> B;
A -> C;
A -> E;

// even these new connection don't mess up the order
B -> F -> G;
C -> F -> G;

{
rank = same;
// Here you enforce the desired order with "invisible" edges and arrowheads
rank2 -> B -> C -> D -> E [ style=invis ];
rankdir = LR;
}
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述


jkm*_*acc 18

为了帮助填写@ TomServo的答案(对于那些在"排名"中苦苦挣扎的人),我已经看到了隐形边缘:

添加<code> rank1 </ code>和<code> rank2 </ code>之后.

这是以前的样子:

在此输入图像描述


joe*_*log 15

我遇到了同样的障碍,并发现魔法咒语是ordering=out

我的完整示例如下所示:

digraph game_tree {
node [shape = circle, ordering=out];
f, h [shape=doublecircle, color=red];
k, n [shape=doublecircle, color=blue];
l, m [shape=doublecircle];
a -> b [label=1];
a -> c [label=2];
a -> d [label=3];
b -> e [label=4];
b -> f [label=5];
c -> g [label=4];
c -> h [label=5];
d -> i [label=4];
d -> j [label=5];
e -> k [label=6];
g -> l [label=6];
i -> m [label=7];
j -> n [label=8];
}
Run Code Online (Sandbox Code Playgroud)

图可视化树

  • 恕我直言,这比上面提出的其他答案要干净得多。使用 `fontcolor="transparent"` 会使标签消失以获得更清晰的结果。 (3认同)
  • 如果您不需要标签,只需执行 `a -&gt; b;` 等,而不是 `a -&gt; b [label=1];` (2认同)

Mik*_*lov 8

你不需要那些魔法rank1rank2

只是:

  1. 像往常一样制作图表。
  2. 在子图中再次添加节点。
digraph test{

// declare nodes all out of desired order
A -> D;
A -> B;
A -> C;
A -> E;

B;C;D;E;

// even these new connection don't mess up the order
B -> F -> G;
C -> F -> G;

{
rank = same;
// Here you enforce the desired order with "invisible" edges and arrowheads
edge[ style=invis];
B -> C -> D -> E ;
rankdir = LR;
}
}
Run Code Online (Sandbox Code Playgroud)