Skip to content
Permalink
Browse files

Merge pull request #4 from Tordek/master

Fixed shadows overlapping when in cumulative mode.
  • Loading branch information...
ruz committed Dec 27, 2015
2 parents 2edd944 + d9419be commit b751c8a8fd99d47caf09bbcdb34eb41a1a6d07b2
Showing with 66 additions and 4 deletions.
  1. +66 −4 Graph/bars.pm
@@ -145,6 +145,39 @@ sub draw_data_set_h
$self->{_data}->error);

my $topvalues = $self->_top_values;
#
# Draw all shadows.
for my $i (0 .. $#values)
{
my $value = $values[$i];
next unless defined $value;

my $l = $self->_get_bottom($ds, $i);
my ($r, $xp) = $self->val_to_pixel($i + 1, $value, $ds);

# calculate top and bottom of bar
my ($t, $b);
my $window = $self->{x_step} - $self->{bargroup_spacing};

if (ref $self eq 'GD::Graph::mixed' || $self->{overwrite})
{
$t = $xp - $window/2 + $bar_s + 1;
$b = $xp + $window/2 - $bar_s;
}
else
{
$t = $xp
- $window/2
+ ($ds - 1) * $window/$self->{_data}->num_sets
+ $bar_s + 1; # GRANTM thinks this +1 should be conditional on bargroup_spacing being absent
$b = $xp
- $window/2
+ $ds * $window/$self->{_data}->num_sets
- $bar_s;
}

$self->_draw_shadow($ds, $i, $value, $topvalues, $l, $t, $r, $b);
}

for my $i (0 .. $#values)
{
@@ -189,8 +222,6 @@ sub draw_data_set_h
}

# draw the bar
$self->_draw_shadow($ds, $i, $value, $topvalues, $l, $t, $r, $b);

if ($value < 0) { ($r,$l) = ($l,$r) }

$self->{graph}->filledRectangle($l, $t, $r, $b, $dsci)
@@ -229,7 +260,39 @@ sub draw_data_set_v
$ds_adj = grep { $_ eq 'bars' } @types[0..$ds-1];
}

for (my $i = 0; $i < @values; $i++)
# Draw all shadows.
for my $i (0 .. $#values)
{
my $value = $values[$i];
next unless defined $value;

my $bottom = $self->_get_bottom($ds, $i);
my ($xp, $t) = $self->val_to_pixel($i + 1, $value, $ds);
my ($l, $r);
my $window = $self->{x_step} - $self->{bargroup_spacing};

if ($self->{overwrite})
{
$l = $xp - $window/2 + $bar_s + 1;
$r = $xp + $window/2 - $bar_s;
}
else
{
$l = $xp
- $window/2
+ ($ds_adj - 1) * $window/$bar_sets
+ $bar_s + 1; # GRANTM thinks this +1 should be conditional on bargroup_spacing being absent
$r = $xp
- $window/2
+ $ds_adj * $window/$bar_sets
- $bar_s;
}

$self->_draw_shadow($ds, $i, $value, $topvalues, $l, $t, $r, $bottom);
}

# Then all bars.
for my $i (0 .. $#values)
{
my $value = $values[$i];
next unless defined $value;
@@ -272,7 +335,6 @@ sub draw_data_set_v
}

# draw the bar
$self->_draw_shadow($ds, $i, $value, $topvalues, $l, $t, $r, $bottom);

if ($value < 0) { ($bottom,$t) = ($t,$bottom) }
$self->{graph}->filledRectangle($l, $t, $r, $bottom, $dsci)

0 comments on commit b751c8a

Please sign in to comment.
You can’t perform that action at this time.