2010-01-19 9 views
9

Ich habe hier eine Testgrafik, die ich anpassen möchte, damit sie schöner aussieht.graphviz: kleinere Verbesserungen, um das Diagramm schöner aussehen zu lassen

alt text

Hier ist die graphviz (dot) Quelle, test6.dot:

  • ich den Knoten fließen wollen 10 -> 11 -> 12 -> 8 -> 13 -> 14 zu:

    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 
        } 
    

    Fragen/Änderungen würde ich gerne machen in einer vertikalen Linie sein (vertausche 8 und 9 horizontal). Wie kann ich das machen? (selbe mit 1 -> 2 -> 3 -> X2 -> 5; vertauschen 6 und 1)

  • Ich möchte X1 auf der gleichen vertikalen Position als 10, und die gleiche horizontale Position wie 6. Wie kann ich das tun?
  • Ich möchte 8 und X3 und 7 auf der gleichen vertikalen Position sein, auch mit 14 und X4 und 3. Wie kann ich das tun?
  • Die ranksep=0.3; Anweisung funktioniert gut, außer dass 8 -> 13 -> 14 eine größere Lücke hat, wie auch X3 -> gap -> X4. Warum gehorcht es nicht der ranksep = 0.3-Regel, und wie repariere ich das?

Antwort

17

Unten ist das Beste, was ich tun kann: Phantomknoten und Kanten helfen. Aber ich kann nicht eine bestimmte Reihenfolge in der Querrichtung (die andere Richtung von rankdir) ermutigen.

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; 
    } 

    } 
Verwandte Themen