NAME

Graph::Simple::Node - Represents a node (a box) 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 Graph::Simple.

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.

as_html()

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

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.

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.

set_attribute()

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

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

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.

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.

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.

EXPORT

None by default.

SEE ALSO

Graph::Simple.

AUTHOR

Tels http://bloodgate.com

LICENSE

Copyright (C) 2004 - 2005 by Tels

This library is free software; you can redistribute it and/or modify it under the terms of the GPL. See the LICENSE file for more details.