| 1 | package Bio::Graphics::Glyph::three_letters; | ||
| 2 | # DAS-compatible package to use for drawing a line of groups of three letters | ||
| 3 | |||
| 4 | # Non object-oriented utilities used here-and-there in Bio::Graphics modules | ||
| 5 | |||
| 6 | =head1 NAME | ||
| 7 | |||
| 8 | Bio::Graphics::Glyph::three_letters - DAS-compatible package to use for drawing a line of groups of three letters | ||
| 9 | |||
| 10 | =cut | ||
| 11 | |||
| 12 | use strict; | ||
| 13 | use base qw(Bio::Graphics::Glyph::repeating_shape); | ||
| 14 | |||
| 15 | sub pad_top { | ||
| 16 | my $self = shift; | ||
| 17 | my $top = $self->SUPER::pad_top; | ||
| 18 | my $extra = 0.2 * $self->font->height; | ||
| 19 | return $top + $extra; | ||
| 20 | } | ||
| 21 | |||
| 22 | sub default_interval | ||
| 23 | { | ||
| 24 | return 20; | ||
| 25 | } | ||
| 26 | |||
| 27 | sub default_text | ||
| 28 | { | ||
| 29 | return "CAG"; | ||
| 30 | } | ||
| 31 | |||
| 32 | sub draw_repeating_shape | ||
| 33 | { | ||
| 34 | my ($self, $gd, $x1, $y1, $x2, $y2, $fg) = @_; | ||
| 35 | |||
| 36 | my $text = defined $self->option('text') ? $self->option('text') : $self->default_text(); | ||
| 37 | |||
| 38 | while (length $text < 3) | ||
| 39 | { | ||
| 40 | $text .= " "; | ||
| 41 | } | ||
| 42 | |||
| 43 | $text = substr($text,0,3); | ||
| 44 | my @letters = split //, $text; | ||
| 45 | |||
| 46 | my $oneThird = ($x2-$x1) / 3; | ||
| 47 | my $secondLetterX = $x1 + $oneThird; | ||
| 48 | my $thirdLetterX = $x1 + 2*$oneThird; | ||
| 49 | |||
| 50 | my $font = $self->option('labelfont') || $self->font; | ||
| 51 | $gd->string($font, $x1, $y2-$font->height, $letters[0], $self->fontcolor); | ||
| 52 | $gd->string($font, $secondLetterX, $y2-1.7*$font->height, $letters[1], $self->fontcolor); | ||
| 53 | $gd->string($font, $thirdLetterX, $y2-$font->height, $letters[2], $self->fontcolor); | ||
| 54 | } | ||
| 55 | |||
| 56 | 1; | ||
| 57 | |||
| 58 | __END__ |