子图水平,其节点垂直对齐

3

我有问题无法水平排列我的子图和垂直排列子图内的节点。所有子图和节点都只在一行上(水平或垂直)。

digraph G {
  rankdir = LR;
  subgraph cluster_0 {
    rankdir = TB;
    node [style=filled];
    label = "Title 1";
    color=black
    N1 -> N2;
  }
  subgraph cluster_1 {
    rankdir = TB;
    node [style=filled];
    label = "Title 2";
    color=black
    N3 -> N4 -> N5;
  }
  subgraph cluster_2 {
    rankdir = TB;
    node [style=filled];
    ...
  }
  ...

  N2 -> N3;
  ...

  N1 [label = "BA_A", fillcolor="green", shape="Msquare"]
  N2 [label = "W2", fillcolor="green", shape="octagon"]
  N3 [label = "BA_A", fillcolor="green", shape="Msquare"]
  N4 [label = "W2", fillcolor="green", shape="octagon"]
  N5 [label = "W2_ERROR", fillcolor="red", shape="octagon"]
  N6 [label = "W3", fillcolor="green", shape="invtriangle"]
  ...
}

我也尝试了{rank=same; N1; N3; ...;},这将节点从子图中取出。
2个回答

3
您可以使用类似以下的方式:
digraph G {
  rankdir = LR;
  subgraph cluster_0 {
    {rank=same N1 N2}
    label = "Title 1";
    N1 -> N2;
  }
  subgraph cluster_1 {
    {rank=same N3 N4 N5}
    label = "Title 2";
    N3 -> N4 -> N5;
  }
  subgraph cluster_2 {
    node [style=filled];
    label = "Title 3";
    N6;
  }

  N2 -> N3;
  N5 -> N6;
  N1 [label = "BA_A", fillcolor="green", shape="Msquare"]
  N2 [label = "W2", fillcolor="green", shape="octagon"]
  N3 [label = "BA_A", fillcolor="green", shape="Msquare"]
  N4 [label = "W2", fillcolor="green", shape="octagon"]
  N5 [label = "W2_ERROR", fillcolor="red", shape="octagon"]
  N6 [label = "W3", fillcolor="green", shape="invtriangle"]
}

output


谢谢!你有想法如何将所有子图移到最顶部吗?子图之间的边缘将具有弯曲连接。 - myborobudur
不是立即的。 - Ohad Eytan

2
在您的情况下,我更喜欢从上到下的布局。
digraph G {
  rankdir = TB;
  node [style=filled];
  subgraph cluster_0 {
    N1 N2
    label = "Title 1";
    edge [dir = back]
    N2 -> N1;
  }
  subgraph cluster_1 {
    N3 N4 N5
    label = "Title 2";
    edge [dir = back]
    N5 -> N4 -> N3;
  }
  subgraph cluster_2 {
    label = "Title 3";
    N6
  }
  N2 -> N3 [constraint=none];
  N5 -> N6 [constraint=none];
  N1 [label = "BA_A", fillcolor="green", shape="Msquare"]
  N2 [label = "W2", fillcolor="green", shape="octagon"]
  N3 [label = "BA_A", fillcolor="green", shape="Msquare"]
  N4 [label = "W2", fillcolor="green", shape="octagon"]
  N5 [label = "W2_ERROR", fillcolor="red", shape="octagon"]
  N6 [label = "W3", fillcolor="green", shape="invtriangle"]
}

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接