NAME
GraphViz - Interface to the GraphViz graphing tool
SYNOPSIS
use GraphViz;
my $g = GraphViz->new();
$g->add_node({ name => 'London'});
$g->add_node({ name => 'Paris', label => 'City of\nlurve'});
$g->add_node({ name => 'New York'});
$g->add_edge({ from => 'London',
to => 'Paris',});
$g->add_edge({ from => 'London',
to => 'New York',
label => 'Far'});
$g->add_edge({ from => 'Paris',
to => 'London',});
print $g->as_text;
Prints the following:
digraph test {
London -> Paris;
London -> New_York [label=Far];
Paris -> London;
London [label=London];
New_York [label="New York"];
Paris [label="City of\nlurve"];
}
DESCRIPTION
This provides an object-orientated interface to generating the ".dot" files needed by the "dotneato" program in the GraphViz project (http://www.graphviz.org/). It constructs a file which can then be used to draw directed graphs in a variety of formats (Postscript, GIF, etc.)
At the moment this is a very simple library (it is a very simple format). Some features of the format are not currently implemented, such as graph attributes. Feature requests are welcome!
I am not going to document the ".dot" file format: the node and edge attributes are available in the "dot" manpage, so you should check that out if you want to use non-default attributes.
METHODS
new
This is the constructor. It currently takes no arguments:
my $g = GraphViz->new();
add_node
A graph consists of at least one node. This method creates a new node and assigns it attributes. Various attributes are possible: "name" suggests a name for the node (if you do not supply one, one is generated for you and returned), "label" provides a label for the node (the label defaults to the name if none is specified). See the "dot" manpage under "NODE ATTRIBUTES" for others.
$g->add_node({ name => 'Paris', label => 'City of\nlurve'});
add_edge
Edges are directed links between nodes. This method creates a new edge between two nodes and optionally assigns it attributes. Two mandatory parameters are 'from' and 'to', which indicate the node names that the edge connects. Optional attributes such as 'label' are also available (see the "dot" manpage under the "EDGE ATTRIBUTES" for others).
$g->add_edge({ from => 'London',
to => 'New York',
label => 'Far'});
AUTHOR
Leon Brocard <acme@astray.com>
COPYRIGHT
Copyright (C) 2000, Leon Brocard
This module is free software; you can redistribute it or modify it under the same terms as Perl itself.