本文介绍如何使用ditaa与PlantUML与dot进行绘制流程图。ditaa与PlantUML都依赖java环境,所以事先需要有Java环境(不管我们使用的是何种OS)。Java环境的设置很简单,如果本地没有Java环境,请到Oracle官网下载之,这里就省略了。而dot绘图语言需要安装graphviz软件。
本文作者使用的Windows环境,而Gnu/Linux环境则配置起来相对简单些。
有了Java的基础环境,接下来需要安装graphviz(dot绘图语言的解释器)软件,安装过程省略。安装之后的一个截图为:
之后,需要下载两个jar包,相当于Emacs的两个插件,一个是ditaa使用的jar包,一个plantuml使用的jar包,把下载好的jar包放到指定的目录,本文把他们放到了这里(如果没有相应的目录请动手创建),
另外,最好也在该目录里放置一份(Windows下面,而Linux则不需要此步骤),我的Emacs是安装在了F盘,所以,大家的与我的不一样,请进行相应的修改之(如果没有相应的目录,请手工创建),
至此,整个基础环境已经给搭建起来了。接下来进行Emacs的相关配置,主要设置jde-jdk-registry,
可以把下面的配置贴到.emacs文件里,
(custom-set-variables '(jde-jdk-registry (quote (("1.6.43" . "C:\\Program Files\\java\\jdk1.6.0_43"))))) (org-babel-do-load-languages 'org-babel-load-languages '((ditaa . t) ; this line activates ditaa (plantuml . t) ; this line activates plantuml (python . t) (perl . t) (ruby . t) (R . t) (sh . t) (gnuplot . t) (org . t) (latex . t) (java . t) (emacs-lisp . t) (calc . t) (sql . t) (dot . t) ; this line activates graphviz(dot) )) (setq org-ditta-jar-path (expand-file-name "~/.emacs.d/elpa/contrib/scripts/ditta.jar")) (setq org-plantuml-jar-path (expand-file-name "~/.emacs.d/elpa/contrib/scripts/plantuml.jar")) ;; org mode do not prompt me (setq org-confirm-babel-evaluate nil) (setq org-src-fontify-natively t)
上面的准备工作完成了之后,就可以使用Emacs进行流程图的绘制了。来看看几个截图吧:
PlantUML
#+BEGIN_SRC plantuml :file images/heartbeat_topo.png :Client: <-down-> [Route] note right of Client : who can serve me note right of [Route] : VIP 192.168.56.222 [Route] <-down-> [master.liucc.com\n192.168.56.101] [Route] <-down-> [slave.liucc.com\n192.168.56.102] #+END_SRC
在Emacs下面如何编译生成图片呢?让光标置于#+BEGIN_SRC与#+END_SRC之间的任何位置,使用组合键“C-c C-c”即可完成编译。
#+BEGIN_SRC plantuml :file images/pxe02.png hide footbox title PXE工作流程 participant PXE_Client participant TFTP_Server participant DHCP_Server PXE_Client -> DHCP_Server: 请求IP地址 activate PXE_Client #FFBBBB activate DHCP_Server #FFBBCC DHCP_Server -> DHCP_Server: 是否为合法的\n来自PXE_Client\n的DHCP请求? PXE_Client <-- DHCP_Server: 返回IP地址和bootstrap的位置 deactivate DHCP_Server PXE_Client -> TFTP_Server: 请求传送bootstrap activate TFTP_Server #FFAABB PXE_Client <-- TFTP_Server: 同意指定传输块大小(blksize)? PXE_Client -> TFTP_Server: 同意 PXE_Client <-- TFTP_Server: 发送bootstrap PXE_Client -> PXE_Client: 执行bootstrap(pxelinux.0) PXE_Client -> TFTP_Server: 请求传送配置文件\n(pxelinux.cfg/<IP_ADDR>) PXE_Client -> PXE_Client: 读配置文件 PXE_Client -> PXE_Client: 用户根据情况选择 PXE_Client -> TFTP_Server: 请求传送Linux内核 PXE_Client <-- TFTP_Server: 发送Linux内核 PXE_Client -> TFTP_Server: 请求传送Linux根文件系统 PXE_Client <-- TFTP_Server: 发送Linux根文件系统 deactivate TFTP_Server PXE_Client -> PXE_Client: 启动Linux内核(带参数) deactivate PXE_Client #+END_SRC
2. ditaa
#+BEGIN_SRC ditaa :file images/linux-os.png +---------------------------------------------------------+ | Applications | | +----------------------------------------------------+ | | System Libraries | +----+----------------------------------------------------+ | System Call Interface | +------------------------+--------------+-----------------+ +---------+ | VFS | Socket | | | | +------------------------+--------------+ Scheduler +-------+ CPU | | File Systems | TCP/UDP | | | | +------------------------+--------------+-----------------+ +----+----+ | Volume Manager | IP | Virtual | | +------------------------+--------------+ Memory | | | Block Device Interface | Ethernet | | | +------------------------+--------------+-----------------+ +----+----+ | Device Driver | | DRAM | +-----------------------------+---------------------------+ +---------+ | | +-------+--------+ | I/O Bridge | +-------+--------+ | | ------+-----------------+--------------------+------ | | +---------+--------+ +----------+---------+ | I/O Controller | | Network Controller | +-+-------+------+-+ +----+----------+----+ | | | | | +---+---+ | +---+---+ +----+----+ +---+----+ | Disk | ... | Swap | | Port | | Port | +-------+ +-------+ +---------+ +--------+ #+END_SRC
#+BEGIN_SRC ditaa :file images/linux02.png :cmdline -E -r -s 1.0 +---------------------------------------+ | Applications | | cRED | +-------------------+ | | cBLU | | | Libraries | | +-------------------+-------------------+ | | | Kernel +-------------------+ | cYEL | cGRE | | +-------+--------+ Drivers | | | Firmware c1AF| | +-----------+----------------+----------+ | Hardware c1AC | +---------------------------------------+ #+END_SRC
3. dot
#+BEGIN_SRC dot :file images/dot04.png :cmdline -Kdot -Tpng digraph structs { node[shape=record] struct1 [label="<f0> left|<f1> mid\ dle|<f2> right"]; struct2 [label="{<f0> one|<f1> 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; } #+END_SRC
#+BEGIN_SRC dot :file images/dot01.png :cmdline -Kdot -Tpng digraph G { size="8,6" ratio=expand edge [dir=both] plcnet [shape=box, label="PLC Network"] subgraph cluster_wrapline { label="Wrapline Control System" color=purple subgraph { rank=same exec sharedmem [style=filled, fillcolor=lightgrey, shape=box] } edge[style=dotted, dir=none] exec -> opserver exec -> db plc -> exec edge [style=line, dir=both] exec -> sharedmem sharedmem -> db plc -> sharedmem sharedmem -> opserver } plcnet -> plc [constraint=false] millwide [shape=box, label="Millwide System"] db -> millwide subgraph cluster_opclients { color=blue label="Operator Client" rankdir=LR labelloc=b node[label=client] opserver -> client1 opserver -> client2 opserver -> client3 } } #+end_src
#+BEGIN_SRC dot :file images/dot_html01.png :cmdline -Kdot -Tpng digraph G { rankdir=LR node [shape=plaintext] a [ label=< <TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0"> <TR><TD ROWSPAN="3" BGCOLOR="yellow">class</TD></TR> <TR><TD PORT="here" BGCOLOR="lightblue">qualifier</TD></TR> </TABLE>> ] b [shape=ellipse style=filled label=< <TABLE BGCOLOR="bisque"> <TR><TD COLSPAN="3">elephant</TD> <TD ROWSPAN="2" BGCOLOR="chartreuse" VALIGN="bottom" ALIGN="right">two</TD> </TR> <TR><TD COLSPAN="2" ROWSPAN="2"> <TABLE BGCOLOR="grey"> <TR> <TD>corn</TD> </TR> <TR> <TD BGCOLOR="yellow">c</TD> </TR> <TR> <TD>f</TD> </TR> </TABLE> </TD> <TD BGCOLOR="white">penguin</TD> </TR> <TR> <TD COLSPAN="2" BORDER="4" ALIGN="right" PORT="there">4</TD> </TR> </TABLE>> ] c [ label=<long line 1<BR/>line 2<BR ALIGN="LEFT"/>line 3<BR ALIGN="RIGHT"/>> ] subgraph { rank=same b c } a:here -> b:there [dir=both arrowtail = diamond] c -> b d [shape=triangle] d -> c [label=< <TABLE> <TR><TD BGCOLOR="red" WIDTH="10"> </TD> <TD>Edge labels<BR/>also</TD> <TD BGCOLOR="blue" WIDTH="10"> </TD> </TR> </TABLE>> ] } #+END_SRC
好了,就到这里。