Family tree layout with Dot/GraphViz

前端 未结 6 1409
慢半拍i
慢半拍i 2020-12-22 17:33

I am trying to draw a family tree with Dot and GraphViz.

This is what I currently have:

# just graph set-up
digraph simpsons {
ratio = \"auto\"
minc         


        
6条回答
  •  醉酒成梦
    2020-12-22 17:59

    I'm almost there, inspired by an old response on the graphviz-interest mailinglist and doug's answer.

    The following code:

    digraph G {
      edge [dir=none];
      node [shape=box];
    
      "Abraham"   [shape=box, regular=1, color="blue"] ;
      "Mona"      [shape=box, regular=1, color="pink"] ;
      "Clancy"    [shape=box, regular=1, color="blue"] ;
      "Jackeline" [shape=box, regular=1, color="pink"] ;
      "Herb"      [shape=box, regular=1, color="blue"] ;
      "Homer"     [shape=box, regular=1, color="blue"] ;
      "Marge"     [shape=box, regular=1, color="pink"] ;
      "Patty"     [shape=box, regular=1, color="pink"] ;
      "Selma"     [shape=box, regular=1, color="pink"] ;
      "Bart"      [shape=box, regular=1, color="blue"] ;
      "Lisa"      [shape=box, regular=1, color="pink"] ;
      "Maggie"    [shape=box, regular=1, color="pink"] ;
      "Ling"      [shape=box, regular=1, color="blue"] ;
    
      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; Abraham -> a1 -> Mona};
      {rank=same; b1 -> b2 -> b3};
      {rank=same; Herb; Homer};
      a1 -> b2
      b1 -> Herb
      b3 -> Homer
    
      p1 [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; Homer -> p1 -> Marge};
      {rank=same; q1 -> q2 -> q3};
      {rank=same; Bart; Lisa; Maggie};
      p1 -> q2;
      q1 -> Bart;
      q2 -> Lisa;
      q3 -> Maggie;
    
      x1 [shape=circle,label="",height=0.01,width=0.01];
      y1 [shape=circle,label="",height=0.01,width=0.01];
      y2 [shape=circle,label="",height=0.01,width=0.01];
      y3 [shape=circle,label="",height=0.01,width=0.01];
      {rank=same; Clancy -> x1 -> Jackeline};
      {rank=same; y1 -> y2 -> y3};
      {rank=same; Marge; Patty; Selma};
      {rank=same; Bart; Ling}
      x1 -> y2;
      y1 -> Marge;
      y2 -> Patty;
      y3 -> Selma;
      Selma -> Ling;
    }
    

    now produces this:

    alt text

    So, looks good except for that strange edge around Homer.If I could find a way to move Abraham, Mona and Herb to the left hand side of the picture then I would have a perfectly aligned picture.

    Any ideas on how to achieve that?

提交回复
热议问题