2.4 mgv.rb Create graph data for Graphviz (DOT)

The graph data in CSV format is converted to a .dot file format for processing by Graphviz.

Graph processing commands (e.g. mpolishing) contained in Take package reads and generates graphs expressed in CSV format. Visualization (graphic image) helps users to understand attributes of the graph, such as the scale and density. By converting graph data into DOT plain text graph description language, the graphs can be visualized in softwares such as Graphviz (http://www.graphviz.org) and Gephi (http://www.gephi.org).

Graphviz is intended for the visualization of small graphs, thus, it may not be practical for large graphs with several hundred and thousands of vertices. It is recommended to use Gephi for drawing of large-scale graphs.

2.4.1 Format

mgv.rb [ni=] [nf=] [nv=] [nr=] [-nl] ei= ef= [ev=] [er=] [-el] [-d] [o=] [--help]

ni=

: File name of vertex set

nf=

: Field name of vertex

nv=

: Field name of vertex attribute (size of vertex)

nr=

: Enlargement ratio when drawing graph. This parameter accepts integer values from 1 to 10. Default is set at 3

-nl

: Specified value at nv= is added to the node name

ei=

: File name of edge set

ef=

: ID field name of beginning vertex and end vertex

ev=

: Field name of edge attribute (thickness of edge)

er=

: Enlargement ratio of edge when drawing graph. This parameter accepts integer values from 1 to 10. Default is set at 10.

-el

: Show width of edge specified at ev=

-d

: Specify directed graph

o=

: Output file name (.dot file)

--help

: Show help

The input graph data may only be specified at ei= parameter as edge set CSV data. In order to include the attribute of vertices (size), the CSV data of the vertices set used can be specified at ni= parameter.

Display graph data in CSV format

One row represents one edge, which corresponds to the start of vertex and end of vertex stored in two fields.

node1,node2
A,B
B,C
C,A
C,D
E,D

Example of .dot format graph data

Contains information related to vertices and information of edges.

digraph G { 
  edge [dir=none]

    n0 [label="A" height=0.5 width=0.75] 
n1 [label="B" height=0.5 width=0.75] 
n2 [label="C" height=0.5 width=0.75] 
n3 [label="D" height=0.5 width=0.75] 
n4 [label="E" height=0.5 width=0.75] 


    n0 -> n1 [style="setlinewidth(1.0)"]
n1 -> n2 [style="setlinewidth(1.0)"]
n2 -> n0 [style="setlinewidth(1.0)"]
n2 -> n3 [style="setlinewidth(1.0)"]
n4 -> n3 [style="setlinewidth(1.0)"]

}

Example to draw by Graphviz

Graphviz GUI allows users to interact with graph data, the dot command installed with Graphviz allows for conversion to graphic (.png file). The visual of graph is shown in diagram 2.5.

$ dot -Tpng rsl1.dot > rsl1.png
$ open rsl1.png

\includegraphics[scale=0.5]{figure/mgv0.eps}
Table 2.5: Example of drawing with Graphviz


2.4.2 Examples

例1: 基本例

開始頂点と終了頂点からなる枝集合ファイルのみを与える。

$ more edge1.csv
node1,node2
A,B
B,C
C,A
C,D
E,D
$ mgv.rb ei=edge1.csv ef=node1,node2 o=rsl1.dot

\includegraphics[scale=0.5]{figure/mgv1.eps}

例2: 枝に属性(太さ)を指定する例

ev=パラメータでval項目を属性(太さ)として指定している。 同時に-elオプションを付けることで、属性値もグラフに描画される。

$ more edge2.csv
node1,node2,val
A,B,10
B,C,20
C,A,30
C,D,40
E,D,20
$ mgv.rb ei=edge2.csv ef=node1,node2 ev=val -el o=rsl2.dot

\includegraphics[scale=0.5]{figure/mgv2.eps}

例3: 頂点に属性(大きさ)を指定する例

ni=パラメータで頂点集合ファイルを指定する。 nv=パラメータで、val項目を属性(大きさ)として指定している。

$ more node1.csv
node,val
A,10
B,15
C,8
D,5
E,20
$ more edge1.csv
node1,node2
A,B
B,C
C,A
C,D
E,D
$ mgv.rb ei=edge1.csv ef=node1,node2 ni=node1.csv nf=node nv=val o=rsl3.dot

\includegraphics[scale=0.3]{figure/mgv3.eps}

例4: 頂点に属性(大きさ)と拡大率を指定する例

nr=パラメータで、ノードの拡大率を指定している。

$ more node1.csv
node,val
A,10
B,15
C,8
D,5
E,20
$ more edge1.csv
node1,node2
A,B
B,C
C,A
C,D
E,D
$ mgv.rb ei=edge1.csv ef=node1,node2 ni=node1.csv nf=node nv=val nr=5 o=rsl4.dot

\includegraphics[scale=0.3]{figure/mgv4.eps}