File Coverage

blib/lib/Bio/Phylo/Forest/DrawNodeRole.pm
Criterion Covered Total %
statement 35 43 81.4
branch 8 14 57.1
condition n/a
subroutine 7 8 87.5
pod 3 3 100.0
total 53 68 77.9


line stmt bran cond sub pod time code
1             package Bio::Phylo::Forest::DrawNodeRole;
2 34     34   44990 use strict;
  34         75  
  34         837  
3 34     34   153 use Carp;
  34         63  
  34         1650  
4 34     34   15091 use Bio::Phylo::Forest::NodeRole;
  34         95  
  34         248  
5 34     34   265 use base 'Bio::Phylo::Forest::NodeRole';
  34         70  
  34         18186  
6             {
7              
8             our $AUTOLOAD;
9             my @properties = qw(x y radius tip_radius node_color node_outline_color
10             node_shape node_image branch_color branch_shape branch_width branch_style
11             collapsed collapsed_clade_width font_face font_size font_style font_color
12             font_weight text_horiz_offset text_vert_offset rotation clade_label
13             clade_label_font);
14              
15             =head1 NAME
16              
17             Bio::Phylo::Forest::DrawNodeRole - Tree node with extra methods for tree drawing
18              
19             =head1 SYNOPSIS
20              
21             # see Bio::Phylo::Forest::Node
22              
23             =head1 DESCRIPTION
24              
25             This module defines a node object and its methods. The node is fairly
26             syntactically rich in terms of navigation, and additional getters are provided to
27             further ease navigation from node to node. Typical first daughter -> next sister
28             traversal and recursion is possible, but there are also shrinkwrapped methods
29             that return for example all terminal descendants of the focal node, or all
30             internals, etc.
31              
32             Node objects are inserted into tree objects, although technically the tree
33             object is only a container holding all the nodes together. Unless there are
34             orphans all nodes can be reached without recourse to the tree object.
35              
36             In addition, this subclass of the default node object L
37             has getters and setters for drawing trees and nodes, e.g. X/Y coordinates, font
38             and text attributes, etc.
39              
40             =head1 METHODS
41              
42             =head2 MUTATORS
43              
44             =over
45              
46             =item set_collapsed()
47              
48             Type : Mutator
49             Title : set_collapsed
50             Usage : $node->set_collapsed(1);
51             Function: Sets whether the node's descendants are shown as collapsed into a triangle
52             Returns : $self
53             Args : true or false value
54              
55             =item set_collapsed_clade_width()
56              
57             Sets collapsed clade width.
58              
59             Type : Mutator
60             Title : set_collapsed_clade_width
61             Usage : $node->set_collapsed_clade_width(6);
62             Function: sets the width of collapsed clade triangles relative to uncollapsed tips
63             Returns :
64             Args : Positive number
65              
66             =item set_x()
67              
68             Type : Mutator
69             Title : set_x
70             Usage : $node->set_x($x);
71             Function: Sets x
72             Returns : $self
73             Args : x
74              
75             =item set_y()
76              
77             Type : Mutator
78             Title : set_y
79             Usage : $node->set_y($y);
80             Function: Sets y
81             Returns : $self
82             Args : y
83              
84             =item set_radius()
85              
86             Type : Mutator
87             Title : set_radius
88             Usage : $node->set_radius($radius);
89             Function: Sets radius
90             Returns : $self
91             Args : radius
92              
93             =cut
94              
95             *set_node_radius = \&set_radius;
96             *get_node_radius = \&get_radius;
97              
98             =item set_tip_radius()
99              
100             Type : Mutator
101             Title : set_tip_node_radius
102             Usage : $tree->set_tip_radius($node_radius);
103             Function: Sets tip radius
104             Returns : $self
105             Args : tip radius
106              
107             =item set_node_color()
108              
109             Type : Mutator
110             Title : set_node_color
111             Usage : $node->set_node_color($node_color);
112             Function: Sets node_color
113             Returns : $self
114             Args : node_color
115              
116             =item set_node_outline_color()
117              
118             Type : Mutator
119             Title : set_node_outline_color
120             Usage : $node->set_node_outline_color($node_outline_color);
121             Function: Sets node outline color
122             Returns : $self
123             Args : node_color
124              
125             =item set_node_shape()
126              
127             Type : Mutator
128             Title : set_node_shape
129             Usage : $node->set_node_shape($node_shape);
130             Function: Sets node_shape
131             Returns : $self
132             Args : node_shape
133              
134             =item set_node_image()
135              
136             Type : Mutator
137             Title : set_node_image
138             Usage : $node->set_node_image($node_image);
139             Function: Sets node_image
140             Returns : $self
141             Args : node_image
142              
143             =item set_branch_color()
144              
145             Type : Mutator
146             Title : set_branch_color
147             Usage : $node->set_branch_color($branch_color);
148             Function: Sets branch_color
149             Returns : $self
150             Args : branch_color
151              
152             =item set_branch_shape()
153              
154             Type : Mutator
155             Title : set_branch_shape
156             Usage : $node->set_branch_shape($branch_shape);
157             Function: Sets branch_shape
158             Returns : $self
159             Args : branch_shape
160              
161             =item set_branch_width()
162              
163             Type : Mutator
164             Title : set_branch_width
165             Usage : $node->set_branch_width($branch_width);
166             Function: Sets branch width
167             Returns : $self
168             Args : branch_width
169              
170             =item set_branch_style()
171              
172             Type : Mutator
173             Title : set_branch_style
174             Usage : $node->set_branch_style($branch_style);
175             Function: Sets branch style
176             Returns : $self
177             Args : branch_style
178              
179             =item set_font_face()
180              
181             Type : Mutator
182             Title : set_font_face
183             Usage : $node->set_font_face($font_face);
184             Function: Sets font_face
185             Returns : $self
186             Args : font_face
187              
188             =item set_font_size()
189              
190             Type : Mutator
191             Title : set_font_size
192             Usage : $node->set_font_size($font_size);
193             Function: Sets font_size
194             Returns : $self
195             Args : font_size
196              
197             =item set_font_style()
198              
199             Type : Mutator
200             Title : set_font_style
201             Usage : $node->set_font_style($font_style);
202             Function: Sets font_style
203             Returns : $self
204             Args : font_style
205              
206             =item set_font_weight()
207              
208             Type : Mutator
209             Title : set_font_weight
210             Usage : $node->set_font_weight($font_weight);
211             Function: Sets font_weight
212             Returns : $self
213             Args : font_weight
214              
215             =item set_font_color()
216              
217             Type : Mutator
218             Title : set_font_color
219             Usage : $node->set_font_color($color);
220             Function: Sets font_color
221             Returns : font_color
222             Args : A color, which, depending on the underlying tree drawer, can either
223             be expressed as a word ('red'), a hex code ('#00CC00') or an rgb
224             statement ('rgb(0,255,0)')
225              
226             =item set_text_horiz_offset()
227              
228             Type : Mutator
229             Title : set_text_horiz_offset
230             Usage : $node->set_text_horiz_offset($text_horiz_offset);
231             Function: Sets text_horiz_offset
232             Returns : $self
233             Args : text_horiz_offset
234              
235             =item set_text_vert_offset()
236              
237             Type : Mutator
238             Title : set_text_vert_offset
239             Usage : $node->set_text_vert_offset($text_vert_offset);
240             Function: Sets text_vert_offset
241             Returns : $self
242             Args : text_vert_offset
243              
244             =item set_rotation()
245              
246             Type : Mutator
247             Title : set_rotation
248             Usage : $node->set_rotation($rotation);
249             Function: Sets rotation
250             Returns : $self
251             Args : rotation
252              
253             =item set_clade_label()
254              
255             Type : Mutator
256             Title : set_clade_label
257             Usage : $node->set_clade_label('Mammalia');
258             Function: Sets a label for an entire clade to be visualized outside the tree
259             Returns : $self
260             Args : string
261              
262             =item set_clade_label_font()
263              
264             Type : Mutator
265             Title : set_clade_label_font
266             Usage : $node->set_clade_label_font({ '-face' => 'Verdana' });
267             Function: Sets font properties for the clade label
268             Returns : $self
269             Args : {
270             '-face' => 'Verdana', # Arial, Times, etc.
271             '-weight' => 'bold',
272             '-style' => 'italic',
273             '-colour' => 'red',
274             }
275            
276             =back
277              
278             =head2 ACCESSORS
279              
280             =over
281              
282             =item get_collapsed()
283              
284             Type : Mutator
285             Title : get_collapsed
286             Usage : something() if $node->get_collapsed();
287             Function: Gets whether the node's descendants are shown as collapsed into a triangle
288             Returns : true or false value
289             Args : NONE
290              
291             =item get_first_daughter()
292              
293             Gets invocant's first daughter.
294              
295             Type : Accessor
296             Title : get_first_daughter
297             Usage : my $f_daughter = $node->get_first_daughter;
298             Function: Retrieves a node's leftmost daughter.
299             Returns : Bio::Phylo::Forest::Node
300             Args : NONE
301              
302             =cut
303              
304             sub get_first_daughter {
305 59451     59451 1 78494 my $self = shift;
306 59451 50       176278 if ( $self->get_collapsed ) {
307 0         0 return;
308             }
309             else {
310 59451         122647 return $self->SUPER::get_first_daughter;
311             }
312             }
313              
314             =item get_last_daughter()
315              
316             Gets invocant's last daughter.
317              
318             Type : Accessor
319             Title : get_last_daughter
320             Usage : my $l_daughter = $node->get_last_daughter;
321             Function: Retrieves a node's rightmost daughter.
322             Returns : Bio::Phylo::Forest::Node
323             Args : NONE
324              
325             =cut
326              
327             sub get_last_daughter {
328 22     22 1 33 my $self = shift;
329 22 50       74 if ( $self->get_collapsed ) {
330 0         0 return;
331             }
332             else {
333 22         57 return $self->SUPER::get_last_daughter;
334             }
335             }
336              
337             =item get_children()
338              
339             Gets invocant's immediate children.
340              
341             Type : Query
342             Title : get_children
343             Usage : my @children = @{ $node->get_children };
344             Function: Returns an array reference of immediate
345             descendants, ordered from left to right.
346             Returns : Array reference of
347             Bio::Phylo::Forest::Node objects.
348             Args : NONE
349              
350             =cut
351              
352             sub get_children {
353 0     0 1 0 my $self = shift;
354 0 0       0 if ( $self->get_collapsed ) {
355 0         0 return [];
356             }
357             else {
358 0         0 return $self->SUPER::get_children;
359             }
360             }
361              
362             =item get_x()
363              
364             Type : Accessor
365             Title : get_x
366             Usage : my $x = $node->get_x();
367             Function: Gets x
368             Returns : x
369             Args : NONE
370              
371             =item get_y()
372              
373             Type : Accessor
374             Title : get_y
375             Usage : my $y = $node->get_y();
376             Function: Gets y
377             Returns : y
378             Args : NONE
379              
380             =item get_radius()
381              
382             Type : Accessor
383             Title : get_radius
384             Usage : my $radius = $node->get_radius();
385             Function: Gets radius
386             Returns : radius
387             Args : NONE
388              
389             =item get_node_color()
390              
391             Type : Accessor
392             Title : get_node_color
393             Usage : my $node_color = $node->get_node_color();
394             Function: Gets node_color
395             Returns : node_color
396             Args : NONE
397              
398             =item get_node_outline_color()
399              
400             Type : Accessor
401             Title : get_node_outline_color
402             Usage : my $node_outline_color = $node->get_node_outline_color();
403             Function: Gets node outline color
404             Returns : node_color
405             Args : NONE
406              
407             =item get_node_shape()
408              
409             Type : Accessor
410             Title : get_node_shape
411             Usage : my $node_shape = $node->get_node_shape();
412             Function: Gets node_shape
413             Returns : node_shape
414             Args : NONE
415              
416             =item get_node_image()
417              
418             Type : Accessor
419             Title : get_node_image
420             Usage : my $node_image = $node->get_node_image();
421             Function: Gets node_image
422             Returns : node_image
423             Args : NONE
424              
425             =item get_collapsed_clade_width()
426              
427             Gets collapsed clade width.
428              
429             Type : Mutator
430             Title : get_collapsed_clade_width
431             Usage : $w = $node->get_collapsed_clade_width();
432             Function: gets the width of collapsed clade triangles relative to uncollapsed tips
433             Returns : Positive number
434             Args : None
435              
436             =item get_branch_color()
437              
438             Type : Accessor
439             Title : get_branch_color
440             Usage : my $branch_color = $node->get_branch_color();
441             Function: Gets branch_color
442             Returns : branch_color
443             Args : NONE
444              
445             =item get_branch_shape()
446              
447             Type : Accessor
448             Title : get_branch_shape
449             Usage : my $branch_shape = $node->get_branch_shape();
450             Function: Gets branch_shape
451             Returns : branch_shape
452             Args : NONE
453              
454             =item get_branch_width()
455              
456             Type : Accessor
457             Title : get_branch_width
458             Usage : my $branch_width = $node->get_branch_width();
459             Function: Gets branch_width
460             Returns : branch_width
461             Args : NONE
462              
463             =item get_branch_style()
464              
465             Type : Accessor
466             Title : get_branch_style
467             Usage : my $branch_style = $node->get_branch_style();
468             Function: Gets branch_style
469             Returns : branch_style
470             Args : NONE
471              
472             =item get_font_face()
473              
474             Type : Accessor
475             Title : get_font_face
476             Usage : my $font_face = $node->get_font_face();
477             Function: Gets font_face
478             Returns : font_face
479             Args : NONE
480              
481             =item get_font_size()
482              
483             Type : Accessor
484             Title : get_font_size
485             Usage : my $font_size = $node->get_font_size();
486             Function: Gets font_size
487             Returns : font_size
488             Args : NONE
489              
490             =item get_font_style()
491              
492             Type : Accessor
493             Title : get_font_style
494             Usage : my $font_style = $node->get_font_style();
495             Function: Gets font_style
496             Returns : font_style
497             Args : NONE
498            
499             =item get_font_weight()
500              
501             Type : Mutator
502             Title : get_font_weight
503             Usage : my $font_weight = $node->get_font_weight();
504             Function: Gets font_weight
505             Returns : font_weight
506             Args : NONE
507              
508             =item get_font_color()
509              
510             Type : Accessor
511             Title : get_font_color
512             Usage : my $color = $node->get_font_color();
513             Function: Gets font_color
514             Returns : font_color
515             Args : NONE
516              
517             =item get_text_horiz_offset()
518              
519             Type : Accessor
520             Title : get_text_horiz_offset
521             Usage : my $text_horiz_offset = $node->get_text_horiz_offset();
522             Function: Gets text_horiz_offset
523             Returns : text_horiz_offset
524             Args : NONE
525              
526             =item get_text_vert_offset()
527              
528             Type : Accessor
529             Title : get_text_vert_offset
530             Usage : my $text_vert_offset = $node->get_text_vert_offset();
531             Function: Gets text_vert_offset
532             Returns : text_vert_offset
533             Args : NONE
534              
535             =item get_rotation()
536              
537             Type : Accessor
538             Title : get_rotation
539             Usage : my $rotation = $node->get_rotation();
540             Function: Gets rotation
541             Returns : rotation
542             Args : NONE
543              
544             =item get_clade_label()
545              
546             Type : Accessor
547             Title : get_clade_label
548             Usage : my $l = $node->get_clade_label();
549             Function: Gets a label for an entire clade to be visualized outside the tree
550             Returns : string
551             Args : NONE
552              
553             =item get_clade_label_font()
554              
555             Type : Accessor
556             Title : get_clade_label_font
557             Usage : my %h = %{ $node->get_clade_label_font() };
558             Function: gets font properties for the clade label
559             Returns : undef or hashref
560             Args : NONE
561            
562             =back
563              
564             =cut
565              
566             sub AUTOLOAD {
567 60084     60084   88211 my $self = shift;
568 60084         71445 my $method = $AUTOLOAD;
569 60084         187214 $method =~ s/.+://; # strip package name
570 60084         101468 $method =~ s/colour/color/; # map British/Canadian to American :)
571            
572             # if the user calls some non-existant method, try to do the
573             # usual way, with this message, from perspective of caller
574 60084         75009 my $template = 'Can\'t locate object method "%s" via package "%s"';
575            
576 60084 100       173795 if ( $method =~ /^set_(.+)$/ ) {
    100          
577 126         255 my $prop = $1;
578 126 50       254 if ( grep { /^\Q$prop\E$/ } @properties ) {
  3024         7186  
579 126         197 my $value = shift;
580 126         403 return $self->set_meta_object( "map:$prop" => $value );
581             }
582             else {
583 0         0 croak sprintf $template, $method, __PACKAGE__;
584             }
585             }
586             elsif ( $method =~ /^get_(.+)$/ ) {
587 59957         112098 my $prop = $1;
588 59957 50       88168 if ( grep { /^\Q$prop\E$/ } @properties ) {
  1438968         3066797  
589 59957         82981 my $value = shift;
590 59957         157092 return $self->get_meta_object( "map:$prop" );
591             }
592             else {
593 0         0 croak sprintf $template, $method, __PACKAGE__;
594             }
595             }
596             else {
597 1         189 croak sprintf $template, $method, __PACKAGE__;
598             }
599             }
600              
601              
602             # podinherit_insert_token
603              
604             =head1 SEE ALSO
605              
606             There is a mailing list at L
607             for any user or developer questions and discussions.
608              
609             =over
610              
611             =item L
612              
613             This object inherits from L, so methods
614             defined there are also applicable here.
615              
616             =item L
617              
618             Also see the manual: L and L.
619              
620             =back
621              
622             =head1 CITATION
623              
624             If you use Bio::Phylo in published research, please cite it:
625              
626             B, B, B, B
627             and B, 2011. Bio::Phylo - phyloinformatic analysis using Perl.
628             I B<12>:63.
629             L
630              
631             =cut
632              
633             }
634             1;