Permalink
Browse files

Expanded overlaying functionality for xyplot

  • Loading branch information...
Ahmed Elnaiem authored and lstein committed Jul 4, 2011
1 parent 491f516 commit 2603c689eb58546f1a3cd61b85e2677c42c050e6
Showing with 39 additions and 17 deletions.
  1. +6 −7 lib/Bio/Graphics/Glyph.pm
  2. +2 −2 lib/Bio/Graphics/Glyph/generic.pm
  3. +30 −6 lib/Bio/Graphics/Glyph/xyplot.pm
  4. +1 −2 lib/Bio/Graphics/Panel.pm
View
@@ -479,6 +479,7 @@ sub bounds {
my $self = shift;
my ($dx,$dy) = @_;
$dx += 0; $dy += 0;
+
($dx + $self->{left},
$dy + $self->top + $self->pad_top,
$dx + $self->{left} + $self->{width} - 1,
@@ -698,8 +699,7 @@ sub fillcolor {
# we also look for the "fillcolor" option for Ace::Graphics compatibility
sub bgcolor {
my $self = shift;
- my $bgcolor;
- ($bgcolor) = $self->feature->get_tag_values('bgcolor') if $self->feature->has_tag('bgcolor');
+ my ($bgcolor) = $self->feature->get_tag_values('bgcolor');
$bgcolor ||= $self->option('bgcolor'); # Let feature attribute override color
my $index = defined $bgcolor ? $bgcolor : $self->option('fillcolor');
$index = 'white' unless defined $index;
@@ -831,7 +831,7 @@ sub layout_sort {
sub layout {
my $self = shift;
return $self->{layout_height} if exists $self->{layout_height};
-
+
my @parts = $self->parts;
return $self->{layout_height} =
$self->height + $self->pad_top + $self->pad_bottom unless @parts;
@@ -846,8 +846,8 @@ sub layout {
$_->layout foreach @parts; # recursively lay out
- # no bumping requested, or only one part here
- if (@parts == 1 || !$bump_direction) {
+ # no bumping requested, or only one part here, or the tracks are supposed to be overlay
+ if (@parts == 1 || !$bump_direction || ($bump_direction eq 'fast' and $self->code_option('overlay') == 1)) {
my $highest = 0;
foreach (@parts) {
my $height = $_->layout_height;
@@ -860,7 +860,6 @@ sub layout {
return $self->{layout_height} = $self->optimized_layout(\@parts)
+ $self->pad_bottom + $self->pad_top -1;# - $self->top + 1;
}
-
my (%bin1,%bin2);
my $limit = 0;
my $recent_pos = 0;
@@ -912,6 +911,7 @@ sub layout {
}
$g->move(0,$pos);
+
$self->add_collision(\%bin1,CM1,CM2,$left,$g->top,$right,$g->bottom);
$recent_pos = $pos;
@@ -1010,7 +1010,6 @@ sub optimized_layout {
$part->move(0,$offset);
$overbumped = $offset if $bump_limit > 0 && $offset >= $bump_limit * $rect->[2];
}
-
return $overbumped && $overbumped < $layout->totalHeight ? $overbumped : $layout->totalHeight;
}
@@ -489,8 +489,8 @@ sub draw_label {
sub render_label {
my $self = shift;
- my ($gd,$font,$x,$y,$label) = @_;
- $gd->string($font,$x,$y,$label,$self->labelcolor);
+ my ($gd,$font,$x,$y,$label,$is_legend) = @_;
+ if(!$is_legend){$gd->string($font,$x,$y,$label,$self->labelcolor);}
$self->panel->add_key_box($self,$label,$x,$y)
if $self->record_label_positions;
}
@@ -149,6 +149,7 @@ sub graph_type {
sub draw {
my $self = shift;
my ($gd,$dx,$dy) = @_;
+
my ($left,$top,$right,$bottom) = $self->calculate_boundaries($dx,$dy);
my @parts = $self->parts;
@@ -197,6 +198,7 @@ sub draw {
$self->panel->startGroup($gd);
$self->_draw_grid($gd,$scale,$min_score,$max_score,$dx,$dy,$y_origin);
+
$self->panel->endGroup($gd);
for my $draw_method (@draw_methods) {
@@ -207,8 +209,9 @@ sub draw {
$self->_draw_scale($gd,$scale,$min_score,$max_score,$dx,$dy,$y_origin);
$self->panel->endGroup($gd);
- $self->draw_label(@_) if $self->option('label');
- $self->draw_description(@_) if $self->option('description');
+ $self->draw_label(@_) if ($self->option('label') && !$self->option('overlay'));
+ $self->draw_description(@_) if ($self->option('description') && !$self->option('overlay'));
+ $self->draw_legend(@_) if $self->option('overlay');
$self->panel->endGroup($gd);
}
@@ -321,8 +324,9 @@ sub _draw_boxes {
my @parts = $self->parts;
my $lw = $self->linewidth;
- my $positive = $self->pos_color;
- my $negative = $self->neg_color;
+ # Make the boxes transparent
+ my $positive = $self->pos_color + 1073741824;
+ my $negative = $self->neg_color + 1073741824;
my $height = $self->height;
my $midpoint = $self->midpoint ? $self->score2position($self->midpoint)
@@ -336,7 +340,7 @@ sub _draw_boxes {
my $part = $parts[$i];
my $next = $parts[$i+1];
-
+
my ($color,$negcolor);
# special check here for the part_color being defined so as not to introduce lots of
@@ -377,7 +381,8 @@ sub _draw_line {
my $current_x = ($x1+$x2)/2;
my $current_y = $first_part->{_y_position};
- for my $part (@parts) {
+ for my $part (@parts) {
+
($x1,$y1,$x2,$y2) = $part->calculate_boundaries($left,$top);
my $next_x = ($x1+$x2)/2;
my $next_y = $part->{_y_position};
@@ -659,6 +664,25 @@ sub draw_label {
$label);
}
+sub draw_legend {
+ my $self = shift;
+ my ($gd,$left,$top,$partno,$total_parts) = @_;
+ my $color = $self->option('fgcolor');
+ my $name = $self->feature->{name};
+
+ my $label = "<a id=\"legend_$name\" target=\"_blank\" href=\"#\"> <font color=\'$color\';\">" . $name . "</font></a>" or return;
+
+ my $font = $self->labelfont;
+ my $x = $self->left + $left - $font->width*length($label) - $self->extra_label_pad;
+ my $y = $self->{top} + $top;
+ my $is_legend = 1;
+ $self->render_label($gd,
+ $font,
+ $x,
+ $y,
+ $label,
+ $is_legend);
+}
1;
@@ -570,7 +570,6 @@ sub gd {
$offset = $pt;
for my $track (@{$self->{tracks}}) {
$self->startGroup($gd);
-
my $draw_between = $between_key && $track->option('key');
my $has_parts = $track->parts;
my $side_key_height = 0;
@@ -825,7 +824,7 @@ sub format_key {
sub add_key_box {
my $self = shift;
- my ($track,$label,$x,$y) = @_;
+ my ($track,$label,$x,$y, $is_legend) = @_;
my $value = [$label,$x,$y,$x+$self->{key_font}->width*CORE::length($label),$y+$self->{key_font}->height,$track];
push @{$self->{key_boxes}},$value;
}

0 comments on commit 2603c68

Please sign in to comment.