| 1 | package Bio::Graphics::Glyph::track; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base qw(Bio::Graphics::Glyph); | ||
| 5 | |||
| 6 | # track sets connector to empty | ||
| 7 | sub connector { | ||
| 8 | my $self = shift; | ||
| 9 | return $self->SUPER::connector(@_) if $self->all_callbacks; | ||
| 10 | return 'none'; | ||
| 11 | } | ||
| 12 | |||
| 13 | sub draw { | ||
| 14 | my $self = shift; | ||
| 15 | my ($gd,$left,$top,$partno,$total_parts) = @_; | ||
| 16 | |||
| 17 | # the clipping code here prevents poorly-behaving glyphs from | ||
| 18 | # drawing outside the track | ||
| 19 | my @clip; | ||
| 20 | if ($gd->can('clip')) { | ||
| 21 | @clip = $gd->clip(); | ||
| 22 | # glyphs are allowed a slop area of ~3 on either side and 6 on the top and bottom | ||
| 23 | # in order to spill out over their boundaries. Beyond this they start overlapping | ||
| 24 | # with other glyphs in an ugly way. | ||
| 25 | my @cliprect = ($left-$self->panel->pad_left, | ||
| 26 | $top-6, | ||
| 27 | $self->panel->right+$self->panel->pad_right, | ||
| 28 | $top+$self->layout_height+6); | ||
| 29 | $gd->clip(@cliprect); | ||
| 30 | } | ||
| 31 | |||
| 32 | my @parts = $self->parts; | ||
| 33 | |||
| 34 | # give the glyph a chance to do track-wide normalization if it supports it | ||
| 35 | $self->normalize_track(@parts); | ||
| 36 | |||
| 37 | # dynamic assignment of colors | ||
| 38 | if ($self->option('color_series') || $self->option('color_cycle')) { | ||
| 39 | my $series = $self->option('color_cycle'); | ||
| 40 | $series ||= 'red blue green yellow orange brown aqua black fuchsia green lime maroon navy olive purple silver teal magenta'; | ||
| 41 | my @color_series = ref($series) eq 'ARRAY' ? @$series : split /\s+/,$series; | ||
| 42 | my $index = 0; | ||
| 43 | my %color_cache; | ||
| 44 | my $closure = sub { | ||
| 45 | my $glyph = pop; | ||
| 46 | return $color_cache{$glyph} ||= $color_series[$index++ % @color_series]; | ||
| 47 | }; | ||
| 48 | $self->configure(bgcolor => $closure); | ||
| 49 | } | ||
| 50 | |||
| 51 | local $Bio::Graphics::Panel::GlyphScratch; # set $GlyphScratch to undef | ||
| 52 | for (my $i=0; $i<@parts; $i++) { | ||
| 53 | $parts[$i]->draw_highlight($gd,$left,$top); | ||
| 54 | $parts[$i]->draw_it($gd,$left,$top,0,1); | ||
| 55 | } | ||
| 56 | |||
| 57 | $gd->clip(@clip) if @clip; | ||
| 58 | } | ||
| 59 | |||
| 60 | # do nothing for components | ||
| 61 | # sub draw_component { } | ||
| 62 | |||
| 63 | sub normalize_track { | ||
| 64 | my $self = shift; | ||
| 65 | my @parts = @_; | ||
| 66 | @parts = map {$_->isa('Bio::Graphics::Glyph::group') ? $_->parts : $_} @parts; | ||
| 67 | $parts[0]->normalize_track(@parts) if $parts[0] && $parts[0]->can('normalize_track'); | ||
| 68 | } | ||
| 69 | |||
| 70 | sub bump { | ||
| 71 | my $self = shift; | ||
| 72 | return 1 if $self->option('group_subtracks'); | ||
| 73 | my $bump = $self->SUPER::bump; | ||
| 74 | return 1 if $bump eq 'fast' or $bump == 3; | ||
| 75 | return $bump; | ||
| 76 | } | ||
| 77 | |||
| 78 | 1; | ||
| 79 | |||
| 80 | |||
| 81 | __END__ |