OpenSource For You

Visualisin­g Graph using DOT

- By: Karthikeya­n R and AnandaVelM­urugan Chandra Mohan Karthikeya­n R is a Java developer and technophil­e who loves to keep in touch with emerging technologi­es. Anand is a data analyst who loves playing with data using R. He likes exploring new technologi­es.

The DOT language describes three main objects: graph, node and edges. A DOT file starts with either ‘graph’ or ‘digraph’, followed by a graph name. ‘digraph’ is used for a directed graph and ‘graph’ for an undirected graph. The name can contain any alphanumer­ic character, but spaces are not allowed. Nodes of the graph are contained within curly braces. Double hyphens represent the edges of the undirected graph while the ‘arrow' is used for showing directiona­lity. The following example represents a fournode undirected graph:

graph hello { a -- b -- c; b -- d;

}

It can be turned into a directed graph by changing ‘graph’ to ‘digraph’ and replacing the double hyphen with arrows. The following is the modified script:

digraph graphname { a -> b -> c; b -> d;

}

Some of the important attributes that can be controlled in the DOT file are the node shape, labels, colour, fonts, style of connection­s, etc. One graph may enclose another graph and it is specified as a sub-graph in DOT. Vertices in the outer node can even share vertices with the enclosed sub-graph's node:

graph hello2 { // Hello World with nice colors and big fonts

Node1 [label="Hello, World!", color=Blue, fontcolor=Red,

fontsize=24, shape=box, style=filled]

Node2 [label="Hello, Again!", color=Red, fontcolor=Blue,

fontsize=24, shape=oval, style=solid]

Node3 [label="Hello, Again!", color=Blue, fontcolor=Blue,

fontsize=24, shape=circle, style=dashed]

Node1 -- Node2 [color=red] Node1 -- Node3 [style=dotted,color=red] subgraph hello3{

Node4 [label="Hello, Again!", color=Blue, fontcolor=Blue,

fontsize=24, shape=circle, style=dashed]

Node5 [label="Hello, Again!", color=Blue, fontcolor=Blue,

fontsize=24, shape=circle, style=dashed]

Node4 -- Node5 } Node3 -- Node5 }

The DOT language only specifies the graph and the layout is taken care of by various layout engines present as part of Graphviz. In GVEdit, users can switch the layout engine easily. It is even possible to generate this DOT file programmat­ically and many languages provide bindings for that. The presence of the dot command line utility helps in automating the graph creation too.

Apart from those discussed in this article, there are many more powerful DSLs available for visualisin­g data. Each library provides a different level of functional­ity; some provide readily available charts with a few configurat­ions, like Vega, and some provide implementa­tion from scratch, like Processing. A few other notable libraries for visualisat­ion are gRaphaël JS, a good charting library that supports older browsers; Paper JS for rendering vector graphics in Canvas; Kartograph JS for building interactiv­e maps; and Tangle JS for creating user interactiv­e reactive documents.

References

[1] http://processing.org/ [2] http://trifacta.github.io/vega/ [3] http://www.graphviz.org/

 ??  ?? Figure 3: Graph Output1
Figure 3: Graph Output1
 ??  ??

Newspapers in English

Newspapers from India