Creating scripts
{ graph [ dpi = 144 ]; rankdir = LR; node [shape=record, width=.2, height=.2];
node0 [label = “<p0> | <p1> | <p2> | <p3> | <p4> | | ", height = 3]; node[ width=2 ]; node1 [label = "{<e> r0 | 123 | <p> }" ]; node2 [label = "{<e> r10 | 13 | <p> }" ]; node3 [label = "{<e> r11 | 23 | <p> }" ]; node4 [label = "{<e> r12 | 326 | <p> }" ]; node5 [label = "{<e> r13 | 1f3 | <p> }" ]; node6 [label = "{<e> r20 | 143 | <p> }" ]; node7 [label = "{<e> r40 | b23 | <p> }" ]; node0:p0 -> node1:e; node0:p1 -> node2:e; node2:p -> node3:e; node3:p -> node4:e; node4:p -> node5:e; node0:p2 -> node6:e; node0:p4 -> node7:e; }
( Theoutputfromthecode,above,isshownintheimageto theleft). You’ll be able to see the table after compiling it using: $ dot -T png hashtable.dot -o hashtable.png
As you can see, you can create a node by prefixing a [] with a name and an edge by putting -> between the two node names you want to connect. Each node can have a title, which you can add using the label attribute. An | character separates the various parts of the label of a node. In order to access them individually afterwards, use the node name, a colon ( : ) and the identifier of the label part you want to use ( e.g. node4:p ). The name of each part of the label is defined inside a <> tag (e.g. <e> ). This notation allows you to connect two nodes more precisely.
Each node[] statement you put into your code affects all nodes in the graph starting from the position you place it. The rankdir=LR command tells the DOT language to place nodes from left to right because by default, graphs are positioned from top to bottom. Perl as well as any other programming language may create plain DOT code without the need for a special module. The following Perl code, saved as useGV.pl, illustrates how to use Perl without any special modules in order to produce plain Graphviz code: #!/usr/bin/perl -w use strict; die <<Thanatos unless @ARGV; usage: $0 directory Thanatos # Preamble print <<START; digraph G { rankdir = LR; graph [dpi = 300, bgcolor = "gray"]; nodesep=.05; node[height=.05, shape=record, fontsize=10, color="red"]; START my $counter = 0; foreach my $arg (@ARGV) {
print "\t".$arg.$counter." [shape=box, label=\"$arg\"];"; print “\n”; $counter++; } # Create the edges my $i= 0; for ($i=0; $i<$#ARGV; $i++) {
print "\t"."$ARGV[$i]$i->$ARGV[($i+1)]". ($i+1).";\n"; if ($i == ($#ARGV-1)) { last; } } # Close the Graphviz file print <<END; } END
The useGV.pl script accepts multiple command line