DOT中使用圖(
digraph
/graph
/subgraph
)、節點(node
)和邊(edge
)來描述關係圖/流程圖,在配合一些屬性的設置完成繪圖。node
digraph/graph/subgraph graphName{
label="示例";
bgcolor="beige"
......
}
複製代碼
其中,digraph
/graph
/subgraph
分別表明無向圖、有向圖和子圖,graphName
則是圖片的名稱。bash
digraph
用來描述有向圖,關係使用 ->
來描述graph
用來描述無向圖,關係使用 --
來描述label
和bgcolor
爲定義的圖片屬性graphName
定義圖片的名稱//
和 #
註釋單行, /* */
多行註釋。屬性名 | 默認值 | 說明 |
---|---|---|
label | 圖片標籤,如上面示例 |
|
bgcolor | 背景顏色,顏色文檔點此 | |
fontcolor | black | 字體顏色,定義上面示例 的顏色 |
fontname | Times-Roman | 字體 |
fontsize | 14 | 字體大小 |
rank | 子圖等級限制, same,min,max,source,sink | |
rankdir | TB | 排序方向,LR(left to right) or TB(top to bottom) |
compound | false | If true, allow edges between clusters. 配合 lhead 和 ltail 使用 |
node
)的用法digraph demo {
label="示例"
bgcolor="beige"
//定義節點默認屬性
node[color="grey"]
//定義節點
root[label="根節點", shape="box"]
left[label="左子節點", shape="box"]
node[color="#FF6347"]
right[label="右子節點", shape="ellipse"]
//定義關係(邊)
root -> {left,right}[label="父子"]
left -> subnode[label="父子"]
{rank=same; left, right}
}
複製代碼
root
、left
、right
、subnode
爲節點。節點能夠提早定義如root[label="根節點", shape="box"]
,也能夠在定義邊的關係時直接使用如left -> subnode[label="父子"]
。[]
內屬性,屬性能夠針對圖、節點、邊來設置。rank
定義設置節點處在同一行,輔助渲染出來的圖的效果。屬性名 | 默認值 | 說明 |
---|---|---|
label | node name | 節點顯示內容 |
color | black | node邊框顏色 |
fontcolor | black | 字體顏色 |
fillcolor | 背景色 | |
fontname | Times-Roman | 字體 |
fontsize | 14 | 字體大小 |
shape | ellipse | 形狀,box、ellipse、circle、diamond、plaintext、point、triangle、invtriangle |
style | 圖形樣式,eg. bold、dashed、dotted、filled | |
image | 背景圖片地址 |
digraph demo {
bgcolor="floralwhite"
"box"[shape=box]
"polygon"[shape=polygon,sides=7]
"ellipse"[shape=ellipse]
"circle"[shape=circle]
"point"[shape=point]
"triangle"[shape=triangle]
"invtriangle"[shape=invtriangle]
"plaintext"[shape=plaintext]
"diamond"[shape=diamond]
}
複製代碼
digraph demo {
label="示例"
bgcolor="beige"
//定義節點默認屬性
node[color="grey"]
//定義節點
root[label="根節點", shape="box"]
left[label="左子節點", shape="box"]
node[color="#FF6347"]
right[label="右子節點", shape="ellipse"]
//定義關係(邊)
root -> {left,right}[label="父子"]
//定義邊的默認屬性
edge[color="#FF6347"]
left -> subnode[label="父子"]
{rank=same; left, right}
}
複製代碼
edge用來定義邊的默認屬性。用法與node類似,做用域從本次定義到下一次定義截住。特定邊設置的屬性會覆蓋默認值。markdown
本質上來講,node和edge也是屬於節點,是預留用於描述節點屬性和邊屬性的特殊節點ide
無向圖關係使用--
描述,有向圖關係使用->
描述oop
屬性名 | 默認值 | 說明 |
---|---|---|
label | 描述關係 | |
color | black | 箭頭顏色 |
fontcolor | black | 關係文字顏色 |
dir | forward | 設置方向:forward,back,both,none |
arrowhead | normal | 箭頭頭部形狀。box、crow、diamond、dot、none、normal、vee。箭頭文檔點此 |
arrowtail | 箭頭尾部形狀 | |
arrowsize | 1.0 | 箭頭大小 |
style | 圖形樣式,eg. bold、dashed、dotted、filled | |
lhead | 當 compound 爲true時,lhead用於指定邊指向的cluster | |
ltail | 與ltail相似 |
digraph demo {
bgcolor="floralwhite"
rankdir=LR
"box"->"crow"[arrowhead=box]
"crow"->"curve"[arrowhead=crow]
"curve"->"diamond"[arrowhead=curve]
"diamond"->"dot"[arrowhead=diamond]
"dot"->"inv"[arrowhead=dot]
"inv"->"none"[arrowhead=inv]
"none"->"normal"[arrowhead=none]
"normal"->"tee"[arrowhead=normal]
"tee"->"vee"[arrowhead=tee]
"vee"->"box"[arrowhead=vee]
#來個高級的用法
a->b[arrowhead=lcrowortee]
}
複製代碼
一個圖能夠包含多個子圖,以及子圖也能夠嵌套子圖。子圖的名字須爲cluster*
,不然就直接當節點渲染了。字體
digraph demo {
bgcolor="beige"
subgraph cluster_husband {
node[color="grey"]
{"爸爸", "媽媽"} -> "我"
}
subgraph cluster_wife {
{"岳父", "岳母"} -> "老婆"
}
"我" -> "老婆"[label="夫妻", dir="both"]
{rank=same; "我", "老婆"}
}
複製代碼
渲染效果以下:spa
digraph demo {
bgcolor="beige"
rankdir=LR;
node [shape="record", height=0.1]
node0[label="{<f1> G | <f2> next}"]
node1[label="{<f1> E | <f2> next}"]
node0:f2 -> node1:f1
}
複製代碼
rankdir=LR
描述圖像爲橫向node0[label="{<f1> G | <f2> next}"]
中,{}描述同個節點中的多個分割位與rankdir
一致digraph demo {
bgcolor="beige"
node [shape="record", height=.1]
node0[label="<f1> A | <f2> B | <f3> C | <f4> "]
node1[label="<f1> D | <f2> E | <f3> F"]
node2[label="<f1> G | <f2> H | <f3> I"]
node0:f1 -> node1:f1
node0:f2 -> node2:f1
}
複製代碼