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

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 55 CC 3 SCAR 18.4
CC
3
Cov
0%
draw_component
12.0
my_description
2.0
my_options
2.0
CRAP 6.3
1 package Bio::Graphics::Glyph::lightning;
2  
3 # A lightning bolt glyph to add some pizazz to your displays. Yeow!
4  
5 use strict;
6 use base qw(Bio::Graphics::Glyph::generic);
7  
8 sub my_description {
9 return <<END;
10 This glyph draws a lightning bolt of specified height with relative
11 width, with the point of the lightning bolt centered on the
12 feature. The height of the bolt is specified by the "height"
13 option. Due to the complexity of this glyph, it doesn\'t resolve well
14 with heights less than 11 pixels.
15 END
16 }
17 sub my_options {
18 {
19 orient => [
20 [qw(N S)],
21 'N',
22 'Control the direction of the lightning bolt. One of',
23 '<N>orth, or <S>outh'],
24 }
25 }
26  
27 sub draw_component {
28 my $self = shift;
29 my $gd = shift;
30 my $fg = $self->fgcolor;
31  
32 # find the center and vertices
33 my ($x1,$y1,$x2,$y2) = $self->calculate_boundaries(@_);
34  
35 my $h = $self->option('height');
36 my $w = $h*0.6;
37  
38 my $poly_pkg = $self->polygon_package;
39 my $polygon = $poly_pkg->new();
40  
41 # lightning bolt points up or down
42 if ($self->option('orient') eq 'N') {
43 $y1 = $y1 + $h/4;
44 $polygon->addPt($x2,$y1+($h/2));
45 $polygon->addPt($x2-($w*0.7),$y1+($h/2));
46 $polygon->addPt($x2-($w*0.2),$y1+($h*0.15));
47 $polygon->addPt($x2-($w*0.6),$y1+($h*0.15));
48 $polygon->addPt($x2,$y1-$h/2);
49 $polygon->addPt($x2-($w*0.1),$y1-($h*0.05));
50 $polygon->addPt($x2+($w*0.5),$y1-($h*0.05));
51 $polygon->addPt($x2,$y1+($h/2));
52 }
53 else {
54 $y1 = $y1 + $h/2;
55 $polygon->addPt($x1,$y1-($h/2));
56 $polygon->addPt($x1+($w*0.7),$y1-($h/2));
57 $polygon->addPt($x1+($w*0.2),$y1-($h*0.15));
58 $polygon->addPt($x1+($w*0.6),$y1-($h*0.15));
59 $polygon->addPt($x1,$y1+$h/2);
60 $polygon->addPt($x1+($w*0.1),$y1+($h*0.05));
61 $polygon->addPt($x1-($w*0.5),$y1+($h*0.05));
62 $polygon->addPt($x1,$y1-($h/2));
63 }
64  
65 # Have to draw TWO polygons for fills in order to get an outline
66 # because filledPolygon in GD croaks with extra parameters (and
67 # doesn't support drawing of stroke anyways).
68 if (my $c = $self->bgcolor) {
69 $gd->filledPolygon($polygon,$c);
70 $gd->polygon($polygon,$fg);
71 } else {
72 $gd->polygon($polygon,$fg);
73 }
74 }
75  
76 1;
77  
78 __END__