如何更改Graphviz子图的排名?

18

我希望子图 clusterCG 与编号为 3 的节点排列在同一条直线上(但 clusterCG 中不应包含节点 3)。

digraph G{
 rankdir = LR;
 node [shape = none]

 1->2->3->4[arrowhead=none]

 node [shape = ellipse]

 A->A2->A3;

 subgraph clusterCG{
  shape = rect;
  rank=same;
  A2;
  B;
  C;
  color=blue;
  label="C";
 }

 { rank=same; 1; A;}
 { rank=same; 3; CG;}
 { rank=same; 4; A3;}
}

enter image description here

CG被生成为独立的3级节点。

我希望子图clusterCG的等级为3。


FDSg,你应该接受这个答案。在我看来它很好!我知道你自己写的,但它确实很有帮助。 - Ellis Whitehead
我同意。这帮助我解决了在不同布局中遇到的一个困难问题。谢谢。 - melston
2个回答

18

使用不同的排名算法,添加参数 "newrank=true"

 digraph G {
 newrank=true
 rankdir = LR;
 node [shape = none]

 1->2->3->4[arrowhead=none]

 node [shape = ellipse]

 A->A2->A3;

 subgraph clusterCG{
  shape = rect;
  rank=same;

  A2;
  B;
  C;
  color=blue;
  label="C";
 }

 { rank=same; 1; A;}
 { rank=same; 3; A2}
 { rank=same; 4; A3;}
}

11

也许不是最好的解决方案,但似乎零大小节点是唯一有效的方法。

digraph G{
 rankdir = LR;
 node [shape = none]

1->2->3->4[arrowhead=none]

node [shape = ellipse]
ACG[shape = none,label="",width=0, height=0];

CG->A2 [style=invis,constraint=false];

A->ACG[arrowhead=none];
ACG->A2->A3;

 subgraph clusterCG{
  shape = rect;
  rank=same;
  A2;
  B;
  C;
  color=blue;
  label="C";
 }

 { rank=same; 1; A;}
 { rank=same; 2; ACG;}
 { rank=same; 4; A3;}

}

输入图像描述


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