java用dot graphviz,带Dot / GraphViz的族谱布局

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"

mincross = 2.0

# draw some nodes

"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"] ;

# creating tiny nodes w/ no label, no color

"ParentsHomer" [shape=diamond,style=filled,label="",height=.1,width=.1] ;

"ParentsMarge" [shape=diamond,style=filled,label="",height=.1,width=.1] ;

"ParentsBart" [shape=diamond,style=filled,label="",height=.1,width=.1] ;

# draw the edges

"Abraham" -> "ParentsHomer" [dir=none, weight=1] ;

"Mona" -> "ParentsHomer" [dir=none, weight=1] ;

"ParentsHomer" -> "Homer" [dir=none, weight=2] ;

"ParentsHomer" -> "Herb" [dir=none, weight=2] ;

"Clancy" -> "ParentsMarge" [dir=none, weight=1] ;

"Jackeline" -> "ParentsMarge" [dir=none, weight=1] ;

"ParentsMarge" -> "Marge" [dir=none, weight=2] ;

"ParentsMarge" -> "Patty" [dir=none, weight=2] ;

"ParentsMarge" -> "Selma" [dir=none, weight=2] ;

"Homer" -> "ParentsBart" [dir=none, weight=1] ;

"Marge" -> "ParentsBart" [dir=none, weight=1] ;

"ParentsBart" -> "Bart" [dir=none, weight=2] ;

"ParentsBart" -> "Lisa" [dir=none, weight=2] ;

"ParentsBart" -> "Maggie" [dir=none, weight=2] ;

"Selma" -> "Ling" [dir=none, weight=2] ;

}

If I run this through dot (dot simpsons.dot -Tsvg > simpsons.svg),

I get the following layout:

5192e971c689fdb0725c7853a97c02bb.png

However, I'd like the edges to be more "family tree"-like: a T-junction between two married persons with the vertical line of the T again branching in an upside-down T-junction with small subdivisions for each of the children, like this mock-up, done in KolourPaint:

2429c6d0eccda4d8999d4b1f44b628ed.png

What is the dot syntax that I have to use to achieve this?

解决方案

Here is an other solution :

digraph simpsons {

subgraph Generation0 {

rank = same

Abraham [shape = box, color = blue]

Mona [shape = box, color = pink]

AbrahamAndMona [shape = point]

Abraham -> AbrahamAndMona [dir = none]

AbrahamAndMona -> Mona [dir = none]

Clancy [shape = box, color = blue]

Jackeline [shape = box, color = pink]

ClancyAndJackeline [shape = point]

Clancy -> ClancyAndJackeline [dir = none]

ClancyAndJackeline -> Jackeline [dir = none]

}

subgraph Generation0Sons {

rank = same

AbrahamAndMonaSons [shape = point]

HerbSon [shape = point]

HomerSon [shape = point]

HerbSon -> AbrahamAndMonaSons [dir = none]

HomerSon -> AbrahamAndMonaSons [dir = none]

MargeSon [shape = point]

PattySon [shape = point]

SelmaSon [shape = point]

MargeSon -> PattySon [dir = none]

PattySon -> SelmaSon [dir = none]

}

AbrahamAndMona -> AbrahamAndMonaSons [dir = none]

ClancyAndJackeline -> PattySon [dir = none]

subgraph Generation1 {

rank = same

Herb [shape = box, color = blue]

Homer [shape = box, color = blue]

Marge [shape = box, color = pink]

Patty [shape = box, color = pink]

Selma [shape = box, color = pink]

HomerAndMarge [shape = point]

Homer -> HomerAndMarge [dir = none]

Marge -> HomerAndMarge [dir = none]

}

HerbSon -> Herb [dir = none]

HomerSon -> Homer [dir = none]

MargeSon -> Marge [dir = none]

PattySon -> Patty [dir = none]

SelmaSon -> Selma [dir = none]

subgraph Generation1Sons {

rank = same

BartSon [shape = point]

LisaSon [shape = point]

MaggieSon [shape = point]

BartSon -> LisaSon [dir = none]

LisaSon -> MaggieSon [dir = none]

}

HomerAndMarge -> LisaSon [dir = none]

subgraph Generation2 {

rank = same

Bart [shape = box, color = blue]

Lisa [shape = box, color = pink]

Maggie [shape = box, color = pink]

Ling [shape = box, color = blue]

}

Selma -> Ling [dir = none]

BartSon -> Bart [dir = none]

LisaSon -> Lisa [dir = none]

MaggieSon -> Maggie [dir = none]

}

And the result :

6qxNG.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值