Search code examples
graphvizdot

How to implement Grandchild (Enkel1) into Family-Tree with graphviz?


I´m building a Family tree with Grandparents, Parents, Children and Grandchildren (Children with Ex-Partners are possible too). Its working perfect, but there is a Problem with the grandchilds. When i try to connect v1 with Enkel1, i´m getting Problems with the layout. I don`t understand this Problem because its working exactly with "Ex-Kind" and Point c1. Can you please give me a tipp?

Thank you so much,

Peter

digraph G { 
edge [dir=none]; 
node [shape=box]; 
graph [splines=ortho compound=true, pad="0.4", nodesep="0.2",          ranksep="0.2"]; 
mindist=1

"Max\nMustermann" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ;
"Maxi\nTestermann" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ;
"Moritz\nMustermann" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ; 
"Nina\nMustermann" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ; 
"Volker\nVersuch" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ; 
"Veronika\nVersuch" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ; 
"Maximilian\nMustermann"[shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ; 
"Maxima\nMustermann" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ; 
"Bart" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ;
"Lisa" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ; 
"Maggie" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ; 
"Ex\nPartner" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ;
"Schwiegertochter" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ;
"Enkel1" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ;
"Ex-Kind" [shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10] ;

a1 [shape=circle,label="",height=0.01,width=0.01];
b1 [shape=circle,label="",height=0.01,width=0.01]; 
b2 [shape=circle,label="",height=0.01,width=0.01]; 
b3 [shape=circle,label="",height=0.01,width=0.01];


{rank=same; "Maximilian\nMustermann" -> a1 -> "Maxima\nMustermann"}; 
{rank=same; b1 -> b2 -> b3}; 
a1 -> b2; 
b1 -> "Max\nMustermann"; 
b2 -> "Maxi\nTestermann";
b3 -> "Moritz\nMustermann";

c1 [shape=circle,label="",height=0.01,width=0.01];
{rank=same; "Ex\nPartner" -> c1 -> "Moritz\nMustermann"}; 

c1->"Ex-Kind";


x1 [shape=circle,label="",height=0.01,width=0.01]; 
{rank=same; "Volker\nVersuch" -> x1 -> "Veronika\nVersuch"}; 
{rank=same"Maxima\nMustermann"; "Volker\nVersuch" }
x1 ->  "Nina\nMustermann"; 

p1 [shape=circle,label="",height=0.01,width=0.01]; 
p2 [shape=circle,label="",height=0.01,width=0.01]; 
p3 [shape=circle,label="",height=0.01,width=0.01]; 
q1 [shape=circle,label="",height=0.01,width=0.01]; 
q2 [shape=circle,label="",height=0.01,width=0.01]; 
q3 [shape=circle,label="",height=0.01,width=0.01]; 


{rank=same; "Moritz\nMustermann" -> p1 -> "Nina\nMustermann"}; 
{rank=same;q1 -> q2 -> q3}; 
{rank=same;"Bart";"Lisa";"Maggie"}; 

p1 -> p2 -> p3 ->q2; 
q1 -> Bart; 
q2 -> Lisa;
q3 -> Maggie;

v1 [shape=circle,label="",height=0.01,width=0.01];
{rank=same; "Bart" -> v1 -> "Schwiegertochter"}; 







}

Solution

  • You need to force the order of the last (Bart) row with invisible edges; I have added

    { rank = same; Schwiegertochter -> Lisa -> Maggie[ style = invis ] }
    

    at the bottom; I also have (more for my own pleasure than for real need) cleaned up the code, coming up with

    digraph G 
    { 
        graph[ splines=ortho, pad="0.4", nodesep="0.2", ranksep="0.2" ];
        mindist=1
    
        node[ shape=box, regular=0,color="black", style="filled" fillcolor="grey", width=1.5, height = 0.5, fontsize=10 ]; 
        "Max\nMustermann", "Maxi\nTestermann", "Moritz\nMustermann", "Nina\nMustermann"; 
        "Volker\nVersuch", "Veronika\nVersuch", "Maximilian\nMustermann", "Maxima\nMustermann"; 
        "Bart", "Lisa", "Maggie", "Ex\nPartner", "Schwiegertochter", "Enkel1", "Ex-Kind";
    
        node[ shape=circle,label="",height=0.01,width=0.01 ];
        a1, b1, b2, b3, c1, x1, p1, p2, p3, q1, q2, q3, v1;
    
        edge[ dir=none ];
    
        { rank=same; "Maximilian\nMustermann" -> a1 -> "Maxima\nMustermann" }
        { rank=same; b1 -> b2 -> b3 }
        a1 -> b2; 
        b1 -> "Max\nMustermann"; 
        b2 -> "Maxi\nTestermann";
        b3 -> "Moritz\nMustermann";
    
        { rank=same; "Ex\nPartner" -> c1 -> "Moritz\nMustermann" }
    
        c1->"Ex-Kind";
    
    
        { rank=same; "Volker\nVersuch" -> x1 -> "Veronika\nVersuch" }
        { rank=same"Maxima\nMustermann"; "Volker\nVersuch" }
        x1 ->  "Nina\nMustermann"; 
    
        { rank=same; "Moritz\nMustermann" -> p1 -> "Nina\nMustermann"}
        { rank=same;q1 -> q2 -> q3}
        { rank=same;"Bart";"Lisa";"Maggie" }
    
        p1 -> p2 -> p3 ->q2; 
        q1 -> Bart; 
        q2 -> Lisa;
        q3 -> Maggie;
    
        { rank=same; "Bart" -> v1 -> "Schwiegertochter" }
        { rank = same; Schwiegertochter -> Lisa -> Maggie[ style = invis ] }
        v1 -> Enkel1;
    }
    

    which gives you

    enter image description here