【问题标题】:Vertically aligning a node joining subgraphs in Graphviz在 Graphviz 中垂直对齐连接子图的节点
【发布时间】:2013-05-13 18:31:25
【问题描述】:

我向 Dot 提供以下输入:

digraph G {
  subgraph cluster1 {
    fontsize = 20;
    label = "Group 1";
    A -> B -> C -> D;
    style = "dashed";
  }

  subgraph {
    O [shape=box];
  }

  subgraph cluster2 {
    fontsize = 20;
    label = "Group 2";
    Z -> Y -> X -> W [dir=back];
    style = "dashed";
  }

  D -> O [constraint=false];
  W -> O [constraint=false, dir=back];
}

它会产生:

如何对齐节点O 使其与DW 具有相同的等级?也就是说,如下图:

A   Z
|   |
B   Y
|   |
C   X
|   |
D-O-W

添加

 { rank=same; D; O; W; }

产生错误

Warning: D was already in a rankset, ignored in cluster G
Warning: W was already in a rankset, ignored in cluster G

我想我可以通过在O 的子图中添加不可见的节点和边来破解它,但我想知道我是否遗漏了一些点魔法。

【问题讨论】:

    标签: alignment graphviz dot


    【解决方案1】:

    您可以使用rankdir=LR 的方法并使用constraint=false 作为集群内的边缘:

    digraph G {
      rankdir=LR;
    
      subgraph cluster1 {
        fontsize = 20;
        label = "Group 1";
        rank=same;
        A -> B -> C -> D [constraint=false];
        style = "dashed";
      }
    
      subgraph cluster2 {
        fontsize = 20;
        label = "Group 2";
        rank=same;
        Z -> Y -> X -> W [dir=back, constraint=false];
        style = "dashed";
      }
    
      O [shape=box];
      D -> O -> W;
    }
    

    这不是点魔法 :-),但它实现了这一点:

    使用不可见节点进行黑客攻击也可以:

    digraph G {
      subgraph cluster1 {
        fontsize = 20;
        label = "Group 1";
        A -> B -> C -> D;
        style = "dashed";
      }
    
      subgraph {
        O1[style=invis];
        O2[style=invis];
        O3[style=invis];
        O [shape=box];
    
        O1 -> O2 -> O3 -> O [style=invis];
      }
    
      subgraph cluster2 {
        fontsize = 20;
        label = "Group 2";
        Z -> Y -> X -> W [dir=back];
        style = "dashed";
      }
    
      edge[constraint=false];
      D -> O -> W;
    }
    

    结果几乎相同:

    【讨论】:

    • 感谢您的及时和翔实的回复!我最初用不可见的节点破解了它,但已经切换到第一个解决方案。感觉更优雅,效果更佳。
    猜你喜欢
    • 2018-05-16
    • 1970-01-01
    • 2015-01-21
    • 2021-08-22
    • 2014-08-02
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    相关资源
    最近更新 更多