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

filter: Statementstmt 0.0% 0 / 40 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 70 CC 6 SCAR 21.1
CC
6
Cov
0%
draw
20.0
pad_top
6.0
pad_left
6.0
CRAP 8.3
1 package Bio::Graphics::Glyph::scale;
2  
3 use strict;
4 use base qw(Bio::Graphics::Glyph::segmented_keyglyph Bio::Graphics::Glyph::xyplot);
5  
6 sub my_description {
7 return <<END;
8 This glyph is used internally by GBrowse to draw a scale bar.
9 It should not be used explicitly.
10 END
11 }
12  
13 sub my_options {
14 return;
15 }
16  
17 sub draw {
18 my $self = shift;
19  
20 my ($gd,$dx,$dy) = @_;
21 my ($left,$top,$right,$bottom) = $self->calculate_boundaries($dx,$dy);
22  
23 $self->panel->startGroup($gd);
24  
25 my $max_score = $self->max_score || 100;
26 my $min_score = $self->min_score || 0;
27  
28 $max_score = Bio::Graphics::Glyph::xyplot::max10($max_score);
29 $min_score = Bio::Graphics::Glyph::xyplot::min10($min_score);
30  
31 my $height = $bottom - $top;
32 my $scale = $max_score > $min_score ? $height/($max_score-$min_score)
33 : 1;
34 my $x = $left;
35 my $y = $top + $self->pad_top;
36  
37 # position of "0" on the scale
38 my $y_origin = $min_score <= 0 ? $bottom - (0 - $min_score) * $scale : $bottom;
39 $y_origin = $top if $max_score < 0;
40  
41 $self->panel->startGroup($gd);
42 $self->_draw_scale($gd,$scale,$min_score,$max_score,$dx,$dy,$y_origin);
43  
44 $self->panel->endGroup($gd);
45 }
46  
47 sub _determine_side {
48 my $self = shift;
49 return 'three';
50 }
51  
52 # Added pad_top subroutine (pad_top of Glyph.pm, which is called when executing $self->pad_top
53 # returns 0, so we need to override it here)
54 sub pad_top {
55 my $self = shift;
56 my $pad = $self->Bio::Graphics::Glyph::generic::pad_top(@_);
57 if ($pad < ($self->font('gdTinyFont')->height)) {
58 $pad = $self->font('gdTinyFont')->height; # extra room for the scale
59 }
60 $pad;
61 }
62  
63 sub pad_left {
64 my $self = shift;
65 my $pad = $self->SUPER::pad_left(@_);
66 return $pad unless $self->option('variance_band');
67 $pad += length('+1sd')/2 * $self->font('gdTinyFont')->width+3;
68 return $pad;
69 }
70  
71 sub new {
72 my $self = shift;
73 return $self->SUPER::new(@_,-level=>-1);
74 }
75  
76 1;
77  
78 __END__