Graphviz 集群更改内部节点的布局顺序 - 如何更正?

Graphviz cluster changes layout order of internal nodes - how to correct?

以下 graphviz 节点在使用点渲染时按预期排列成 C 形:

digraph G {
newrank=true;
"001_getCtInputChunk" [shape=rect, label="@disk_cache\ngetCtInputChunk"];
"004_augmentCtInputChunk" [shape=rect, label=augmentCtInputChunk];
"002_cache_dir" [shape=cylinder, label="Cache Dir\n(.pkl.gz)"];
"003_LunaDataset" [shape=box3d, label=LunaDataset];
"001_getCtInputChunk" -> "002_cache_dir";
"002_cache_dir" -> "001_getCtInputChunk";
"001_getCtInputChunk" -> "003_LunaDataset";
"003_LunaDataset" -> "004_augmentCtInputChunk";
subgraph  {
rank=same;
"001_getCtInputChunk" [shape=rect, label="@disk_cache\ngetCtInputChunk"];
"002_cache_dir" [shape=cylinder, label="Cache Dir\n(.pkl.gz)"];
}

subgraph  {
rank=same;
"004_augmentCtInputChunk" [shape=rect, label=augmentCtInputChunk];
"003_LunaDataset" [shape=box3d, label=LunaDataset];
}

}

当我如下将节点放入集群时,布局变为 Z 形:

digraph G {
newrank=true;
subgraph cluster_dsets {
label="dsets.py";
shape=rect;
"001_getCtInputChunk" [label="@disk_cache\ngetCtInputChunk", shape=rect];
"004_augmentCtInputChunk" [label=augmentCtInputChunk, shape=rect];
"002_cache_dir" [label="Cache Dir\n(.pkl.gz)", shape=cylinder];
"003_LunaDataset" [label=LunaDataset, shape=box3d];
}

"001_getCtInputChunk" -> "002_cache_dir";
"002_cache_dir" -> "001_getCtInputChunk";
"001_getCtInputChunk" -> "003_LunaDataset";
"003_LunaDataset" -> "004_augmentCtInputChunk";
subgraph  {
rank=same;
"001_getCtInputChunk" [label="@disk_cache\ngetCtInputChunk", shape=rect];
"002_cache_dir" [label="Cache Dir\n(.pkl.gz)", shape=cylinder];
}

subgraph  {
rank=same;
"004_augmentCtInputChunk" [label=augmentCtInputChunk, shape=rect];
"003_LunaDataset" [label=LunaDataset, shape=box3d];
}

}

我怎样才能强制集群节点以与非集群节点相同的 C 形布局?我更喜欢一个通用的解决方案,因为我的实际图表要复杂得多,并且在几个地方都有这个问题。

我目前正在使用 pydot 生成图表,以防相关。

我更改了几个小细节以非常接近您正在寻找的结果。 nodesep 在使用 dir=both 时(而不是两条明确的边)提供了更好的分隔,为箭头留出足够的空间。当然 dir-both 使用 rank=same 将主要方向绘制到左侧,因此您的节点现在被反转显示在声明的顺序中。最后,我更改了最左边元素的宽度,使它们对齐得更好。

digraph G {

nodesep=0.5;

newrank=true;

subgraph cluster_dsets {
    label="dsets.py";
    shape=rect;
    "001_getCtInputChunk" [label="@disk_cache\ngetCtInputChunk", shape=rect, width=1.8];
    "004_augmentCtInputChunk" [label=augmentCtInputChunk, shape=rect];
    "002_cache_dir" [label="Cache Dir\n(.pkl.gz)", shape=cylinder];
    "003_LunaDataset" [label=LunaDataset, shape=box3d, width=1.8];
    }

"001_getCtInputChunk" -> "002_cache_dir" [dir=both];
"001_getCtInputChunk" -> "003_LunaDataset";
"003_LunaDataset" -> "004_augmentCtInputChunk";

subgraph  {
    rank=same;
    "001_getCtInputChunk" [label="@disk_cache\ngetCtInputChunk", shape=rect];
    "002_cache_dir" [label="Cache Dir\n(.pkl.gz)", shape=cylinder];
    }

subgraph  {
    rank=same;
    "004_augmentCtInputChunk" [label=augmentCtInputChunk, shape=rect];
    "003_LunaDataset" [label=LunaDataset, shape=box3d];
    }

}