Skip Menu |

This queue is for tickets about the Text-Graph CPAN distribution.

Report information
The Basics
Id: 25893
Status: resolved
Priority: 0/
Queue: Text-Graph

People
Owner: cpan.wade [...] anomaly.org
Requestors: jdhedden [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.23
Fixed in: 0.50



Subject: Text::Graph::DataSet not loaded
Thanks for making Text::Graph. It was just what I needed for my project. I did notice a couple of issues: Graph.pm doesn't load Text::Graph::DataSet when needed. Therefore, the first example in the POD: use Text::Graph; my $graph = Text::Graph->new( 'Bar' ); print $graph->to_string( [1,2,4,5,10,3,5], labels => [ qw/aaaa bb ccc dddddd ee f ghi/ ], ); Fails with: Can't locate object method "new" via package "Text::Graph::DataSet" (perhaps you forgot to load "Text::Graph::DataSet"?) at /usr/lib/perl5/5.8/Text/Graph.pm line 126. Also, setting maxlen to (maxval-minval)+1 is not correct. Consider plotting data from 0 to 10. 0 is '', 1 is '*' and so on. In this case, the length of the bar for 10 is 10, but with the +1, maxlen would be 11 and not 10. The attached patch corrects the above and also does the following: Removes the 'line' field and get_line method - not used Removes use of Exporter - not needed because there are no exports Removes TextHistogram example from POD - doesn't exist Avoids calculating $scale when maxlen is not defined - just sets it to 1 Updates version numbers Updates copyrights Other minor whitespace cleanups Looking forward to your next release. Thanks again.
Subject: tg.patch
diff -urN Text-Graph-0.23/Graph/DataSet.pm Text-Graph-patched/Graph/DataSet.pm --- Text-Graph-0.23/Graph/DataSet.pm 2005-02-14 23:43:36.000000000 -0500 +++ Text-Graph-patched/Graph/DataSet.pm 2007-03-28 14:04:46.000000000 -0400 @@ -1,18 +1,9 @@ package Text::Graph::DataSet; use strict; -use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); -require Exporter; - -@ISA = qw(Exporter); -# Items to export into callers namespace by default. Note: do not export -# names by default without a very good reason. Use EXPORT_OK instead. -# Do not simply export all your public functions/methods/constants. -@EXPORT = qw( - -); -$VERSION = '0.2'; +use vars qw($VERSION); +$VERSION = '0.24'; sub new @@ -20,10 +11,10 @@ my $class = shift; my $obj = { values => [], - labels => undef, - hash => undef, - sort => sub { sort @_ } - }; + labels => undef, + hash => undef, + sort => sub { sort @_ } + }; if(@_) { @@ -63,7 +54,7 @@ sub get_labels ($) { my $self = shift; - + wantarray ? @{$self->{labels}} : $self->{labels}; } @@ -85,7 +76,7 @@ $self->{labels} = [ keys %{$self->{hash}} ]; } } - + $self->{values} = [ @{$self->{hash}}{@{$self->{labels}}} ]; } elsif(!defined $self->{labels}) @@ -184,7 +175,7 @@ =head1 COPYRIGHT -Copyright 2004 G. Wade Johnson +Copyright 2004-2007 G. Wade Johnson This module is free software; you can distribute it and/or modify it under the same terms as Perl itself. diff -urN Text-Graph-0.23/Graph.pm Text-Graph-patched/Graph.pm --- Text-Graph-0.23/Graph.pm 2005-06-05 01:43:20.000000000 -0400 +++ Text-Graph-patched/Graph.pm 2007-03-28 14:32:30.000000000 -0400 @@ -1,18 +1,11 @@ package Text::Graph; use strict; -use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); -require Exporter; +use vars qw($VERSION); +$VERSION = '0.24'; -@ISA = qw(Exporter); -# Items to export into callers namespace by default. Note: do not export -# names by default without a very good reason. Use EXPORT_OK instead. -# Do not simply export all your public functions/methods/constants. -@EXPORT = qw( - -); -$VERSION = '0.23'; +use Text::Graph::DataSet; sub new @@ -22,19 +15,19 @@ my $obj = { _initialize($style), # data display - log => 0, - # data limit - maxval => undef, - minval => undef, - maxlen => undef, - # graph display + log => 0, + # data limit + maxval => undef, + minval => undef, + maxlen => undef, + # graph display separator => ' :', - right => 0, - showval => 0, + right => 0, + showval => 0, @_ - }; + }; $obj->{fill} = $obj->{marker} unless defined $obj->{fill}; - + bless $obj, $class; } @@ -48,11 +41,11 @@ if('bar' eq $lstyle) { - ( style => 'Bar', marker => '*', line => ' ' ); + ( style => 'Bar', marker => '*'); } elsif('line' eq $lstyle) { - ( style => 'Line', marker => '*', fill => ' ', line => '.' ); + ( style => 'Line', marker => '*', fill => ' '); } else { @@ -63,7 +56,6 @@ # Data Display Options sub get_marker ($) { $_[0]->{marker}; } sub get_fill ($) { $_[0]->{fill}; } -sub get_line ($) { $_[0]->{line}; } sub is_log ($) { $_[0]->{log}; } # Data Limit Options @@ -107,12 +99,11 @@ sub to_string ($;$) { my $self = shift; - + join( "\n", $self->make_labelled_lines( @_ ) ) . "\n"; } - #-------------------------------------------- # INTERNAL: Convert input parameters to a graph data object as needed. sub _make_graph_data (@) @@ -188,15 +179,19 @@ $parms->{maxval} = $max unless defined $parms->{maxval}; } - $parms->{maxlen} = $parms->{maxval} - $parms->{minval} + 1 - unless defined $parms->{maxlen}; - my $scale = $parms->{maxlen}/($parms->{maxval} - $parms->{minval} + 1); + my $scale; + if (defined $parms->{maxlen}) { + $scale = $parms->{maxlen}/($parms->{maxval} - $parms->{minval}); + } else { + $parms->{maxlen} = $parms->{maxval} - $parms->{minval}; + $scale = 1; + } - @values = map { _makebar( ($_-$parms->{minval})*$scale, - $parms->{marker}, + @values = map { _makebar( ($_-$parms->{minval})*$scale, + $parms->{marker}, $parms->{fill} ) } - map { _make_within( $_, $parms->{minval}, $parms->{maxval} ) } + map { _make_within( $_, $parms->{minval}, $parms->{maxval} ) } @values; if($parms->{showval}) @@ -204,7 +199,7 @@ foreach(0..$#values) { $values[$_] .= (' ' x ($parms->{maxlen}-length $values[$_])) - .' ('. $orig[$_] . ')'; + .' ('. $orig[$_] . ')'; } } @@ -232,7 +227,6 @@ } - #-------------------------------------------- # INTERNAL: This routine expects a number, a minimum, and a maximum. # It returns a number with the range. @@ -277,22 +271,18 @@ Although this approach is B<not> appropriate for all data analysis, it can be useful in some cases. -=head1 AUTHOR - -G. Wade Johnson, wade@anomaly.org - =head1 Functions =head2 new -The list below describes the parameters. +The list below describes the parameters. =over 4 =item * B<minval> - Minimum value cutoff. All values below I<minval> are considered -equal to I<minval>. The default value for I<minval> is 0. Setting the +equal to I<minval>. The default value for I<minval> is 0. Setting the I<minval> to C<undef> causes C<TextHistogram::Bars> to use the minimum of I<values> as I<minval>. @@ -306,16 +296,16 @@ B<maxlen> - Maximum length of a histogram bar. This parameter is used to scale the histogram to a particular size. The default value for I<maxlen> is -(C<maxval - minval + 1>). +(C<maxval - minval>). =item * -B<marker> - Character to be used for the highest point on each bar of the +B<marker> - Character to be used for the highest point on each bar of the histogram. The default value for I<marker> is '*'. =item * -B<fill> - Character to be used for drawing the bar of the histogram, +B<fill> - Character to be used for drawing the bar of the histogram, except the highest point. The default value for I<fill> is the value of I<marker>. @@ -332,7 +322,7 @@ =item * -B<separator> - String which separates the labels from the histogram bars. The +B<separator> - String which separates the labels from the histogram bars. The default value of I<separator> is ' :'. =item * @@ -350,10 +340,6 @@ The C<get_fill> method returns the fill character used for this graph. -=head2 get_line - -The C<get_line> method returns the line character used for this graph. - =head2 is_log The C<is_log> method returns a flag telling whether this is a logarithmic @@ -432,7 +418,6 @@ f :** ghi :**** - =head2 Line Graph of an Array use Text::Graph; @@ -451,7 +436,6 @@ f : * ghi : * - =head2 Bar Graph of an Anonymous Hash use Text::Graph; @@ -501,14 +485,6 @@ =head2 Filled Line Graph With Advanced Formatting - use TextHistogram; - TextHistogram::Print( [1,22,43,500,1000,300,50], - labels => [ qw/aaaa bb ccc dddddd ee f ghi/ ], - right => 1, # right-justify labels - fill => '.', # change fill-marker - log => 1, # logarithmic graph - showval => 1 # show actual values - ); use Text::Graph; use Text::Graph::DataSet; my $dataset = Text::Graph::DataSet->new ([1,22,43,500,1000,300,50], @@ -533,15 +509,17 @@ =head1 SEE ALSO -perl(1). +perl(1) + +=head1 AUTHOR + +G. Wade Johnson, wade@anomaly.org =head1 COPYRIGHT -Copyright 2002-2004 G. Wade Johnson +Copyright 2002-2007 G. Wade Johnson This module is free software; you can distribute it and/or modify it under the same terms as Perl itself. -perl(1). - =cut diff -urN Text-Graph-0.23/t/00Graph_config.t Text-Graph-patched/t/00Graph_config.t --- Text-Graph-0.23/t/00Graph_config.t 2005-02-14 22:54:28.000000000 -0500 +++ Text-Graph-patched/t/00Graph_config.t 2007-03-28 14:00:36.000000000 -0400 @@ -1,7 +1,7 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 29; +use Test::More tests => 26; use Data::Dumper; use Text::Graph; @@ -13,7 +13,6 @@ isa_ok( $graph, 'Text::Graph' ); is( $graph->get_marker, '*', "Default Bar marker" ); is( $graph->get_fill, '*', "Default Bar fill" ); -is( $graph->get_line, ' ', "Default Bar line" ); # test Line construction $graph = Text::Graph->new( 'Line' ); @@ -22,18 +21,15 @@ isa_ok( $graph, 'Text::Graph' ); is( $graph->get_marker, '*', "Default Line marker" ); is( $graph->get_fill, ' ', "Default Line fill" ); -is( $graph->get_line, '.', "Default Line line" ); # Test complete configuration -$graph = Text::Graph->new( 'Bar', marker => '+', fill => '-', line => ',', - log => 1, +$graph = Text::Graph->new( 'Bar', marker => '+', fill => '-', log => 1, maxval => 100, minval => 2, maxlen => 50, separator => ' :: ', right => 1, showval => 1); is( $graph->get_marker, '+', "New marker" ); is( $graph->get_fill, '-', "New fill" ); -is( $graph->get_line, ',', "New line" ); # test Data Display Options ok( $graph->is_log, "is a log graph" ); diff -urN Text-Graph-0.23/t/Graph.t Text-Graph-patched/t/Graph.t --- Text-Graph-0.23/t/Graph.t 2005-02-14 23:00:02.000000000 -0500 +++ Text-Graph-patched/t/Graph.t 2007-03-28 14:00:46.000000000 -0400 @@ -1,12 +1,12 @@ #!/usr/bin/perl -w use strict; -use Test::More tests => 14; +use Test::More tests => 13; use Data::Dumper; BEGIN { use_ok( 'Text::Graph' ); } -can_ok( 'Text::Graph', qw(new get_marker get_fill get_line is_log +can_ok( 'Text::Graph', qw(new get_marker get_fill is_log get_maxlen get_maxval get_minval get_separator is_right_justified show_value make_lines to_string) ); @@ -18,7 +18,6 @@ isa_ok( $graph, 'Text::Graph' ); is( $graph->get_marker, '*', "Default marker" ); is( $graph->get_fill, '*', "Default fill" ); -is( $graph->get_line, ' ', "Default line" ); # test Data Display Options ok( !$graph->is_log, "Default is linear" );
Show quoted text
> Also, setting maxlen to (maxval-minval)+1 is not correct. > > The attached patch corrects the above
Darn. Forgot to update the tests after fixing the +1 issue. Corrected patch is attached.

