dot命令生成流程图

来源:互联网 发布:手机shell是什么软件 编辑:程序博客网 时间:2024/05/16 10:22

    dot命令是graphviz的一部分,通过编写一些类似脚本的语言,可以容易地生成流程图。下面在新建一个文件tmp.dot,内容如下:

digraph G {# 定义全局属性    fontname = "Courier New"    fontsize = 8    # 从下往上    rankdir = BT# 定义节点属性    node [            shape = "record" # 矩形,默认是椭圆            color = "blue" # 边框蓝色    ]# 定义边的属性    edge [            fontsize = 9    ]# 换行符是\l,而要新建一个新的单元格,则需要是用|。{}里面的是内容    Reportable [        label = "{Reportable | + getSummary() : Map\<String, Integer\> | + getDetail() : Map\<String, Integer\> | + isDetailVisible() : boolean}"    ]# 特殊字符要转义    LineCounter [        label = "{LineCounter | + count(String line) : boolean | + getType() : String}"    ]    CharCounter [        label = "{CharCounter | + count(Character c) : boolean | + getType() : String}"    ]   AbstractCharCounter [        label = "{AbstractCharCounter | characterMap : Map\<Character, Integer\> | + count(Character c) : boolean | + getSummary() : Map\<String, Integer\> | +getDetail() : Map\<String, Integer\> }"    ]   AbstractLineCounter [        label = "{AbstractLineCounter |  + count(String line) : boolean | + getSummary() : Map\<String, Integer\> | +getDetail() : Map\<String, Integer\> }"    ]   PredicateCharacter[label = "{Predicate\<Character\> | + apply(Character c) : boolean}"]   PredicateString[label = "{Predicate\<String\> | + apply(String line) : boolean}"]   BlankCharCounter[label = "{BlankCharCounter | + apply(Character c) : boolean | + getType() : String | + isDetailVisible() : boolean }"]   ChineseCharCounter[label = "{ChineseCharCounter | - chinesePattern : Pattern | + apply(Character c) : boolean | + getType() : String | + isDetailVisible() : boolean }"]   LetterCharCounter[label = "{LetterCharCounter | - chinesePattern : Pattern | + apply(Character c) : boolean | + getType() : String | + isDetailVisible() : boolean }"]    NumberCharCounter[label = "{NumberCharCounter | + apply(Character c) : boolean | + getType() : String | + isDetailVisible() : boolean }"]    LineNumberCounter[label = "{LineNumberCounter | + apply(Character c) : boolean | + getType() : String | + isDetailVisible() : boolean }"]    parentInterface [label = "parent interface" color = "green" style=filled]    childInterface [label = "child interface" color = "green" style=filled]    abstractClass [ label = "abstract class : implement some methods using the abstract methods" color = "green" style=filled]    specificClass [ label = "specific class : implement all unimplemented methods" color = "green" style=filled]    LineProcessor [label = "{LineProcessor\<List\<Reportable\>\>}" ]    ReportableLineProcessor [ label = "{ReportableLineProcessor | + ReportableLineProcessor() | + processsLine(String line) : boolean | + getResult() : List\<Reportable\>}"]    # 定义在同一层    {rank = same; parentInterface; Reportable; LineProcessor}    {rank = same; childInterface; LineCounter; CharCounter; PredicateCharacter; PredicateString}    {rank = same; abstractClass; AbstractLineCounter; AbstractCharCounter;}    {rank = same; specificClass; LineNumberCounter; BlankCharCounter; ChineseCharCounter; LetterCharCounter; NumberCharCounter; ReportableLineProcessor}   # 箭头为空心,接口之间的继承   LineCounter -> Reportable[arrowhead="empty"]   CharCounter -> Reportable[arrowhead="empty"]   AbstractCharCounter -> CharCounter[arrowhead="empty"]   AbstractLineCounter -> LineCounter[arrowhead="empty"]   AbstractCharCounter -> PredicateCharacter[arrowhead="empty"]   AbstractLineCounter -> PredicateString[arrowhead="empty"]   # 实现类的UML   BlankCharCounter -> AbstractCharCounter[arrowhead="empty", style="dashed"]   ChineseCharCounter -> AbstractCharCounter[arrowhead="empty", style="dashed"]   LetterCharCounter -> AbstractCharCounter[arrowhead="empty", style="dashed"]   NumberCharCounter -> AbstractCharCounter[arrowhead="empty", style="dashed"]   LineNumberCounter -> AbstractLineCounter[arrowhead="empty", style="dashed"]   ReportableLineProcessor -> LineProcessor[arrowhead="empty", style="dashed"]}

    首先安装graphviz

sudo apt-get install graphviz

    然后生成运行如下命令,生成流程图:

dot -Tpng -o hello.png tmp.dot

    打开图片:

xdg-open hello.png

    结果如下:
这里写图片描述

实例2:

digraph otherOp{        node [            shape = "record"            color = "blue"        ]    edge[        arrowhead = "empty"    ]    // 子图,必须以cluster开头    subgraph cluster0{        // 子图用浅灰色填充        style = filled        color = lightgray        // 子图名字        label = "web server"        // 制定整个client_socket填充,且填充的颜色为red,这时边缘是蓝色。不指定颜色,则会用上面的边缘颜色blue填充,导致无法看到边缘。            // 这里使用s0,s1...占位符号        client_socket [label = "{<s0>|<s1>head|<s2>|<s3>...|<s4>|<s5>tail|<s6>}" style = "filled" fillcolor = "red"]            // 指定边上的文字        master_thread -> client_socket : s1[label = "produce socket"]        worker_thread [label = "{<w0> worker_thread 1| <w1> worker_thread 2 | <w2>worker_thread 3}"]        client_socket : s5 -> worker_thread : w0            client_socket : s4 -> worker_thread : w1 [ label = "consume socket"]            client_socket : s3 -> worker_thread : w2        producer[ label = "producer" style = filled fillcolor = "green"]        consumer[ label = "comsumer" style = filled fillcolor = "green"]        Queue[ label = "Queue" style = filled fillcolor = "green"]        {rank = same; producer; master_thread}        {rank = same; consumer; worker_thread}        {rank = same; Queue; client_socket}    }    request1 -> master_thread[color = "red"]    request2 -> master_thread[color = "red"]    request3 -> master_thread[color = "red"]    // 边是虚线,且是橙色    request1 -> worker_thread : w0 [ style = "dashed" color = "orange", label = "process request"]    request2 -> worker_thread : w1 [ style = "dashed" color = "orange" label = "process request"]    request3 -> worker_thread : w2 [ style = "dashed" color = "orange" label = "process request"]        Browser[ label = "Browser" style = filled fillcolor = "green"]    {rank = same; Browser; request1; request2; request3}}

    结果:
这里写图片描述
    多个点相互连接的简便写法是
{a; b} -> {c; d}
参考
http://gashero.iteye.com/blog/1748795

0 0