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

filter: Statementstmt 0.0% 0 / 46 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 20 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 96 CC 10 SCAR 34.1
CC
10
Cov
0%
draw_label
56.0
arrowheads
20.0
my_description
2.0
CRAP 30.1
1 package Bio::Graphics::Glyph::anchored_arrow;
2 # package to use for drawing an arrow
3  
4 use strict;
5 use base qw(Bio::Graphics::Glyph::arrow);
6  
7 sub my_description {
8 return <<END;
9 This glyph draws an arrowhead which is anchored at one or both ends
10 (has a vertical base) or has one or more arrowheads. The arrowheads
11 indicate that the feature does not end at the edge of the picture, but
12 continues.
13 END
14 }
15  
16 sub my_options {
17 return {
18 tick => [
19 [0..2],
20 0,
21 'Draw a scale with tickmarks on the arrow.',
22 'A value of 0 suppresses the scale.',
23 'A value of 1 draws major ticks only.',
24 'A value of 2 draws major and minor ticks.',],
25 relative_coords=> [
26 'boolean',
27 undef,
28 'When drawing the scale, start numbering at position 1 instead of at',
29 'the start of the feature in global (e.g. chromosomal) coordinates.'],
30 relative_coords_offset=> [
31 'integer',
32 1,
33 'When drawing a scale with relative_coords set to true, begin numbering',
34 'the scale at this starting value.'],
35 no_arrows => [
36 'boolean',
37 undef,
38 "Do not draw an arrow when the glyph is partially offscreen."],
39 };
40 }
41  
42 sub draw_label {
43 my $self = shift;
44 my ($gd,$left,$top,$partno,$total_parts) = @_;
45 my $label = $self->label or return;
46 my $label_align = $self->option('label_align');
47 if ($label_align && ($label_align eq 'center' || $label_align eq 'right')) {
48 my $x = $self->left + $left;
49 my $font = $self->option('labelfont') || $self->font;
50 my $middle = $self->left + $left + ($self->right - $self->left) / 2;
51 my $label_width = $self->string_width($label,$font);
52 if ($label_align eq 'center') {
53 my $new_x = $middle - $label_width / 2;
54 $x = $new_x if ($new_x > $x);;
55 }
56 else {
57 my $new_x = $left + $self->right - $label_width;
58 $x = $new_x if ($new_x > $x);
59 }
60 $x = $self->panel->left + 1 if $x <= $self->panel->left;
61 #detect collision (most likely no bump when want centering label)
62 #lay down all features on one line e.g. cyto bands
63 return if (!$self->option('bump') && ($label_width + $x) > $self->right);
64 $gd->string($font,
65 $x,
66 $self->top + $top,
67 $label,
68 $self->fontcolor);
69 }
70 else {
71 $self->SUPER::draw_label(@_);
72 }
73 }
74  
75 sub arrowheads {
76 my $self = shift;
77 my ($ne,$sw,$base_e,$base_w);
78 my $feature = $self->feature;
79 my $gstart = $feature->start;
80 my $gend = $feature->end;
81 my $pstart = $self->panel->start;
82 my $pend = $self->panel->end;
83  
84 if (!defined $gstart || $gstart <= $pstart) { # off left end
85 $sw = 1;
86 }
87 if (!defined $gend || $gend >= $pend) { # off right end
88 $ne = 1;
89 }
90 ($sw,$ne) = ($ne,$sw) if $self->panel->{flip};
91 return ($sw,$ne,!$sw,!$ne);
92 }
93  
94 sub no_trunc {
95 !shift->option('no_arrows');
96 }
97  
98 1;
99  
100 __END__