以下代码生成上图:
digraph G {
//---graph config
fontname=Helvetica
rankdir = RL
splines = polyline
compound = true
//concentrate = true
labeljust = c
labelloc = t
ranksep=0.5
nodesep=0.5
//size="10,10"
ratio=compress
edge [
minlen=1
arrowsize=0.75
labeldistance=5
fontname=Helvetica
fontsize=12
fontcolor=black
labelfontsize=12
labelfontcolor=red
labelfontname=Helvetica
]
node [
fontname=Helvetica
fontsize=12
fontcolor=black
regular=true
shape=diamond
// width=0.25
// height=0.25
]
// --- # nodes
{// records
node [shape=record, width=1]
b10 [label=" { R-7 | 5 } | B/10 "]
b20 [label=" { R-6 | 10 } | B/20 "]
b30 [label=" { R-5 | 10 } | B/30 "]
d10 [label=" { R-10 | 15 } | D/10 "]
d20 [label=" { R-9 | 10 } | D/20 "]
d30 [label=" { R-8 | 10 } | D/30 "]
a20 [label=" { R-2 | 5 } | A/20 "]
a30 [label=" { R-1 | 10 } | A/30 "]
}
{// circles
node [shape=circle]
e [label="E"]
c [label="C"]
}
{// box
node [shape=box]
a [label="A"]
}
//--- # edges
{
edge [weight = 1000]
//straight
c -> b10 -> b20 -> b30
e -> d10 -> d20 -> d30
a20 -> a30 -> a
//combination
{b30 d30} -> a20
}
//--- # Clusters
// subgraph cluster_1{
// label="a "
// e d10 d20
// }
// subgraph cluster_2{
// label="b "
// c b10 b20 b30
// }
// subgraph cluster_3{
// label="c "
// a30 a20
// }
// --- # bugfixes
{// c before e
edge [style=invis]
c -> e
{rank=source e c} // force same rank before other nodes
}
}
这和我想要的一样好看和干净。 但是,我希望能够标记和评论结构的某些部分,我认为集群应该是正确的方法。
如果您取消注释代码的CLUSTERS部分,您将获得以下代码和相应的图表:
digraph G {
//---graph config
fontname=Helvetica
rankdir = RL
splines = polyline
compound = true
//concentrate = true
labeljust = c
labelloc = t
ranksep=0.5
nodesep=0.5
//size="10,10"
ratio=compress
edge [
minlen=1
arrowsize=0.75
labeldistance=5
fontname=Helvetica
fontsize=12
fontcolor=black
labelfontsize=12
labelfontcolor=red
labelfontname=Helvetica
]
node [
fontname=Helvetica
fontsize=12
fontcolor=black
regular=true
shape=diamond
// width=0.25
// height=0.25
]
// --- # nodes
{// records
node [shape=record, width=1]
b10 [label=" { R-7 | 5 } | B/10 "]
b20 [label=" { R-6 | 10 } | B/20 "]
b30 [label=" { R-5 | 10 } | B/30 "]
d10 [label=" { R-10 | 15 } | D/10 "]
d20 [label=" { R-9 | 10 } | D/20 "]
d30 [label=" { R-8 | 10 } | D/30 "]
a20 [label=" { R-2 | 5 } | A/20 "]
a30 [label=" { R-1 | 10 } | A/30 "]
}
{// circles
node [shape=circle]
e [label="E"]
c [label="C"]
}
{// box
node [shape=box]
a [label="A"]
}
//--- # edges
{
edge [weight = 1000]
//straight
c -> b10 -> b20 -> b30
e -> d10 -> d20 -> d30
a20 -> a30 -> a
//combination
{b30 d30} -> a20
}
//--- # Clusters
subgraph cluster_1{
label="a "
e d10 d20
}
subgraph cluster_2{
label="b "
c b10 b20 b30
}
subgraph cluster_3{
label="c "
a30 a20
}
// --- # bugfixes
{// c before e
edge [style=invis]
c -> e
{rank=source e c} // force same rank before other nodes
}
}
从代码末尾的错误修正部分可以看出,我希望节点C和E绝对出现在所有其他节点上方的相同等级。
此外,我希望记录的上下序列与第一个示例中的漂亮直线相连。我介绍的边缘的重量没有帮助。
有没有人知道如何解决这个问题,以及如何使graphviz产生一个漂亮的干净图形,如例#1中只有3个拥抱框和相应的标签添加?
答案 0 :(得分:2)
我试图只修改所需内容:
style=invis
(针对d30)这是我最近使用graphviz版本(2.29)获得的内容:
不完美,但更接近。
digraph G {
//---graph config
fontname=Helvetica
rankdir = RL
splines = polyline
compound = true
//concentrate = true
labeljust = c
labelloc = t
ranksep=0.5
nodesep=0.5
//size="10,10"
ratio=compress
edge [
minlen=1
arrowsize=0.75
labeldistance=5
fontname=Helvetica
fontsize=12
fontcolor=black
labelfontsize=12
labelfontcolor=red
labelfontname=Helvetica
]
node [
fontname=Helvetica
fontsize=12
fontcolor=black
regular=true
shape=diamond
// width=0.25
// height=0.25
]
// --- # nodes
{// records
node [shape=record, width=1]
d10 [label=" { R-10 | 15 } | D/10 "]
d20 [label=" { R-9 | 10 } | D/20 "]
d30 [label=" { R-8 | 10 } | D/30 "]
b10 [label=" { R-7 | 5 } | B/10 "]
b20 [label=" { R-6 | 10 } | B/20 "]
b30 [label=" { R-5 | 10 } | B/30 "]
a20 [label=" { R-2 | 5 } | A/20 "]
a30 [label=" { R-1 | 10 } | A/30 "]
}
{// circles
node [shape=circle]
e [label="E"]
c [label="C"]
}
{// box
node [shape=box]
a [label="A"]
}
//--- # edges
{
//straight
c -> b10 -> b20 -> b30
e -> d10 -> d20 -> d30
a20 -> a30 -> a
//combination
{b30 d30} -> a20}
//--- # Clusters
subgraph cluster_1{
label="a "
e d10 d20
}
subgraph cluster_2{
label="b "
c b10 b20 b30
}
subgraph cluster_3{
label="c "
a30 a20
}
subgraph cluster_4{
label=""
style=invis
d30
}
}