Graph::Simple::Node - Represents a node in a simple graph


NAME

Graph::Simple::Node - Represents a node in a simple graph


SYNOPSIS

        use Graph::Simple::Node;
        my $bonn = Graph::Simple::Node->new(
                name => 'Bonn',
                border => 'solid 1px black',
        );
        my $berlin = Graph::Simple::Node->new(
                name => 'Berlin',
        )


DESCRIPTION

A Graph::Simple::Node represents a node in a simple graph. Each node has contents (a text, an image or another graph), and dimension plus an origin. The origin is typically determined by a graph layouter module like the Graph::Simple manpage.


METHODS

        my $node = Graph::Simple::Group->new( $options );

Create a new node. $options are the possible options:

        name            Name of the node
        border          Border style and color

error()

        $last_error = $node->error();
        $node->error($error);                   # set new messags
        $node->error('');                       # clear error

Returns the last error message, or '' for no error.

as_ascii()

        my $ascii = $node->as_ascii();

Return the node as a little box drawn in ASCII art as a string.

as_txt()

        my $txt = $node->as_txt();

Return the node in simple txt format, including attributes.

as_svg()

        my $svg = $node->as_svg();

Returns the node as Scalable Vector Graphic. The actual code for that routine is defined the Graph::Simple::As_svg.pm manpage.

as_graphviz()

        my $txt = $node->as_graphviz_txt();

Returns the node as graphviz compatible text which can be feed to dot etc to create images.

as_pure_txt()

        my $txt = $node->as_pure_txt();

Return the node in simple txt format, without the attributes.

as_html()

        my $html = $node->as_html($tag, $id, $noquote);

Return the node in HTML. The $tag is the optional name of the HTML tag to surround the node name with. $id is an optional ID that is tagged onto the classname for the CSS. If the last parameter, $noquote, is true, then the node's name will not be quoted/encoded for HTML output. This is usefull if it's name is already quoted.

Example:

        print $node->as_html('span');

Would print something like:

        <span class="node"> Bonn </span>

While:

        print $node->as_html('td');

Would print something like:

        <td class="node"> Bonn </td>

The following:

        print $node->as_html('span', '12');

Would print something like:

        <span class="node12"> Bonn </span>

attribute()

        $node->attribute('border');

Returns the respective attribute of the node or undef if it was not set. If there is a default attribute for all nodes of the specific class the node is in, then this will be returned.

attributes_as_txt

        my $txt = $node->attributes_as_txt();

Return the attributes of this node as text description.

set_attribute()

        $node->set_attribute('border', 'none');

Sets the specified attribute of this (and only this!) node to the specified value.

del_attribute()

        $node->del_attribute('border');

Deletes the specified attribute of this (and only this!) node.

set_attributes()

        $node->set_attributes( $hash );

Sets all attributes specified in $hash as key => value pairs in this (and only this!) node.

name()

        my $name = $node->name();

Return the name of the node.

label()

        my $label = $node->label();

Return the label of the node. If no label was set, returns the name of the node.

title()

        my $title = $node->title();

Returns a potential title that can be used for mouse-over effects. If no title was set (or autogenerated), will return an empty string.

dimensions()

        my ($w,$h) = $node->dimensions();

Returns the dimensions of the node/cell derived from the label (or name) in characters. Assumes the label/name has literal '\n' replaced by "\n".

contents()

        my $contents = $node->contents();

For nested nodes, returns the contents of the node.

width()

        my $width = $node->width();

Returns the width of the node. This is a unitless number.

height()

        my $height = $node->height();

Returns the height of the node. This is a unitless number.

pos()

        my ($x,$y) = $node->pos();

Returns the position of the node. Initially, this is undef, and will be set from Graph::Simple::layout.

relpos()

        my ($dx,$dy) = $node->relpos();

Returns the position of the node relativ to the origin. For the origin node itself (see origin() or for nodes not belonging to any cluster, returns <0,0>.

x()

        my $x = $node->x();

Returns the X position of the node. Initially, this is undef, and will be set from Graph::Simple::layout.

y()

        my $y = $node->y();

Returns the Y position of the node. Initially, this is undef, and will be set from Graph::Simple::layout.

id()

        my $id = $node->id();

Returns the node's unique ID number.

predecessors()

        my @pre = $node->predecessors();

Returns all nodes (as objects) that link to us.

successors()

        my @suc = $node->successors();

Returns all nodes (as objects) that we are linking to.

add_to_groups()

groups()

        my @groups = $node->groups();

In scalar context, return number of groups this node belongs to. In list context, returns all groups as list of objects, sorted by their name.

group()

cluster()

        my $cluster = $node->cluster();
        $node->cluster('clustername');
        $node->cluster($cluster);

Get or set the cluster that this node belongs to.

place()

        if ($node->place($x,$y,$cells))
          {
          ...
          }

Tries to place the node at position ($x,$y) by checking that <$cells-{"$x,$y"}>> is still free. If the node belongs to a cluster, checks all nodes of the cluster and when all of them can be placed without a problem, does so.

Returns true if the operation succeeded, otherwise false.


EXPORT

None by default.


SEE ALSO

the Graph::Simple manpage.


AUTHOR

Copyright (C) 2004 - 2005 by Tels http://bloodgate.com.

See the LICENSE file for more details.