Skip to content
This repository has been archived by the owner on Dec 22, 2023. It is now read-only.

Commit

Permalink
Fix StackedBar to work properly when keys don't match up in a dataset…
Browse files Browse the repository at this point in the history
…. Fixes RT #57372
  • Loading branch information
gphat committed Aug 7, 2011
1 parent e9d337d commit b8ac02f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
4 changes: 3 additions & 1 deletion Changes
Expand Up @@ -12,7 +12,9 @@ Revision history for Perl extension Chart::Clicker.
- Add get_value_for_key to Series
- Fix name of get_all_series_keys in POD
- Add get_series_values_for_key to DataSet
- Change DataSet::get_series_values to return an arrayref.
- Change DataSet::get_series_values to return an arrayref
- Fix an issue where series whose keys don't match cause weird StackedBar
results (Fixes RT #57372)

2.69
- Add note about CentOS.
Expand Down
22 changes: 13 additions & 9 deletions lib/Chart/Clicker/Renderer/StackedBar.pm
Expand Up @@ -134,23 +134,27 @@ override('finalize', sub {
# Iterate over each key...
for (my $i = 0; $i < scalar(@keys); $i++) {

# Mark the x, since it's the same for each Y value
my $x = $domain->mark($width, $keys[$i]);
my $accum = 0;

# Get all the values from every dataset's series for each key
my @values;
foreach my $ds (@{ $dses }) {
push(@values, @{ $ds->get_series_values($i) });
push(@values, @{ $ds->get_series_values_for_key($keys[$i]) });
}

# Mark the x, since it's the same for each Y value
my $x = $domain->mark($width, $keys[$i],);
my $accum = 0;

my $val = 0;
for my $j (0 .. $#values) {
my $sval = $values[$j];
if(defined($sval)) {
next if $sval == $range->baseline; # no reason to draw anything if no value
$val += $sval;
}

# Skip this if there is no value for the specified key position
next if !defined($sval);

# Skip it if it's equal to our baseline, as there's no reason to
# draw anything if so
next if $sval == $range->baseline;
$val += $sval;

my $y = $range->mark($height, $val);
next unless defined($y);
Expand Down

0 comments on commit b8ac02f

Please sign in to comment.