1. 基础例子

2. 3dX]

graph simple { a — b; b — d; b — c; d — a; }

.使用下面的命令转换为图片
[source, shell]

dot -Tpng -o simple.png simple.dot

====
image::simple.png[simple]
====

=== 调整布局
[source, dot]

graph different_layout { rankdir = LR; <1> a — b; b — c; b — d; d — a; }

<1> 排列方向自左向右(Rank direction Left to Right)

image::different_layout.png[diffenent_layout]

=== 简单有向图

[source, dot]

digraph simple_digraph { a → b; b → c; a → c; }

====
image::digraph.png[digraph]
====

=== 带标签的简单有向图

[source, dot]

digraph digraph_with_label { T[label="Teacher"] P[label="Pupil"] T → P [label="Instrutions", fontcolor=darkgreen] }

====
image::digraph_with_label.png[digraph_with_label]
====

=== 修改形状和颜色

[source, dot]

digraph attribute { T[label="Teacher" color=Blue, fontcolor=Red, fontsize=24, shape=circle] P[label="Pupil" color=Red, fontcolor=Black, fontsize=18, shape=box] T → P [label="Instrutions", fontcolor=darkgreen] }

====
image::attribute.png[attribute]
====


NOTE: 这里可供选择的形状有box、polygon、ellipse、oval、circle、point、egg、triangle、plaintext、diamond、trapezium、parallelogram、house、pentagon、hexagon、septagon、octagon、doublecircle、doubleoctagon、tripleoctagon更多形状请参考 http://www.graphviz.org/content/node-shapes[这里]。

=== 小结

[source, dot]

digraph summery { start [label="Start with a Node"] next [label="Choose your shape", shape=box] warning [label="Don’t go overboard", color=Blue, fontcolor=Red, fontsize=24,style=filled, fillcolor=green, shape=octagon] end [label="Darw your graph!", shape=box, style=filled, fillcolor=yellow]

  start -> next
  start -> warning
  next -> end [label="Getting batter...", fontcolor=darkblue]
}
====
image::summery.png[summery]
====

== 高级

=== 节约时间的技巧

[source, dot]

digraph hierachy { nodesep = 1.0 // increases the separation between nodes

node [color=Red, fontname=Courier, shape=box] // All nodes will this shape and colour
edge [color=Blue, style=dashed] // All the lines look like this
  Headteacher -> {Deputy1 Deputy2 BusinessManager}
  Deputy1 -> {Teacher1 Teacher2}
  BusinessManager->ITManager
  {rank=same;ITManager Teacher1 Teacher2} // Put them on the same level
}
====
image::hierarchy.png[hierarchy]
====

=== 记录

[source, dot]

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

  struct1:f1 -> struct2:f0;
  struct1:f0 -> struct3:f1;
}
====
image::structs.png[structs]
====

== 例子

=== 有限状态机

[source, dot]

digraph finite_state_machine { 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 Tirgger"] S3 → S2 [label="Release Tigger"] }

====
image::finite_state_machine.png[finite_state_machine]
====

=== 数据流示意图

[source, dot]

digraph dfd { node[shape=record] store[label="<f0> left | <f1> Some data store"] proc1[label="{<f0> 1.0 | <f1> Some process here\n\n\n}" shape=Mrecord]; enti1[label="Customer" shape=box]; store:f1 → proc1:f0; enti1 → proc1:f0; }

====
image::dfd.png[dfd]
====

[source, dot]

digraph dfd2 { node[shape=record] subgraph level0 { enti1[label="Customer" shape=box]; enti2[label="Manager" shape=box]; }

subgraph cluster_level1 {
  label = "Level 1";
  proc1 [label="{<f0> 1.0 | <f1> One process here\n\n\n}" shape=Mrecord];
  proc2 [label="{<f0> 2.0 | <f1> Other process here\n\n\n}" shape=Mrecord];
  store1 [label="<f0> | <f1> Data store one"];
  store2 [label="<f0> | <f1> Data store two"];
  {rank=same; store1, store2}
}
  enti1 -> proc1
  enti2 -> proc2
  store1 -> proc1
  store2 -> proc2
  proc1 -> store2
  store2 -> proc1
}
====
image::dfd2.png[dfd2]
====

=== 对象继承

[source, dot]

digraph obj { node[shape=record]; rankdir }