Graph::Easy is a Perl module that lets you generate graphs consisting of various shaped nodes connected by edges (with optional labels).
SYNOPSIS
use Graph::Easy;
my $graph = Graph::Easy->new();
# make a fresh copy of the graph
my $new_graph = $graph->copy();
$graph->add_edge ('Bonn', 'Berlin');
# will not add it, since it already exists
$graph->add_edge_once ('Bonn', 'Berlin');
print $graph->as_ascii( ); # prints:
# +------+ +--------+
# | Bonn | --> | Berlin |
# +------+ +--------+
#####################################################
# alternatively, let Graph::Easy parse some text:
my $graph = Graph::Easy->new( '[Bonn] -> [Berlin]' );
#####################################################
# slightly more verbose way:
my $graph = Graph::Easy->new();
my $bonn = $graph->add_node('Bonn');
$bonn->set_attribute('border', 'solid 1px black')
my $berlin = $graph->add_node('Berlin');
$graph->add_edge ($bonn, $berlin);
print $graph->as_ascii( );
# You can use plain scalars as node names and for the edge label:
$graph->add_edge ('Berlin', 'Frankfurt', 'via train');
# adding edges with attributes:
my $edge = Graph::Easy::Edge->new();
$edge->set_attributes( {
label => 'train',
style => 'dotted',
color => 'red',
} );
# now with the optional edge object
$graph->add_edge ($bonn, $berlin, $edge);
# raw HTML section
print $graph->as_html( );
# complete HTML page (with CSS)
print $graph->as_html_file( );
# Other possibilities:
# SVG (possible after you installed Graph::Easy::As_svg):
print $graph->as_svg( );
# Graphviz:
my $graphviz = $graph->as_graphviz();
open $DOT, '|dot -Tpng -o graph.png' or die ("Cannot open pipe to dot: $!");
print $DOT $graphviz;
close $DOT;
# Please see also the command line utility 'graph-easy'
It can read and write graphs in a varity of formats, as well as render them via its own grid-based layouter.
Since the layouter works on a grid (manhattan layout), the output is most usefull for flow charts, network diagrams, or hierarchy trees.
Product's homepage
Requirements:
· Perl