其实我是看了[url=http://www.ffnn.nl/pages/articles/media/uml-diagrams-using-graphviz-dot.php]这篇文章[/url],我跟着做了,发现他最终做的效果还没有我的好。把我的代码贴出来,其实基本上就是用rank=same:
[code]
digraph G {
nodesep=0.8;
node [ fontname="Bitstream Vera Sans", fontsize=8, shape="record" ]
edge [
fontsize=8
arrowhead="empty"
]
Animal [
label = "{Animal|+ name: String\l+ age: Integer\l|+ die(): void\l}"
]
subgraph clusterAnimalImpl {
label="Package animal.impl"
Dog [
label = "{Dog||+ bark(): void\l}"
]
Cat [
label = "{Cat||+ meow(): void\l}"
]
{ rank=same; Dog; Cat }
}
Dog -> Animal
Cat -> Animal
edge [
arrowhead = "none"
headlabel = "0..*"
taillabel = "0..*"
]
Dog -> Cat
}
[/code]
效果:
[img]http://marlonyao.iteye.com/upload/picture/pic/80692/ceea378c-af5c-3144-9c60-7a794e78406b.png[/img]
[code]
digraph G {
nodesep=0.8;
node [ fontname="Bitstream Vera Sans", fontsize=8, shape="record" ]
edge [
fontsize=8
arrowhead="empty"
]
Animal [
label = "{Animal|+ name: String\l+ age: Integer\l|+ die(): void\l}"
]
subgraph clusterAnimalImpl {
label="Package animal.impl"
Dog [
label = "{Dog||+ bark(): void\l}"
]
Cat [
label = "{Cat||+ meow(): void\l}"
]
{ rank=same; Dog; Cat }
}
Dog -> Animal
Cat -> Animal
edge [
arrowhead = "none"
headlabel = "0..*"
taillabel = "0..*"
]
Dog -> Cat
}
[/code]
效果:
[img]http://marlonyao.iteye.com/upload/picture/pic/80692/ceea378c-af5c-3144-9c60-7a794e78406b.png[/img]