Graph::XGMML - Simple Graph.pm-like interface for generating XGMML graphs
use Graph::XGMML; my $output = ''; my $graph = Graph::XGMML->new( directed => 1, OUTPUT => \$output, ); $graph->add_node('foo'); $graph->add_node('bar'); $graph->add_edge('foo', 'bar'); $graph->end;
To produce useful diagrams on extremely large graphs, sometimes it is necesary to move beyond simple graphing tools to applications specifically designed for rendering very large graphs, many of which were designed for biology applications (such as my favourite Cytoscape).
Graph::XGMML is a module that can be used to generate export files for arbitrarily large graphs in eXtensible Graph Modelling Markup Language, so that the graphs can be imported into these specialised tools.
The API is intentionally designed to appear similar to more popular modules such as Graph, Graph::Easy and GraphViz.
# Quick constructor to write to a file $graph = Graph::XGMML->new( directed => 1, OUTPUT => IO::File->new('file', 'w'), ); # Anonymous constructor $graph = Graph::XGMML->new( directed => 1, );
The new constructor is used to create a graph writer.
new
It takes a single optional boolean directed parameter, which indicates if the graphs you will be generating will be directed or undirected.
directed
If any additional parameters are passed to new, the constructor will make an additional call to the start method to start writing the document header and to open the root graph node, passing it the extra parameters.
start
graph
Returns a new Graph::XGMML object, or throws an exception (dies) on error.
The start method allows you to explicitly start the document writing, if the original constructor was produced without additional parameters.
Any parameters are passed directly to the underlying XML::Writer constructor which produces the object that will be used to generate the XML.
Returns true if the document is started successfully, or throws an exception (dies) on error.
# Add a simple node $graph->add_node( 'name' ); # Add optional tag attributes $graph->add_node( 'name', label => 'Tag Label', weight => 100, );
The add_node method is used to add a new node to the graph.
add_node
Because the Graph::XGMML object doesn't remember its state as it produces the graph, you must specify all nodes in the graph explicitly.
The first parameter is the identifier for the node. Any additional parameters will be treated XGMML node element tag pairs.
node
Returns true or throws an exception (dies) on error.
The add_vertex method is an alias to add_node, provided for increased compatibility with the Graph API.
add_vertex
It takes the same parameters as add_node.
# Add a simple edge $graph->add_edge( 'foo' => 'bar' ); # Add with optional attributes $graph->add_edge( 'foo' => 'bar', weight => 1, );
The c<add_edge> method adds an edge to the graph.
The first two parameters are the source and target of the edge. Any additional parameters should be a set of key/value pairs of edge attributes.
# Explicitly terminate the document $graph->end;
The end method is used to indicate that the graph is completed that the XML should be terminated.
end
If you do not call it yourself, it will be called for you at DESTROY-time.
DESTROY
Bugs should always be submitted via the CPAN bug tracker
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Graph-XGMML
For other issues, contact the maintainer.
Adam Kennedy <adamk@cpan.org>
Graph, Graph::Easy, GraphViz
Copyright 2009 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install Graph::XGMML, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Graph::XGMML
CPAN shell
perl -MCPAN -e shell install Graph::XGMML
For more information on module installation, please visit the detailed CPAN module installation guide.