Search code examples
graphviz

How to center Graphiz transition label?


how can I center label in graphviz ?

digraph "toto" {
graph ["rankdir"="TB"]
node ["shape"="box"]
"BROUILLON" ["label"="Brouillon","margin"="0.4,0.0"]
"A_VALIDER_RH" ["label"="À valider par la RH","margin"="0.4,0.0","color"="red"]
"A_VALIDER_RH" -> "BROUILLON" ["label"="Refuser"]
"BROUILLON" -> "A_VALIDER_RH" ["label"="Soumettre"]
}

I have:

enter image description here

expected:

enter image description here


Solution

  • You will need to use extra nodes for the labels:

    digraph "toto" 
    {
        // graph[ "rankdir" = "TB" ]
        
        // nodes
        node[ shape = box ];
        BROUILLON[ label= "Brouillon", margin = "0.4,0.0" ];
        A_VALIDER_RH[ label = "À valider par la RH", margin = "0.4,0.0", color = red ];
        node[ shape = plaintext ];
        n1[ label = "Soumettre" ];
        n2[ label = "Refuser" ];
    
        // edges
        BROUILLON -> n1 ->  A_VALIDER_RH;
        BROUILLON -> n2 -> A_VALIDER_RH[ dir = back ];
    }
    

    yields enter image description here