| 1 | package Bio::Graphics::Glyph::dot; | ||
| 2 | # DAS-compatible package to use for drawing a ring or filled circle | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use base qw(Bio::Graphics::Glyph::point_glyph); | ||
| 6 | use constant PI => 3.14159; | ||
| 7 | sub my_description { | ||
| 8 | return <<END; | ||
| 9 | This glyph draws an ellipse the width of the scaled feature passed, | ||
| 10 | and height a possibly configured height (See Bio::Graphics::Glyph). | ||
| 11 | END | ||
| 12 | } | ||
| 13 | sub my_options { | ||
| 14 | { | ||
| 15 | point => [ | ||
| 16 | 'boolean', | ||
| 17 | undef, | ||
| 18 | 'If true, draws a fixed-radius ellipse at the center of the feature,', | ||
| 19 | 'regardless of the feature\'s length.'], | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | sub draw { | ||
| 24 | my $self = shift; | ||
| 25 | my $gd = shift; | ||
| 26 | my $fg = $self->fgcolor; | ||
| 27 | |||
| 28 | # now draw a circle | ||
| 29 | my ($left,$top) = @_; | ||
| 30 | my ($x1,$y1,$x2,$y2) = $self->calculate_boundaries(@_); | ||
| 31 | my $xmid = (($x1+$x2)/2); my $width = abs($x2-$x1); | ||
| 32 | my $ymid = (($y1+$y2)/2); my $height = abs($y2-$y1); | ||
| 33 | |||
| 34 | # only point ovals allowed now | ||
| 35 | my $r = $self->height; | ||
| 36 | |||
| 37 | # Code to maintain compliancy with gd 1.8.4 | ||
| 38 | # gd 1.8.4 does not support the ellipse() or filledEllipse() methods. | ||
| 39 | # Let's maintain the filledEllipse approach for installations | ||
| 40 | # using gd2 or for drawing images with GD::SVG | ||
| 41 | # Otherwise, we will use fill as before. | ||
| 42 | # The can() method fails with GD::SVG. Why? | ||
| 43 | my $bg = $self->bgcolor; | ||
| 44 | if ($gd->can('filledEllipse') || $gd =~ /SVG/ ) { | ||
| 45 | $gd->filledEllipse($xmid,$ymid,$r,$r,$bg) if ($bg); | ||
| 46 | # Draw the border (or unfilled ellipse) | ||
| 47 | $gd->ellipse($xmid,$ymid,$r,$r,$fg); | ||
| 48 | } else { | ||
| 49 | # Let's draw a circle in the gd 1.8.4 manner | ||
| 50 | $gd->arc($xmid,$ymid,$r,$r,0,360,$fg); | ||
| 51 | $gd->fillToBorder($xmid,$ymid,$fg,$bg) if ($bg); | ||
| 52 | } | ||
| 53 | |||
| 54 | #how about a fuse for the bomb? | ||
| 55 | #work in degrees, not radians. So we define PI above | ||
| 56 | if(defined $self->option('stem')){ | ||
| 57 | my $angle = $self->option('stem'); | ||
| 58 | |||
| 59 | $gd->line($xmid+($r/PI*sin($angle*PI/180)), | ||
| 60 | $ymid+($r/PI*cos($angle*PI/180)), | ||
| 61 | $xmid+($r*sin($angle*PI/180)), | ||
| 62 | $ymid+($r*cos($angle*PI/180)),$fg); | ||
| 63 | } | ||
| 64 | |||
| 65 | $self->draw_label($gd,@_) if $self->option('label'); | ||
| 66 | } | ||
| 67 | |||
| 68 | 1; | ||
| 69 | |||
| 70 | __END__ |