2011-11-19 28 views
8

Cần vẽ một biểu đồ phức tạp, sẽ có 3 loại cạnh và một số loại nút được xác định trước.graphviz xác định thêm "mặc định"

Có thể xác định được phần nào hơn (ví dụ: không chỉ một mặc định) "loại cạnh" (hoặc loại nút) để sử dụng sau này?

có nghĩa là một cái gì đó như:

edge [colorscheme=paired12, color=8, fontsize=11, fontname="Arial narrow"]; 
edge2 [colorscheme=paired12, color=3, fontsize=11, fontname="Arial narrow", style=bold]; 
edge3 [colorscheme=paired12, color=5, fontsize=14, fontname="Arial narrow"]; 

node1 -> node2; /* will use the default edge definition from the above */ 
node2 -> node3 [edgetype=edge2]; /* will use the second edge definition */ 
node2 -> node4 [edgetype=edge3]; /* and so on... */ 

Trên đây, OFC, là không đúng - chỉ dành cho lời giải thích ...

Trả lời

7

Sử dụng gvpr rất đơn giản, nếu bạn tìm ra những điều cơ bản:

input.dot

digraph test { 
    node1 -> node2[label="test 1"]; /* will use the default edge definition from the above */ 
    node2 -> node3 [label="test 2", edgetype="edge2"]; /* will use the second edge definition */ 
    node2 -> node4 [label="test 3", edgetype="edge3"]; /* and so on... */ 
} 

filter.gvpr

E { 
    color="red"; 
    fontsize=11; 
    fontname="Arial narrow" 
} 
E[edgetype == "edge2"] { 
    color="green"; 
    fontsize=11; 
    fontname="Arial narrow"; 
    style="bold" 
} 
E[edgetype == "edge3"] { 
    color="blue"; 
    fontsize=14; 
    fontname="Arial narrow" 
} 

Với lệnh

gvpr -c -f filter.gvpr -o output.dot input.dot

sẽ sản xuất các output.dot file:

digraph test { 
    node1 -> node2 [color=red, 
     fontname="Arial narrow", 
     fontsize=11, 
     label="test 1"]; 
    node2 -> node3 [color=green, 
     edgetype=edge2, 
     fontname="Arial narrow", 
     fontsize=11, 
     label="test 2", 
     style=bold]; 
    node2 -> node4 [color=blue, 
     edgetype=edge3, 
     fontname="Arial narrow", 
     fontsize=14, 
     label="test 3"]; 
} 
+1

wow! Thật tuyệt! Thanx. ;) – jm666

+1

Bạn được chào đón, hãy xem https://github.com/ellson/graphviz/tree/master/cmd/gvpr/lib, để biết thêm các ví dụ (phức tạp) bạn có thể làm gì với 'gvpr'. – nepda

4

Không, đó là không thể.

Tôi thường nhóm các định nghĩa cạnh theo loại của chúng và xác định lại mặc định trước mỗi nhóm. Ví dụ:

// type 1 edges 
edge [colorscheme=paired12, color=8, fontsize=11, fontname="Arial narrow"]; 
n1 -> n2; 
n3 -> n4; 
... 

// type 2 edges 
edge [colorscheme=paired12, color=3, fontsize=11, fontname="Arial narrow", style=bold]; 
n10 -> n11; 
... 

// type 3 edges 
edge [colorscheme=paired12, color=5, fontsize=14, fontname="Arial narrow"]; 
... 

Một khác - phức tạp hơn - khả năng sẽ được sử dụng một công cụ như gvpr cho phép bạn thao tác một đồ thị, và thêm thuộc tính cạnh lúc đó.

+0

Thanx, gọn gàng ý tưởng Định nghĩa lại và nhóm các cạnh ... – jm666

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