Full Blog TOC

Full Blog Table Of Content with Keywords Available HERE

Monday, March 18, 2024

Creating graphs using Graphvis dot file

 

Graphvis is an open source graph visualization software. One of the covered aspects is a standard for DOT file, which describes a graph. These graphs can be later visualized using related software and also in online visualization sites such as Graphvis Online.

In this post we will explore the dot file various capabilities.

For more amazing graphs, see the gallery.

A simple undirected graph


graph test {
a -- b -- c;
}




A simple directed graph

digraph test {
a -> b -> c;
}


Multiple graphs with styles


  • To have a sub-graph in its own box: use the prefix "cluster" in the graph name.
  • Edge connections:
    • node to node edges
    • cluster to cluster edges
  • Use "node" to apply attributes to all nodes in the scope

digraph {

compound=true;

subgraph cluster_a{
label="A";
node [style=filled fillcolor="#ff00ff" fontcolor="white" shape=box];
a1[shape=star];
a1 -> {a2 a3};
}

subgraph cluster_b{
label="B";
b1 -> b2;
}

a1 -> b1[label="nodes edge"];
a2 -> b2[label="clusters edge" ltail="cluster_a" lhead="cluster_b"];
}




Record node

  • Enables multiple segments in a node.
  • We can tag a segment, and use it later in an edge.
digraph {

subgraph x{
node[shape="record"];
a[label="{line 1|<x>line2}"];
b[label="{line1|{lin2_col1|<y>line2_col2|line2_col3}}"];
a:x->b:y;
}

}





Use HTML in a label

We can use HTML for a label, but only in a table format.

digraph {

staging [
label=<<table border="0" cellborder="1" cellspacing="0" cellpadding="4">
<tr> <td> <b>important</b></td> </tr>
<tr> <td> to have fun</td> </tr>
</table>>
shape=plain
]

}








No comments:

Post a Comment