GraphViz::Graph - Object Oriented interface to graphviz.
Version 0.03
use GraphViz::Graph; my $graph = GraphViz::Graph->new('filename-without-suffix'); # Create nodes: my $nd_1 = $graph->node(…); my $nd_2 = $graph->node(…); # Connect nodes: $graph->edge($nd_1, $nd_2); # Create .dot file, run graphviz/dot to # create filename-without-suffix.png: $graph->create('png');
Note: GraphViz::Graph needs dot somewhere in $PATH.
GraphViz::Graph
dot
$PATH
my $graph = GraphViz::Graph->new('FileNameBase');
Start a graph. 'FileNameBase' is the base name for the produced dot and png/pdf/svg… etc. output file. (See "create").
'FileNameBase'
# Add text label: $graph->label({text => 'Graph Title'}'); # Add html label: $graph->label({html => '<font point-size="20">Say <font face="Courier">Hello World</font></font>'}'); # Position label: my $graph_lbl = $graph->label(…); $graph_lbl -> loc('t'); # t = top
Add a label to a graph. Note, a graph can only have one label. This label is most probably used as a title.
For positioning the label, see "loc" in GraphViz::Graph::Label.
my $nd_foo = GraphViz::Graph->node(); # … later: $nd_foo -> label({html=>"<b>Bold</b><i>Italic</i>"});
Add a node to a graph. The returned object is a GraphViz::Graph::Node.
Add an edge to a graph.
my $nd_one = $graph->node(); my $nd_two = $graph->node(); my $nd_three = $graph->node(); $nd_one->label({html=>"…"}); $nd_two->label({html=>"<table> <tr><td port='port_f'>f</td><td>g</td></tr> </table>"}); $graph->edge($nd_one, $nd_two->port('port_f')): $graph->edge($nd_two, $nd_three);
$graph->same_rank($node_one, $node_two); $graph->same_rank($node_one, $node_two, $node_three, …);
Put two or more nodes on the same rank.
my $graph = GraphViz::Graph->new('my_file'); # Do stuff... $graph->node(…); # Finally, create the graphviz output: # The call to create produces (as per constructor) # - my_file.dot # - my_file.pdf $ graph->create('pdf');
This function is internally used by the constructur (new()) of GraphViz::Graph::Edge.
new()
Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at: http://www.perlfoundation.org/artistic_license_2_0
The tests need Test::Files.
Since GraphViz::Graph needs dot, the tests are skipped if
The source code is on github
To install GraphViz::Graph, copy and paste the appropriate command in to your terminal.
cpanm
cpanm GraphViz::Graph
CPAN shell
perl -MCPAN -e shell install GraphViz::Graph
For more information on module installation, please visit the detailed CPAN module installation guide.