开发者

Straight edge between clusters in Graphviz

I'm trying to have an edge between clusters in Graphviz where the edge does not affect the ranking.

This looks fine:

digraph {
  subgraph clusterX {
    A    
    B
  }

  subgraph clusterY {
    C
    D
  } 

  A ->开发者_开发技巧; B
  B -> C [constraint=false]
  C -> D
}

Straight edge between clusters in Graphviz

However when I add a label to the C -> D edge the B -> C edge tries to circumvent said label (which looks ugly).

digraph {
  subgraph clusterX {
    A    
    B
  }

  subgraph clusterY {
    C
    D
  } 

  A -> B
  B -> C [constraint=false]
  C -> D [label=yadda]
}

Straight edge between clusters in Graphviz

Any idea how I can keep the edge from B to C straight?


The easiest way to achieve this is to add splines=false to the dot file - this forces the rendering of the edges to be straight lines:

digraph {
 splines=false;
 subgraph clusterX {
    A;
    B;
 }

 subgraph clusterY {
    C;
    D;
 } 

 A -> B;
 B -> C [constraint=false];
 C -> D [label=yadda];
}

Output:

Straight edge between clusters in Graphviz


You can use this version :

digraph G { 
  subgraph cluster_X {
    A [ pos = "0,1!" ]; 
    B [ pos = "0,0!" ];
  } 
  subgraph cluster_Y {
    C [ pos = "1,1!" ]; 
    D [ pos = "1,0!" ];
  } 
  A -> B
  B -> C[label="yadda"]
  C -> D;
}

Then you use neato (not dot)

neato -Tpng -oyadda.png yadda.dot

And the result is :

Straight edge between clusters in Graphviz


Instead of the label attribute, you can use the attributes xlabel or headlbel or taillabel.

  • Result with xlabel:

    Straight edge between clusters in Graphviz


    Script:

    digraph {
        subgraph clusterX { A B }
        subgraph clusterY { C D } 
        A -> B
        B -> C [constraint=false]
        C -> D [xlabel=yadda]
    }
    
  • Result with headlabel:

    Straight edge between clusters in Graphviz


    Script:

    digraph {
        subgraph clusterX { A B }
        subgraph clusterY { C D } 
        A -> B
        B -> C [constraint=false]
        C -> D [headlabel=yadda]
    }
    
  • Result with taillabel:

    Straight edge between clusters in Graphviz


    Script:

    digraph {
        subgraph clusterX { A B }
        subgraph clusterY { C D } 
        A -> B
        B -> C [constraint=false]
        C -> D [taillabel=yadda]
    }
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