2012-02-01 103 views
6

Có cách nào để các hộp hiển thị theo chiều ngang trong một số trường hợp và theo chiều dọc trong các hộp khác không? (xem related question).Sắp xếp các ô theo chiều ngang và sau đó theo chiều dọc trong graphviz

Đây là mã và đầu ra mà tôi nhận được:

mã:

/** 
** 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"; 
       } 

    } 

} 

Output:

First Diagram

Rõ ràng đây là quá dài. Điều tôi muốn là di chuyển từng khớp thần kinh vào dòng riêng của nó (tôi nghĩ nó được gọi là 'thứ hạng' trong Graphviz-jargon). Rõ ràng, không có cách nào để làm điều này, nhưng có một trick. Vì vậy, tôi đi cùng mã trên và giới thiệu các cạnh vô hình như vậy

mã:

/** 
** 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"; 
       } 

    } 

} 

và đầu ra hiện nay trông hấp dẫn hơn.

đầu ra: Second smaller diagram

Nhưng bây giờ có một khoảng cách lớn giữa các hộp synap. Đặt nodesep=0.1 hoặc len=0.1 không có hiệu lực. Bất cứ ai có thể cho tôi biết làm thế nào để sửa lỗi này, hoặc làm thế nào để thiết kế lại này. Chú ý: Nếu bất cứ ai tò mò tại sao tôi đi từ 1 đến 2 đến n, đó là vì tôi dự định đặt một hình elip trong đó, nhưng tôi không có đầu mối làm thế nào để làm điều đó ... băng qua cây cầu đó khi tôi nhận được cho nó.

Trả lời

8

Đó là ranksep bạn đang tìm kiếm - thêm dòng này vào các thuộc tính cho biểu đồ:

ranksep = 0.1 

Trong dot, điều này mang lại sự tách biệt cấp bậc mong muốn, theo đơn vị inch. Đây là khoảng cách dọc tối thiểu giữa phần dưới cùng của các nút trong một thứ hạng và các đỉnh của nút trong phần tiếp theo.

Các vấn đề liên quan