NAME

GraphViz::Graph - Object Oriented interface to graphviz.

VERSION

Version 0.03

SYNOPSIS

    use GraphViz::Graph;

    my $graph = GraphViz::Graph->new('filename-without-suffix');

    # Create nodes:
    my $nd_1 = $graph->node(…);
    my $nd_2 = $graph->node(…);

    # Connect nodes:
    $graph->edge($nd_1, $nd_2);

    # Create .dot file, run graphviz/dot to
    # create filename-without-suffix.png:
    $graph->create('png');

Note: GraphViz::Graph needs dot somewhere in $PATH.

METHODS

new

    my $graph = GraphViz::Graph->new('FileNameBase');

Start a graph. 'FileNameBase' is the base name for the produced dot and png/pdf/svg… etc. output file. (See "create").

label

    # Add text label:
    $graph->label({text => 'Graph Title'}');

    # Add html label:
    $graph->label({html => '<font point-size="20">Say <font face="Courier">Hello World</font></font>'}');

    # Position label:
    my $graph_lbl = $graph->label(…);
    $graph_lbl -> loc('t'); # t = top

Add a label to a graph. Note, a graph can only have one label. This label is most probably used as a title.

For positioning the label, see "loc" in GraphViz::Graph::Label.

node

    my $nd_foo = GraphViz::Graph->node();
    # … later:
    $nd_foo -> label({html=>"<b>Bold</b><i>Italic</i>"});

Add a node to a graph. The returned object is a GraphViz::Graph::Node.

edge

Add an edge to a graph.

    my $nd_one   = $graph->node();
    my $nd_two   = $graph->node();
    my $nd_three = $graph->node();

    $nd_one->label({html=>"…"});

    $nd_two->label({html=>"<table>
      <tr><td port='port_f'>f</td><td>g</td></tr>
    </table>"});

    $graph->edge($nd_one, $nd_two->port('port_f')):
    $graph->edge($nd_two, $nd_three);

same_rank

    $graph->same_rank($node_one, $node_two);
    $graph->same_rank($node_one, $node_two, $node_three, …);

Put two or more nodes on the same rank.

create

    my $graph = GraphViz::Graph->new('my_file');

    # Do stuff...
    $graph->node(…);
  
    # Finally, create the graphviz output:
    # The call to create produces (as per constructor)
    #   - my_file.dot
    #   - my_file.pdf
    $ graph->create('pdf');

node_or_port_to_string_

This function is internally used by the constructur (new()) of GraphViz::Graph::Edge.

Copyright

Copyright © 2017 René Nyffenegger, Switzerland. All rights reserved.

This program is free software; you can redistribute it and/or modify it under the terms of the the Artistic License (2.0). You may obtain a copy of the full license at: http://www.perlfoundation.org/artistic_license_2_0

Testing

The tests need Test::Files.

Since GraphViz::Graph needs dot, the tests are skipped if

Source Code

The source code is on github