Peter A
Peter A

Reputation: 1

How to place Graphviz graph centered

How can I place vertex A on the middle of the page, so that the graph stays a bit symmetric?

I have no clue how to make this work, I tried looking at the Graphviz documentation but did not find anything. I am using the dot language.

Here is the image:

enter image description here

    digraph {
        A [color="black",penwidth=2.0 style="filled" fillcolor="gray"];
        B [color="black" style="filled" fillcolor="gray"];
        D [color="black" style="filled" fillcolor="gray"];
        C [color="black" style="filled" fillcolor="gray"];
        F [color="black" style="filled" fillcolor="gray"];
        E [color="black" style="filled" fillcolor="gray"];
        G [color="black" style="filled" fillcolor="gray"];
        H [color="black" style="filled" fillcolor="gray"];
        I [color="black" style="filled" fillcolor="gray"];
        J [color="black",penwidth=2.0 style="filled" fillcolor="gray"];
        K [color="black" style="filled" fillcolor="gray"];
        L [color="black" style="filled" fillcolor="gray"];
        M [color="black" style="filled" fillcolor="gray"];
        A -> B[label="1093.53",weight="1093.53"];
        A -> B[label="878.80",weight="878.80"];//color=red,penwidth=2.0];
        A -> B[label="1136.33",weight="1136.33"];
    
        B -> C[label="257.72",weight="257.72"];
        B -> D[label="816.70",weight="816.70" ];//color=red,penwidth=2.0];
    
        C -> E[label="2340.11"]
        E -> F[label="825.67"]
    
        D -> G[label="3829.78"]//color=red,penwidth=2.0]
        D -> H[label="3163.72"]
        D -> H[label="3439.66"]
        D -> I[label="3573.77"]
        D -> I[label="3985.40"]
        K -> D[label="852.19"]
        D -> M[label="1318.09"]
        D -> J[label="5044.72"]
        D -> G[label="4026.24"]
    
        H -> I[label="231.29"]
        I -> H[label="320.08"]
        H -> G[label="867.07"]
    
        G -> J[label="997.73"]//color=red,penwidth=2.0]
        G -> J[label="1027.49"]
        G -> J[label="1050.44"]
        G -> J[label="2064.04"]
    
        A -> K[label="901.48",weight="901.48"]//,color="#7a82de:black;0.01",penwidth=1.5]
        K -> L[label="850.34",weight="850.34"]//,color="#7a82de:black;0.01",penwidth=1.5]
        D -> L[label="525.88",weight="525.88"]
        L -> I[label="3031.98",weight="3031.98" ]//,color="#7a82de:black;0.01",penwidth=1.5]
        I -> J[label="1935.57",weight="1935.57" ]//,color="#7a82de:black;0.01",penwidth=1.5]
    
        F -> M[label="1690.73",weight="1690.73"]
        E -> M[label="2709.56",weight="2709.56"]
    
        M ->G[label="3176.20",weight="3176.20"]
    }

Can someone help me? Thanks in advance.

Upvotes: 0

Views: 323

Answers (1)

sroush
sroush

Reputation: 6801

(guessing that middle of the page means centered in the graph - natural language is ambiguous)
The closest Graphiz comes to this request is the twopi layout engine (https://graphviz.org/docs/layouts/twopi/).
Here is your input fed to twopi with just 3 changes (only root=A is required)

  • graph [root=A label=twopi]
  • A [color="black",penwidth=2.0 style="filled" fillcolor="red"];

Giving:
enter image description here

Upvotes: 1

Related Questions