【问题标题】:Order of nodes in graphvizgraphviz中的节点顺序
【发布时间】:2021-05-09 08:47:58
【问题描述】:

我正在处理这个图表:

digraph "example.gsn.yaml" {

  ## Elements
  "G1" [shape="box", label=<<B>G1</B><BR align="left"/>Goal 1>];
  "G2" [shape="box", label=<<B>G2</B><BR align="left"/>Goal 2>];
  "G4" [shape="box", label=<<B>G4</B><BR align="left"/>Goal 4>];
  "G3" [shape="box", label=<<B>G3</B><BR align="left"/>Goal 3>];
  "C1" [shape="box", style="rounded", label=<<B>C1</B><BR align="left"/>Context 1>];
  "S1" [shape="parallelogram", label=<<B>S1</B><BR align="left"/>Strategy 1>];
  "A1" [shape="oval", label=<<B>A1</B><BR align="left"/>Argument 1>];
  "A1":e -> "A1":e [headlabel=< <B>A</B> >, labeldistance=2.5, penwidth=0, arrowhead=none];
  "Sn1" [shape="circle", label=<<B>Sn1</B><BR align="left"/>Solution 1>];
  "Sn2" [shape="circle", label=<<B>Sn2</B><BR align="left"/>Solution 2>];
  "J1" [shape="oval", label=<<B>J1</B><BR align="left"/>Justification 1>];
  "J1":e -> "J1":e [headlabel=< <B>J</B> >, labeldistance=2.5, penwidth=0, arrowhead=none];

  ## Relations
  "G1" -> "G2";
  "G1" -> "G3";
  "G1" -> "G4";
  "G2" -> "S1";
  "G4" -> "Sn2";
  "G3" -> "Sn1";
  "G3" -> "C1" [arrowhead=empty];
  {rank = same; "G3"; "C1"; }
  "S1" -> "Sn1";
  "S1" -> "J1" [arrowhead=empty];
  "S1" -> "A1" [arrowhead=empty];
  {rank = same; "A1"; "S1"; }
  {rank = same; "S1"; "J1"; }
}


我想尽量减少交叉。 我的首选布局是 A1、S1 和 J1 按从左到右的顺序位于同一级别。 但是我不知道该怎么做。

有人可以帮忙吗?提前致谢。

【问题讨论】:

    标签: graphviz dot


    【解决方案1】:

    许多“明显”的解决方案都不起作用(排序、重量、不可见的边缘)。将 A1、J1 和 S1 放在一个集群中就可以了:

    digraph "example.gsn.yaml" {
      ## Elements
      "G1" [shape="box", label=<<B>G1</B><BR align="left"/>Goal 1>];
      "G2" [shape="box", label=<<B>G2</B><BR align="left"/>Goal 2>];
      "G4" [shape="box", label=<<B>G4</B><BR align="left"/>Goal 4>];
      "G3" [shape="box", label=<<B>G3</B><BR align="left"/>Goal 3>];
      "C1" [shape="box", style="rounded", label=<<B>C1</B><BR align="left"/>Context 1>];
      "S1" [shape="parallelogram", label=<<B>S1</B><BR align="left"/>Strategy 1>];
      "A1" [shape="oval", label=<<B>A1</B><BR align="left"/>Argument 1>];
      "A1":e -> "A1":e [headlabel=< <B>A</B> >, labeldistance=2.5, penwidth=0, arrowhead=none];
      "Sn1" [shape="circle", label=<<B>Sn1</B><BR align="left"/>Solution 1>];
      "Sn2" [shape="circle", label=<<B>Sn2</B><BR align="left"/>Solution 2>];
      "J1" [shape="oval", label=<<B>J1</B><BR align="left"/>Justification 1>];
      "J1":e -> "J1":e [headlabel=< <B>J</B> >, labeldistance=2.5, penwidth=0, arrowhead=none];
    
      subgraph clusterg1{
        graph[peripheries=0]  // no box around the cluster
        {rank = same; node[group=g1] edge[style=invis]  "A1" -> "S1" ->  "J1"}
      }
    
      ## Relations
      "G1" -> "G2";
      "G1" -> "G3";
      "G1" -> "G4";
      "G2" -> "S1";
      "G4" -> "Sn2";
      "G3" -> "Sn1";
      "G3" -> "C1" [arrowhead=empty];
      {rank = same; "G3"; "C1"; }
      "S1" -> "Sn1";
      "S1" -> "J1" [arrowhead=empty];
      "A1" -> "S1" [arrowhead=empty dir=back];
    }
    

    附言A1->S1 箭头对吗?

    【讨论】:

    • 非常感谢。我很高兴这并不明显。我现在设法做到了没有看不见的边缘。箭头错了,但我猜这是dir=back 中的一个错误。可以改用arrowtail。 ``` "G1" -> "G4"; “G2”->“S1”; “G4”->“Sn2”; “G3”->“Sn1”;子图cluster4 {图[周边=0]; { 排名 = 相同; “G3”->“C1”[箭头=空]; } } "S1" -> "Sn1";子图cluster6 {图[周边=0]; { 排名 = 相同; “S1”->“A1”[箭头=空]; "J1" -> "S1" [dir=back, arrowhead=empty]; } } } ```
    猜你喜欢
    • 2019-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-04
    • 1970-01-01
    • 2017-10-31
    • 2014-01-16
    • 2014-10-09
    相关资源
    最近更新 更多