From 413ce87a584f9f1189d69985e36d25b976c97360 Mon Sep 17 00:00:00 2001 From: pmichaud Date: Thu, 5 Nov 2009 00:51:46 +0000 Subject: [PATCH] Fixes vertical graphs w/ large numbers of columns. --- lib/Imager/Graph/Vertical.pm | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/lib/Imager/Graph/Vertical.pm b/lib/Imager/Graph/Vertical.pm index 30eb7e3..2e89932 100644 --- a/lib/Imager/Graph/Vertical.pm +++ b/lib/Imager/Graph/Vertical.pm @@ -648,7 +648,7 @@ sub _draw_columns { my $bottom = $graph_box->[1]; my $zero_position = int($bottom + $graph_height - (-1*$min_value / $value_range) * ($graph_height -1)); - my $bar_width = int($graph_width / $column_count - 1); + my $bar_width = $graph_width / $column_count; my $outline_color; if ($style->{'features'}{'outline'}) { @@ -671,11 +671,19 @@ sub _draw_columns { my @data = @{$series->{'data'}}; my $data_size = scalar @data; for (my $i = 0; $i < $data_size; $i++) { - my $x1 = int($left + $bar_width * (scalar @$col_series * $i + $series_pos)) + scalar @$col_series * $i + $series_pos + ($column_padding / 2); + my $part1 = $bar_width * (scalar @$col_series * $i); + my $part2 = ($series_pos) * $bar_width; + my $x1 = $left + $part1 + $part2; if ($has_stacked_columns) { - $x1 += ($i + 1) * $bar_width + $i + 1; + $x1 += ($bar_width * ($i+1)); + } + $x1 = int($x1); + + my $x2 = int($x1 + $bar_width - $column_padding)-1; + # Special case for when bar_width is less than 1. + if ($x2 < $x1) { + $x2 = $x1; } - my $x2 = $x1 + $bar_width - $column_padding; my $y1 = int($bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height); @@ -722,7 +730,7 @@ sub _draw_stacked_columns { my $graph_width = $self->_get_number('graph_width'); my $graph_height = $self->_get_number('graph_height'); - my $bar_width = int($graph_width / $column_count -1); + my $bar_width = $graph_width / $column_count; my $column_series = 0; if (my $column_series_data = $self->_get_data_series()->{'column'}) { $column_series = (scalar @$column_series_data); @@ -751,8 +759,14 @@ sub _draw_stacked_columns { my @data = @{$series->{'data'}}; my $data_size = scalar @data; for (my $i = 0; $i < $data_size; $i++) { - my $x1 = int($left + $bar_width * ($column_series * $i)) + $column_series * $i + ($column_padding / 2); - my $x2 = $x1 + $bar_width - $column_padding; + my $part1 = $bar_width * $i * $column_series; + my $part2 = 0; + my $x1 = int($left + $part1 + $part2); + my $x2 = int($x1 + $bar_width - $column_padding) - 1; + # Special case for when bar_width is less than 1. + if ($x2 < $x1) { + $x2 = $x1; + } my $y1 = int($bottom + ($value_range - $data[$i] + $min_value)/$value_range * $graph_height); -- 2.30.2