graphviz 描述语言
2023 11月25日
介绍一下
https://graphviz.org/
graphviz是一个开源工具包,用于绘制“DOT”语言描述的图形。dot语言是图形描述语言,以.dot
结尾,其简单的语法和文本字符形式,便于记录、分发、以及后续修改。在编写好后,graphviz负责将它渲染成png、pdf、或svg,其中,图形会自动进行排布。
举个例子(dot)
官网的例子:https://graphviz.org/doc/info/shapes.html
有向图
用来画有数据流向的,例如数据流图,流程图,简单的依赖关系
digraph helloWorld {
a -> b -> c -> d;
b -> d;
a -> c;
a -> d;
}
无向图
用来画思维导图
// 无向图使用graph
graph helloWorld {
// 表示横向绘制
rankdir=LR;
// -- 表示无向图
// {} 表示组
start -- {learning, play, read};
learning -- {fe};
fe -- {react, vue, angular};
play -- {lol, dota2};
read -- 《对赌》;
}
二叉树
graph tree {
// 用来设置所有节点属性,node edge等
node [
// box polygon square rectangle
// see: https://graphviz.org/doc/info/shapes.html
shape=rectangle
]
// 用于设置某条边的属性
a --{b,e} [color=red]
b -- {c,f}
c -- d [style=dashed]
f -- {g,h} [style=dotted]
}
子图
graph tree {
// 用来设置所有节点属性,node edge等
node [
// box polygon square rectangle
// see: https://graphviz.org/doc/info/shapes.html
shape=rectangle
]
// 用于设置某条边的属性
a --{b,e} [color=red];
b -- {c,f};
c -- d [style=dashed];
f -- {g,h} [style=dotted];
// 以cluster_开头,会被矩形隔离起来
subgraph cluster_level3 {
bgcolor=red;
c;
f;
}
subgraph cluster_root {
label="root"
bgcolor=pink;
a;
}
}
其他布局引擎
https://graphviz.org/docs/layouts/
graphviz是一个强大的工具,除了常见的dot布局引擎,还有neato、fdp、circo等强大的引擎。这些等后续会使用到在介绍吧。
playground
- 官网指向的playground
- google 排名第一的playground
- 一个挺好用的库(使用wasm)