HTML::InfoVis::Graph - Generate a JSON structure suitable for loadJSON classes


  use HTML::InfoVis;
  my $graph = HTML::InfoVis::Graph->new;
  $graph->add_edge( 'foo' => 'bar' );
  print "var json = " . $graph->as_json . "\n";


HTML::InfoVis::Graph is used to generate a JSON structure suitable for loading by any InfoVis Javascript object that has the loadJSON method.

This is a basic first implementation, designed to prove the concept of converting Perl graphs into InfoVis graphs.

It provides a few Graph-like methods to populate the graph, and a single method for generating an anonymous JSON structure representing the graph.



  my $graph = HTML::InfoVis::Graph->new(

The default constructor takes a single optional param of a Graph object that represents the graph structure.

Returns a new HTML::InfoVis::Graph object.


  $graph->add_node( 'foo' );

The add_node method is a pass-through method to the underlying Graph add_vertex method.


  $graph->add_edge( 'foo' => 'bar' );

The add_edge method is a pass-through method to the underlying Graph add_edge method.


  my $json = $graph->as_json;

The as_json method generates a serialized anonymous JSON structure that represents the graph in a form suitable for loading by any InfoVis loadJSON method.

Because it is generated anonymously, if you wish to assign it to a variable you will need to do that yourself in your JavaScript template.


Bugs should be reported via the CPAN bug tracker at

For other issues, or commercial enhancement or support, contact the author.


Adam Kennedy <>


Copyright 2009 - 2012 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.