【发布时间】:2014-01-26 13:35:00
【问题描述】:
预脚本
...当我完成这些示例时,我看到了'roundtrip' flow topic,它看起来不错。 既然我已经把这个放在这里了,不妨问一下:还有其他选择吗?
原帖
在子图中有没有办法在矩形布局中自动布局节点?
例如,假设我有给定的结构:
digraph
{
rankdir="LR";
node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];
a -> b -> c -> d -> e -> f -> g -> h -> b;
}
这产生了图表
我的目标是让它们排列成一个矩形,每行三个节点,形成
如果我尝试限制排名并更改rankdir,它不会像预期的那样(我假设因为你不能像这样更改rankdir):
digraph
{
rankdir="LR";
node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];
a -> b -> c -> d -> e -> f -> g -> h -> b;
subgraph
{
rankdir="TB";
rank="same";
c; d; e;
}
subgraph
{
rankdir="TB";
rank="same";
f; g; h;
}
}
如果我手动完成并按照我的意愿分配排名,它会起作用:
digraph
{
rankdir="LR";
node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];
a -> b -> c -> d -> e -> f -> g -> h -> b;
{ rank="same"; c; h; }
{ rank="same"; d; g; }
{ rank="same"; e; f; }
}
编辑
刚刚试了下方法,效果不错。我确实必须取消最右边的边缘以防止它形成不对称的形状,但总体而言就像一个魅力(而且更直观)!
digraph
{
rankdir="LR";
node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];
a -> b -> c -> d -> e;
e -> f [ constraint="false" ];
b -> h -> g -> f [ dir="back" ];
}
【问题讨论】: