Graphviz Notes
来自Jack's Lab
(版本间的差异)
(→Introduction) |
|||
第7行: | 第7行: | ||
<br><br> | <br><br> | ||
− | == | + | == 以图片为节点 == |
+ | |||
+ | <pre> | ||
+ | digraph abc{ | ||
+ | node [shape="record"]; | ||
+ | edge [style="dashed"]; | ||
+ | |||
+ | a [style="filled", color="black", fillcolor="chartreuse"]; | ||
+ | b; | ||
+ | c [shape="none", image="chrome-icon.png", label=""]; | ||
+ | d; | ||
+ | |||
+ | a -> b; | ||
+ | b -> d; | ||
+ | c -> d [color="red"]; | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | |||
+ | <br><br> | ||
+ | |||
+ | == 子图 == | ||
+ | |||
+ | <source lang=bash> | ||
+ | digraph abc{ | ||
+ | |||
+ | node [shape="record"]; | ||
+ | edge [style="dashed"]; | ||
+ | |||
+ | a [style="filled", color="black", fillcolor="chartreuse"]; | ||
+ | b; | ||
+ | |||
+ | subgraph cluster_cd{ | ||
+ | label="c and d"; | ||
+ | bgcolor="mintcream"; | ||
+ | c; | ||
+ | d; | ||
+ | } | ||
+ | |||
+ | a -> b; | ||
+ | b -> d; | ||
+ | c -> d [color="red"]; | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | == FSM == | ||
<source lang=bash> | <source lang=bash> | ||
第33行: | 第80行: | ||
<br><br> | <br><br> | ||
+ | |||
+ | == 时序图 == | ||
+ | |||
+ | <source lang=bash> | ||
+ | digraph G { | ||
+ | rankdir="LR"; | ||
+ | node[shape="point", width=0, height=0]; | ||
+ | edge[arrowhead="none", style="dashed"] | ||
+ | |||
+ | { | ||
+ | rank="same"; | ||
+ | edge[style="solided"]; | ||
+ | LC[shape="plaintext"]; | ||
+ | LC -> step00 -> step01 -> step02 -> step03 -> step04 -> step05; | ||
+ | } | ||
+ | |||
+ | { | ||
+ | rank="same"; | ||
+ | edge[style="solided"]; | ||
+ | Agency[shape="plaintext"]; | ||
+ | Agency -> step10 -> step11 -> step12 -> step13 -> step14 -> step15; | ||
+ | } | ||
+ | |||
+ | { | ||
+ | rank="same"; | ||
+ | edge[style="solided"]; | ||
+ | Agent[shape="plaintext"]; | ||
+ | Agent -> step20 -> step21 -> step22 -> step23 -> step24 -> step25; | ||
+ | } | ||
+ | |||
+ | step00 -> step10 [label="sends email new custumer", arrowhead="normal"]; | ||
+ | step11 -> step01 [label="declines", arrowhead="normal"]; | ||
+ | step12 -> step02 [label="accepts", arrowhead="normal"]; | ||
+ | step13 -> step23 [label="forward to", arrowhead="normal"]; | ||
+ | step24 -> step14; | ||
+ | step14 -> step04 [arrowhead="normal"]; | ||
+ | } | ||
+ | </source> | ||
<br><br> | <br><br> | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | == UML == | ||
+ | |||
+ | <source lang=bash> | ||
+ | digraph G{ | ||
+ | |||
+ | fontname = "Courier New" | ||
+ | fontsize = 10 | ||
+ | |||
+ | node [ fontname = "Courier New", fontsize = 10, shape = "record" ]; | ||
+ | edge [ fontname = "Courier New", fontsize = 10 ]; | ||
+ | |||
+ | Animal [ label = "{Animal |+ name : String\l+ age : int\l|+ die() : void\l}" ]; | ||
+ | |||
+ | subgraph clusterAnimalImpl{ | ||
+ | bgcolor="yellow" | ||
+ | Dog [ label = "{Dog||+ bark() : void\l}" ]; | ||
+ | Cat [ label = "{Cat||+ meow() : void\l}" ]; | ||
+ | }; | ||
+ | |||
+ | edge [ arrowhead = "empty" ]; | ||
+ | |||
+ | Dog->Animal; | ||
+ | Cat->Animal; | ||
+ | Dog->Cat [arrowhead="none", label="0..*"]; | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | == 语法树 == | ||
+ | |||
+ | <source lang=bash> | ||
+ | digraph ast{ | ||
+ | fontname = "Microsoft YaHei"; | ||
+ | fontsize = 10; | ||
+ | |||
+ | node [shape = circle, fontname = "Microsoft YaHei", fontsize = 10]; | ||
+ | edge [fontname = "Microsoft YaHei", fontsize = 10]; | ||
+ | node [shape="plaintext"]; | ||
+ | |||
+ | mul [label="mul(*)"]; | ||
+ | add [label="add(+)"]; | ||
+ | |||
+ | add -> 3 | ||
+ | add -> 4; | ||
+ | mul -> add; | ||
+ | mul -> 5; | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | == 模块生命周期 == | ||
+ | |||
+ | <source lang=bash> | ||
+ | digraph module_lc{ | ||
+ | rankdir=TB; | ||
+ | fontname = "Microsoft YaHei"; | ||
+ | fontsize = 12; | ||
+ | |||
+ | node [fontname = "Microsoft YaHei", fontsize = 12, shape = "Mrecord", color="skyblue", style="filled"]; | ||
+ | edge [fontname = "Microsoft YaHei", fontsize = 12, color="darkgreen" ]; | ||
+ | |||
+ | installed [label="已安装状态"]; | ||
+ | resolved [label="已就绪状态"]; | ||
+ | uninstalled [label="已卸载状态"]; | ||
+ | starting [label="正在启动"]; | ||
+ | active [label="已激活(运行)状态"]; | ||
+ | stopping [label="正在停止"]; | ||
+ | start [label="", shape="circle", width=0.5, fixedsize=true, style="filled", color="black"]; | ||
+ | |||
+ | start -> installed [label="安装"]; | ||
+ | installed -> uninstalled [label="卸载"]; | ||
+ | installed -> resolved [label="准备"]; | ||
+ | installed -> installed [label="更新"]; | ||
+ | resolved -> installed [label="更新"]; | ||
+ | resolved -> uninstalled [label="卸载"]; | ||
+ | resolved -> starting [label="启动"]; | ||
+ | starting -> active [label=""]; | ||
+ | active -> stopping [label="停止"]; | ||
+ | stopping -> resolved [label=""]; | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | == 软件模块组成 == | ||
+ | |||
+ | <source lang=bash> | ||
+ | digraph idp_modules{ | ||
+ | |||
+ | rankdir = TB; | ||
+ | fontname = "Microsoft YaHei"; | ||
+ | fontsize = 12; | ||
+ | |||
+ | node [ fontname = "Microsoft YaHei", fontsize = 12, shape = "record" ]; | ||
+ | edge [ fontname = "Microsoft YaHei", fontsize = 12 ]; | ||
+ | |||
+ | subgraph cluster_sl{ | ||
+ | label="IDP支持层"; | ||
+ | bgcolor="mintcream"; | ||
+ | node [shape="Mrecord", color="skyblue", style="filled"]; | ||
+ | network_mgr [label="网络管理器"]; | ||
+ | log_mgr [label="日志管理器"]; | ||
+ | module_mgr [label="模块管理器"]; | ||
+ | conf_mgr [label="配置管理器"]; | ||
+ | db_mgr [label="数据库管理器"]; | ||
+ | }; | ||
+ | |||
+ | subgraph cluster_md{ | ||
+ | label="可插拔模块集"; | ||
+ | bgcolor="lightcyan"; | ||
+ | node [color="chartreuse2", style="filled"]; | ||
+ | mod_dev [label="开发支持模块"]; | ||
+ | mod_dm [label="数据建模模块"]; | ||
+ | mod_dp [label="部署发布模块"]; | ||
+ | }; | ||
+ | |||
+ | mod_dp -> mod_dev [label="依赖..."]; | ||
+ | mod_dp -> mod_dm [label="依赖..."]; | ||
+ | mod_dp -> module_mgr [label="安装...", color="yellowgreen", arrowhead="none"]; | ||
+ | mod_dev -> mod_dm [label="依赖..."]; | ||
+ | mod_dev -> module_mgr [label="安装...", color="yellowgreen", arrowhead="none"]; | ||
+ | mod_dm -> module_mgr [label="安装...", color="yellowgreen", arrowhead="none"]; | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | == hash表的实例 == | ||
+ | |||
+ | <source lang=bash> | ||
+ | digraph st{ | ||
+ | fontname = "Verdana"; | ||
+ | fontsize = 10; | ||
+ | rankdir = LR; | ||
+ | rotate = 90; | ||
+ | |||
+ | node [ shape="record", width=.1, height=.1]; | ||
+ | node [fontname = "Verdana", fontsize = 10, color="skyblue", shape="record"]; | ||
+ | |||
+ | edge [fontname = "Verdana", fontsize = 10, color="crimson", style="solid"]; | ||
+ | node [shape="plaintext"]; | ||
+ | |||
+ | st_table [label=< | ||
+ | <table border="0" cellborder="1" cellspacing="0" align="left"> | ||
+ | <tr> | ||
+ | <td>st_table</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>num_bins=5</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td>num_entries=3</td> | ||
+ | </tr> | ||
+ | <tr> | ||
+ | <td port="bins">bins</td> | ||
+ | </tr> | ||
+ | </table> | ||
+ | >]; | ||
+ | |||
+ | node [shape="record"]; | ||
+ | num_bins [label=" <b1> | <b2> | <b3> | <b4> | <b5> ", height=2]; | ||
+ | node[ width=2 ]; | ||
+ | |||
+ | entry_1 [label="{<e>st_table_entry|<next>next}"]; | ||
+ | entry_2 [label="{<e>st_table_entry|<next>null}"]; | ||
+ | entry_3 [label="{<e>st_table_entry|<next>null}"]; | ||
+ | |||
+ | st_table:bins -> num_bins:b1; | ||
+ | num_bins:b1 -> entry_1:e; | ||
+ | entry_1:next -> entry_2:e; | ||
+ | num_bins:b3 -> entry_3:e; | ||
+ | } | ||
+ | </source> | ||
+ | |||
+ | <br><br> | ||
+ | |||
+ | == 数据结构 == | ||
+ | |||
+ | <source lang=bash> | ||
+ | digraph st2{ | ||
+ | fontname = "Verdana"; | ||
+ | fontsize = 10; | ||
+ | rankdir=TB; | ||
+ | |||
+ | node [fontname = "Verdana", fontsize = 10, color="skyblue", shape="record"]; | ||
+ | |||
+ | edge [fontname = "Verdana", fontsize = 10, color="crimson", style="solid"]; | ||
+ | |||
+ | st_hash_type [label="{<head>st_hash_type|(*compare)|(*hash)}"]; | ||
+ | st_table_entry [label="{<head>st_table_entry|hash|key|record|<next>next}"]; | ||
+ | st_table [label="{st_table|<type>type|num_bins|num_entries|<bins>bins}"]; | ||
+ | |||
+ | st_table:bins -> st_table_entry:head; | ||
+ | st_table:type -> st_hash_type:head; | ||
+ | st_table_entry:next -> st_table_entry:head [style="dashed", color="forestgreen"]; | ||
+ | } | ||
+ | </source> | ||
<br><br> | <br><br> | ||
<br><br> | <br><br> |
2016年4月26日 (二) 09:12的版本
目录 |
1 Introduction
$ dot test.dot -T png -o test.png
2 以图片为节点
digraph abc{ node [shape="record"]; edge [style="dashed"]; a [style="filled", color="black", fillcolor="chartreuse"]; b; c [shape="none", image="chrome-icon.png", label=""]; d; a -> b; b -> d; c -> d [color="red"]; }
3 子图
digraph abc{ node [shape="record"]; edge [style="dashed"]; a [style="filled", color="black", fillcolor="chartreuse"]; b; subgraph cluster_cd{ label="c and d"; bgcolor="mintcream"; c; d; } a -> b; b -> d; c -> d [color="red"]; }
4 FSM
digraph automata_0 { size = "8.5, 11"; fontname = "Microsoft YaHei"; fontsize = 10; node [shape = circle, fontname = "Microsoft YaHei", fontsize = 10]; edge [fontname = "Microsoft YaHei", fontsize = 10]; 0 [ style = filled, color=lightgrey ]; 2 [ shape = doublecircle ]; 0 -> 2 [ label = "a " ]; 0 -> 1 [ label = "other " ]; 1 -> 2 [ label = "a " ]; 1 -> 1 [ label = "other " ]; 2 -> 2 [ label = "a " ]; 2 -> 1 [ label = "other " ]; "Machine: a" [ shape = plaintext ]; }
5 时序图
digraph G { rankdir="LR"; node[shape="point", width=0, height=0]; edge[arrowhead="none", style="dashed"] { rank="same"; edge[style="solided"]; LC[shape="plaintext"]; LC -> step00 -> step01 -> step02 -> step03 -> step04 -> step05; } { rank="same"; edge[style="solided"]; Agency[shape="plaintext"]; Agency -> step10 -> step11 -> step12 -> step13 -> step14 -> step15; } { rank="same"; edge[style="solided"]; Agent[shape="plaintext"]; Agent -> step20 -> step21 -> step22 -> step23 -> step24 -> step25; } step00 -> step10 [label="sends email new custumer", arrowhead="normal"]; step11 -> step01 [label="declines", arrowhead="normal"]; step12 -> step02 [label="accepts", arrowhead="normal"]; step13 -> step23 [label="forward to", arrowhead="normal"]; step24 -> step14; step14 -> step04 [arrowhead="normal"]; }
6 UML
digraph G{ fontname = "Courier New" fontsize = 10 node [ fontname = "Courier New", fontsize = 10, shape = "record" ]; edge [ fontname = "Courier New", fontsize = 10 ]; Animal [ label = "{Animal |+ name : String\l+ age : int\l|+ die() : void\l}" ]; subgraph clusterAnimalImpl{ bgcolor="yellow" Dog [ label = "{Dog||+ bark() : void\l}" ]; Cat [ label = "{Cat||+ meow() : void\l}" ]; }; edge [ arrowhead = "empty" ]; Dog->Animal; Cat->Animal; Dog->Cat [arrowhead="none", label="0..*"]; }
7 语法树
digraph ast{ fontname = "Microsoft YaHei"; fontsize = 10; node [shape = circle, fontname = "Microsoft YaHei", fontsize = 10]; edge [fontname = "Microsoft YaHei", fontsize = 10]; node [shape="plaintext"]; mul [label="mul(*)"]; add [label="add(+)"]; add -> 3 add -> 4; mul -> add; mul -> 5; }
8 模块生命周期
digraph module_lc{ rankdir=TB; fontname = "Microsoft YaHei"; fontsize = 12; node [fontname = "Microsoft YaHei", fontsize = 12, shape = "Mrecord", color="skyblue", style="filled"]; edge [fontname = "Microsoft YaHei", fontsize = 12, color="darkgreen" ]; installed [label="已安装状态"]; resolved [label="已就绪状态"]; uninstalled [label="已卸载状态"]; starting [label="正在启动"]; active [label="已激活(运行)状态"]; stopping [label="正在停止"]; start [label="", shape="circle", width=0.5, fixedsize=true, style="filled", color="black"]; start -> installed [label="安装"]; installed -> uninstalled [label="卸载"]; installed -> resolved [label="准备"]; installed -> installed [label="更新"]; resolved -> installed [label="更新"]; resolved -> uninstalled [label="卸载"]; resolved -> starting [label="启动"]; starting -> active [label=""]; active -> stopping [label="停止"]; stopping -> resolved [label=""]; }
9 软件模块组成
digraph idp_modules{ rankdir = TB; fontname = "Microsoft YaHei"; fontsize = 12; node [ fontname = "Microsoft YaHei", fontsize = 12, shape = "record" ]; edge [ fontname = "Microsoft YaHei", fontsize = 12 ]; subgraph cluster_sl{ label="IDP支持层"; bgcolor="mintcream"; node [shape="Mrecord", color="skyblue", style="filled"]; network_mgr [label="网络管理器"]; log_mgr [label="日志管理器"]; module_mgr [label="模块管理器"]; conf_mgr [label="配置管理器"]; db_mgr [label="数据库管理器"]; }; subgraph cluster_md{ label="可插拔模块集"; bgcolor="lightcyan"; node [color="chartreuse2", style="filled"]; mod_dev [label="开发支持模块"]; mod_dm [label="数据建模模块"]; mod_dp [label="部署发布模块"]; }; mod_dp -> mod_dev [label="依赖..."]; mod_dp -> mod_dm [label="依赖..."]; mod_dp -> module_mgr [label="安装...", color="yellowgreen", arrowhead="none"]; mod_dev -> mod_dm [label="依赖..."]; mod_dev -> module_mgr [label="安装...", color="yellowgreen", arrowhead="none"]; mod_dm -> module_mgr [label="安装...", color="yellowgreen", arrowhead="none"]; }
10 hash表的实例
digraph st{ fontname = "Verdana"; fontsize = 10; rankdir = LR; rotate = 90; node [ shape="record", width=.1, height=.1]; node [fontname = "Verdana", fontsize = 10, color="skyblue", shape="record"]; edge [fontname = "Verdana", fontsize = 10, color="crimson", style="solid"]; node [shape="plaintext"]; st_table [label=< <table border="0" cellborder="1" cellspacing="0" align="left"> <tr> <td>st_table</td> </tr> <tr> <td>num_bins=5</td> </tr> <tr> <td>num_entries=3</td> </tr> <tr> <td port="bins">bins</td> </tr> </table> >]; node [shape="record"]; num_bins [label=" <b1> | <b2> | <b3> | <b4> | <b5> ", height=2]; node[ width=2 ]; entry_1 [label="{<e>st_table_entry|<next>next}"]; entry_2 [label="{<e>st_table_entry|<next>null}"]; entry_3 [label="{<e>st_table_entry|<next>null}"]; st_table:bins -> num_bins:b1; num_bins:b1 -> entry_1:e; entry_1:next -> entry_2:e; num_bins:b3 -> entry_3:e; }
11 数据结构
digraph st2{ fontname = "Verdana"; fontsize = 10; rankdir=TB; node [fontname = "Verdana", fontsize = 10, color="skyblue", shape="record"]; edge [fontname = "Verdana", fontsize = 10, color="crimson", style="solid"]; st_hash_type [label="{<head>st_hash_type|(*compare)|(*hash)}"]; st_table_entry [label="{<head>st_table_entry|hash|key|record|<next>next}"]; st_table [label="{st_table|<type>type|num_bins|num_entries|<bins>bins}"]; st_table:bins -> st_table_entry:head; st_table:type -> st_hash_type:head; st_table_entry:next -> st_table_entry:head [style="dashed", color="forestgreen"]; }