2013-10-21 5 views
7

텍스트, 노드 및 가장자리가 포함 된 Graphviz에서 범례/키를 만들려고합니다. this post을 읽는 동안 HTML 테이블이 내가하려는 작업과 작동하지 않는 것 같습니다.Graphviz 범례/노드가있는 키

은 현재 내가 사용하고있는 코드는 다음과 같습니다

The result of this code is

하지만 난이 더 같은 것을 싶습니다 - 작은 것이 바람직 크기 :

digraph G { 
fontname="Helvetica"; 
labelloc=t; 
rankdir=LR; 
label="Course Graph"; 

node[style=filled, fontname="Helvetica", colorscheme=greens3, color=1]; 

subgraph cluster_key { 
    rank=min; 

    label="Key"; 
    rankdir=LR; 

    kc1[label="Course", peripheries=2, color=2]; 
    k1[shape=plaintext, style=solid, label="Required Course"] 
    prereq[label="Course 1"]; 
    kc2[label="Course 2"]; 
    prereq->kc2; 
    k2[shape=plaintext, style=solid, label="Course 1 is a prerequisite for Course 2"] 
    coreq1[label="Course 1"]; 
    coreq2[label="Course 2"]; 
    coreq1->coreq2[dir=both]; 
    k3[shape=plaintext, style=solid, label="Course 1 and Course 2 are corequisite"] 

    or[style="dashed", color="black", shape="diamond", label="OR"]; 
    or1[label="Course 1"]; 
    or1 -> or[style="dashed", dir="none"]; 
    or2[label="Course 2"]; 
    or2 -> or[style="dashed", dir="none"]; 
    kc3[label="Course 3"] 
    or->kc3; 
    k4[shape=plaintext, style=solid, label="You must take either Course 1 OR\nCourse 2 before taking Course 3"] 
    { rank=min;k1 k2 k3 k4 } 
} 

c3[color=3, peripheries=2]; 
c4[color=3, peripheries=2]; 

c1->c2[dir=both]; 
c2->c3; 

c4_reqs[style="dashed", color="black", shape="diamond", label="OR"]; 
c4_reqs->c4; 
c2->c4_reqs[style="dashed", dir="none"]; 
c5->c4_reqs[style="dashed", dir="none"]; 

} 

이 코드의 결과는 다음과 같습니다

ebut I would like something more like

답변

9

너 멀지 않았어. 약간의 조정을 통해 나는 다음과 같은 결과를 얻었다 : 내가 만든

enter image description here

가장 중요한 변화는 제대로 줄 노드를 얻기 위해 사용 rank=source 대신 rank=min했다.

텍스트 맞춤을 수정하려면 텍스트를 오른쪽으로 정렬하려면 \r을 사용하고 (\l은 왼쪽에서 동일 함) 동일한 모든 일반 텍스트 노드에 동일한 너비를 지정합니다. 의 모든 배치하여

digraph G { 
    fontname="Helvetica"; 
    labelloc=t; 
    rankdir=LR; 
    label="Course Graph"; 

    node[style=filled, fontname="Helvetica", colorscheme=greens3, color=1]; 

    subgraph cluster_key { 
     //rank=min; /* this doesn't really do anything for you */ 

     label="Key"; 
     //rankdir=LR; /* this is also not needed*/ 

     kc1[label="Course", peripheries=2, color=2]; 
     k1[shape=plaintext, style=solid, label="Required Course\r", width=3.5] // Add fixed width so all nodes line up 

     prereq[label="Course 1"]; 
     kc2[label="Course 2"]; 
     prereq->kc2; 
     k2[shape=plaintext, style=solid, label="Course 1 is a prerequisite for Course 2\r", width=3.5] // Add fixed width 

     coreq1[label="Course 1"]; 
     coreq2[label="Course 2"]; 
     coreq1->coreq2[dir=both]; 
     k3[shape=plaintext, style=solid, label="Course 1 and Course 2 are corequisite\r", width=3.5] // Add fixed width 

     or[style="dashed", color="black", shape="diamond", label="OR"]; 
     or1[label="Course 1"]; 
     or1 -> or[style="dashed", dir="none"]; 
     or2[label="Course 2"]; 
     or2 -> or[style="dashed", dir="none"]; 
     kc3[label="Course 3"] 
     or->kc3; 
     k4[shape=plaintext, style=solid, label="You must take either Course 1 OR\rCourse 2 before taking Course 3\r", width=3.5] // Add fixed width 

     { rank=source;k1 k2 k3 k4 } // Use "source in stead of min 
    } 

    c3[color=3, peripheries=2]; 
    c4[color=3, peripheries=2]; 

    c1->c2[dir=both]; 
    c2->c3; 

    c4_reqs[style="dashed", color="black", shape="diamond", label="OR"]; 
    c4_reqs->c4; 
    c2->c4_reqs[style="dashed", dir="none"]; 
    c5->c4_reqs[style="dashed", dir="none"]; 

} 
보조 노트에

는 코드가 조금 정리 될 수있다 : 전체 코드는 다음과 같습니다

는 (I 내가 변경 한 몇 가지 의견을 추가) 일반 텍스트 노드를 함께 사용하므로 속성을 더 자주 선언 할 필요가 없습니다. 그러면 코드의 다른 부분으로 분할되지 않는 노드 및 순위 특성의 이점이 추가됩니다.

{ 
     rank=source 
     node [shape=plaintext, style=solid, width=3.5] 

     k1 [label="Required Course\r"] 
     k2 [label="Course 1 is a prerequisite for Course 2\r"] 
     k3 [label="Course 1 and Course 2 are corequisite\r"] 
     k4 [label="You must take either Course 1 OR\rCourse 2 before taking Course 3\r"] 
    }