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: 1363
Status: resolved
Priority: 0/
Queue: GDGraph

People
Owner: bwarfield [...] cpan.org
Requestors: parussel [...] yahoo.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.35
Fixed in: 1.4305



Subject: Multiple bar graphs in a mixed graph will not render side by side
Using GDGraph-1.35 (perl v5.6.1) on Windows 2000 Professional. When drawing mixed charts with multiple bar charts and a line chart, the bar charts do not render side by side. The following script is a combination of the provided sample scripts (sample14.pl and sample 61.pl). The resulting .png renders as expected, with the two bars on each date rendered in the same space, and the line over the entire graph. (I say as expected because you elude to this issue in the documentation.) The intent of the script is to render two bars side by side for each date, and a line over the entire graph. Based on your documentation, it appears that you are already aware of this issue. I just wanted to get this one on the wish list, as the fix would make my life much easier. GD::Graph is a great tool, thanks for putting it out there! Paul Russell <parussel@yahoo.com> use strict; use GD::Graph::mixed; my @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [ 1, 2, 5, 6, 7, 8, 9, 10, 11], [ 2, 2, 1, 1, 3, 2, 2, 4, 0], [ 9, 8, 9, 5, 7, 7, 8, 3, 3] ); my $my_graph = new GD::Graph::mixed(); $my_graph->set( types => [ qw( lines) ], default_type => 'bars', ); $my_graph->set( x_label => 'X Label', y_label => 'Y label', title => 'A Mixed Type Graph', y1_max_value => 40, y2_max_value => 8, y_min_value => 0, y_tick_number => 8, y_label_skip => 1, x_plot_values => 0, y_plot_values => 0, long_ticks => 1, x_ticks => 0, legend_marker_width => 24, line_width => 3, marker_size => 5, bar_width => 4, #bar_spacing => 1, transparent => 0, values_vertical => 1, values_format => "%4.1f", x_label_position => 1/2, cumulate => 0, overwrite => 1 ); $my_graph->set_legend( qw( incomming outgoing total ) ); $my_graph->plot(\@data) or die $my_graph->error; save_chart($my_graph, 'bars_all_over_each_other'); 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; }
use strict; use GD::Graph::mixed; ## define your data set my @data = ( ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"], [ 1, 2, 5, 6, 7, 8, 9, 10, 11], [ 2, 2, 1, 1, 3, 2, 2, 4, 0], [ 9, 8, 9, 5, 7, 7, 8, 3, 3] ); my $my_graph = new GD::Graph::mixed(); $my_graph->set( types => [ qw( lines) ], default_type => 'bars', ); $my_graph->set( x_label => 'X Label', y_label => 'Y label', title => 'A Mixed Type Graph', y1_max_value => 40, y2_max_value => 8, y_min_value => 0, y_tick_number => 8, y_label_skip => 1, x_plot_values => 0, y_plot_values => 0, long_ticks => 1, x_ticks => 0, legend_marker_width => 24, line_width => 3, marker_size => 5, bar_width => 4, #bar_spacing => 1, transparent => 0, values_vertical => 1, values_format => "%4.1f", x_label_position => 1/2, cumulate => 0, overwrite => 1 ); $my_graph->set_legend( qw( incomming outgoing total ) ); $my_graph->plot(\@data) or die $my_graph->error; save_chart($my_graph, 'bars_all_over_each_other'); 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: [PATCH] Multiple bar graphs in a mixed graph will not render side by side
From: Ben_Warfield [...] nrgn.com
Attached is a patchset that seems to me to fix this issue. Note that it's generated against an already-patched version of GD::Graph, based on the patch I submitted in Bug #3346 (http://rt.cpan.org/NoAuth/Bug.html?id=3346): the changes interlock a fair amount, and it seemed simpler (if a bit optimistic) to do it this way. I numbered them 1.4301 and 1.4302 to make it clear what the order of patch application should be. Possibly I should have backported this change to the original 1.43 source as well, but speaking for myself, I *like* that change, so I'm going to assume (until he tells me otherwise) that Martien likes it too. I'm happy to provide a combined patch if needed, and able (if less happy) to produce the backport if it's called for. Notes on the patch: I tried briefly to make this work with "hbars", then realized it made no sense to try (and that hbars was not a valid type in the normal mixed case), so I gave up. I also made a couple of changes that might seem gratuitous in Graph/mixed.pm, changing some direct access of internals to use a new "types" method. These are obviously pretty easy to back out if need be, I just wanted to limit the number of places I could screw up by mistyping a hash key or forgetting what the base array index was. --Ben Warfield
diff -u --exclude samples --exclude '*blib' --exclude 'Makefile*' --exclude '*~' -r GDGraph-1.4301/Graph/bars.pm GDGraph-1.43-A/Graph/bars.pm --- GDGraph-1.4301/Graph/bars.pm 2004-03-08 20:32:32.000000000 -0500 +++ GDGraph-1.43-A/Graph/bars.pm 2004-03-08 20:40:36.000000000 -0500 @@ -233,6 +233,13 @@ my $topvalues = $self->_top_values; + my ($bar_sets,$ds_adj) = ( $self->{_data}->num_sets , $ds ); + if ( $self->isa( 'GD::Graph::mixed' ) ) { + my @types = $self->types; + $bar_sets = grep { $_ eq 'bars' } @types; + $ds_adj = grep { $_ eq 'bars' } @types[0..$ds-1]; + } + for (my $i = 0; $i < @values; $i++) { my $value = $values[$i]; @@ -258,7 +265,7 @@ my ($l, $r); my $window = $self->{x_step} - $self->{group_spacing}; - if (ref $self eq 'GD::Graph::mixed' || $self->{overwrite}) + if ($self->{overwrite}) { $l = $xp - $window/2 + $bar_s + 1; $r = $xp + $window/2 - $bar_s; @@ -267,11 +274,11 @@ { $l = $xp - $window/2 - + ($ds - 1) * $window/$self->{_data}->num_sets + + ($ds_adj - 1) * $window/$bar_sets + $bar_s + 1; $r = $xp - $window/2 - + $ds * $window/$self->{_data}->num_sets + + $ds_adj * $window/$bar_sets - $bar_s; } diff -u --exclude samples --exclude '*blib' --exclude 'Makefile*' --exclude '*~' -r GDGraph-1.4301/Graph/mixed.pm GDGraph-1.43-A/Graph/mixed.pm --- GDGraph-1.4301/Graph/mixed.pm 2003-02-10 17:12:41.000000000 -0500 +++ GDGraph-1.43-A/Graph/mixed.pm 2004-03-08 21:17:53.000000000 -0500 @@ -60,7 +60,7 @@ my $rc; - my $type = $self->{types}->[$ds-1] || $self->{default_type}; + my $type = $self->types($ds); # Try to execute the draw_data_set function in the package # specified by type @@ -88,7 +88,7 @@ my $self = shift; my $ds = $_[0]; - my $type = $self->{types}->[$ds-1] || $self->{default_type}; + my $type = $self->types($ds); eval '$self->GD::Graph::'.$type.'::draw_legend_marker(@_)'; @@ -96,4 +96,23 @@ $self->{default_type}.'::draw_legend_marker(@_)' if $@; } +# undocumented as can be: returns the type-list (with the default +# inserted as appropriate), or the type associated with a particular +# (1-indexed) dataset number (undef if there is no such dataset). The +# range check means that this cannot be called when there is no +# GD::Graph::Data object in $self->{_data}. + +sub types +{ + my $self = shift; + if ( defined $_[0] ) { + $_[0] > 0 && $_[0] <= $self->{_data}->num_sets + ? $self->{types}->[$_[0] - 1] || $self->{default_type} + : undef + } else { + map { $self->{types}->[$_ - 1] || $self->{default_type} } + 1 .. $self->{_data}->num_sets; + } +} + "Just another true value"; diff -u --exclude samples --exclude '*blib' --exclude 'Makefile*' --exclude '*~' -r GDGraph-1.4301/Graph.pm GDGraph-1.43-A/Graph.pm --- GDGraph-1.4301/Graph.pm 2004-03-08 20:32:32.000000000 -0500 +++ GDGraph-1.43-A/Graph.pm 2004-03-08 20:46:55.000000000 -0500 @@ -32,7 +32,7 @@ package GD::Graph; ($GD::Graph::prog_version) = '$Revision: 1.53 $' =~ /\s([\d.]+)/; -$GD::Graph::VERSION = '1.4301'; +$GD::Graph::VERSION = '1.4302'; use strict; use GD;