blib/lib/Bio/Graphics/Glyph/fixedwidth.pm untested

filter: Statementstmt 0.0% 0 / 78 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 17 Podpod 0.0% 0 / 13 totaltotal 0.0% 0 / 129 CC 9 SCAR 19.5
CC
9
Cov
0%
draw
20.0
pad_right
12.0
pad_left
6.0
CRAP 7.0
1 package Bio::Graphics::Glyph::fixedwidth;
2  
3 use strict;
4 use base 'Bio::Graphics::Glyph::box';
5 use Carp 'cluck';
6 use constant TOP_SPACING => 8;
7  
8 sub my_description {
9 return <<END;
10 This glyph is a base class for glyphs that wish to draw a fixed width
11 content, such as an icon, image, scatterplot, and it would be
12 inappropriate for the content to be stretched to match the start and
13 end point of the associated feature. Instead the glyph draws a simple
14 box spanning the feature\'s start:end region, two diagonal connecting
15 lines, and then a fixed width rectangle beneath the box.
16  
17 See the "stackedplot" glyph for an example of a glyph that uses this base
18 class.
19 END
20 }
21  
22 sub my_options {
23 {
24 fixed_width => [
25 'integer',
26 0,
27 'Width of the content.'],
28 fixed_height => [
29 'integer',
30 undef,
31 'Height of the content. If undef, then the glyph -height is used.'],
32 fixed_gap => [
33 'integer',
34 8,
35 'Vertical gap between the box that shows the extent of the',
36 'feature and the fixed-width content. If -fixed_gap is less',
37 'than 8 then the diagonal connecting lines are not drawn.'],
38 }
39 }
40  
41 sub pad_left {
42 my $self = shift;
43 my $pl = $self->SUPER::pad_left;
44 my $width = $self->width;
45 my $needed = $self->width_needed;
46 my $extra = ($needed-$width)/2 + 1;
47 if ($extra > $pl) {
48 return $extra;
49 } else {
50 return $pl;
51 }
52 }
53  
54 sub pad_right {
55 my $self = shift;
56 my $pr = $self->SUPER::pad_right;
57 my $width = $self->width;
58 my $needed = $self->width_needed;
59 my $extra = ($needed-$width)/2;
60 $extra = 0 if $extra < 0;
61 if ($extra > 0 && $extra > $pr) {
62 return $extra;
63 } else {
64 return $pr-$extra;
65 }
66 }
67  
68 sub width_needed {
69 my $self = shift;
70 $self->option('fixed_width');
71 }
72  
73 sub height_needed {
74 my $self = shift;
75 my $h = $self->option('fixed_height');
76 return $h if defined $h;
77 return $self->SUPER::height;
78 }
79  
80 sub height {
81 shift->height_needed;
82 }
83  
84 sub span_height {
85 shift->option('span_height') || 3;
86 }
87  
88 sub top_spacing {
89 my $self = shift;
90 my $spacing = $self->option('fixed_gap');
91 return $spacing if defined $spacing;
92 return TOP_SPACING;
93 }
94  
95 sub pad_top {
96 my $self = shift;
97 my $top = $self->SUPER::pad_top;
98 return $top + $self->top_spacing + $self->span_height;
99 }
100  
101 sub maxdepth { 0 }
102  
103 sub draw {
104 my $self = shift;
105 my $gd = shift;
106 my ($dx,$dy) = @_;
107 my($x1,$y1,$x2,$y2) = $self->bounds(@_);
108  
109 my $width = $self->width_needed;
110 my $xmid = ($x1+$x2) / 2;
111  
112 my $top = $y1 - $self->span_height-$self->top_spacing;
113 my $bottom = $y2;
114  
115 my $left = $xmid - $width/2;
116 my $right = $xmid + $width/2;
117  
118 my $fgcolor = $self->fgcolor;
119  
120 my $span_height = $self->span_height;
121 $self->filled_box($gd,$x1,$top,$x2,$top+$span_height);
122  
123 if ($self->top_spacing >= 8) {
124 $top += $span_height;
125 $gd->line($x1,$top+2,$x1,$top+4,$fgcolor);
126 $gd->line($x2,$top+2,$x2,$top+4,$fgcolor);
127 $gd->line($x1,$top+4,$left,$y1-4,$fgcolor);
128 $gd->line($x2,$top+4,$right,$y1-4,$fgcolor);
129 $gd->line($left,$y1-4,$left,$y1-2,$fgcolor);
130 $gd->line($right,$y1-4,$right,$y1-2,$fgcolor);
131 }
132  
133 $self->draw_contents($gd,$left,$y1,$right,$y2);
134  
135 my $pl = $self->pad_left;
136 $self->draw_label($gd,$dx-$pl,$dy) if $self->option('label');
137 $self->draw_description($gd,$dx-$pl,$dy) if $self->option('description');
138 }
139  
140 sub draw_contents {
141 my $self = shift;
142 my ($gd,$left,$top,$right,$bottom) = @_;
143 $self->filled_box($gd,$left,$top,$right,$bottom);
144 }
145  
146 1;
147  
148 __END__