Skip Menu |

This queue is for tickets about the GDGraph CPAN distribution.

Maintainer(s)' notes

There are plenty of good ideas of what people can do published here on the queue. Turning a patch from the tracker into a pull request is not one of them. In order to get maintainers' attention way more quickier, PR should have at least a sample included. We know it's hard to test images generating software, but it doesn't mean we can not test numbers produced by intermediate algorithms used to generate these images, so either a test or a sample.

Report information
The Basics
Id: 2944
Status: resolved
Priority: 0/
Queue: GDGraph

People
Owner: bwarfield [...] cpan.org
Requestors: rgarcia [...] hexaflux.com
xiashao [...] vip.sina.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in:
  • 1.43
  • 1.4305
  • 1.4306
  • 1.4307
Fixed in: 1.4308



Subject: show_values problem in stacked bars
I want to create a chart with horizontal stacked bars, where the value for each bar is printed inside of the bar itself. I'm not sure this can even be done. Working with the samples provided with GDGraph (1.35), I can create the horizontal stacked bar graph just fine, but the values end up getting printed in an odd manner. For the code below, the values that are printed for each bar don't end up 4 pixels outside of the bar (which I expect since I haven't gotten to trying to move them inside of the bar yet), and the values seem to be randomly chosen from either of the series. Any suggestions for: 1) getting the values to appear correctly for stacked horizontal bar graphs 2) getting the values to appear inside of the bar itself, rather than to the right (if I use the option values_space set to a negative number, the values seem to appear to the left of the bar). Thanks! Derek # This code demonstrates the problem I am having with labels inside the bars # of a stacked bar chart use strict; use GD::Graph::hbars; my @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4], [ 1, 1.5, 3, 2, 3, 1.5, 3, 4, 4 ] ); my $graph = GD::Graph::hbars->new(400, 300); $graph->set_legend('Pass', 'Fail'); $graph->set( x_label => 'X Label', y_label => 'Y label', title => 'Some simple graph', y_max_value => 10, y_tick_number => 10, y_label_skip => 2, bar_spacing => 8, cumulate => 'true', dclrs => [ qw( green lred ) ], show_values => 1, values_space => 4, ) or warn $graph->error; my $format = $graph->export_format; $graph->plot(\@data)->$format(); save_chart($graph,'bugs_graph'); sub save_chart { my $chart = shift or die "Need a chart!"; my $name = shift or die "Need a name!"; local(*OUT); my $ext = $chart->export_format; open(OUT, ">$name.$ext") or die "Cannot open $name.$ext for write: $!"; binmode OUT; print OUT $chart->gd->$ext(); close OUT; }
Subject: Bad alignment of values in cumulative histograms
It appears that the values displayed on top of bars on cumulative histograms are not properly lined up with the bars. The attached patch (by Romeo Juncu) fixes the problem.
--- bars.pm.orig 2003-11-24 15:08:30.000000000 -0600 +++ bars.pm 2003-11-24 15:13:09.000000000 -0600 @@ -312,12 +312,18 @@ return $self unless $self->{show_values}; my $text_angle = $self->{values_vertical} ? PI/2 : 0; - + my @numPoints = $self->{_data}->num_points(); for (my $dsn = 1; $dsn <= $self->{_data}->num_sets; $dsn++) { - my @values = $self->{_data}->y_values($dsn) or + my @values = (); + if (!$self->get("cumulate")) { + @values = $self->{_data}->y_values($dsn) or return $self->_set_error("Impossible illegal data set: $dsn", $self->{_data}->error); + } else { + my $nPoints = $numPoints[$dsn] || 0; + @values = map {$self->{_data}->get_y_cumulative($dsn, $_)} (0..$nPoints - 1) ; + } my @display = $self->{show_values}->y_values($dsn) or next; for (my $i = 0; $i < @values; $i++)
From: CC
Hello the patch actually fixe the problem for cumulative barchart graph. But I still have the problem for mixed graph where I have both cumulative and linespoints graphs. Any idea? Cheers [guest - Mon Nov 24 08:28:17 2003]: Show quoted text
> It appears that the values displayed on top of bars on cumulative > histograms > are not properly lined up with the bars. The attached patch (by Romeo > Juncu) fixes the problem.
I applied the patch, so this is fixed in 1.4305. I haven't tested the mixed-graph case mentioned in the anonymous comment above yet, though, so I'm leaving the status as stalled rather than resolved.
From: cyrille.mars [...] free.fr
On Sat Feb 11 19:06:05 2006, BWARFIELD wrote: Show quoted text
> I applied the patch, so this is fixed in 1.4305. I haven't tested the > mixed-graph case mentioned > in the anonymous comment above yet, though, so I'm leaving the status > as stalled rather than > resolved.
Hello, I made a patch to bars.pm to display the value inside the bar in cummulative mode. best regards, Cyrille
--- bars.pm.orig 2006-03-03 12:42:20.000000000 +0100 +++ bars.pm 2006-03-03 12:40:53.000000000 +0100 @@ -331,7 +331,12 @@ $self->{_data}->error); } else { my $nPoints = $numPoints[$dsn] || 0; - @values = map {$self->{_data}->get_y_cumulative($dsn, $_)} (0..$nPoints - 1) ; + @values = map {my $p = $_; + my $val = $self->{_data}->[$dsn][$p]; + $val /= 2; + map({$val+= $self->{_data}->[$_][$p]} (1..$dsn-1)) if $dsn > 1; + $val; + } (0..$nPoints - 1) ; } my @display = $self->{show_values}->y_values($dsn) or next; @@ -377,6 +382,7 @@ } $self->{gdta_values}->set_text($value); + $self->{gdta_values}->set_align('top', 'center') if ($self->get("cumulate")); $self->{gdta_values}->draw($xp, $yp, $text_angle); } }
RT-Send-CC: cyrille.mars [...] free.fr
The patch to put the values inside rather than at the top of the bars is interesting, but not a change I'd feel comfortable making on a default basis, and not *really* part of this particular bug in any case. I do think it's a behavior worth having available, so feel free, Cyrille, to resubmit it as a feature request (if you don't, I probably will myself just so I don't forget it), but it'll probably have to wait a little bit. Meanwhile, the original bug is now well and truly squashed (or will be, next time I upload to CPAN), so I'm marking this resolved, for real this time.