graphviz-如何在一个周期中以矩形布局排列节点? [英] graphviz - How to arrange nodes in a cycle in a rectangular layout?
问题描述
前脚本
...刚完成这些示例时,我看到了 往返"流程主题,看起来不错. 既然我已经把它放在这里了,不妨问:还有其他选择吗?
... And just when I finished producing these example, I saw the 'roundtrip' flow topic, which looks nice. Since I've already put this on here, might as well ask: are there another alternatives?
原始帖子
在子图中有没有一种方法可以自动在矩形布局中布置节点?
Is there a way to automatically lay out nodes in a rectangular layout when in a subgraph?
例如,假设我具有给定的结构:
As an example, say I have the given structure:
digraph
{
rankdir="LR";
node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];
a -> b -> c -> d -> e -> f -> g -> h -> b;
}
这产生了图
我的目标是使它们排列成一个矩形,该矩形由三个节点组成的行,形成
My goal is to have them line up in a rectangle with rows of three nodes, forming
如果我尝试限制排名并更改rankdir
,则不会达到预期的效果(我想是因为您不能像这样更改rankdir
):
If I try to constrain the rank and change the rankdir
, it is not as expected (I'm assuming because you can't change rankdir
like this):
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;
}
}
如果我手动进行并根据需要分配等级以进行排队,那么它会起作用:
If I go through and manually and assign rank to line up as I desired, it works:
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; }
}
修改
只需尝试一下该方法即可,效果很好.我确实必须取消约束最右侧的边缘以防止其形成不对称的形状,但总体上却像是一种魅力(而且更加直观)!
Just tried out the method, worked well. I did have to unconstrain the right-most edge to prevent it from making an asymetric shape, but overall worked like a charm (and much more intuitive)!
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" ];
}
推荐答案
不确定将其放在哪里,但我会继续将其张贴在此处作为附带答案.
Not sure where to put this, but I will go ahead and post it here as a side answer.
我尝试了一个更大的周期:
I tried out a larger cycle:
digraph
{
rankdir="LR";
node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];
x -> y;
y -> aa [ constraint="false" ];
aa -> ab -> ac -> ba;
{ rank="same"; ba -> bb -> bc -> ca; }
da -> cc -> cb -> ca [ dir="back" ];
{ rank="same"; aa -> dc -> db -> da [ dir="back" ]; };
}
还尝试了蛇形图案:
digraph
{
rankdir="LR";
node [ shape="circle", style="bold, filled", fillcolor="#dddddd" ];
x -> y;
y -> aa [ constraint="false" ];
aa -> ab -> ac;
ac -> ba [ constraint="false" ];
bc -> bb -> ba [ dir="back" ];
bc -> ca [ constraint="false" ];
ca -> cb -> cc;
cc -> da [ constraint="false" ];
dc -> db -> da [ dir="back" ];
y -> dc [ dir="back", constraint="false" ];
// { rank="same"; aa; bc; ca; dc; };
}
这还是有点混乱.
这篇关于graphviz-如何在一个周期中以矩形布局排列节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!