Graph/Glyph/tree.pm

filter: Statementstmt 98.0% 51 / 52 Branchbran 83.3% 10 / 12 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 6 / 6 Podpod 50.0% 1 / 2 totaltotal 94.8% 73 / 77 CC 10 SCAR 16.4
CC
10
Cov
96%
_draw
8.0
getmaxy
3.0
BEGIN
1.0
CRAP 5.1
« Graph/Glyph/bezier.pm ↑ Summary Graph/Data/Datum.pm »
1 package SVG::Graph::Glyph::tree;
2  
3 1 ▶use base SVG::Graph::Glyph;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head2 draw
8  
9 Title : draw
10 Usage :
11 Function:
12 Example :
13 Returns :
14 Args :
15  
16  
17 =cut
18  
19 1 ▶sub draw{
Subroutine draw: called CC=1 SCAR=0.0
Pod documented
20 1 my ($self,@args) = @_;
21  
22 1 my $id = 'n'.sprintf("%07d",int(rand(9999999)));
23 # my $frame_transform = $self->frame_transform;
24 1 my $group = $self->svg->group(id=>"tree$id");
25  
26 1 my($data) = $self->group->data;
27 1 my $root = $data->root;
28 1 my $xsize = $self->xsize;
29 1 my $ysize = $self->ysize;
30 1 my $yscale = $ysize / $root->depth;
31 1 my $xscale = $xsize / (scalar($root->leaves_under));
32 1 my $xoffset = $self->xoffset;
33 1 my $yoffset = $self->yoffset;
34  
35  
36 1 $group->line(x1=>$xoffset+($xsize/2),x2=>$xoffset+($xsize/2),y1=>$yoffset,y2=>$yoffset+($yscale*$root->branch_length),style=>{$self->_style});
37  
38 1 my $maxy = $self->getmaxy(node=>$root, yscale=>$yscale, yoffset=>$yoffset+($yscale*$root->branch_length));
39
40 #root branch
41 1 $self->_draw(group=>$group,node=>$root,
42 xsize=>$xsize,
43 yscale=>$yscale,
44 xoffset=>$xoffset,yoffset=>$yoffset+($yscale*$root->branch_length),
45 maxy=>$maxy
46 );
47 }
48  
49 22 ▶sub getmaxy {
Subroutine getmaxy: called CC=3 SCAR=11.0
Pod undocumented
50 22 my($self,%a) = @_;
51 22 my $maxy = $a{yoffset};
52 22 foreach my $d ($a{node}->daughters){
53 21 my $temp = $self->getmaxy(node=>$d, yscale=>$a{yscale}, yoffset => $a{yoffset} + ($d->branch_length * $a{yscale}));
54 21 ▶ if ($temp > $maxy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($temp > $maxy) 21 0 21
55 21 $maxy = $temp;
56 }
57 }
58
59 22 return $maxy;
60  
61 }
62  
63 =head2 _draw
64  
65 Title : _draw
66 Usage :
67 Function:
68 Example :
69 Returns :
70 Args :
71  
72  
73 =cut
74  
75 22 ▶sub _draw {
Subroutine _draw: called CC=8 SCAR=20.8
76 22 my($self,%a) = @_;
77  
78 22 my $xoffset = $a{xoffset};
79 22 my $xoffset_old;
80 22 my $maxy = $a{maxy};
81 22 my $c = 1;
82  
83 22 foreach my $d ($a{node}->daughters){
84  
85 21 ▶ my %style = $a{node}->_style ? $a{node}->_style : $self->_style;
Branch: 1 branch
BranchTrueFalseTotal
$a{'node'}->_style ? : 19 2 21
86  
87 21 my $frac = $d->leaves_under / $a{node}->leaves_under;
88 21 $xoffset_old = $xoffset;
89  
90 #horizontal bar spanning the domain of a child subtree
91 21 ▶ if(!$d->left_sisters and !$d->right_sisters){
Branch: 3 branches
BranchTrueFalseTotal
if (not $d->left_sisters || $d->right_sisters) { } 19 2 21
elsif (not $d->left_sisters) { } 1 1 2
elsif (not $d->right_sisters) { } 1 0 1
Condition100%3/3
$d->left_sisters || $d->right_sisters
l!l&&r!l&&!r
1119
MC/DC100%2/2
$d->left_sisters || $d->right_sisters
$d->left_sisters $d->right_sisters
Truth table100%3/3
A || B
A= $d->left_sistersB= $d->right_sisters
ABresult
1X1
011
000
92 } elsif(!$d->left_sisters){
93 $a{group}->line(x1=>$xoffset+($frac*$a{xsize}/2),
94 y1=>$a{yoffset},
95 x2=>$xoffset+($frac*$a{xsize}),
96 y2=>$a{yoffset},
97 1 style=>{%style});
98  
99 #warn join ' ', $a{node}->_style;
100  
101 } elsif(!$d->right_sisters){
102 $a{group}->line(x1=>$xoffset,
103 y1=>$a{yoffset},
104 x2=>$xoffset+($frac*$a{xsize}/2),
105 y2=>$a{yoffset},
106 1 style=>{%style});
107 } else {
108 $a{group}->line(x1=>$xoffset,
109 y1=>$a{yoffset},
110 x2=>$xoffset+($frac*$a{xsize}),
111 y2=>$a{yoffset},
112 0 style=>{%style});
113 }
114  
115  
116  
117 21 ▶ if($d->depth_under <= 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($d->depth_under <= 1) { } 3 18 21
118 $a{group}->line(x1=>(($frac*$a{xsize}+$xoffset)+($xoffset))/2,x2=>(($frac*$a{xsize}+$xoffset)+($xoffset))/2,
119 y1=>$a{yoffset},
120 3 y2=>$maxy,
121 style=>{%style}
122 );
123 }
124 else {
125 #root branch of the child subtree
126 $a{group}->line(x1=>(($frac*$a{xsize}+$xoffset)+($xoffset))/2,x2=>(($frac*$a{xsize}+$xoffset)+($xoffset))/2,
127 y1=>$a{yoffset},
128 18 y2=>$a{yoffset}+($a{yscale}*$d->branch_length),
129 style=>{%style}
130 );
131 }
132
133 #root branch label
134 21 my($cx,$cy) = ((($frac*$a{xsize}+$xoffset)+($xoffset))/2 , $maxy);
135 #my($cx,$cy) = ((($frac*$a{xsize}+$xoffset)+($xoffset))/2 , $a{yoffset}+($a{yscale}*$d->branch_length));
136 21 $a{group}->text(x=>$cx,
137 y=>$cy,
138 # style=>{'font-size'=>'15px'},
139 style=>{$self->_style,'stroke-width'=>0.5},
140 transform=>"rotate(90,$cx,$cy)"
141 )->cdata($d->branch_label());
142 #->cdata($d->name);
143  
144  
145 21 $xoffset += $frac*$a{xsize};
146 21 $c++;
147  
148 $self->_draw(group=>$a{group},node=>$d,
149 xsize=>$xoffset - $xoffset_old,
150 yscale=>$a{yscale},
151 xoffset => $xoffset_old,
152 21 yoffset => $a{yoffset} + ($d->branch_length * $a{yscale}),
153 maxy => $maxy
154 );
155 }
156  
157  
158 }
159  
160 1 1;
« Graph/Glyph/bezier.pm ↑ Summary Graph/Data/Datum.pm »