背景
平时需要经常梳理代码关系,可以使用绘图软件直接绘画,但是修改不方便。如果使用文本绘图就会高效一些,Graphviz就是一种方法,Graphviz的形状为record的node,结合label中|可以模拟画出一个节点多个子成员,结合label中<tag>可以通过node名字直接访问到从而可以灵活的创建数据结构关系
要点
- rankdir=LR是左右分布
- node的shape=record才能用|方式
- lable中 <xxx>是定义成员名字,方便访问
- 主体结构三类,rankdir node定义方式;具体node节点定义节点;通过lable中tag进行连接
- label 中|用来增加一个node中的一行
- label 中\l用来定义字符左对齐
- label 中两个|之间表示的一行,如果用{}表示会嵌套一个整体进来{}内部可以继续用|进行分割(主要用在某些场景有类似union场景)
- 技巧:主要在label中操作,想添加一行就用|增加
模板
digraph struct {
rankdir=LR;
node [shape=record, style=filled, fillcolor=lightblue]
struct_type1 [label="<title> struct type1 |
<m1> - struct m1 m1 \l|
<t2> - struct type2 t2 \l
"
]
struct_type1:m1 -> struct_m1:title
struct_type1:t2 -> struct_type2:title
struct_m1 [label="<title> struct m1 |
<m1> - uint8 m1
"
]
struct_type2 [ color=red, style=filled, fillcolor="green"
label="<title> struct type1 |
<n1> - uint8 n1 \l|
{<n2> abc|def\l}|
<n3> - uint8 n3 \l
"
]
}
效果
可以使用Graph Galaxy软件进行测试(Graph Galaxy软件使用介绍)
后记
更多信息逐渐更新