DOT Language
```graphviz
digraph{
## rankdir=TD
rankdir=RL
node[shape = "record"]
1[label = "<m>1 | {<p>prev |<n>next}",group = list];
2[label = "<m>2 | {<p>prev |<n>next}",group = list];
4[label = "<m>4 | {<p>prev |<n>next}",group = list];
5[label = "<m>5 | {<p>prev |<n>next}",group = list];
6[label = "<m>6 | {<p>prev |<n>next}",group = list];
7[label = "<m>7 | {<p>prev |<n>next}",group = list];
in0,in1,in2[style=invis]
//p [shape=none,label=pending,fontcolor=blue]
{rank=same 2 5 7}
6->4->1
7->6
5->4
2->1
1->in0[style=invis]
4->in1[style=invis]
6->in2[style=invis]
{rank=same 1 6}
//{rank=same 6 4 1 }
//0:next:e -> 1:prev:w[ weight = 100, style = invis ];
}
```
## 1
```graphviz
digraph _graph_name_ {
# 設定 (其實沒有順序,這整個文檔每行亂調輸出都一樣)
rankdir=LR; # 順序由左至右(上下是"TD")
graph [fontname="DFKai-SB"]; # 此三行是設定字型
node [fontname="DFKai-SB"]; # 中文務必指定
edge [fontname="DFKai-SB"]; # 不然可能會出現亂碼
# 這邊是 graph (圖面)
label="我是標題";
{rank=same A B C } # 同層(強迫上下)
{rank=same F G H } # 同層(強迫上下)
{rank=same D E } # 同層(強迫上下)
# 這邊是 node (節點)
A[label = "我是開始"]
B[label = "label\n是文字", shape=box]
C[label = "shape\n指定形狀\n(這是box)", shape=box]
D[shape=box] # 不給 label 就會直接用名稱
E[label = "diamond\n菱形", shape=diamond]
F[label = "n\n會換行", shape=box]
G[label = "$mathmode$\n要用LaTeX處理", shape=diamond]
H[label = "我是結束"]
# 這邊是 edge (邊)
A->B->C->D->E # 可以一直連
E->C [label="否"]
E->F [label="是"]
F->G
G->B [label="是"]
G->H [label="否"]
}
```
## 2
```graphviz
digraph _graph_name_{
rankdir=TD;
label="example";
{rank=same H A B C}
H[label = "HEAD" , shape=box]
A[label = "node0" ]
B[label = "node1" ]
C[label = "node2"]
# edge
H->A->B->C
C->B->A->H
C->H
H->C
}
```
## 3
```graphviz
digraph _graph_name_{
rankdir=TD;
label="example";
{rank=same H A B C}
H[label = "HEAD" , shape=box]
A[label = "node0" ]
B[label = "node1" ]
C[label = "node2"]
# edge
H->A->B->C
C->B->A->H
C->H
H->C
}
```
## 4
```graphviz
digraph {
rankdir=LR
A -> B
A -> D
{rank=same; A ;B;};
}
```
## 5
```graphviz
digraph{
## rankdir=TD
rankdir=LR
node [shape=box,color=blue]
node1 [style=filled]
node2 [style=filled ,fillcolor=red]
node0->node1
node1->node2
node4->node5[arrowhead=vee]
}
```
## 6
```graphviz
digraph {
rankdir=TD
node [shape=box,color=red]
edge [arrowhead=vee]
{a b c} -> {d e f}
}
```
## 7
```graphviz
digraph G {
rankdir=LR;
node[shape=record];
map [label="hlist_head.first |<ht0> |<ht1> |<ht2> |<ht3> |<ht4> |<ht5> |<ht7> |<ht8> "];
node[shape=none]
null1 [label=NULL]
null2 [label=NULL]
subgraph cluster_1 {
style=filled;
color=lightgrey;
node [shape=record];
hn1 [label="hlist_node | {<prev>pprev | <next>next}"];
label="hash_key 1"
}
subgraph cluster_2 {
style=filled;
color=lightgrey;
node [shape=record];
hn2 [label="hlist_node | {<prev>pprev | <next>next}"];
label="hash_key 2"
}
subgraph cluster_3 {
style=filled;
color=lightgrey;
node [shape=record];
hn3 [label="hlist_node | {<prev>pprev | <next>next}"];
label="hash_key 3"
}
map:ht1 -> hn1
hn1:next -> hn2
hn2:next -> null1
hn2:prev:s -> hn1:next:s
map:ht5 -> hn3
hn3:next -> null2
hn1:prev:s -> map:ht1
hn3:prev:s -> map:ht5
}
```
## 8
```graphviz
digraph G {
rankdir = LR;
splines = false;
node[shape = "record"]
list_head[label = "<m>list_head | <n>first"]
node_1[label = "<m>dll_node_1 | {<p>prev | <n>next}", group = list];
node_2[label = "<m>dll_node_2 | {<p>prev | <n>next}", group = list];
node_3[label = "<m>dll_node_3 | {<p>prev | <n>next}", group = list];
NULL_1, NULL_2[shape = plaintext, label = "NULL", group = list]
{rank = "min" list_head NULL_1}
list_head -> node_1:m;
node_1:p -> NULL_1
node_1:n -> node_2:m;
node_2:p -> node_1:m;
node_2:n -> node_3:m;
node_3:p -> node_2:m;
node_3:n -> NULL_2;
}
```
## 9
```graphviz
digraph{
node [pos="2,3!"];
A->B->C->D
edge [splines=curved];
A->B->C->D
}
```
## 10
```graphviz
digraph structs {
node[shape=record];
struct5 [label="<prev>prev|<data>new node|<next>next",color=purple]
rankdir=LR;
node[shape=box];
struct0 [label= "start"];
struct1 [label= "last"];
struct2 [label= "node1"];
struct3 [label= "node2"];
struct4 [label= "node3"];
{
rank="same";
struct0 -> struct2
}
{
rank="same";
struct1 -> struct4
}
struct2 -> struct3[arrowhead=vee, dir=both, tailclip=true, arrowsize=1];
struct3 -> struct4[arrowhead=vee, dir=both, tailclip=true, arrowsize=1];
struct4 -> struct2[arrowhead=vee, dir=both, tailclip=true, arrowsize=1];
struct5:next -> struct2 [color=red];
}
```
## 11
```graphviz
digraph structs {
node[shape=record];
struct5 [label="<prev>prev|<data>new node|<next>next"]
rankdir=LR;
node[shape=box];
struct0 [label= "start"];
struct1 [label= "last"];
struct2 [label= "node1"];
struct3 [label= "node2"];
struct4 [label= "node3"];
{
rank="same";
struct0 -> struct2
}
{
rank="same";
struct1 -> struct4
}
struct2 -> struct3[arrowhead=vee, dir=both, tailclip=true, arrowsize=1];
struct3 -> struct4[arrowhead=vee, dir=both, tailclip=true, arrowsize=1];
struct4 -> struct2[arrowhead=vee, tailclip=true, arrowsize=1];
struct5:next -> struct2;
struct2->struct5:data[color=red]
}
```
```graphviz
digraph{
rankdir=LR
k[style=invis]
a->b->c->d->e
{ran}
}
```
# Ref:
1. [Graphviz-用指令來畫關係圖](https://www.netadmin.com.tw/netadmin/zh-tw/technology/122966CB664D4A17ABAAD11FC2AA887C?page=1)
2. [Official manual](https://graphviz.org/doc/info/attrs.html)
```graphviz
digraph G {
rankdir = LR;
splines = false;
node[shape = "record"]
list_head[label = "<m>list_head | <n>first"]
node_1[label = "<m>hlist_node_1 | {<p>pprev | <n>next}", group = list];
node_2[label = "<m>hlist_node_2 | {<p>pprev | <n>next}", group = list];
node_n[label = "<m>hlist_node_n | {<p>pprev | <n>next}", group = list];
NULL[shape = plaintext, label = "NULL", group = list]
{rank = "min" list_head}
list_head -> node_1 -> node_2 [
weight = 10, style = invis
]
list_head:n -> node_1:m;
node_1:p -> list_head:n;
node_1:n -> node_2:m;
node_2:p -> node_1:n;
node_2:n -> NULL;
}
```
---------------------------------