2017_09_02-結構化圖形繪製軟件GraphViz的使用

說明:上傳後圖片和排版丟失,完整內容見pdf

pdf: hhttps://download.csdn.net/download/taotaoyouarebaby/9961643

3   graphViz3

3.1  無向圖.4

3.2  帶標籤加權無向圖.4

3.3  有向圖.5

3.3.1  畫圖引擎.5

3.4  標註路徑.5

3.5  子圖. 6

3.6  大型圖形:rank=same對齊.7

3.7  UML元素.8

3.7.1  node[..],edge[..]設置節點、連線屬性.9

3.7.2  node[shape=”record”]9

3.7.3  類表示:AnimalClass9

3.7.4  繼承關係:edge[arrowhead= "empty"]10

3.7.5  N:M關係:edge[arrowhead=”none”,headlabel=””,taillabel=””]10

3.7.6  包:使用子圖實現subgraph clusterxxx {}11

1   graphViz

參考:http://graphs.grevian.org/example

 

1.1   無向圖

graph {

    rankdir=LR

    a -- b;

    a -- c;

    a -- e;

   

    b -- c;

    e -- c;

   

    c -- d;

}

說明:

Ø  --: 無向圖連線,可指定 節點集合 到 節點集合的連線,實現批量指定連線。

Ø  rankdir=LR:指定圖形排布方式,TB:從上到下,BT:從下到上;LR:從左到右;RL:從右到左。默認爲TB

Ø  位置:圖形和連線出現的位置與圖形元素的聲明順序有關

 

1.2   帶標籤加權無向圖

graph {

    rankdir=LR

    a [label="start",color=red,style=filled]

    d [label="end",color=black,fontcolor=white,style=filled]

 

    a -- b[label="10",weight="10"];

    a -- c[label="1",weight="1"];

    a -- e[label="1",weight="1"];

   

    b -- c[label="4",weight="4"];

    e -- c[label="1",weight="1"];

   

    c -- d[label="6",weight="6"];

}

 

說明:

Ø  label=”start”:指定節點或連線的標籤內容

Ø  color=red:指定節點的顏色

Ø  fontcolor=white:指定節點標籤字體的顏色

Ø  style=filled:指定 節點或連線 風格,filled:填充滿, 對於線:style=dotted:虛線

Ø  weight:兩個節點之間的連線weight越大,則節點靠得更近。

 

1.3   有向圖

digraph {

    a -> b[label="0.2",weight="2"];

    a -> c[label="0.4",weight="4"];

    c -> b[label="0.6",weight="6"];

    c -> e[label="0.6",weight="6"];

    e -> e[label="0.1",weight="1"];

    e -> b[label="0.7",weight="7"];

}

說明:

畫圖引擎:要畫出右圖,需要切換畫圖引擎爲circo.

 

1.3.1畫圖引擎

圖形引擎

特點

circo

適合多環路結構的圖形

dot

 

neato

 

fdp

 

sfdp

 

twopi

放射狀佈局

 

1.4   標註路徑

由circo圖形引擎生成:

graph {

    a -- b -- d -- c -- f[color=red,penwidth=3.0];

    b -- c;

    d -- e;

    e -- f;

    a -- d;

}  

 

1.5   子圖

由dot圖形引擎生成:

 

digraph {

    splines=line;

    subgraph cluster_0 {

       label="Subgraph A";

       a -> b;

       b -> c;

       c -> d;

    }

 

    subgraph cluster_1 {

       label="Subgraph B";

       a -> f;

       f -> c;

    }

}

說明:

Ø  splines=line:指定只使用直線

Ø  subgraph clusterXXX: 子圖命名必需以cluster開關,否則無法合併到一個框圖中。而且只有dot引擎支持。

 

1.6   大型圖形:rank=same對齊

graph {

   rankdir=LR;

   a -- { b c d }; b -- { c e }; c -- { e f }; d -- { f g }; e -- h;

   f -- { h i j g }; g -- k; h -- { o l }; i -- { l m j }; j -- { m n k };

   k -- { n r }; l -- { o m }; m -- { o p n }; n -- { q r };

   o -- { s p }; p -- { s t q }; q -- { t r }; r -- t; s -- z; t -- z;

   { rank=same b c d };

   { rank=same e f g } ;

   { rank=same h i j k };

   { rank=same l m n };

   { rank=same o p q r };

   { rank=same s t };

}

說明:

Ø  a -- { b c d }; : 指定 節點-> 節點集合 的連線

Ø  rank=same:將節點對齊排列,左右或上下

Ø  ranksep=1:指定兩級rank之間的距離,inch. 在上圖中ranksep越大,a,c離的越開

Ø  nodesep=1: 指定同級rank之間的距離,inch. 在上圖中nodesep越大,a,c,d離的越開

 

1.7   UML元素

引用:http://www.ffnn.nl/pages/articles/media/uml-diagrams-using-graphviz-dot.php

使用dot引擎生成:如果使用circo引擎,則無法生成子圖

 

digraph G {

        fontname = "Bitstream Vera Sans"

        fontsize = 8

 

        node [

                fontname = "Bitstream Vera Sans"

                fontsize = 8

                shape = "record"

        ]

 

        edge [

                fontname = "Bitstream Vera Sans"

                fontsize = 8

        ]

 

        Animal [

                label = "{Animal|+ name : string\l+ age : int\l|+ die() : void\l}"

        ]

 

        subgraph clusterAnimalImpl {

                label = "Package animal.impl"

 

                Dog [

                        label = "{Dog||+ bark() : void\l}"

                ]

 

                Cat [

                        label = "{Cat||+ meow() : void\l}"

                ]

        }

 

        edge [

                arrowhead = "empty"

        ]

 

        Dog -> Animal

        Cat -> Animal

 

        edge [

                arrowhead = "none"

 

                headlabel = "0..*"

                taillabel = "0..*"

        ]

 

        Dog -> Cat

}

 

1.7.1node[..],edge[..]設置節點、連線屬性

1.7.2node[shape=”record”]

設置節點爲record,這樣的節點可以被分割,適合構造類圖

 

1.7.3 類表示:AnimalClass

Animal [

       label = "{Animal|+ name : string\l+ age : int\l|+ die() : void\l}"

]

說明:

Ø  "{" and "}":表示要創建一個record的圖形,並帶有分隔線。

Ø  "|" : 代表分隔線。這時用於分隔類名、方法、屬性

Ø  "\l" : 換行,後面的字符左對齊

 

1.7.4繼承關係:edge[arrowhead= "empty"]

edge [

       arrowhead = "empty"

]

 

Dog -> Animal

Cat -> Animal

 

1.7.5N:M關係:edge[arrowhead=”none”,headlabel=””,taillabel=””]

edge [

    arrowhead = "none"

 

    headlabel = "0..*"

    taillabel = "0..*"

]

 

 

1.7.6包:使用子圖實現subgraph clusterxxx {}

subgraph clusterAnimalImpl {
                label = "Package animal.impl"

                ... Cat/Dog類

}

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章