2010-01-19 122 views
9

我有一个测试图,我想调整,使其看起来更好。graphviz:小调整,使图形看起来更好

alt text

这里是graphviz的(点)源,test6.dot

digraph G { 
    ranksep=0.3; size="6.0,6.0"; 
    node [fontsize=11]; 

    subgraph clusterA { 
     X2 [shape=box]; 

     node [style=filled]; 
     1 -> 2 -> 3 -> X2 -> 5; 
     6; 
     7; 
     label = "A"; 
     color=blue 
    } 
    X1 [shape=box]; 
    subgraph clusterB { 
     node [style=filled]; 
     8; 
     9; 
     10 -> 11 -> 12; 
     12 -> 9; 
     12 -> 8 -> 13; 
     13 -> 14; 
     label = "B"; 
     color=blue 
    } 
    subgraph clusterC { 
     label = "C"; 
     { 
     node [style="invis"]; 
     gap; 
     } 
     node [shape=box]; 

     edge [style="invis"]; 
     X3 -> gap -> X4;   
    } 

    14 -> X4 -> 3; 
    6 -> X1 -> 10; 
    { edge [dir="both"]; 
     8 -> X3 -> 7; 
    } 

    9 -> X3 
    } 

问题/变化我想提出:

  • 我想节点10 -> 11 -> 12 -> 8 -> 13 -> 14到流处于垂直线(水平交换8和9)。我怎样才能做到这一点? (同样与1 -> 2 -> 3 -> X2 -> 5;交换6和1)
  • 我想X1是在相同的垂直位置为10,并且我怎样才能做到这一点,相同的水平位置6.?
  • 我希望8和X3和7处于同一垂直位置,也与14和X4和3.我该怎么做?除了注意8 -> 13 -> 14有较大的差距
  • ranksep=0.3;声明的伟大工程,一样X3 -> gap -> X4。为什么它不服从ranksep = 0.3规则,我该如何解决这个问题?

回答

17

下面是我能做的最好的:幻像节点和边缘的帮助。但我似乎无法鼓励横向(从rankdir的另一个方向)的特定排序。

alt text

digraph G { 
    ranksep=0.3; size="6.0,6.0"; 
    rankdir=TB; 

    node [fontsize=11]; 

    subgraph clusterA { 
     X2 [shape=box]; 
     label = "A"; 
     color=blue; 

     node [style=filled]; 
     /* force 1, 6, and 7 to be at the top together, 
      add enough phantoms to keep things in nice columns */ 
     { 
      node [style="invis", label=""]; 
      phantom3; 
      phantom4; 
      phantom5; 
      phantom6; 
     } 


      rank = same; 
      1 -> 2 -> 3 -> X2 -> 5;   

      edge [style="invis"]; 
      6 -> phantom3 -> phantom5; 
      7 -> phantom4 -> phantom6; 

    } 
    subgraph clusterB { 
     node [style=filled]; 
     label = "B"; 
     color=blue; 
     /* create an invisible phantom node 
      to take up space */ 
     { 
     node [style="invis",label=""]; 
     phantom1; 
     phantom1b; 
     } 

     { rank=same; 11; 
     phantom1; 
     } 

     10 -> 11 -> 12 -> 8 -> 13 -> 14; 
     12 -> 9; 
     phantom1 -> 9 -> phantom1b [style="invis"]; 

    } 


    /* force X1 to be at the same vertical pos as 10 
     (this yields a warning though) */ 
    { rank = same; 
     X1 [shape=box]; 
     10; 
    } 

    6 -> X1; 
    X1 -> 10 [weight=0.5]; 

    subgraph clusterC { 
     label = "C"; 

     phantom2 [style="invis", label=""]; 

     node [shape=box]; 

     edge [style="invis"]; 
     X3 -> phantom2 -> X4;   
    } 

    9 -> X3 [weight=0.5]; 

    { 
     edge [weight=20]; 
     14 -> X4 -> 3; 
     3 -> X4 -> 14 [style="invis"]; 
     /* add a reverse path so graphviz doesn't force 14 above X4 above 3 */ 
    } 
    { 
     edge [dir="both", weight=20]; 
     8 -> X3 -> 7; 
     7 -> X3 -> 8 [style="invis"]; 
     edge [style="invis"]; 
     X4 -> phantom6; 
     1 -> phantom2; 
     8 -> phantom2; 
    } 

    }