繁体   English   中英

在 Graphviz 的嵌套子图中放置节点

[英]Placement of nodes in a nested subgraph in Graphviz

我正在尝试创建二进制的 plot,在不同的 colors 中为不同的节点着色和标记。

为了获得子树周围的边界,我使用了几乎可以正常工作的子图:

graph G
{
graph [ranksep="0.25", nodesep="0.25"]
rankdir = TB;
node [shape=ellipse, style=filled, fillcolor="#0068B4", color=white, fontcolor=white, penwidth=10]
edge [arrowtail="none"]

subgraph cluster_0 {
  node [fillcolor="#99CC00"]
  color="#99CC00"
  style=filled
  fillcolor=white
  fontcolor="#99CC00"
  label="12 is the root of\n26's left child\r"
  18;
    subgraph cluster_01 {
      node [fillcolor="#00B0F0"]
      color="#00B0F0"
      fontcolor="#00B0F0"
      style=filled
      fillcolor=white
      label="4 is the root of                         \n12's left child                         \r"
      7   [fillcolor=white]
      4 -- 13
      4 --  7 [style=invisible]
      7 -- 13 [style=invisible] 
      { rank=same; 7, 13 }
      { rank=same; 4, 18 }
      
    }


  12 -- {4,18}
  
  { rank=same; 12 }
}

subgraph cluster_1 {
  node [fillcolor="#C00000"]
  color="#C00000"
  style=filled
  fillcolor=white
  fontcolor="#C00000"
  label="32 is the root of\n26's right child\r"
  
  35   [fillcolor=white]

  32 -- 38
  32 -- 35 [style=invisible]
  35 -- 38 [style=invisible] 
  
  { rank=same; 32 }
  { rank=same; 35, 38 }
}


26 -- {12, 32}


{ rank=same; 26 }

}

这导致了这个 output:

上面graphviz代码的输出

如您所见,节点 18 位于蓝色子集群内。 除了在 4 和 18 之间放置一个空白虚拟节点(如不可见节点 7 和 35)之外,是否有一种简单的方法可以将该节点“开箱即用”?

但是,添加graph [newrank=true]并重新排列几行会使事情变得更好:

graph G
{
graph [ranksep="0.25", nodesep="0.25" newrank=true]
rankdir = TB;
node [shape=ellipse, style=filled, fillcolor="#0068B4", color=white, fontcolor=white, penwidth=10]
edge [arrowtail="none"]

subgraph cluster_0 {
  node [fillcolor="#99CC00"]
  color="#99CC00"
  style=filled
  fillcolor=white
  fontcolor="#99CC00"
  label="12 is the root of\n26's left child\r"
    subgraph cluster_01 {
      node [fillcolor="#00B0F0"]
      color="#00B0F0"
      fontcolor="#00B0F0"
      style=filled
      fillcolor=white
      label="4 is the root of                         \n12's left child                         \r"
      7   [fillcolor=white]
      4 -- 13
      4 --  7 [style=invisible]
      7 -- 13 [style=invisible] 
      { rank=same; 7, 13 }
    }
      { rank=same; 4, 18 }
  12 -- {4,18}
  { rank=same; 12 }
}

subgraph cluster_1 {
  node [fillcolor="#C00000"]
  color="#C00000"
  style=filled
  fillcolor=white
  fontcolor="#C00000"
  label="32 is the root of\n26's right child\r"
  35   [fillcolor=white]
  32 -- 38
  32 -- 35 [style=invisible]
  35 -- 38 [style=invisible] 
  { rank=same; 32 }
  { rank=same; 35, 38 }
}
26 -- {12, 32}
{ rank=same; 26 }
}

给出: 在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM