Search code examples
graphviz

Control position of clusters in Graphviz


I have a graphiz project where I would like to position my clusters horizontally from left to right with cluster_c2 (called QGIS) in the middle. I have attempted to use the newrank=true; as described here without success. The current output of my graphviz script is:

enter image description here

My current script is:

digraph {

    node [shape=record, fontname="Arial"];
    rankdir=LR;

    L [label="Line"]
    ML [label="Multi-Line"]
    QL [label="Line"]
    QML [label = "Multi-Line"]
    QCS [label = "Circular-String"]
    QCC [label = "Compound-Curve"]
    P [label="PolyLine"]

    subgraph cluster_c1 {
        label = "SpatiaLite";
        fontname="Arial";
        L;
        ML;
    }

    subgraph cluster_c2 {
        label = "QGIS";
        fontname="Arial";
        QL;
        QML;
        QCS;
        QCC;
    }

    subgraph cluster_c3 {
        label = "Shapefile";
        fontname="Arial";
        P;
    }

    L -> QL   [dir=both];
    QCS -> L [color=grey];
    QCS -> ML   [color=grey];
    QCC -> ML  [color=grey];
    QML -> ML [dir=both];
    QCC -> L [ color=grey];
    QML-> L [color=grey];
    QL -> ML [color=grey];
    QCS -> P;
    QCC -> P;
    QML -> P [dir=both];
    QL -> P ;

}

Solution

  • I don't know how it works, but it seems that combination of newrank="true" and rank=same inside each subgraph works:

    digraph {
      node [shape=record, fontname="Arial"];
      newrank=true;
      rankdir=LR;
    
      L [label="Line"];
      ML [label="Multi-Line"];
      QL [label="Line"];
      QML [label = "Multi-Line"];
      QCS [label = "Circular-String"];
      QCC [label = "Compound-Curve"];
      P [label="PolyLine"];
    
      subgraph cluster_c1 { 
        rank=same;
        label = "SpatiaLite";
        fontname="Arial";
        L;
        ML;
      }
    
      subgraph cluster_c2 { 
        rank=same;
        label = "QGIS";
        fontname="Arial";
        QL;
        QML;
        QCS;
        QCC;
      }
    
      subgraph cluster_c3 { 
        rank=same;
        label = "Shapefile";
        fontname="Arial";
        P;
      }
    
      L -> QL   [dir=both];   
      ML -> QML [dir=both];        
      QCS -> L [color=grey];
      QCS -> ML   [color=grey];   
      QCC -> ML  [color=grey];   
      QCC -> L [ color=grey];
      QML-> L [color=grey];  
      QL -> ML [color=grey];    
      QCS -> P; 
      QCC -> P; 
      QML -> P [dir=both];
      QL -> P ;
    }
    

    enter image description here