在Graphviz中使用子图时对齐节点

时间:2018-02-20 09:25:14

标签: graphviz subgraph

我想在Graphviz中使用子图时对齐节点。

它在没有子图的情节中非常有效。但是当我引入子图时,节点会发生(意外的?)移位。

这是一个简单的例子。

digraph My_test_without_subgraphs {

  graph [overlap = true, compound = true, rankdir = LR]

  node [shape = box, color = lightgrey, style = filled, fontcolor = black]
  T1 [label = 'my task 1']
  T2 [label = 'my task 2']
  T3 [label = 'my task 3']
  T4 [label = 'my task 4']

  T1 -> T3
  T2 -> T3
  T3 -> T4

}

digraph My_test_with_subgraphs {

  graph [overlap = true, compound = true, rankdir = LR]

  node [shape = box, color = lightgrey, style = filled, fontcolor = black]
  T1 [label = 'my task 1']
  T2 [label = 'my task 2']
  T3 [label = 'my task 3']
  T4 [label = 'my task 4']

  subgraph cluster1 {
  label = 'cluster 1'
  color = cornsilk
  style = filled
  T1 -> T3
  T2 -> T3
  }

  subgraph cluster2 {
    label = 'cluster 2'
    color = cornsilk
    style = filled
    T3 -> T4
  }
}

2 个答案:

答案 0 :(得分:1)

是的,保证金可以解决问题。值本身并不那么重要,只要它是一个小数字8。

顺便说一句,请使用“而不是”,某些口译员,尤其是在线编辑,会引发错误。

digraph My_test_with_subgraphs {

  graph [overlap = true, compound = true, rankdir = LR]

  node [shape = box, color = lightgrey, style = filled, fontcolor = black]
  T1 [label = "my task 1"]
  T2 [label = "my task 2"]
  T3 [label = "my task 3"]
  T4 [label = "my task 4"]

  subgraph cluster1 {
  label = "cluster 1"
  color = cornsilk
  style = filled
  T1 -> T3
  T2 -> T3
  }

  subgraph cluster2 {
    margin = 6
    label = "cluster 2"
    color = cornsilk
    style = filled
    T3 -> T4
  }
}

结果: graph1

{{1}}

结果 graph2

答案 1 :(得分:0)

向第二个群集添加稍微小的边距,如下所示:

margin = 7.99

诀窍。

不要问我为什么......