当前位置: 首页 > 图形_可视化 > 正文

Graphviz 语法学习

目 录
 [ 隐藏 ]

1. 综合示例

digraph{
 //attributes
 edge[color = Blue, style = "dashed",]
 label="byPass-Branch"
 node[color=red];
 //nodes
 headNode->node1;
 headNode->node2;
 node1->node3;

 node[shape=box,color=black];
 //distribute
 headNode->fromApp1[style=dotted];
 headNode->fromApp2[style=dotted];
 headNode->headApp[style=dotted,color=blue];

 node1->headApp[style=dotted];
 node1->fromApp3[style=dotted];
 node1->node1App[style=dotted,color=blue];

 node2->headApp[style=dotted];
 node2->node2App[style=dotted,color=blue];

 node3->node1App[style=dotted];
 node3->fromApp4[style=dotted];
 node3->node3App[style=dotted,color=blue];
}

2. 标签

digraph {
 player[label = "player", color = Blue, fontcolor = Red, fontsize = 24, shape = box];
 game[label = "game", color = Red, fontcolor = Blue, fontsize = 24, shape = ellipse];

 player -> game[label = "play"]
}

3. 综合例子

digraph demo{
 label="儿茶酚胺合成代谢路径";

 酪氨酸 -> L多巴 -> 多巴胺 -> 去甲肾上腺素 -> 肾上腺素;

 下丘脑 -> 多巴胺;
 交感神经元 -> 去甲肾上腺素;
 肾上腺髓质 -> 去甲肾上腺素,肾上腺素;

 酪氨酸 [label="酪氨酸",color=green];
 多巴胺 [label="多巴胺", color=red];
 肾上腺素 [label="肾上腺素", color=red];

 下丘脑 [shape=box];
 交感神经元 [shape=box];
 肾上腺髓质 [shape=box];
}

4. 子视图

digraph {

 label = visitNet

 rankdir = LR

 node[color = Red, fontsize = 24, shape = box]
 edge[color = Blue, style = "dashed"]

 user[style = "filled", color = "yellow", fillcolor = "chartreuse"]
 subgraph cluster_cd{
 label = "server and browser"
 bgcolor = green;

 browser -> server
 }

 user -> computer;
 computer -> browser;
}

5. 结构视图

digraph {
 node[shape = record];
 struct1[label = " left| mid\ dle| right"];
 struct2[label = " one| two"];
 struct3[label = "hello\nworld | {b|{c| d|e}|f}|g|h"];
 struct1:f1 -> struct2:f0;
 struct1:f2 -> struct3:here;
}

6. 树形视图

digraph tree {

 fontname = "PingFang-SC-Light"
 fontsize = 24

 node[shape = "plaintext"]

 1 -> 2[label="ss"];
 1 -> 3;
 2 -> 4;
 2 -> 5;
 3 -> 6;
 3 -> 7;
 4 -> 8;
 4 -> 9;
 5 -> 10;
 5 -> 11;
 6 -> 12;
 6 -> 13;
 7 -> 14;
 7 -> 15;
}

7. 时序图

digraph time {

 rankdir = "LR";
 node[shape = "point", width = 0, height = 0];
 edge[arrowhead = "none", style = "dashed"];

 {
 rank = "same"
 edge[style = "solided"];
 APP[shape = "plaintext"];
 APP -> step00 -> step01 -> step02 -> step03 -> step04 -> step05;
 }
 {
 rank="same";
 edge[style="solided"];
 SDK[shape="plaintext"];
 SDK -> step10 -> step11 -> step12 -> step13 -> step14 -> step15;
 }
 {
 rank="same";
 edge[style="solided"];
 AliPay[shape="plaintext"];
 AliPay -> step20 -> step21 -> step22 -> step23 -> step24 -> step25;
 }
 {
 rank="same";
 edge[style="solided"];
 Server[shape="plaintext"];
 Server -> step30 -> step31 -> step32 -> step33 -> step34 -> step35;
 }

 step00 -> step10 [label="sends order info", arrowhead="normal"];
 step11 -> step21 [label="open AliPay", arrowhead="normal"];
 step22 -> step12 [label="pay success", arrowhead="normal"];
 step13 -> step03 [label="pay success", arrowhead="normal"];
 step24 -> step34 [label="pay success", arrowhead="normal"];
}

8. 一个hash表的数据结构

Hash 表的内容 如下

struct st_hash_type {
 int (*compare) ();
 int (*hash) ();
};

struct st_table_entry {
 unsigned int hash;
 char *key;
 char *record;
 st_table_entry *next;
};

struct st_table {
 struct st_hash_type *type;
 int num_bins;
/* slot count */
 int num_entries;
/* total number of entries */
 struct st_table_entry **bins;
/* slot */
};

图形化如下

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="{

st_hash_type|(*compare)|(*hash)}"];
 st_table_entry [label="{st_table_entry|hash|key|record|next}"];
 st_table [label="{st_table|type|num_bins|num_entries|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"];
}

9. 模块的生命周期图

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=""];
}

10. 简单的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..*"];
}

11. 有限状态机

digraph finite_state_machine {
 label="My Graph";
 rankdir=LR;
 size="8,5"
 node [shape = circle];
 S0 -> S1 [ label = "Lift Nozzle" ]
 S1 -> S0 [ label = "Replace Nozzle" ]
 S1 -> S2 [ label = "Authorize Pump" ]
 S2 -> S0 [ label = "Replace Nozzle" ]
 S2 -> S3 [ label = "Pull Trigger" ]
 S3 -> S2 [ label = "Release Trigger" ]
}

12. 矩阵test

$$
\begin{pmatrix}
1&\alpha_1&\alpha_1^2&\cdots&\alpha_1^n\\
1&\alpha_2&\alpha_2^2&\cdots&\alpha_2^n\\
\vdots&\vdots&\vdots&\ddots&\vdots\\
1&\alpha_n&\alpha_n^2&\cdots&\alpha_n^n
\end{pmatrix}
$$

赞 赏

   微信赞赏  支付宝赞赏


本文固定链接: https://www.jack-yin.com/coding/graph-viz/2837.html | 边城网事

该日志由 边城网事 于2019年08月12日发表在 图形_可视化 分类下, 你可以发表评论,并在保留原文地址及作者的情况下引用到你的网站或博客。
原创文章转载请注明: Graphviz 语法学习 | 边城网事

Graphviz 语法学习 暂无评论

发表评论

快捷键:Ctrl+Enter