Graphviz 的一些範例
Dotted edges etc 虛線邊緣等等
This example uses a edge's attribute style
to draw a dotted edge.
這個例子使用邊緣的屬性 style
來繪製虛線邊緣。
digraph D {
A [shape=diamond]
B [shape=box]
C [shape=circle]
A -> B [style=dashed, color=grey]
A -> C [color="black:invis:black"]
A -> D [penwidth=5, arrowhead=none]
}
形式:記錄 vs. 純文字
If the shape
attribute is set to record
, the text (as controlled with the label
attribute) is layouted in tabular form.
如果 shape
屬性設置為 record
,則文字(由 label
屬性控制)以表格形式排列。
The vertical bar (|
) starts a new row or column.
垂直欄( |
)開始一個新的行或列。
The curly braces { ... }
change (flip) the direction of |
.
花括號 { ... }
可以改變(翻轉) |
的方向。
digraph D {
node [fontname="Arial"];
node_A [shape=record label="shape=record|{above|middle|below}|right"];
node_B [shape=plaintext label="shape=plaintext|{curly|braces and|bars without}|effect"];
}
Multiple edges 多重邊
Normally, a dependency (an edge) is declared with an arrow: Node1 -> Node2
. Multiple nodes can be listed in curly braces, thus declaring multiple edges in one go.
通常,依賴關係(邊緣)是用箭頭聲明的: Node1 -> Node2
。多個節點可以在花括號中列出,從而一次聲明多個邊緣。
digraph D {
A -> {B, C, D} -> {F}
}
Left, mid and right aligned text
左對齊、置中對齊和右對齊的文字
\l
makes the preceding (!) text left aligned, \n
makes it centered and \r
makes it right aligned.
\l
使前面的文字靠左對齊, \n
使其置中, \r
使其靠右對齊。
digraph L {
node [shape=record fontname=Arial];
a [label="one\ltwo three\lfour five six seven\l"]
b [label="one\ntwo three\nfour five six seven"]
c [label="one\rtwo three\rfour five six seven\r"]
a -> b -> c
}
Giving the graph a title
給圖表加上標題
With the label
attribute, the graph can be given a caption:
使用 label
屬性,可以為圖表新增標題:
digraph D {
label = "The foo, the bar and the baz";
labelloc = "t"; // place the label at the top (b seems to be default)
node [shape=plaintext]
FOO -> {BAR, BAZ};
}
HTML like labels 類似 HTML 的標籤
If the text of label
is enclosed in <…>
rather than in "…"
, the text is treated as HTML and rendered as HTML like label.
如果 label
的文字被包含在 <…>
而不是 "…"
中,則該文字將被視為 HTML 並像標籤一樣呈現為 HTML。
digraph D {
label = <The <font color='red'><b>foo</b></font>,<br/> the <font point-size='20'>bar</font> and<br/> the <i>baz</i>>;
labelloc = "t"; // place the label at the top (b seems to be default)
node [shape=plaintext]
FOO -> {BAR, BAZ};
}
rank 等級、排名、地位、階級
{ rank=same node_1 node_2 … }
specifies that the specified nodes have the same rank, that is, that their distance from the top or left border is equal.
{ rank=same node_1 node_2 … }
指定了指定的節點具有相同的等級,也就是它們距離頂部或左邊界的距離相等。
digraph R {
node [shape=record];
{ rank=same rA sA tA }
{ rank=same uB vB wB }
rA -> sA;
sA -> vB;
t -> rA;
uB -> vB;
wB -> u;
wB -> tA;
}
Subgraph (clusters) 子圖(叢集)
digraph Q {
node [shape=record];
and_1 [label = "Node 1"];
and_2 [label = "Node 2"];
and_3_a [label = "Above Right Node 3"];
and_3_l [label = "Left of Node 3"];
and_3 [label = "Node 3"];
and_3_r [label = "Right of Node 3"];
and_4 [label = "Node 4"];
and_3_a -> and_3_r;
and_1 -> and_2 -> and_3 -> and_4;
subgraph cluster_R {
{rank=same and_3_l and_3 and_3_r}
and_3_l -> and_3 -> and_3_r [color=grey arrowhead=none];
}
}
Nested clusters 巢狀式群集
digraph D {
subgraph cluster_p {
label = "Parent";
subgraph cluster_c1 {
label = "Child one";
a;
subgraph cluster_gc_1 {
label = "Grand-Child one";
b;
}
subgraph cluster_gc_2 {
label = "Grand-Child two";
c;
d;
}
}
subgraph cluster_c2 {
label = "Child two";
e;
}
}
}
HTML table HTML 表格
HTML tables are produced if the value of the label
attribute is enclosed in <…>
rather than "…"
:
如果 label
屬性的值被包含在 <…>
而不是 "…"
中,則會產生 HTML 表格:
digraph H {
aHtmlTable [
shape=plaintext
color=blue // The color of the border of the table
label=<
<table border='1' cellborder='0'>
<tr><td>col 1</td><td>foo</td></tr>
<tr><td>COL 2</td><td>bar</td></tr>
</table>
>];
}
Nested HTML table 巢狀的 HTML 表格
HTML tables can be nested HTML 表格可以巢狀
digraph {
tbl [
shape=plaintext
label=<
<table border='0' cellborder='1' color='blue' cellspacing='0'>
<tr><td>foo</td><td>bar</td><td>baz</td></tr>
<tr><td cellpadding='4'>
<table color='orange' cellspacing='0'>
<tr><td>one </td><td>two </td><td>three</td></tr>
<tr><td>four </td><td>five </td><td>six </td></tr>
<tr><td>seven</td><td>eight</td><td>nine </td></tr>
</table>
</td>
<td colspan='2' rowspan='2'>
<table color='pink' border='0' cellborder='1' cellpadding='10' cellspacing='0'>
<tr><td>eins</td><td>zwei</td><td rowspan='2'>drei<br/>sechs</td></tr>
<tr><td>vier</td><td>fünf</td> </tr>
</table>
</td>
</tr>
<tr><td>abc</td></tr>
</table>
>];
}
Colors 顏色
digraph D {
node [shape=plaintext]
some_node [
label=<
<table border="0" cellborder="1" cellspacing="0">
<tr><td bgcolor="yellow">Foo</td></tr>
<tr><td bgcolor="lightblue"><font color="#0000ff">Bar</font></td></tr>
<tr><td bgcolor="#f0e3ff"><font color="#ff1020">Baz</font></td></tr>
</table>>
];
}
Rounded box 圓角盒子
digraph H {
aHtmlTable [
shape=plaintext
label=<
<table border='1' cellborder='0' style='rounded'>
<tr><td>col 1</td><td>foo</td></tr>
<tr><td>COL 2</td><td>bar</td></tr>
</table>
>];
}
Ports 連接埠
digraph H {
parent [
shape=plaintext
label=<
<table border='1' cellborder='1'>
<tr><td colspan="3">The foo, the bar and the baz</td></tr>
<tr><td port='port_one'>First port</td><td port='port_two'>Second port</td><td port='port_three'>Third port</td></tr>
</table>
>];
child_one [
shape=plaintext
label=<
<table border='1' cellborder='0'>
<tr><td>1</td></tr>
</table>
>];
child_two [
shape=plaintext
label=<
<table border='1' cellborder='0'>
<tr><td>2</td></tr>
</table>
>];
child_three [
shape=plaintext
label=<
<table border='1' cellborder='0'>
<tr><td>3</td></tr>
</table>
>];
parent:port_one -> child_one;
parent:port_two -> child_two;
parent:port_three -> child_three;
}
Project Dependencies 專案相依性
digraph D {
node [shape=plaintext fontname="Sans serif" fontsize="8"];
task_menu [ label=<
<table border="1" cellborder="0" cellspacing="1">
<tr><td align="left"><b>Task 1</b></td></tr>
<tr><td align="left">Choose Menu</td></tr>
<tr><td align="left"><font color="darkgreen">done</font></td></tr>
</table>>];
task_ingredients [ label=<
<table border="1" cellborder="0" cellspacing="1">
<tr><td align="left"><b>Task 2</b></td></tr>
<tr><td align="left">Buy ingredients</td></tr>
<tr><td align="left"><font color="darkgreen">done</font></td></tr>
</table>>];
task_invitation [ label=<
<table border="1" cellborder="0" cellspacing="1">
<tr><td align="left"><b>Task 4</b></td></tr>
<tr><td align="left">Send invitation</td></tr>
<tr><td align="left"><font color="darkgreen">done</font></td></tr>
</table>>];
task_cook [ label=<
<table border="1" cellborder="0" cellspacing="1">
<tr><td align="left"><b>Task 5</b></td></tr>
<tr><td align="left">Cook</td></tr>
<tr><td align="left"><font color="red">todo</font></td></tr>
</table>>];
task_table[ label=<
<table border="1" cellborder="0" cellspacing="1">
<tr><td align="left"><b>Task 3</b></td></tr>
<tr><td align="left">Lay table</td></tr>
<tr><td align="left"><font color="red">todo</font></td></tr>
</table>>];
task_eat[ label=<
<table border="1" cellborder="0" cellspacing="1">
<tr><td align="left"><b>Task 6</b></td></tr>
<tr><td align="left">Eat</td></tr>
<tr><td align="left"><font color="red">todo</font></td></tr>
</table>>];
task_menu -> task_ingredients;
task_ingredients -> task_cook;
task_invitation -> task_cook;
task_table -> task_eat;
task_cook -> task_eat;
}