带子图的graphviz三级布局

带子图的graphviz三级布局,graphviz,rank,dot,Graphviz,Rank,Dot,我试图以自动生成的流程图的形式定位元素。 通常,输入(绿色)应位于最左侧,输出(红色)应位于最右侧,其余应根据布局放置在中间。 我正在使用rank=source和rank=sink进行此操作。 在标准图形中,它工作得很好 但是,当我开始嵌套图形时,rank=source似乎不起作用。我希望(电、开关、室温)的三个输入放在最左边(因为它发生在子图中),子图+状态(棕色圆圈)和输入与输出之间的蓝色框 有没有办法指定“排名=中心”(或类似的东西?) 我已经查看了,但是没有找到正确的属性(以及在哪里指定

我试图以自动生成的流程图的形式定位元素。 通常,
输入(绿色)应位于最左侧,
输出(红色)应位于最右侧,其余应根据布局放置在中间。
我正在使用
rank=source
rank=sink
进行此操作。 在标准图形中,它工作得很好

但是,当我开始嵌套图形时,
rank=source
似乎不起作用。我希望(电、开关、室温)的三个输入放在最左边(因为它发生在子图中),子图+状态(棕色圆圈)和输入与输出之间的蓝色框

有没有办法指定“排名=中心”(或类似的东西?)

我已经查看了,但是没有找到正确的属性(以及在哪里指定它们)

有向图{
节点[fontsize=8页边距=“.1,.01”宽度=.5高度=.5形状=框]
边[fontsize=8]
rankdir=LR;
ranksep=.25;
nodesep=.5;
子图簇_4386357488{
label=“”
样式=实体
{rank=来源;
4386357544[label=“electronic”style=fillfillcolor=“#b5fed9”]
4386357712[label=“室温”style=fillfillcolor=“#b5fed9”]
4386357768[label=“switch”style=fillfillcolor=“#b5fed9”]
}
{
4386357880[label=“off”style=fillfillcolor=“#e2cbc1”shape=doublecircle]
4386357936[label=“on”style=fillfillcolor=“#e2cbc1”shape=circle]
4386357656[label=“on_time”style=fillfillcolor=“#d2ceef”]
}
{rank=sink;
4386357600[label=“light”style=fillfillcolor=“#fcc5b3”]
4386357824[label=“temperature”style=fillfillcolor=“#fcc5b3”]
}
4386357880 -> 4386357936
4386357936 -> 4386357880
{
子图簇_4386357992{

label=“您可以通过添加不可见边来获得所需的布局,将三个输入连接到图表的其余部分,以便graphviz布局算法可以正确计算它们的秩。您可以通过向边格式添加
style=invi
来使任何边不可见

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"]
    }

}
}
有向图{
节点[fontsize=8页边距=“.1,.01”宽度=.5高度=.5形状=框]
边[fontsize=8]
rankdir=LR;
ranksep=.25;
nodesep=.5;
子图簇_4386357488{
label=“”
样式=实体
{rank=来源;
4386357544[label=“electronic”style=fillfillcolor=“#b5fed9”]
4386357712[label=“室温”style=fillfillcolor=“#b5fed9”]
4386357768[label=“switch”style=fillfillcolor=“#b5fed9”]
}
{
4386357880[label=“off”style=fillfillcolor=“#e2cbc1”shape=doublecircle]
4386357936[label=“on”style=fillfillcolor=“#e2cbc1”shape=circle]
4386357656[label=“on_time”style=fillfillcolor=“#d2ceef”]
}
{rank=sink;
4386357600[label=“light”style=fillfillcolor=“#fcc5b3”]
4386357824[label=“temperature”style=fillfillcolor=“#fcc5b3”]
}
4386357880 -> 4386357936
4386357936 -> 4386357880
#添加不可见边以实现正确布局
4386357544->4386357880[style=“invis”]
4386357712->4386357880[style=“invis”]
4386357768->4386357880[style=“invis”]
{
子图簇_4386357992{

标签=”没有一个等级=中心,但是还有其他方法来让这些节点来调整你想要的方式。我有一个关于如何帮助你的想法,但是我对你想要的安排很不清楚。你想要左边的所有绿色盒子,中间的棕色圆圈,右边的橙色盒子吗?或者你只是用那种方式去装饰它们?你能为元素的排列添加一个大致的草图吗?我添加了一个图像来解释我想要什么。在每个框中,绿色框(输入)应该在左边,红色框(输出)应该在右边,其余的在中间(如
dot
所示)。因此应该有一种“流”从左到右。我一直在试图理解为什么该解决方案使用的是不可见边,而不是没有它们。我的怀疑是,只有当节点连接到图的其余部分时,dot才能对齐节点,但我不确定。你能告诉我这是否正确吗@Craig@S.K.-我对这一点的理解来自于我在回答您的问题。“室温”和“室温”之间的边缘导致
dot
将“室温”放置在比“室温”低一级的位置。这似乎覆盖了此节点在最低级别的位置,可能是一个错误。它还强制“通电”和“开关”将节点放置在相同的列组而不是最低的列组上。如果从原始文件中删除此边,您将获得所需的布局,尽管缺少一条边。
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"]
    }

}
}