Thursday, December 18, 2008

Automate graph drawing with Grapviz



The picture shows an example of using Graphviz to draw a graph for Traffic Information module. The arrows depict the objects's communication using Observer Pattern.


digraph TIComponent {

graph [ label = "\nTraffic Infomation's communication",
size = "11",
fontsize = 20,

fontcolor=blue4];


node [ //shape = box,

color = darkslateblue,

style = filled,

fillcolor = deepskyblue1];

edge [ decorate = false ]

rankdir=TB

subgraph cluster_TI {
style=filled;
color=lightblue1;
l
abel="TI Kernel";

ranke=source

Tuner;

Receiver;
Cache;

Database;
}

subgraph cluster_Device {
//node [shape = box]

style=filled;

color=khaki;

label="HAL";


Device;
}

subgraph cluster_App {
style=filled;

color=plum1;

label="Application";

"Client 1";
"Client 2";
}

Tuner->"Client 1" [label="new station", labelfloat=false, color=darkgreen, fontcolor=darkgreen];
Tuner->Receiver [label="status of band scan",color=magenta, fontcolor=magenta];
Receiver->Cache [label="TrafficData", color=firebrick3, fontcolor=firebrick3];
Receiver->Tuner [label="search next station", color=gold2, fontcolor=gold2];
Cache->"Client 2" [label="message update", color=violet, fontcolor=violet];
Cache->"Client 1" [label="message update", color=violet, fontcolor=violet];
Database->Cache [arrowhead="dot", minlen=2];
Device->Receiver [arrowhead="dot", minlen=0];
Device->Tuner [headlabel="new station", labelfloat=true, color=darkgreen, minlen=2, labeldistance=2, fontcolor=darkgreen];
Tuner->Device [label="search next station", labelfloat=true, color=gold2, minlen=1, fontcolor=gold2];

}


To generate output as png from the dot, type

$ dot -Tpng -ooutput.png inputfile.dot