2012-02-01 21 views
6

有沒有辦法讓箱子在某些情況下水平顯示,而在其他情況下是垂直顯示的? (見related question)。水平整理箱子然後垂直整理graphviz

下面是代碼和輸出,我得到:

代碼:

/** 
** Diagram representing the Simulator Engine 
**/ 
digraph G { 
     graph [ 
      rankdir = "TB" 
     ]; 

     /** 
     ** The simulator engine rectangle 
     **/ 
    subgraph cluster_simulator_engine { 
     style=filled; 
     color=lightgrey; 
     node [style=filled,color=white]; 
     label = "Simulator Engine"; 

       /** 
       ** The first topology 
       **/ 
       subgraph cluster_T1 { 
         color=white; 
         node [style=filled]; 

         /** 
         ** The n^th neuron 
         **/ 
         subgraph cluster_T1_N3 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron n"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T1_N3_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T1_N3_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T1_N3_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/ 
         } 

         /** 
         ** The second neuron 
         **/ 
         subgraph cluster_T1_N2 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron 2"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T1_N2_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T1_N2_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T1_N2_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/ 
         } 


         /** 
         ** The third neuron 
         **/ 
         subgraph cluster_T1_N1 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron 1"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T1_N1_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T1_N1_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T1_N1_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/ 
         } 


         label = "Topology 1"; 
       } 

       /** 
       ** The second topology 
       **/ 
       subgraph cluster_T2 { 
         color=white; 
         node [style=filled]; 

         /** 
         ** The n^th neuron 
         **/ 
         subgraph cluster_T2_N3 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron n"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T2_N3_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T2_N3_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T2_N3_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/ 
         } 

         /** 
         ** The second neuron 
         **/ 
         subgraph cluster_T2_N2 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron 2"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T2_N2_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T2_N2_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T2_N2_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/ 
         } 


         /** 
         ** The third neuron 
         **/ 
         subgraph cluster_T2_N1 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron 1"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T2_N1_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T2_N1_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T2_N1_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           /*"T1_N1_S3" -> "T1_N1_S2" [style=invis];*/ 
         } 


         label = "Topology 2"; 
       } 

    } 

} 

輸出:

First Diagram

這顯然是太長了。我想要的是將每個突觸移動到自己的行中(我認爲它被稱爲Graphviz術語中的「排名」)。顯然,沒有辦法做到這一點,但有一個trick。因此,我採取相同的代碼和上面的介紹可見邊,像這樣

代碼:

/** 
** Diagram representing the Simulator Engine 
**/ 
digraph G { 
     graph [ 
      rankdir = "TB" 
     ]; 

     /** 
     ** The simulator engine rectangle 
     **/ 
    subgraph cluster_simulator_engine { 
     style=filled; 
     color=lightgrey; 
     node [style=filled,color=white]; 
     label = "Simulator Engine"; 

       /** 
       ** The first topology 
       **/ 
       subgraph cluster_T1 { 
         color=white; 
         node [style=filled]; 

         /** 
         ** The n^th neuron 
         **/ 
         subgraph cluster_T1_N3 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron n"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T1_N3_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T1_N3_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T1_N3_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           "T1_N3_S1" -> "T1_N3_S2" [style=invis]; 
           "T1_N3_S2" -> "T1_N3_S3" [style=invis]; 
         } 

         /** 
         ** The second neuron 
         **/ 
         subgraph cluster_T1_N2 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron 2"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T1_N2_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T1_N2_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T1_N2_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           "T1_N2_S2" -> "T1_N2_S3" [style=invis]; 
           "T1_N2_S1" -> "T1_N2_S2" [style=invis]; 
         } 


         /** 
         ** The third neuron 
         **/ 
         subgraph cluster_T1_N1 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron 1"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T1_N1_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T1_N1_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T1_N1_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           "T1_N1_S1" -> "T1_N1_S2" [style=invis]; 
           "T1_N1_S2" -> "T1_N1_S3" [style=invis]; 
         } 


         label = "Topology 1"; 
       } 

       /** 
       ** The second topology 
       **/ 
       subgraph cluster_T2 { 
         color=white; 
         node [style=filled]; 

         /** 
         ** The n^th neuron 
         **/ 
         subgraph cluster_T2_N3 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron n"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T2_N3_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T2_N3_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T2_N3_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           "T2_N3_S1" -> "T2_N3_S2" [style=invis]; 
           "T2_N3_S2" -> "T2_N3_S3" [style=invis]; 
         } 

         /** 
         ** The second neuron 
         **/ 
         subgraph cluster_T2_N2 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron 2"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T2_N2_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T2_N2_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T2_N2_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           "T2_N2_S1" -> "T2_N2_S2" [style=invis]; 
           "T2_N2_S2" -> "T2_N2_S3" [style=invis]; 
         } 


         /** 
         ** The third neuron 
         **/ 
         subgraph cluster_T2_N1 { 
           color=lightgrey; 
           node [style=filled]; 
           label = "Neuron 1"; 

           /** 
           ** The n^th synapse 
           **/ 
           "T2_N1_S3" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse n" 
           ]; 

           /** 
           ** The second synapse 
           **/ 
           "T2_N1_S2" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 2" 
           ]; 

           /** 
           ** The first synapse 
           **/ 
           "T2_N1_S1" [ 
            style=filled 
            shape=box 
            color=white 
            label="Synapse 1" 
           ]; 

           "T2_N1_S1" -> "T2_N1_S2" [style=invis]; 
           "T2_N1_S2" -> "T2_N1_S3" [style=invis]; 
         } 


         label = "Topology 2"; 
       } 

    } 

} 

現在輸出看起來更具吸引力。

輸出: Second smaller diagram

但現在有突觸箱之間的巨大差距。設置nodesep=0.1len=0.1不起作用。任何人都可以告訴我如何解決這個問題,或者如何重新設計這個。

注意:如果有人很好奇我爲什麼從1到2到n,那是因爲我打算在那裏放一個橢圓,但我不知道該怎麼做......當我得到這個橋時到它。

回答

8

這是你要找的ranksep - 這行添加到該圖形的屬性:

ranksep = 0.1 

在點,這給期望的等級分離,以英寸爲單位。這是一個排名爲 的節點的底部與下一個節點的頂​​部之間的最小垂直距離。