SpringGraph - Directed Graph alternative to GraphViz


SpringGraph documentation  | view source Contained in the SpringGraph distribution.

Index


NAME

Top

SpringGraph - Directed Graph alternative to GraphViz

SYNOPSIS

Top

use SpringGraph qw(calculate_graph draw_graph);

## object oriented interface ##

my $graph = new SpringGraph;

# add a node to the graph (with optional label)

$graph->add_node('Paris', label =>'City of Love');

# add an edge to the graph (with optional label, and directed)

$graph->add_edge('London' => 'New York', label => 'Far', dir=>1);

# output the graph to a file

$graph->as_png($filename);

# get the graph as GD image object

$graph->as_gd;

## procedural interface ##

my %node = ( london => { label => 'London (Waterloo)'}, paris => { label => 'Paris' }, brussels => { label => 'Brussels'}, );

my %link = ( london => { paris => {style => 'dotted'}, 'new york' => {} }, # non-directed, dotted and plain lines paris => { brussels => { dir => 1} }, # directed from paris to brussels );

my $graph = calculate_graph(\%node,\%link);

draw_graph($filename,\%node,\%link);

DESCRIPTION

Top

SpringGraph.pm is a rewrite of the springgraph.pl script, which provides similar functionality to Neato and can read some/most dot files.

The goal of this module is to provide a compatible interface to VCG and/or GraphViz perl modules on CPAN. This module will also provide some extra features to provide more flexibility and power.

METHODS

Top

Class Methods

Top

new

Constructor for the class, returns a new SpringGraph object

my $graph = SpringGraph->new;

calculate_graph

returns a hashref of the nodes in the graph, populated with coordinates

my $graph = calculate_graph(\%node,\%link);

draw_graph

outputs the graph as a png file either to the file specified by the filename or to STDOUT

takes filename, hashref of nodes and list of edges

draw_graph($filename,\%node,\%link);

Object Methods

Top

add_node

adds a node to a graph

takes the name of the node and any attributes such as label

# just like GraphViz.pm :) $graph->add_node('Paris', label =>'City of Love');

add_edge

adds an edge to a graph

takes the source and destination of the edge and attributes such as style (dotted or dashed), or if the line is directed or not

$graph->add_edge('London' => 'New York', dir => 1, style=>'dashed');

as_png

prints the image of the graph in PNG format

takes an optional filename or outputs directly to STDOUT

$graph->as_png($filename);

as_gd

returns the GD image object of the graph

my $gd_im = $graph->as_gd;

as_gd

returns the image of the graph in a string in the format specified or PNG

my $graph_png = $graph->as_image('png');

SEE ALSO

Top

GraphViz

springgraph.pl

http://www.chaosreigns.com/code/springgraph/

GD

AUTHOR

Top

Aaron Trevena, based on original script by 'Darxus'

COPYRIGHT

Top


SpringGraph documentation  | view source Contained in the SpringGraph distribution.