Subject: | [PATCH] use_axis support |
Hello Martien,
attached is a patch to add the obviously planned use_axis support. A new
samples95.pl script derived from samples14.pl tests the new feature. Further changes: MANIFEST (to include the new sample script), META.yml (done automatically by the recent ExtUtils::MakeMaker), samples/Makefile (now using -Mblib=.. instead of -I../blib/lib --- this is the preferred idiom; and added samples95.pl).
The documentation for use_axis is still missing, though.
Regards,
Slaven
#
#
# To apply this patch:
# STEP 1: Chdir to the source directory.
# STEP 2: Run the 'applypatch' program with this patch file as input.
#
# If you do not have 'applypatch', it is part of the 'makepatch' package
# that you can fetch from the Comprehensive Perl Archive Network:
# http://www.perl.com/CPAN/authors/Johan_Vromans/makepatch-x.y.tar.gz
# In the above URL, 'x' should be 2 or higher.
#
# To apply this patch without the use of 'applypatch':
# STEP 1: Chdir to the source directory.
# If you have a decent Bourne-type shell:
# STEP 2: Run the shell with this file as input.
# If you don't have such a shell, you may need to manually create
# the files as shown below.
# STEP 3: Run the 'patch' program with this file as input.
#
# These are the commands needed to create/delete files/directories:
#
touch 'META.yml'
chmod 0644 'META.yml'
touch 'samples/sample95.pl'
chmod 0755 'samples/sample95.pl'
#
# This command terminates the shell and need not be executed manually.
exit
#
#### End of Preamble ####
#### Patch data follows ####
diff -up '/usr/local/dist/cpan/build/GDGraph-1.43/Graph/axestype.pm' 'Graph/axestype.pm'
Index: ./Graph/axestype.pm
Prereq: 1.44
--- ./Graph/axestype.pm Tue Jul 1 07:04:10 2003
+++ ./Graph/axestype.pm Thu Nov 13 15:11:41 2003
@@ -658,7 +658,7 @@ sub setup_coords
my $s = shift;
# Do some sanity checks
- $s->{two_axes} = 0 if $s->{_data}->num_sets != 2 || $s->{two_axes} < 0;
+ $s->{two_axes} = 0 if $s->{_data}->num_sets < 2 || $s->{two_axes} < 0;
$s->{two_axes} = 1 if $s->{two_axes} > 1;
delete $s->{y_label2} unless $s->{two_axes};
@@ -1487,14 +1487,30 @@ sub set_max_min
my $min_range_2 = defined($self->{min_range_2})
? $self->{min_range_2}
: $self->{min_range};
+
+ my(@y_min, @y_max);
+ for my $nd (1 .. $self->{_data}->num_sets)
+ {
+ my $axis = $self->{use_axis}->[$nd - 1];
+ my($y_min, $y_max) = $self->{_data}->get_min_max_y($nd);
+ if (!defined $y_min[$axis] || $y_min[$axis] > $y_min)
+ {
+ $y_min[$axis] = $y_min;
+ }
+ if (!defined $y_max[$axis] || $y_max[$axis] < $y_max)
+ {
+ $y_max[$axis] = $y_max;
+ }
+ }
+
(
$self->{y_min}[1], $self->{y_max}[1],
$self->{y_min}[2], $self->{y_max}[2],
$self->{y_tick_number}
) = _best_dual_ends(
- $self->_correct_y_min_max($self->{_data}->get_min_max_y(1)),
+ $self->_correct_y_min_max($y_min[1], $y_max[1]),
$min_range_1,
- $self->_correct_y_min_max($self->{_data}->get_min_max_y(2)),
+ $self->_correct_y_min_max($y_min[2], $y_max[2]),
$min_range_2,
$self->{y_tick_number}
);
@@ -1844,11 +1860,13 @@ sub val_to_pixel # ($x, $y, $i) in re
my ($x, $y, $i) = @_;
# XXX use_axis
- my $y_min = ($self->{two_axes} && $i == 2) ?
- $self->{y_min}[2] : $self->{y_min}[1];
-
- my $y_max = ($self->{two_axes} && $i == 2) ?
- $self->{y_max}[2] : $self->{y_max}[1];
+ my $y_min = $self->{two_axes}
+ ? $self->{y_min}[$self->{use_axis}[$i-1]]
+ : $self->{y_min}[1];
+
+ my $y_max = $self->{two_axes}
+ ? $self->{y_max}[$self->{use_axis}[$i-1]]
+ : $self->{y_max}[1];
my $y_step = $self->{rotate_chart} ?
abs(($self->{right} - $self->{left})/($y_max - $y_min)) :
diff -up '/usr/local/dist/cpan/build/GDGraph-1.43/MANIFEST' 'MANIFEST'
Index: ./MANIFEST
--- ./MANIFEST Thu Jun 19 08:31:19 2003
+++ ./MANIFEST Thu Nov 13 15:17:06 2003
@@ -57,7 +57,9 @@ samples/sample93.pl
samples/sample94.pl
samples/sample42.dat
samples/sample54.dat
+samples/sample95.pl
samples/save.pl
samples/rgb.txt
samples/logo.png
samples/Makefile
+META.yml Module meta-data (added by MakeMaker)
diff -up /dev/null 'META.yml'
Index: ./META.yml
--- ./META.yml Thu Jan 1 01:00:00 1970
+++ ./META.yml Thu Nov 13 15:17:31 2003
@@ -0,0 +1,12 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
+name: GDGraph
+version: 1.43
+version_from: Graph.pm
+installdirs: site
+requires:
+ GD: 1.18
+ GD::Text: 0.80
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.17
diff -up '/usr/local/dist/cpan/build/GDGraph-1.43/samples/Makefile' 'samples/Makefile'
Index: ./samples/Makefile
--- ./samples/Makefile Fri Jun 20 05:05:37 2003
+++ ./samples/Makefile Thu Nov 13 15:08:05 2003
@@ -6,7 +6,7 @@
# Run the examples by hand, one by one, or do something like
#
# tcsh> foreach s (*.pl)
-# foreach> perl -I. -I../lib -Tw $s
+# foreach> perl -I. -Mblib=.. -Tw $s
# foreach> end
#
# If you use an old version of GD that exports GIF, you will need to
@@ -17,7 +17,7 @@
PERL = perl
EXTRA_OPTS =
-OPTIONS = -I. -I../blib/lib $(EXTRA_OPTS) -w
+OPTIONS = -I. -Mblib=.. $(EXTRA_OPTS) -w
EXT := $(shell perl $(OPTIONS) -MGD::Graph \
-e 'print scalar GD::Graph::export_format')
@@ -34,7 +34,7 @@ SAMPLES := \
sample57 \
sample61 sample62 sample63 \
sample71 \
- sample91 sample92 sample93 sample94
+ sample91 sample92 sample93 sample94 sample95
IMAGES := $(SAMPLES:%=%.$(EXT))
diff -up /dev/null 'samples/sample95.pl'
Index: ./samples/sample95.pl
--- ./samples/sample95.pl Thu Jan 1 01:00:00 1970
+++ ./samples/sample95.pl Thu Nov 13 15:08:43 2003
@@ -0,0 +1,93 @@
+use strict;
+use GD::Graph::bars;
+use GD::Graph::hbars;
+use GD::Graph::Data;
+require 'save.pl';
+
+$GD::Graph::Error::Debug = 5;
+
+my $data = GD::Graph::Data->new(
+[
+ ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
+ [ 5, 12, 24, 33, 19, 8, 6, 15, 21],
+ [ 1, 2, 5, 6, 3, 1.5, 1, 3, 4],
+ [ 2, 4, 4.5, 5, 2.5, 0.5, 1, 2, 3],
+]
+) or die GD::Graph::Data->error;
+
+my $values = $data->copy();
+$values->set_y(1, 7, undef) or warn $data->error;
+$values->set_y(2, 7, undef) or warn $data->error;
+$values->set_y(3, 7, undef) or warn $data->error;
+
+my @names = qw/sample95 sample95-h/;
+
+for my $my_graph (GD::Graph::bars->new(600,400),
+ GD::Graph::hbars->new(600,400))
+{
+ my $name = shift @names;
+ print STDERR "Processing $name\n";
+
+ $my_graph->set(
+ x_label => 'x label',
+ y1_label => 'y1 label',
+ y2_label => 'y2 label',
+ title => 'Using two axes with three datasets',
+ y1_max_value => 40,
+ y2_max_value => 8,
+ y_tick_number => 8,
+ y_label_skip => 2,
+ long_ticks => 1,
+ two_axes => 1,
+ use_axis => [1, 2, 2],
+ legend_placement => 'RT',
+ x_label_position => 1/2,
+
+ bgclr => 'white',
+ fgclr => 'white',
+ boxclr => 'dblue',
+ accentclr => 'dblue',
+ valuesclr => '#ffff77',
+ dclrs => [qw(lgreen lred lred)],
+
+ bar_spacing => 1,
+
+ logo => 'logo.' . GD::Graph->export_format,
+ logo_position => 'BR',
+
+ transparent => 0,
+
+ l_margin => 10,
+ b_margin => 10,
+ r_margin => 10,
+ t_margin => 10,
+
+ show_values => 1,
+ values_format => "%4.1f",
+
+ ) or warn $my_graph->error;
+
+ if ($name =~ /-h$/)
+ {
+ $my_graph->set(x_labels_vertical => 0, values_vertical => 0);
+ $my_graph->set_legend('bottom axis', 'top axis');
+ }
+ else
+ {
+ $my_graph->set(x_labels_vertical => 1, values_vertical => 1);
+ $my_graph->set_legend('left axis', 'right axis');
+ }
+
+ my $font_spec = "../Dustismo_Sans";
+
+ $my_graph->set_y_label_font($font_spec, 12);
+ $my_graph->set_x_label_font($font_spec, 12);
+ $my_graph->set_y_axis_font($font_spec, 10);
+ $my_graph->set_x_axis_font($font_spec, 10);
+ $my_graph->set_title_font($font_spec, 18);
+ $my_graph->set_legend_font($font_spec, 8);
+ $my_graph->set_values_font($font_spec, 8);
+
+ $my_graph->plot($data) or die $my_graph->error;
+ save_chart($my_graph, $name);
+}
#### End of Patch data ####
#### ApplyPatch data follows ####
# Data version : 1.0
# Date generated : Thu Nov 13 15:19:56 2003
# Generated by : makepatch 2.00_07*
# Recurse directories : Yes
# Excluded files : (\A|/).*\~\Z
# (\A|/).*\.a\Z
# (\A|/).*\.bak\Z
# (\A|/).*\.BAK\Z
# (\A|/).*\.elc\Z
# (\A|/).*\.exe\Z
# (\A|/).*\.gz\Z
# (\A|/).*\.ln\Z
# (\A|/).*\.o\Z
# (\A|/).*\.obj\Z
# (\A|/).*\.olb\Z
# (\A|/).*\.old\Z
# (\A|/).*\.orig\Z
# (\A|/).*\.rej\Z
# (\A|/).*\.so\Z
# (\A|/).*\.Z\Z
# (\A|/)\.del\-.*\Z
# (\A|/)\.make\.state\Z
# (\A|/)\.nse_depinfo\Z
# (\A|/)core\Z
# (\A|/)tags\Z
# (\A|/)TAGS\Z
# p 'Graph/axestype.pm' 59159 1068732701 0100644
# p 'MANIFEST' 1056 1068733026 0100644
# c 'META.yml' 0 1068733051 0100644
# p 'samples/Makefile' 2086 1068732485 0100644
# c 'samples/sample95.pl' 0 1068732523 0100755
#### End of ApplyPatch data ####
#### End of Patch kit [created: Thu Nov 13 15:19:56 2003] ####
#### Patch checksum: 264 8534 4226 ####
#### Checksum: 296 9593 27593 ####