7C00.ME/houmu 2013-07-30

用Graphviz来画状态机

今天在网上发现的一个非常有用的可以用来画状态机的工具——Graphviz。基于文本,使用一种特定的语言,生成状态机图片。简介可参考:[http://guiquanz.github.io/2013/01/21/draw-finite-state-machine-by-graphviz/]。

附一段代码:

digraph message {
  rankdir=LR;
  size="16,16"

  node [shape=doublecircle color="blue"] normal;
  node [shape=circle color="blue"] wait_apply;
  node [shape=circle color="blue"] wait_message;
  node [shape=circle] wait_check;

  {rank=same}
  
  normal -> wait_apply [label="1:apply to validate"];
  wait_apply -> wait_message [label="2.1:sever reject apply"];
  wait_apply -> normal [label="2.2:server refuse apply"];
  wait_message -> wait_check [label="3.1:recieved message and send code"];
  wait_message -> normal [label="3.2:timeout for message"];
  wait_check -> normal [label="4.1:server accept code"];
  wait_check -> wait_check [label="4.2:server reject code"];
  wait_check -> normal [label="4.3:server band user"];
}

更多参考资料: