节点的形状可以是以下任意一种:
GraphViz支持html,node节点label内容可以是HTML标签
无需定义, 直接使用,即可生成节点
digraph g {
node [shape = record,height=.1];
"node0" -> "node4";
"node0" -> "node1";
"node1" -> "node2";
"node1" -> "node3";
"node4" -> "node6";
"node4" -> "node5";
}
也可以显式的定义节点
digraph g {
node [shape = record,height=.1];
node0;
node1;
node2;
node3;
node4;
node5;
node6;
"node0" -> "node4";
"node0" -> "node1";
"node1" -> "node2";
"node1" -> "node3";
"node4" -> "node6";
"node4" -> "node5";
}
node label属性自定义node显示的内容
digraph g {
node [shape = record,height=.1];
node0 [label="node0 第一个开始节点"];
node1;
node2;
node3;
node4;
node5;
node6;
"node0" -> "node4";
"node0" -> "node1";
"node1" -> "node2";
"node1" -> "node3";
"node4" -> "node6";
"node4" -> "node5";
}
digraph g {
node [shape = record,height=.1];
node0 [label="node0 \n第一个开始节点\l节点说明\r是这样子\l对齐的是吧\l靠对齐"];
node1[label="第一行说明\n第二行\l"];
node2[label="第一行说明\n第二行\r"];
node3[label="第一行说明\n第二行\n"];
node4[label="第一行说明\n第二行"]
node5;
node6;
"node0" -> "node4";
"node0" -> "node1";
"node1" -> "node2";
"node1" -> "node3";
"node4" -> "node6";
"node4" -> "node5";
}
使用
digraph g {
node [shape = record,height=.1];
node0[label = "G\n开始节点"];
node1[label = " E| "];
node2[label = " | B| "];
node3[label = " F "];
node4[label = " | R| "];
node5[label = " | H| "];
node6[label = " | Y| y2 | y3 | y4 "];
"node0" -> "node4":f1;
"node0" -> "node1":f1;
"node1":f1 -> "node2":f1;
"node1":f2 -> "node3":f1;
"node4":f2 -> "node6":f3;
"node4":f0 -> "node5":f1;
}
node shape值为 record 或者Mrecord 时, 节点就是记录节点,其内容由label定义。
// 用 | 分割多列
// 用 标记行的port值,箭头可指向其准确位置
// 用{ | } 分割多行
digraph g{
a1[shape="record" label="a|b|c|d"];
a2[shape="Mrecord" label="a|b|c|d"];
b1[shape="record" label="{a|b|c|d}"];
b2[shape="Mrecord" label="{ a| b| c| d}"];
c[shape="Mrecord" label=" c1| c2| c3| c4"]
a1->a2;
b1->b2:f3
c:f2->a2;
}
// {} | 嵌套使用,行包含列,列包含行
digraph g{
c[shape="Mrecord" label=" c1| c2| c3| c4"]
d[shape="record" label="{ aa | bb}| c2"];
e[shape="record" label="{ { aa1 | aaaa2} | bb| c2}"];
c:f2->d:fa2;
c:f3->e:w2;
}
digraph g{
struct_c[shape="Mrecord" label=" c1| c2| c3| c4"]
struct_d[shape="record" label="{ aa | bb}| c2"];
struct_e[shape="record" label="{ { aa1 | aaaa2} | bb| c2}"];
struct_c:f2->struct_d:fa2;
struct_c:f3->struct_e:w2;
}
digraph g {
node [shape = record,height=.1];
node0[label=<
a
b
c
>];
node1[label = " E| "];
node2[label = " | B| "];
node3[label = <
hello
world
b
g
h
c
d
e
f
>];
node4[label = " | R| "];
node5[label = " | H| "];
node6[label = " | Y| y2 | y3 | y4 "];
"node0" -> "node4":f1;
"node0" -> "node1":f1;
"node1":f1 -> "node2":f1;
"node1":f2 -> "node3";
"node4":f2 -> "node6":f3;
"node4":f0 -> "node5":f1;
}
节点label属性的内容可以是html,通常情况是一个tabel,可以指定其属性样式等html所支持的标签。
digraph {
d[label=<11 22 33 44
>];
c->d:f2;
e->d:l3;
}
待补充
使用PostScript自定义节点的形状,有兴趣的同学可以参考官方文档说和案例