Graphviz - Graph Visualization Software
官方示意图: Gallery
官方文档:Documentation
windows版本:
本地文档目录: C:\Program Files (x86)\Graphviz2.38\share\graphviz\doc\pdf 或 html
使用方法:C:\Program Files (x86)\Graphviz2.38\bin\ gvedit.exe, 双击运行即可
基本用法参考:
DOT语言:The DOT Language
命令行调用:Command-line Usage
输出格式:Output Formats
结点,边,图形属性:Node, Edge and Graph Attributes
结点形状关键词:Node Shapes
颜色关键词:Color Names
箭头关键词:Arrow Shapes
语法框架:
graph : [ strict ] (graph | digraph) [ ID ] '{' stmt_list '}' //一般用graph图,或digraph有向图
stmt_list : [ stmt [ ';' ] stmt_list ] //stmt有下列四中
stmt : node_stmt
| edge_stmt
| attr_stmt
| ID '=' ID
| subgraph
attr_stmt : (graph | node | edge) attr_list
attr_list : '[' [ a_list ] ']' [ attr_list ]
a_list : ID '=' ID [ (';' | ',') ] [ a_list ]
edge_stmt : (node_id | subgraph) edgeRHS [ attr_list ]
edgeRHS : edgeop (node_id | subgraph) [ edgeRHS ]
node_stmt : node_id [ attr_list ]
node_id : ID [ port ]
port : ':' ID [ ':' compass_pt ]
| ':' compass_pt
subgraph : [ subgraph [ ID ] ] '{' stmt_list '}'
compass_pt : (n | ne | e | se | s | sw | w | nw | c | _)
如:
graph graph_name{
//stmt_list
}
digraph graph_name{
//stmt_list
}
例子:
tree
digraph tree {
size="16,16";
node [color=lightblue2, style=filled];
"xx" -> "yy";
"xx" -> "78";
"yy" -> "zz";
"yy" -> "12";
"12" -> "34";
"34" -> "12"; /*反向*/
"34" -> "45";
"78" -> "910";
}
reference: Graphviz Example: UNIX Family ‘Tree’
流程图:
digraph flow {
node [shape=ellipse, color=lightpink, style=filled];
"Start";
"End";
node [shape=box, color=lightpink, style=filled];
"Do Task";
node [shape=diamond, color=lightpink, style=filled];
"Condition?";
"start_point" [shape=diamond, label="", height=.01, width=.01] ;
"Start" -> "start_point" [dir=none,weight=2];
"start_point" -> "Do Task" [dir=forward,weight=2] ;
"Do Task" -> "Condition?" [dir=forward,weight=2] ;
"Condition?" -> "start_point" [label="Ture", dir=1, weight=0]
"Condition?" -> "End" [label="False"];
}
reference:
Graphviz Example: Entity-Relation Data Model 参考方块 椭圆
Graphviz Example: Cluster Gradients 参考子图
Graphviz Example: lion_share 参考结点
处理脚本
拷贝下列代码,保存为gen_photo.bat, 运行即可
set src_filename=ex1.gv
set photo_type=png
set out_filename=x
dot -Kcirco %src_filename% -T%photo_type% -o %out_filename%_circo.%photo_type%
dot -Kdot %src_filename% -T%photo_type% -o %out_filename%_dot.%photo_type%
dot -Kfdp %src_filename% -T%photo_type% -o %out_filename%_fdp.%photo_type%
dot -Kneato %src_filename% -T%photo_type% -o %out_filename%_neato.%photo_type%
dot -Knop %src_filename% -T%photo_type% -o %out_filename%_nop.%photo_type%
dot -Knop1 %src_filename% -T%photo_type% -o %out_filename%_nop1.%photo_type%
dot -Knop2 %src_filename% -T%photo_type% -o %out_filename%_nop2.%photo_type%
dot -Kosage %src_filename% -T%photo_type% -o %out_filename%_osage.%photo_type%
dot -Kpatchwork %src_filename% -T%photo_type% -o %out_filename%_patchwork.%photo_type%
dot -Ksfdp %src_filename% -T%photo_type% -o %out_filename%_sfdp.%photo_type%
参考:
Graphviz绘图 - DOT语言 - 老彭的博客
使用DOT语言和Graphviz绘图(翻译) - Casa Taloyum