我有一个以树为骨干的图。例如,我有一个节点 A,其子节点 B、C 和 D。假设图形是自上而下绘制的,A 将在一个级别上,然后是 B、C 和 D。我想强制 graphviz在他们的等级内按 B、C、D 的顺序排列它们。这可能吗?如果是这样,怎么做?
如果只有 A、B、C 和 D,我只需将 B、C 和 D 按顺序放入输入点文件中即可获得此效果。但是,如果在 B、C 和/或 D 之外还有其他边,则有时订单会被打乱。这就是我想避免的。
我有一个以树为骨干的图。例如,我有一个节点 A,其子节点 B、C 和 D。假设图形是自上而下绘制的,A 将在一个级别上,然后是 B、C 和 D。我想强制 graphviz在他们的等级内按 B、C、D 的顺序排列它们。这可能吗?如果是这样,怎么做?
如果只有 A、B、C 和 D,我只需将 B、C 和 D 按顺序放入输入点文件中即可获得此效果。但是,如果在 B、C 和/或 D 之外还有其他边,则有时订单会被打乱。这就是我想避免的。
这可以通过如图所示的“不可见”边缘来实现。请注意描述它如何工作的评论。
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;
}
}
你不需要那些魔法rank1
和rank2
.
只是:
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;
}
}
我碰到了同样的障碍,发现魔法咒语是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];
}