Message body is not shown because it is too large.

Show quoted text
> Also, setting maxlen to (maxval-minval)+1 is not correct.
Here's an example that illustrates this: use Text::Graph; use Text::Graph::DataSet; my $graph = Text::Graph->new( 'Line', right => 1, fill => '.', minval => 0, maxval => 10, maxlen => 100, ); print $graph->to_string([5.00, 5.01, 5.02, 5.03, 5.04, 5.05, 5.06, 5.07, 5.08, 5.09, 5.10], [5.00, 5.01, 5.02, 5.03, 5.04, 5.05, 5.06, 5.07, 5.08, 5.09, 5.10]); With the original version, it produces: 5 :............................................* 5.01 :.............................................* 5.02 :.............................................* 5.03 :.............................................* 5.04 :.............................................* 5.05 :.............................................* 5.06 :.............................................* 5.07 :.............................................* 5.08 :.............................................* 5.09 :.............................................* 5.1 :.............................................* In the above, the lines are only 45/46 chars long. With the patched version, it produces: 5 :.................................................* 5.01 :.................................................* 5.02 :.................................................* 5.03 :.................................................* 5.04 :.................................................* 5.05 :..................................................* 5.06 :..................................................* 5.07 :..................................................* 5.08 :..................................................* 5.09 :..................................................* 5.1 :..................................................* These lines are 50/51 chars long as you would expect.
From: GWADEJ [...] cpan.org
On Wed Mar 28 14:49:22 2007, JDHEDDEN wrote: Show quoted text
> Thanks for making Text::Graph. It was just what I needed for my > project. I did notice a couple of issues: > > Graph.pm doesn't load Text::Graph::DataSet when needed. Therefore, the > first example in the POD: > > use Text::Graph; > my $graph = Text::Graph->new( 'Bar' ); > print $graph->to_string( [1,2,4,5,10,3,5], > labels => [ qw/aaaa bb ccc dddddd ee f ghi/ ], > ); > > Fails with: > > Can't locate object method "new" via package "Text::Graph::DataSet" > (perhaps you forgot to load "Text::Graph::DataSet"?) at > /usr/lib/perl5/5.8/Text/Graph.pm line 126.
Oops. That probably happened when I factored out Text::Graph::DataSet and I called it in my code and didn't notice. Thanks for finding that. Show quoted text
> Also, setting maxlen to (maxval-minval)+1 is not correct. Consider > plotting data from 0 to 10. 0 is '', 1 is '*' and so on. In this case, > the length of the bar for 10 is 10, but with the +1, maxlen would be 11 > and not 10.
I had intended the length to be inclusive, so in your example I would need 11 items for 0..10. But looking at the code, I can see that the lowest value is not printed (unlike my earlier versions). I hadn't noticed that. Thanks for the report. Show quoted text
> The attached patch corrects the above and also does the following: > > Removes the 'line' field and get_line method - not used > Removes use of Exporter - not needed because there are no exports > Removes TextHistogram example from POD - doesn't exist > Avoids calculating $scale when maxlen is not defined - just sets it to 1 > Updates version numbers > Updates copyrights > Other minor whitespace cleanups
After looking at the code again, I see a lot of little cleanup stuff I need to do. Let me take a look at your patch. I need to decide if I want to patch the code and cleanup later, or just bite the bullet and do it now. Show quoted text
> Looking forward to your next release. Thanks again.
Thanks for taking the time to help with this. G. Wade
This ticket actually described three separate bugs. 1. Text::Graph::DataSet is not loaded automatically when building a Text::Graph from an array. 2. The length associated with the range of data is not consistent with the min/max value. 3. The get_line() method is no longer necessary or used. Version 0.50 fixes all three of these issues.