标签之间的布局问题 Dot Language Graphviz

Layout Problem between Labels Dot Language Graphviz

我在将 Marge 保持在 Homer 附近并将 Herb 保持在 Lucia 附近以避免出现上述问题时遇到了问题(查看图片)。基本上,我需要让已婚夫妇在一起,把兄弟们推到一边,以免混在一起。 这是我的源代码:

digraph G {
  edge [dir=none];
  node [shape=box];
  graph [splines=ortho];

  "Abraham"   [shape=box, regular=0, color="blue", style="filled" fillcolor="lightblue"] ;
  "Mona"      [shape=box, regular=0, color="red", style="filled" fillcolor="pink"] ;
  a1 [shape=diamond,label="",height=0.25,width=0.25];
  {rank=same; Abraham -> a1 -> Mona};
  "Herb"      [shape=box, regular=0, color="blue", style="filled" fillcolor="lightblue"] ;
  "Lucia"     [shape=box, regular=0, color="red", style="filled"fontcolor="", fillcolor="pink"] ;
  "Homer"     [shape=box, regular=0, color="blue",fontcolor="blue", style="bold, filled" fillcolor="lightblue"] ;
  "Marge"     [shape=box, regular=0, color="red", style="bold,filled"fontcolor="red", fillcolor="pink"] ;
  p2 [shape=diamond,label="",style="",height=0.25,width=0.25];
  {rank=same; Herb -> p2 -> Lucia };
  {rank=same; Herb; Homer}
  b1 [shape=circle,label="",height=0.01,width=0.01];
  b2 [shape=circle,label="",height=0.01,width=0.01];
  b3 [shape=circle,label="",height=0.01,width=0.01];
{rank=same; b1 -> b2 -> b3};
  a1 -> b2;
  b1 -> Herb;
  b3 -> Homer;
  "Gendry"      [shape=box, regular=0, color="blue", style="filled" fillcolor="lightblue"] ;
  Herb -> Gendry;
  p2 -> c2;
  c1 -> Bob;
  c3-> John;
  {rank=same;  c1 -> c2 -> c3}
   c1 [shape=circle,label="",height=0.01,width=0.01];
  "Bob"      [shape=box, regular=0, color="blue", style="filled" fillcolor="lightblue"] ;
  c2 [shape=circle,label="",height=0.01,width=0.01];
  "John"      [shape=box, regular=0, color="blue", style="filled" fillcolor="lightblue"] ;
  c3 [shape=circle,label="",height=0.01,width=0.01];
   
  p1 [shape=diamond,label="",style="bold",height=0.25,width=0.25];
  {rank=same; Homer -> p1 -> Marge};
  {rank=same; Bob; John; Gendry}
}

family-tree-image

您想要的应该使用 直截了当,但正如您发现的那样,这非常困难。有两种方法可以帮助您将 weight 属性添加到边缘以使节点彼此靠近 and/or 使用 clusters 显式分组夫妇关闭。使用 clusters 确实让这对夫妇在一起,但它导致了丑陋的边缘。添加权重有助于“正确”放置不可见节点并产生更漂亮的边缘。

digraph G {
  edge [dir=none];
  node [shape=box];
  graph [splines=ortho];

  subgraph cluster1{
      peripheries=0
  "Abraham"   [shape=box, regular=0, color="blue", style="filled" fillcolor="lightblue"] ;
  "Mona"      [shape=box, regular=0, color="red", style="filled" fillcolor="pink"] ;
  a1 [shape=diamond,label="",height=0.25,width=0.25];
  {rank=same; Abraham -> a1 -> Mona};
  }

  subgraph cluster3{
  peripheries=0
  "Homer"     [shape=box, regular=0, color="blue",fontcolor="blue", style="bold, filled" fillcolor="lightblue"] ;
  "Marge"     [shape=box, regular=0, color="red", style="bold,filled"fontcolor="red", fillcolor="pink"] ;
  {rank=same; Homer -> p1 -> Marge};
  p1 [shape=diamond,label="",style="bold",height=0.25,width=0.25];
  }
  subgraph cluster2{
      peripheries=0
  "Herb"      [shape=box, regular=0, color="blue", style="filled" fillcolor="lightblue"] ;
  "Lucia"     [shape=box, regular=0, color="red", style="filled"fontcolor="", fillcolor="pink"] ;
  {rank=same; Herb -> p2 -> Lucia };
  p2 [shape=diamond,label="",style="",height=0.25,width=0.25];
  }

  b1 [shape=point style=invis width=0 label=""]  //,height=0.01,width=0.01];
  b2 [shape=point style=invis width=0 label=""]  //,height=0.01,width=0.01];
  b3 [shape=point style=invis width=0 label=""]  //,height=0.01,width=0.01];
  {rank=same; weight=0   b1 -> b2 -> b3};
  {
  a1 -> b2;
  b1 -> Herb  [weight=9]
  b3 -> Homer [weight=9]
  }

  "Gendry"      [shape=box, regular=0, color="blue", style="filled" fillcolor="lightblue"] ;

  {rank=same; weight=0  c1 -> c2 -> c3}
   c1 [shape=circle,label="",height=0.01,width=0.01];
  "Bob"      [shape=box, regular=0, color="blue", style="filled" fillcolor="lightblue"] ;
  c2 [shape=circle,label="",height=0.01,width=0.01];
  "John"      [shape=box, regular=0, color="blue", style="filled" fillcolor="lightblue"] ;
  c3 [shape=circle,label="",height=0.01,width=0.01];
   
  Herb -> Gendry;
  p2 -> c2 weight=99;
  c1 -> Bob weight=99;
  c3-> John weight=99;
  {rank=same; Bob; John; Gendry}
}  

产生这个(不是很好,但更好):