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: 62919
Status: open
Priority: 0/
Queue: GDGraph

People
Owner: Nobody in particular
Requestors: patermanns [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 1.44
Fixed in: (no value)



Subject: Suppress last tick on the x-axis [PATCH]
When using x_label_skip, the last tick is always shown even if the x value is not a multiple of x_label_skip. This can be an issue if the last value is only slightly above that of the penultimate tick. Therefore, I have added a new setting - x_label_skip_last - which indicates whether the last tick/label should be skipped if not a multiple of x_label_skip: 0 = show last tick/label (DEFAULT), 1 = skip last tick/label if not a multiple of x_label_skip. A patch to axestype.pm is attached. Note that, although it is independent of my previous patches, the patch assumes that those patches have been applied. If not, the line numbers may have to be adjusted.
Subject: 04_last_tick.diff
*** old\axestype.pm Tue Nov 09 17:24:35 2010 --- new\axestype.pm Wed Nov 10 16:09:07 2010 *************** *** 42,47 **** --- 42,50 ---- # if 2 will print every second, etc.. x_label_skip => 1, y_label_skip => 1, + + # Whether to skip the last label when skipping labels on the x-axis + x_label_skip_last => 0, # Do we want ticks on the x axis? x_ticks => 1, *************** *** 1114,1119 **** --- 1117,1126 ---- my $tick_length = $self->{x_tick_length}; $tick_length = 0 if $self->{x_long_ticks} && ($self->{x_tick_length} > 0); + my $last_tick = $self->{_data}->num_points - 1; + # Stop the last tick appearing if not a multiple of the skip value + $last_tick += $self->{x_label_skip} if $self->{x_label_skip_last}; + for (my $i = 0; $i < $self->{_data}->num_points; $i++) { my ($x, $y) = $self->val_to_pixel($i + 1, 0, 1); *************** *** 1123,1129 **** # CONTRIB Damon Brodie for x_tick_offset next if (!$self->{x_all_ticks} and ($i - $self->{x_tick_offset}) % $self->{x_label_skip} and ! $i != $self->{_data}->num_points - 1 ); if ($self->{x_ticks}) --- 1130,1136 ---- # CONTRIB Damon Brodie for x_tick_offset next if (!$self->{x_all_ticks} and ($i - $self->{x_tick_offset}) % $self->{x_label_skip} and ! $i < $last_tick ); if ($self->{x_ticks}) *************** *** 1142,1148 **** # CONTRIB Damon Brodie for x_tick_offset next if ($i - $self->{x_tick_offset}) % ($self->{x_label_skip}) and ! $i != $self->{_data}->num_points - 1; my $text = $self->{_data}->get_x($i); if (defined $text) --- 1149,1155 ---- # CONTRIB Damon Brodie for x_tick_offset next if ($i - $self->{x_tick_offset}) % ($self->{x_label_skip}) and ! $i < $last_tick; my $text = $self->{_data}->get_x($i); if (defined $text) *************** *** 1178,1183 **** --- 1185,1194 ---- # as the gridlines will overwrite the ticks my $tick_length = $self->{x_tick_length}; $tick_length = 0 if $self->{x_long_ticks} && ($self->{x_tick_length} > 0); + + my $last_tick = $self->{_data}->num_points - 1; + # Stop the last tick appearing if not a multiple of the skip value + $last_tick += $self->{x_label_skip} if $self->{x_label_skip_last}; for (my $i = 0; $i < $self->{_data}->num_points; $i++) { *************** *** 1188,1194 **** # CONTRIB Damon Brodie for x_tick_offset next if (!$self->{x_all_ticks} and ($i - $self->{x_tick_offset}) % $self->{x_label_skip} and ! $i != $self->{_data}->num_points - 1 ); if ($self->{x_ticks}) --- 1199,1205 ---- # CONTRIB Damon Brodie for x_tick_offset next if (!$self->{x_all_ticks} and ($i - $self->{x_tick_offset}) % $self->{x_label_skip} and ! $i < $last_tick ); if ($self->{x_ticks}) *************** *** 1207,1213 **** # CONTRIB Damon Brodie for x_tick_offset next if ($i - $self->{x_tick_offset}) % ($self->{x_label_skip}) and ! $i != $self->{_data}->num_points - 1; my $text = $self->{_data}->get_x($i); if (defined $text) --- 1218,1224 ---- # CONTRIB Damon Brodie for x_tick_offset next if ($i - $self->{x_tick_offset}) % ($self->{x_label_skip}) and ! $i < $last_tick; my $text = $self->{_data}->get_x($i); if (defined $text) *************** *** 1283,1288 **** --- 1294,1303 ---- my $tick_length = $self->{x_tick_length}; $tick_length = 0 if $self->{x_long_ticks} && ($self->{x_tick_length} > 0); + my $last_tick = $self->{x_tick_number}; + # Stop the last tick appearing if not a multiple of the skip value + $last_tick += $self->{x_label_skip} if $self->{x_label_skip_last}; + for my $i (0 .. $self->{x_tick_number}) { my ($value, $x, $y); *************** *** 1318,1325 **** } # If we have to skip labels, we'll do it here. ! # Make sure to always draw the last one. ! next if $i % $self->{x_label_skip} && $i != $self->{x_tick_number}; $self->{gdta_x_axis}->set_text($self->{x_labels}[$i]); --- 1333,1340 ---- } # If we have to skip labels, we'll do it here. ! # Make sure to always draw the last one unless asked not to. ! next if $i % $self->{x_label_skip} && $i < $last_tick; $self->{gdta_x_axis}->set_text($self->{x_labels}[$i]);
From: patermanns [...] gmail.com
Sorry, I forgot to mention that this was tested with ActiveState Perl 5.8.9 on Windows XP and Perl 5.8.8 on Red Hat Enterprise Linux 5.3 (64-bit).
From: patermanns [...] gmail.com
I attach a short test program that shows the issue (test_chartg04a.pl) and one that shows the effect of the new setting (test_chartg04b.pl). I also attach the output from both.
Subject: test_chartg04a.pl
#!/usr/bin/perl -w use strict; use GD::Graph::lines; my $data1 = '50,30,40,150,60,70,80,120,180,90,20,210'; my $data2 = '400,545,450,600,750,400,1200,800,1000,500,900,1100'; my @x_axis_data = qw(00:00 01:00 02:00 03:00 04:00 05:00 06:00 07:00 08:00 09:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00 20:00 21:00 ); my @y1_axis_data = split(/,/, $data1); my @y2_axis_data = split(/,/, $data2); my @data = ( \@x_axis_data, \@y1_axis_data, \@y2_axis_data ); my $graph = GD::Graph::lines->new(240, 175); $graph->set( title => 'Test 2 Axes', transparent => 0, dclrs => [ qw(red blue) ], # bgclr => 'white', line_width => 2, two_axes => 2, x_label_skip => 4, y1_min_value => 0, y1_max_value => 250, y2_min_value => 400, y2_max_value => 1200, tick_length => -4 ) or die $graph->error; $graph->set_legend(split(/,/, 'Line1,Line2')); my $gd = $graph->plot(\@data) or die $graph->error; open(IMAGE,">test_chart04a.png") or die "Cannot open output file\n"; binmode(IMAGE); print IMAGE $gd->png; close(IMAGE);
Subject: test_chartg04b.pl
#!/usr/bin/perl -w use strict; use GD::Graph::lines; my $data1 = '50,30,40,150,60,70,80,120,180,90,20,210'; my $data2 = '400,545,450,600,750,400,1200,800,1000,500,900,1100'; my @x_axis_data = qw(00:00 01:00 02:00 03:00 04:00 05:00 06:00 07:00 08:00 09:00 10:00 11:00 12:00 13:00 14:00 15:00 16:00 17:00 18:00 19:00 20:00 21:00 ); my @y1_axis_data = split(/,/, $data1); my @y2_axis_data = split(/,/, $data2); my @data = ( \@x_axis_data, \@y1_axis_data, \@y2_axis_data ); my $graph = GD::Graph::lines->new(240, 175); $graph->set( title => 'Test 2 Axes', transparent => 0, dclrs => [ qw(red blue) ], # bgclr => 'white', line_width => 2, two_axes => 2, x_label_skip => 4, x_label_skip_last => 1, y1_min_value => 0, y1_max_value => 250, y2_min_value => 400, y2_max_value => 1200, tick_length => -4 ) or die $graph->error; $graph->set_legend(split(/,/, 'Line1,Line2')); my $gd = $graph->plot(\@data) or die $graph->error; open(IMAGE,">test_chart04b.png") or die "Cannot open output file\n"; binmode(IMAGE); print IMAGE $gd->png; close(IMAGE);
Subject: test_chart04b.png
test_chart04b.png
Subject: test_chart04a.png
test_chart04a.png
Subject: New GD::Graph co-maintainer and new release on CPAN
Hello, You recieved this message as you filed a bug report or feature request against GD::Graph module on CPAN. My name is Ruslan and I'm new co-maintainer of the module. I've updated the module to 1.45 with doc changes and released it to CPAN. See distribution status [1]. I have TODO list for several releases, so if your ticket was a patch then turning it into a nice pull request may expedite inclusion :) [1] http://search.cpan.org/~ruz/GDGraph-1.45/Graph.pm#DISTRIBUTION_STATUS -- Best regards, Ruslan.