| 1 | package Bio::Graphics::Glyph::group; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base qw(Bio::Graphics::Glyph::segmented_keyglyph); | ||
| 5 | |||
| 6 | sub my_description { | ||
| 7 | return <<END; | ||
| 8 | This glyph is used internally by Bio::Graphics::Panel for laying out | ||
| 9 | groups of glyphs that are linked together. It should not be used | ||
| 10 | explicitly. | ||
| 11 | END | ||
| 12 | } | ||
| 13 | |||
| 14 | sub my_options { | ||
| 15 | return | ||
| 16 | { | ||
| 17 | group_label => [ | ||
| 18 | 'boolean', | ||
| 19 | undef, | ||
| 20 | 'Attach a label to the group; this is independent of the label option which applies', | ||
| 21 | 'to features within the group' | ||
| 22 | ], | ||
| 23 | group_label_position => [ | ||
| 24 | [qw(top left)], | ||
| 25 | 'left', | ||
| 26 | 'Position in which to draw the group label.' | ||
| 27 | ], | ||
| 28 | } | ||
| 29 | } | ||
| 30 | |||
| 31 | # group sets connector to 'dashed' | ||
| 32 | sub connector { | ||
| 33 | my $self = shift; | ||
| 34 | my $super = $self->SUPER::connector(@_); | ||
| 35 | return $super if $self->all_callbacks; | ||
| 36 | return 'dashed' unless defined($super) && ($super eq 'none' or !$super); | ||
| 37 | } | ||
| 38 | |||
| 39 | # we don't label group (yet) | ||
| 40 | sub label { my $self = shift; | ||
| 41 | return $self->{_group_label} if exists $self->{_group_label}; | ||
| 42 | return $self->{_group_label} = $self->option('group_label') ? $self->feature->display_name : '' | ||
| 43 | } | ||
| 44 | |||
| 45 | sub labelfont { | ||
| 46 | my $self = shift; | ||
| 47 | return $self->getfont('groupfont','gdMediumBoldFont'); | ||
| 48 | } | ||
| 49 | |||
| 50 | sub pad_left { | ||
| 51 | my $self = shift; | ||
| 52 | return 0 unless $self->option('group_label'); | ||
| 53 | return $self->string_width($self->label,$self->labelfont) +3; | ||
| 54 | } | ||
| 55 | |||
| 56 | sub draw { | ||
| 57 | my $self = shift; | ||
| 58 | $self->SUPER::draw(@_) if $self->feature_has_subparts; | ||
| 59 | $self->draw_label(@_) if $self->option('group_label'); | ||
| 60 | } | ||
| 61 | |||
| 62 | sub draw_label { | ||
| 63 | my $self = shift; | ||
| 64 | my $label = $self->label or return; | ||
| 65 | my $panel= $self->panel; | ||
| 66 | |||
| 67 | $self->SUPER::draw_label(@_) unless $panel->{suppress_key}; | ||
| 68 | |||
| 69 | my ($gd,$left,$top,$partno,$total_parts) = @_; | ||
| 70 | my $font = $self->labelfont; | ||
| 71 | |||
| 72 | my $x = $self->left + $left; # valid for both "top" and "left" because the left-hand side is defined by pad_left | ||
| 73 | my $y; | ||
| 74 | if ($self->label_position eq 'top') { | ||
| 75 | $x += $self->pad_left; # offset to beginning of the drawn part of the feature | ||
| 76 | $x = $panel->left + 1 if $x <= $panel->left; | ||
| 77 | $y = $self->top + $top - 1; | ||
| 78 | } elsif ($self->label_position eq 'left') { | ||
| 79 | $y = $self->{top} + ($self->height - $self->font_height($font))/2 + $top; | ||
| 80 | $y = $self->{top} + $top if $y < $self->{top} + $top; | ||
| 81 | } | ||
| 82 | $panel->add_key_box($self,$label,$x,$y); | ||
| 83 | } | ||
| 84 | |||
| 85 | sub label_position { | ||
| 86 | my $self = shift; | ||
| 87 | my $pos = $self->option('group_label_position') || 'left'; | ||
| 88 | return $pos; | ||
| 89 | } | ||
| 90 | |||
| 91 | sub new { | ||
| 92 | my $self = shift; | ||
| 93 | return $self->SUPER::new(@_,-level=>-1); | ||
| 94 | } | ||
| 95 | |||
| 96 | |||
| 97 | # don't allow simple bumping in groups -- it looks terrible... | ||
| 98 | sub bump { | ||
| 99 | my $self = shift; | ||
| 100 | my $bump = $self->SUPER::bump(@_); | ||
| 101 | return 1 if $bump > 1; | ||
| 102 | return -1 if $bump < -1; | ||
| 103 | return $bump; | ||
| 104 | } | ||
| 105 | |||
| 106 | 1; | ||
| 107 | |||
| 108 | __END__ |