2.1 msankey.rb Draw sankey diagram

The sankey diagram is a technique to visualize Directed Acyclic Graph (DAG), in which the weight of edge is defined in proportion with the flow quantity between contact points. The diagram is typically used to visualize energy transfer between processes in power transmission network.

This visualization command calls to internal D3 library (Data-Driven Documents) to generate sankey diagrams (http://bost.ocks.org/mike/sankey/).

The input data is shown in Table 2.1, each edge and node pair and their corresponding value are shown in a row as CSV data. The sankey diagram is generated as one html file which can be displayed in the browser as shown in diagram (2.2).

The orientation of the graph starts from left to right, the first item specified at command parameter f= corresponds to the left, and the second item corresponds to the right. The color bar corresponds to the node, and the edge corresponds to the connecting points. Interval relaxation method is used to determine the output position of the node. For more details, please refer to the original URL above. Based on experiments, it consumes more time to draw 5 nodes $\times $ 10 level positions $=50$ nodes.

In order to use this command, json library in nysol/mcmd library is required.

Table 2.1: Input data (Closed walk directed graph)

node1

node2

val

a

b

1

a

c

2

a

d

1

b

c

3

b

d

3

c

f

1

c

e

4

d

e

1

e

f

3

\includegraphics[scale=0.5]{figure/sankey1.eps}
Table 2.2: Sankey diagram

2.1.1 Format

msankey [i=] f= v= [o=] [t=] [T=] [--help]

i=

: Edge data file

f=

: Two node field names on edge data

v=

: Field name of edge weight

o=

: Output file (HTML file)

t=

: Specify title

-T

: Working directory (default:/tmp)

--help

: Show help

2.1.2 Example

δΎ‹1: Basic Example

Example used in the previous description.

$ more dat1.csv
node1,node2,val
a,b,1
a,c,2
a,d,1
b,c,3
b,d,3
c,f,1
c,e,4
d,e,1
e,f,3
$ msankey.rb i=dat1.csv f=node1,node2 v=val o=output.html
$ head output.html
<!DOCTYPE html>
<html class="ocks-org do-not-copy">
<meta charset="utf-8">
<!--
<title>Sankey Diagram</title>
-->
<title></title>
<style>