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

People
Owner: bwarfield [...] cpan.org
Requestors: Ben_Warfield [...] nrgn.com
grantm [...] cpan.org
Cc:
AdminCc:

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



Subject: Option to add space between groups of bars
When working with a multiple-data-set bar graph, I find it preferable to have the groups for each X value separated by a little additional space to make it clear where one X value ends and the next begins. This is obviously too trivial a feature to ask somebody else to implement, so I did it myself, adding a new group_spacing option (analogous to bar_spacing) for GD::Graph::bars and GD::Graph::hbars. The accompanying patch changes Graph.pm (to document the option), Graph/axestype.pm, Graph/bars.pm and samples/Makefile (since I also added sample code for the new option). I hope it meets with approval. Since I'm not sure I can attach multiple files, I'm including the new sample file (which I've called sample19.pl, because it seemed to fit there) in this message instead of as an attachment--it's basically just a slightly tweaked version of sample12.pl, in any case. Thanks for the great modules! --Ben Warfield #!/usr/local/bin/perl use strict; use GD::Graph::bars; use GD::Graph::hbars; require 'save.pl'; my @data = ( ["1st","2nd","3rd","4th","5th","6th","7th"], [ 5, 12, 24, 33, 19, 18, 6], [ 5, 11, 13, 28, 23, 13, 1], [ 2, 8, 10, 20, 18, 21, 3], [ 10, 20, 19, 36, 23, 19, 11], ); my @names = qw/sample19 sample19-h/; my @dim = (600,400); for my $my_graph (GD::Graph::bars->new(@dim),GD::Graph::hbars->new(@dim)) { my $name = shift @names; print STDERR "Processing $name\n"; $my_graph->set( x_label => 'X Label', y_label => 'Y label', title => 'Four data sets (with grouping space)', y_max_value => 40, y_tick_number => 8, y_label_skip => 2, bar_spacing => 2, shadow_depth => 3, group_spacing => 4, accent_treshold => 200, transparent => 0, ); $my_graph->set_legend(qw(Harry Ron Neville Hermione)); $my_graph->plot(\@data); save_chart($my_graph, $name); }
Download gdgraphpatch
application/octet-stream 4k

Message body not shown because it is not plain text.

Subject: Bars are not grouped on a graphs with multiple data series
The attached patch implements a bargroup_spacing option to control the amount of space between groups of bars. I prefer to use it with bar_spacing set to 0 so that all the matching items from each data series are close together.
Only in lib/GD/Graph: .axestype.pm.swp Only in lib/GD/Graph: .bars.pm.swp diff -ru lib-orig/GD/Graph/axestype.pm lib/GD/Graph/axestype.pm --- lib-orig/GD/Graph/axestype.pm 2004-06-22 20:33:01.000000000 +1200 +++ lib/GD/Graph/axestype.pm 2004-06-18 22:42:00.000000000 +1200 @@ -177,6 +177,7 @@ # Spacing between the bars bar_width => undef, bar_spacing => 0, + bargroup_spacing => 0, # cycle through colours per data point, not set cycle_clrs => 0, diff -ru lib-orig/GD/Graph/bars.pm lib/GD/Graph/bars.pm --- lib-orig/GD/Graph/bars.pm 2004-06-22 20:33:01.000000000 +1200 +++ lib/GD/Graph/bars.pm 2004-06-22 22:15:51.000000000 +1200 @@ -255,6 +255,7 @@ # calculate left and right of bar my ($l, $r); + my $gs = $self->{bargroup_spacing} ? $self->{bargroup_spacing} : 0; if (ref $self eq 'GD::Graph::mixed' || $self->{overwrite}) { @@ -264,12 +265,13 @@ else { $l = $xp - - $self->{x_step}/2 - + ($ds - 1) * $self->{x_step}/$self->{_data}->num_sets - + $bar_s + 1; + - $self->{x_step}/2 + $gs / 2 + + ($ds - 1) * ($self->{x_step} - $gs)/$self->{_data}->num_sets + + $bar_s + + ($gs ? 0 : 1); $r = $xp - - $self->{x_step}/2 - + $ds * $self->{x_step}/$self->{_data}->num_sets + - $self->{x_step}/2 + $gs / 2 + + $ds * ($self->{x_step} - $gs)/$self->{_data}->num_sets - $bar_s; }