graphviz三个行列布局与子图
我试图将元素定位在自动生成的流程图的形式。 一般而言,inputs
(绿色)应该在最左边,outputs
(红色)在最右边,其余的应按照布局放置在中间。 我为此使用rank=source
和rank=sink
。 在标准图形中,它很好地工作。graphviz三个行列布局与子图
但是,当我开始嵌套图形时,rank=source
似乎不起作用。我期望<>(电,开关,房间温度)的三个输入被放置在最左边(因为它在子图内发生)以及子图+状态(棕色圆圈)和输入和输出之间的蓝色框。
有没有指定“等级=中心”(或类似的东西?)
我已经通过了documentation,但没有找到正确的属性(并在指定他们)的方式。
digraph MyGraph {
node [fontsize=8 margin=".1,.01" width=.5 height=.5 shape=box]
edge [fontsize=8]
rankdir=LR;
ranksep = .25;
nodesep= .5;
subgraph cluster_4386357488 {
label = " <<GrowLamp>>"
style=solid
{rank=source;
4386357544 [label="electricity" style=filled fillcolor="#b5fed9"]
4386357712 [label="room_temperature" style=filled fillcolor="#b5fed9"]
4386357768 [label="switch" style=filled fillcolor="#b5fed9"]
}
{
4386357880 [label="off" style=filled fillcolor="#e2cbc1" shape=doublecircle]
4386357936 [label="on" style=filled fillcolor="#e2cbc1" shape=circle]
4386357656 [label="on_time" style=filled fillcolor="#d2ceef"]
}
{rank=sink;
4386357600 [label="light" style=filled fillcolor="#fcc5b3"]
4386357824 [label="temperature" style=filled fillcolor="#fcc5b3"]
}
4386357880 -> 4386357936
4386357936 -> 4386357880
{
subgraph cluster_4386357992 {
label = "<<Adder>>"
style=dashed
{rank=source;
4386358048 [label="heat_in" style=filled fillcolor="#b5fed9"]
4386358104 [label="room_temp_in" style=filled fillcolor="#b5fed9"]
}
{
4386358216 [label="state" style=filled fillcolor="#e2cbc1" shape=doublecircle]
}
{rank=sink;
4386358160 [label="temperature" style=filled fillcolor="#fcc5b3"]
}
4386358216 -> 4386358160 [style="dashed"]
}
subgraph cluster_4386358328 {
label = "<<HeatElement>>"
style=solid
{rank=source;
4386358384 [label="electricity" style=filled fillcolor="#b5fed9"]
}
{
4386358496 [label="on" style=filled fillcolor="#e2cbc1" shape=doublecircle]
}
{rank=sink;
4386358440 [label="heat" style=filled fillcolor="#fcc5b3"]
}
4386358496 -> 4386358440 [style="dashed"]
}
subgraph cluster_4386358608 {
label = "<<LightElement>>"
style=solid
{rank=source;
4386358664 [label="electricity" style=filled fillcolor="#b5fed9"]
}
{
4386358776 [label="off" style=filled fillcolor="#e2cbc1" shape=doublecircle]
4386358832 [label="on" style=filled fillcolor="#e2cbc1" shape=circle]
}
{rank=sink;
4386358720 [label="light" style=filled fillcolor="#fcc5b3"]
}
4386358776 -> 4386358832
4386358832 -> 4386358776
4386358776 -> 4386358720 [style="dashed"]
4386358832 -> 4386358720 [style="dashed"]
}
4386358160 -> 4386357824
4386357712 -> 4386358104
4386358440 -> 4386358048
4386358720 -> 4386357600
4386357936 -> 4386358384 [style="dashed"]
4386357936 -> 4386358664 [style="dashed"]
4386357936 -> 4386357656 [style="dashed"]
}
}
有希望的解决方案: 这里是我想和落得什么。请注意,绿框在各自子图的左侧如何,红框在右侧。在这之间应该有其他的元素,由graphviz定位。
您可以通过添加可见边的三个输入连接到图中的其余部分,以便在graphviz的布局算法可以正确计算出它们的排名获得你想要的布局。通过将style=invis
添加到边缘格式中,可以使任何边缘不可见。
digraph MyGraph {
node [fontsize=8 margin=".1,.01" width=.5 height=.5 shape=box]
edge [fontsize=8]
rankdir=LR;
ranksep = .25;
nodesep= .5;
subgraph cluster_4386357488 {
label = " <<GrowLamp>>"
style=solid
{rank=source;
4386357544 [label="electricity" style=filled fillcolor="#b5fed9"]
4386357712 [label="room_temperature" style=filled fillcolor="#b5fed9"]
4386357768 [label="switch" style=filled fillcolor="#b5fed9"]
}
{
4386357880 [label="off" style=filled fillcolor="#e2cbc1" shape=doublecircle]
4386357936 [label="on" style=filled fillcolor="#e2cbc1" shape=circle]
4386357656 [label="on_time" style=filled fillcolor="#d2ceef"]
}
{rank=sink;
4386357600 [label="light" style=filled fillcolor="#fcc5b3"]
4386357824 [label="temperature" style=filled fillcolor="#fcc5b3"]
}
4386357880 -> 4386357936
4386357936 -> 4386357880
#invisible edges added to achieve correct layout
4386357544 -> 4386357880 [style="invis"]
4386357712 -> 4386357880 [style="invis"]
4386357768 -> 4386357880 [style="invis"]
{
subgraph cluster_4386357992 {
label = "<<Adder>>"
style=dashed
{rank=source;
4386358048 [label="heat_in" style=filled fillcolor="#b5fed9"]
4386358104 [label="room_temp_in" style=filled fillcolor="#b5fed9"]
}
{
4386358216 [label="state" style=filled fillcolor="#e2cbc1" shape=doublecircle]
}
{rank=sink;
4386358160 [label="temperature" style=filled fillcolor="#fcc5b3"]
}
4386358216 -> 4386358160 [style="dashed"]
}
subgraph cluster_4386358328 {
label = "<<HeatElement>>"
style=solid
{rank=source;
4386358384 [label="electricity" style=filled fillcolor="#b5fed9"]
}
{
4386358496 [label="on" style=filled fillcolor="#e2cbc1" shape=doublecircle]
}
{rank=sink;
4386358440 [label="heat" style=filled fillcolor="#fcc5b3"]
}
4386358496 -> 4386358440 [style="dashed"]
}
subgraph cluster_4386358608 {
label = "<<LightElement>>"
style=solid
{rank=source;
4386358664 [label="electricity" style=filled fillcolor="#b5fed9"]
}
{
4386358776 [label="off" style=filled fillcolor="#e2cbc1" shape=doublecircle]
4386358832 [label="on" style=filled fillcolor="#e2cbc1" shape=circle]
}
{rank=sink;
4386358720 [label="light" style=filled fillcolor="#fcc5b3"]
}
4386358776 -> 4386358832
4386358832 -> 4386358776
4386358776 -> 4386358720 [style="dashed"]
4386358832 -> 4386358720 [style="dashed"]
}
4386358160 -> 4386357824
4386357712 -> 4386358104
4386358440 -> 4386358048
4386358720 -> 4386357600
4386357936 -> 4386358384 [style="dashed"]
4386357936 -> 4386358664 [style="dashed"]
4386357936 -> 4386357656 [style="dashed"]
}
}
}
随着2.38版本dot.exe
你应该得到这样一个图:
我一直在试图理解为什么解决方案与不可见边缘一起工作,但不是没有它们。我的猜测是,如果点连接到图的其余部分,点只能对齐节点,但我不确定。 你能告诉我,如果这是正确的? @Craig – stklik
@ S.K.-我对这个问题的理解来自我在回答你的问题时所做的一些测试。 “room_temperature”和“room_temp_in”之间的边缘导致“dot”将“room_temperature”放置在比“room_temp_in”低一个等级的地方。这似乎忽略了这个节点在最低级别的定位,可能是一个错误。它还迫使“电力”和“开关”节点放置在相同的等级上,而不是最低的等级上。如果从原始文件中删除此边缘,则会得到所需的布局,尽管缺少一个边缘。 – Craig
没有一个排名=中心,但也有其他方法来获得节点对准你会的方式喜欢。我有一个关于如何帮助你的想法,但我对于希望的安排很不清楚。你想要左边的所有绿色框,中间的棕色圆圈和右边的橙色框?或者你只是以这种方式wan some他们?你可以添加一个你想要的元素排列的粗略草图吗? – Craig
我添加了一个图像来解释我想要的。在每个盒子里,绿色框(输入)应该在左边,红色框(输出)在右边,其余的在中心(如'dot'看起来合适)。因此,应该有一种从左到右的“流动”。 – stklik