Graph::Easy::Node - Represents a node in a simple graph
use Graph::Easy::Node; my $bonn = Graph::Easy::Node->new( name => 'Bonn', border => 'solid 1px black', ); my $berlin = Graph::Easy::Node->new( name => 'Berlin', )
A Graph::Easy::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::Easy.
Graph::Easy::Node
my $node = Graph::Easy::Group->new( $options );
Create a new node. $options are the possible options:
$options
name Name of the node border Border style and color
$last_error = $node->error(); $node->error($error); # set new messags $node->error(''); # clear error
Returns the last error message, or '' for no error.
my $ascii = $node->as_ascii();
Return the node as a little box drawn in ASCII art as a string.
my $txt = $node->as_txt();
Return the node in simple txt format, including attributes.
my $svg = $node->as_svg();
Returns the node as Scalable Vector Graphic. The actual code for that routine is defined Graph::Easy::As_svg.pm.
my $txt = $node->as_graphviz_txt();
Returns the node as graphviz compatible text which can be feed to dot etc to create images.
my $txt = $node->as_pure_txt();
Return the node in simple txt format, without the attributes.
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.
$tag
$id
$noquote
Example:
print $node->as_html('span');
Would print something like:
<span class="node"> Bonn </span>
While:
print $node->as_html('td');
<td class="node"> Bonn </td>
The following:
print $node->as_html('span', '12');
<span class="node12"> Bonn </span>
$node->attribute('border-style');
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.
my $txt = $node->attributes_as_txt();
Return the attributes of this node as text description.
$node->set_attribute('border-style', 'none');
Sets the specified attribute of this (and only this!) node to the specified value.
$node->del_attribute('border-style');
Deletes the specified attribute of this (and only this!) node.
$node->set_attributes( $hash );
Sets all attributes specified in $hash as key => value pairs in this (and only this!) node.
$hash
my $name = $node->name();
Return the name of the node.
my $label = $node->label();
Return the label of the node. If no label was set, returns the name of the node.
name
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.
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".
my $contents = $node->contents();
For nested nodes, returns the contents of the node.
my $width = $node->width();
Returns the width of the node. This is a unitless number.
my $height = $node->height();
Returns the height of the node. This is a unitless number.
my ($x,$y) = $node->pos();
Returns the position of the node. Initially, this is undef, and will be set from Graph::Easy::layout.
Graph::Easy::layout
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>.
<0,0
my $x = $node->x();
Returns the X position of the node. Initially, this is undef, and will be set from Graph::Easy::layout.
my $y = $node->y();
Returns the Y position of the node. Initially, this is undef, and will be set from Graph::Easy::layout.
my $id = $node->id();
Returns the node's unique ID number.
my @pre = $node->predecessors();
Returns all nodes (as objects) that link to us.
my @suc = $node->successors();
Returns all nodes (as objects) that we are linking to.
my @edges = $node->edges_to($other_node);
Returns all the edge objects that start at $node and go to $other_node.
$node
$other_node
$node->add_to_groups( @groupd );
Add the node to multiple groups at once.
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.
$node->group('groupname');
Returns the group with the specified name if the node belongs to that group, othrwise undef.
my $cluster = $node->cluster(); $node->cluster('clustername'); $node->cluster($cluster);
Get or set the cluster that this node belongs to.
$node->add_to_cluster($cluster);
Add the node to the specified cluster. $cluster is either the cluster name, or a reference pointing to a Graph::Easy::Cluster object.
$cluster
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.
($x,$y)
<$cells-
Returns true if the operation succeeded, otherwise false.
my $shape = $node->shape();
Returns the shape of the node as string, defaulting to 'rect'. Both 'rectangle' and 'box' as node shapes will result in 'rect' as return value.
None by default.
Graph::Easy.
Copyright (C) 2004 - 2005 by Tels http://bloodgate.com.
See the LICENSE file for more details.
To install Graph::Easy, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Graph::Easy
CPAN shell
perl -MCPAN -e shell install Graph::Easy
For more information on module installation, please visit the detailed CPAN module installation guide.