1Graph::Easy::Node(3)  User Contributed Perl Documentation Graph::Easy::Node(3)
2
3
4

NAME

6       Graph::Easy::Node - Represents a node in a Graph::Easy graph
7

SYNOPSIS

9               use Graph::Easy::Node;
10
11               my $bonn = Graph::Easy::Node->new('Bonn');
12
13               $bonn->set_attribute('border', 'solid 1px black');
14
15               my $berlin = Graph::Easy::Node->new( name => 'Berlin' );
16

DESCRIPTION

18       A "Graph::Easy::Node" represents a node in a simple graph. Each node
19       has contents (a text, an image or another graph), and dimension plus an
20       origin. The origin is typically determined by a graph layouter module
21       like Graph::Easy.
22

METHODS

24       Apart from the methods of the base class Graph::Easy::Base, a
25       "Graph::Easy::Node" has the following methods:
26
27   new()
28               my $node = Graph::Easy::Node->new( name => 'node name' );
29               my $node = Graph::Easy::Node->new( 'node name' );
30
31       Creates a new node. If you want to add the node to a Graph::Easy
32       object, then please use the following to create the node object:
33
34               my $node = $graph->add_node('Node name');
35
36       You can then use "$node->set_attribute();" or
37       "$node->set_attributes();" to set the new Node's attributes.
38
39   as_ascii()
40               my $ascii = $node->as_ascii();
41
42       Return the node as a little box drawn in ASCII art as a string.
43
44   as_txt()
45               my $txt = $node->as_txt();
46
47       Return the node in simple txt format, including attributes.
48
49   as_svg()
50               my $svg = $node->as_svg();
51
52       Returns the node as Scalable Vector Graphic. The actual code for that
53       routine is defined Graph::Easy::As_svg.pm.
54
55   as_graphviz()
56       For internal use mostly - use at your own risk.
57
58               my $txt = $node->as_graphviz();
59
60       Returns the node as graphviz compatible text which can be fed to dot
61       etc to create images.
62
63       One needs to load Graph::Easy::As_graphviz first before this method can
64       be called.
65
66   as_graphviz_txt()
67       For internal use mostly - use at your own risk.
68
69               my $txt = $node->as_graphviz_txt();
70
71       Return only the node itself (without attributes) as a graphviz
72       representation.
73
74       One needs to load Graph::Easy::As_graphviz first before this method can
75       be called.
76
77   as_pure_txt()
78               my $txt = $node->as_pure_txt();
79
80       Return the node in simple txt format, without the attributes.
81
82   text_styles_as_css()
83               my $styles = $graph->text_styles_as_css();      # or $edge->...() etc.
84
85       Return the text styles as a chunk of CSS styling that can be embedded
86       into a " style="" " parameter.
87
88   as_html()
89               my $html = $node->as_html();
90
91       Return the node as HTML code.
92
93   attribute(), get_attribute()
94               $node->attribute('border-style');
95
96       Returns the respective attribute of the node or undef if it was not
97       set. If there is a default attribute for all nodes of the specific
98       class the node is in, then this will be returned.
99
100   get_attributes()
101               my $att = $object->get_attributes();
102
103       Return all effective attributes on this object (graph/node/group/edge)
104       as an anonymous hash ref. This respects inheritance and default values.
105
106       Note that this does not include custom attributes.
107
108       See also get_custom_attributes and raw_attributes().
109
110   get_custom_attributes()
111               my $att = $object->get_custom_attributes();
112
113       Return all the custom attributes on this object (graph/node/group/edge)
114       as an anonymous hash ref.
115
116   custom_attributes()
117           my $att = $object->custom_attributes();
118
119       "custom_attributes()" is an alias for get_custom_attributes.
120
121   raw_attributes()
122               my $att = $object->get_attributes();
123
124       Return all set attributes on this object (graph/node/group/edge) as an
125       anonymous hash ref. This respects inheritance, but does not include
126       default values for unset attributes.
127
128       See also get_attributes().
129
130   default_attribute()
131               my $def = $graph->default_attribute($class, 'fill');
132
133       Returns the default value for the given attribute in the class of the
134       object.
135
136       The default attribute is the value that will be used if the attribute
137       on the object itself, as well as the attribute on the class is unset.
138
139       To find out what attribute is on the class, use the three-arg form of
140       attribute on the graph:
141
142               my $g = Graph::Easy->new();
143               my $node = $g->add_node('Berlin');
144
145               print $node->attribute('fill'), "\n";           # print "white"
146               print $node->default_attribute('fill'), "\n";   # print "white"
147               print $g->attribute('node','fill'), "\n";       # print "white"
148
149               $g->set_attribute('node','fill','red');         # class is "red"
150               $node->set_attribute('fill','green');           # this object is "green"
151
152               print $node->attribute('fill'), "\n";           # print "green"
153               print $node->default_attribute('fill'), "\n";   # print "white"
154               print $g->attribute('node','fill'), "\n";       # print "red"
155
156       See also raw_attribute().
157
158   attributes_as_txt
159               my $txt = $node->attributes_as_txt();
160
161       Return the attributes of this node as text description. This is used by
162       the "$graph->as_txt()" code and there should be no reason to use this
163       function on your own.
164
165   set_attribute()
166               $node->set_attribute('border-style', 'none');
167
168       Sets the specified attribute of this (and only this!) node to the
169       specified value.
170
171   del_attribute()
172               $node->del_attribute('border-style');
173
174       Deletes the specified attribute of this (and only this!) node.
175
176   set_attributes()
177               $node->set_attributes( $hash );
178
179       Sets all attributes specified in $hash as key => value pairs in this
180       (and only this!) node.
181
182   border_attribute()
183               my $border = $node->border_attribute();
184
185       Assembles the "border-width", "border-color" and "border-style"
186       attributes into a string like "solid 1px red".
187
188   color_attribute()
189               # returns f.i. #ff0000
190               my $color = $node->get_color_attribute( 'fill' );
191
192       Just like get_attribute(), but only for colors, and returns them as
193       hex, using the current colorscheme.
194
195   get_color_attribute()
196       Is an alias for color_attribute().
197
198   raw_attribute(), get_raw_attribute()
199               my $value = $object->raw_attribute( $name );
200
201       Return the value of attribute $name from the object it this method is
202       called on (graph, node, edge, group etc.). If the attribute is not set
203       on the object itself, returns undef.
204
205       This method respects inheritance, so an attribute value of 'inherit' on
206       an object will make the method return the inherited value:
207
208               my $g = Graph::Easy->new();
209               my $n = $g->add_node('A');
210
211               $g->set_attribute('color','red');
212
213               print $n->raw_attribute('color');               # undef
214               $n->set_attribute('color','inherit');
215               print $n->raw_attribute('color');               # 'red'
216
217       See also attribute().
218
219   raw_color_attribute()
220               # returns f.i. #ff0000
221               my $color = $graph->raw_color_attribute('color' );
222
223       Just like raw_attribute(), but only for colors, and returns them as
224       hex, using the current colorscheme.
225
226       If the attribute is not set on the object, returns "undef".
227
228   text_styles()
229               my $styles = $node->text_styles();
230               if ($styles->{'italic'})
231                 {
232                 print 'is italic\n';
233                 }
234
235       Return a hash with the given text-style properties, aka 'underline',
236       'bold' etc.
237
238   find_grandparent()
239               my $grandpa = $node->find_grandparent();
240
241       For a node that has no origin (is not relative to another), returns
242       $node. For all others, follows the chain of origin back until a node
243       without a parent is found and returns this node.  This code assumes
244       there are no loops, which "origin()" prevents from happening.
245
246   name()
247               my $name = $node->name();
248
249       Return the name of the node. In a graph, each node has a unique name,
250       which, unless a node label is set, will be displayed when rendering the
251       graph.
252
253   label()
254               my $label = $node->label();
255               my $label = $node->label(1);            # raw
256
257       Return the label of the node. If no label was set, returns the "name"
258       of the node.
259
260       If the optional parameter is true, then the label will returned 'raw',
261       that is any potential escape of the form "\N", "\E", "\G", "\T" or "\H"
262       will not be left alone and not be replaced.
263
264   background()
265               my $bg = $node->background();
266
267       Returns the background color. This method honours group membership and
268       inheritance.
269
270   quoted_comment()
271               my $cmt = $node->comment();
272
273       Comment of this object, quoted suitable as to be embedded into
274       HTML/SVG.  Returns the empty string if this object doesn't have a
275       comment set.
276
277   title()
278               my $title = $node->title();
279               my $title = $node->title(1);            # raw
280
281       Returns a potential title that can be used for mouse-over effects.  If
282       no title was set (or autogenerated), will return an empty string.
283
284       If the optional parameter is true, then the title will returned 'raw',
285       that is any potential escape of the form "\N", "\E", "\G", "\T" or "\H"
286       will be left alone and not be replaced.
287
288   link()
289               my $link = $node->link();
290               my $link = $node->link(1);              # raw
291
292       Returns the URL, build from the "linkbase" and "link" (or "autolink")
293       attributes.  If the node has no link associated with it, return an
294       empty string.
295
296       If the optional parameter is true, then the link will returned 'raw',
297       that is any potential escape of the form "\N", "\E", "\G", "\T" or "\H"
298       will not be left alone and not be replaced.
299
300   dimensions()
301               my ($w,$h) = $node->dimensions();
302
303       Returns the dimensions of the node/cell derived from the label (or
304       name) in characters.  Assumes the label/name has literal '\n' replaced
305       by "\n".
306
307   size()
308               my ($cx,$cy) = $node->size();
309
310       Returns the node size in cells.
311
312   contents()
313               my $contents = $node->contents();
314
315       For nested nodes, returns the contents of the node.
316
317   width()
318               my $width = $node->width();
319
320       Returns the width of the node. This is a unitless number.
321
322   height()
323               my $height = $node->height();
324
325       Returns the height of the node. This is a unitless number.
326
327   columns()
328               my $cols = $node->columns();
329
330       Returns the number of columns (in cells) that this node occupies.
331
332   rows()
333               my $cols = $node->rows();
334
335       Returns the number of rows (in cells) that this node occupies.
336
337   is_multicelled()
338               if ($node->is_multicelled())
339                 {
340                 ...
341                 }
342
343       Returns true if the node consists of more than one cell. See als rows()
344       and cols().
345
346   is_anon()
347               if ($node->is_anon())
348                 {
349                 ...
350                 }
351
352       Returns true if the node is an anonymous node. False for
353       "Graph::Easy::Node" objects, and true for "Graph::Easy::Node::Anon".
354
355   pos()
356               my ($x,$y) = $node->pos();
357
358       Returns the position of the node. Initially, this is undef, and will be
359       set from Graph::Easy::layout(). Only valid during the layout phase.
360
361   offset()
362               my ($dx,$dy) = $node->offset();
363
364       Returns the position of the node relativ to the origin. Returns "(0,0)"
365       if the origin node was not sset.
366
367   x()
368               my $x = $node->x();
369
370       Returns the X position of the node. Initially, this is undef, and will
371       be set from Graph::Easy::layout(). Only valid during the layout phase.
372
373   y()
374               my $y = $node->y();
375
376       Returns the Y position of the node. Initially, this is undef, and will
377       be set from Graph::Easy::layout(). Only valid during the layout phase.
378
379   id()
380               my $id = $node->id();
381
382       Returns the node's unique, internal ID number.
383
384   connections()
385               my $cnt = $node->connections();
386
387       Returns the count of incoming and outgoing connections of this node.
388       Self-loops count as two connections, so in the following example, node
389       "N" has four connections, but only three edges:
390
391                           +--+
392                           v  |
393               +---+     +------+     +---+
394               | 1 | --> |  N   | --> | 2 |
395               +---+     +------+     +---+
396
397       See also edges().
398
399   edges()
400               my $edges = $node->edges();
401
402       Returns a list of all the edges (as Graph::Easy::Edge objects) at this
403       node, in no particular order.
404
405   predecessors()
406               my @pre = $node->predecessors();
407
408       Returns all nodes (as objects) that link to us.
409
410   has_predecessors()
411               if ($node->has_predecessors())
412                 {
413                 ...
414                 }
415
416       Returns true if the node has one or more predecessors. Will return true
417       for nodes with selfloops.
418
419   successors()
420               my @suc = $node->successors();
421
422       Returns all nodes (as objects) that we are linking to.
423
424   sorted_successors()
425               my @suc = $node->sorted_successors();
426
427       Return successors of the node sorted by their chain value (e.g.
428       successors with more successors first).
429
430   has_as_successor()
431               if ($node->has_as_successor($other))
432                 {
433                 ...
434                 }
435
436       Returns true if $other ( a node or group) is a successor of node, that
437       is if there is an edge leading from node to $other.
438
439   has_as_predecessor()
440               if ($node->has_as_predecessor($other))
441                 {
442                 ...
443                 }
444
445       Returns true if the node has $other (a group or node) as predecessor,
446       that is if there is an edge leading from $other to node.
447
448   edges_to()
449               my @edges = $node->edges_to($other_node);
450
451       Returns all the edges (as objects) that start at $node and go to
452       $other_node.
453
454   shared_edges()
455               my @edges = $node->shared_edges();
456
457       Return a list of all edges starting/ending at this node, that share a
458       port with another edge.
459
460   nodes_sharing_start()
461               my @nodes = $node->nodes_sharing_start($side, $port);
462
463       Return a list of unique nodes that share a start point with an edge
464       from this node, on the specified side (absolute) and port number.
465
466   nodes_sharing_end()
467               my @nodes = $node->nodes_sharing_end($side, $port);
468
469       Return a list of unique nodes that share an end point with an edge from
470       this node, on the specified side (absolute) and port number.
471
472   edges_at_port()
473               my @edges = $node->edges_to('start', 'south', '0');
474
475       Returns all the edge objects that share the same "start" or "end" port
476       at the specified side and port number. The side must be one of "south",
477       "north", "west" or "east". The port number must be positive.
478
479   incoming()
480               my @edges = $node->incoming();
481
482       Return all edges that end at this node.
483
484   outgoing()
485               my @edges = $node->outgoing();
486
487       Return all edges that start at this node.
488
489   add_to_group()
490               $node->add_to_group( $group );
491
492       Put the node into this group.
493
494   group()
495               my $group = $node->group();
496
497       Return the group this node belongs to, or undef.
498
499   parent()
500               my $parent = $node->parent();
501
502       Returns the parent object of the node, which is either the group the
503       node belongs to, or the graph.
504
505   origin()
506               my $origin_node = $node->origin();
507
508       Returns the node this node is relativ to, or undef otherwise.
509
510   relative_to()
511               $node->relative_to($parent, $dx, $dy);
512
513       Sets itself relativ to $parent with the offset "$dx,$dy".
514
515   shape()
516               my $shape = $node->shape();
517
518       Returns the shape of the node as string, defaulting to 'rect'.
519
520   angle()
521               my $angle = $self->rotation();
522
523       Return the node's rotation, based on the "rotate" attribute, and in
524       case this is relative, on the node's flow.
525
526   flow()
527               my $flow = $node->flow();
528
529       Returns the outgoing flow for this node as absolute direction in
530       degrees.
531
532       The value is computed from the incoming flow (or the general flow as
533       default) and the flow attribute of this node.
534
535   _extra_params()
536               my $extra_params = $node->_extra_params();
537
538       The return value of that method is added as extra params to the HTML
539       tag for a node when as_html() is called. Returns the empty string by
540       default, and can be overridden in subclasses. See also use_class().
541
542       Overridden method should return a text with a leading space, or the
543       empty string.
544
545       Example:
546
547               package Graph::Easy::MyNode;
548               use base qw/Graph::Easy::Node/;
549
550               sub _extra_params
551                 {
552                 my $self = shift;
553
554                 ' ' . 'onmouseover="alert(\'' . $self->name() . '\');"';
555                 }
556
557               1;
558

EXPORT

560       None by default.
561

SEE ALSO

563       Graph::Easy.
564

AUTHOR

566       Copyright (C) 2004 - 2007 by Tels <http://bloodgate.com>.
567
568       See the LICENSE file for more details.
569
570
571
572perl v5.36.0                      2022-07-22              Graph::Easy::Node(3)
Impressum