G. Wade Johnson > Text-Graph-0.23 > Text::Graph

Download:
Text-Graph-0.23.tar.gz

Dependencies

Annotate this POD (1)

CPAN RT

Open  1
View/Report Bugs
Module Version: 0.23   Source  

NAME ^

Text::Graph - Perl extension for generating text-based graphs.

SYNOPSIS ^

  use Text::Graph;
  blah blah blah

DESCRIPTION ^

Some data is easier to analyze graphically than in its raw form. In many cases, however, a full-blown multicolor graphic representation is overkill. In these cases, a simple graph can provide an appropriate graphical representation.

The Text::Graph module provides a simple text-based graph of a dataset. Although this approach is not appropriate for all data analysis, it can be useful in some cases.

AUTHOR ^

G. Wade Johnson, wade@anomaly.org

Functions ^

new

The list below describes the parameters.

get_marker

The get_marker method returns the marker associated with this graph.

get_fill

The get_fill method returns the fill character used for this graph.

get_line

The get_line method returns the line character used for this graph.

is_log

The is_log method returns a flag telling whether this is a logarithmic graph (true) or linear graph (false).

get_maxlen

The get_maxlen method returns the maximum length of the graph this value is used to scale the graph.

get_maxval

The get_maxval method returns the maximum value cutoff defined for this graph. A value of undef means the graph is not cut off.

get_minval

The get_minval method returns the minimum value cutoff defined for this graph. A value of undef means the graph is not cut off.

get_separator

The get_separator method returns the string used to separate the labels from the graph.

is_right_justified

The get_separator method returns true if the labels are right justified, false otherwise.

show_value

The show_value method returns true if the actual values are shown next to the bars, false otherwise.

make_lines

The make_lines method converts a dataset into a list of strings representing the dataset. The make_lines takes either a Text::Graph::DataSet object or the parameters needed to construct such an object. If used in array context, it returns an array of bars. If used in scalar context, it returns a reference to an array of bars.

make_labelled_lines

The make_lines method converts a dataset into a list of strings representing the dataset. The make_lines takes either a Text::Graph::DataSet object or the parameters needed to construct such an object. Unlike make_lines, each line in this returned list is labelled as described in the Text::Graph::DataSet object. If used in array context, it returns an array of bars. If used in scalar context, it returns a reference to an array of bars.

to_string

The to_string method creates a displayable Graph for the supplied dataset. The Graph is labelled as specified in the DataSet. The to_string method accepts all of the same parameters as make_lines.

Examples ^

Bar Graph of an Array

  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/ ],
                         );

Generates the following output:

  aaaa   :
  bb     :*
  ccc    :***
  dddddd :****
  ee     :*********
  f      :**
  ghi    :****

Line Graph of an Array

  use Text::Graph;
  my $graph = Text::Graph->new( 'Line' );
  print $graph->to_string( [1,2,4,5,10,3,5],
                           labels => [ qw/aaaa bb ccc dddddd ee f ghi/ ],
                         );

Generates the following output:

  aaaa   :
  bb     :*
  ccc    :  *
  dddddd :   *
  ee     :        *
  f      : *
  ghi    :   *

Bar Graph of an Anonymous Hash

  use Text::Graph;
  my $graph = Text::Graph->new( 'Bar' );
  print $graph->to_string( { a=>1, b=>5, c=>20, d=>10, e=>17 } );

Generates the following output:

  a :
  b :****
  c :*******************
  d :*********
  e :****************

Bar Graph of an Anonymous Hash in Reverse Order

  use Text::Graph;
  use Text::Graph::DataSet;
  my $graph = Text::Graph->new( 'Bar' );
  my $dataset = Text::Graph::DataSet->new ({ a=>1, b=>5, c=>20, d=>10, e=>17 },
                                        sort => sub { sort { $b cmp $a } @_ });
  print $graph->to_string( $dataset );

Generates the following output:

  e :****************
  d :*********
  c :*******************
  b :****
  a :

Bar Graph of Part of an Anonymous Hash

  use Text::Graph;
  use Text::Graph::DataSet;
  my $graph = Text::Graph->new( 'Bar' );
  my $dataset = Text::Graph::DataSet->new ({ a=>1, b=>5, c=>20, d=>10, e=>17 },
                                        labels => [ qw(e b a d) ]);
  print $graph->to_string( $dataset );

Generates the following output:

  e :****************
  b :****
  a :
  d :*********

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],
                                        [ qw/aaaa bb ccc dddddd ee f ghi/ ]);
  my $graph = Text::Graph->new( 'Line',
                                right  => 1,    # right-justify labels
                                fill => '.',    # change fill-marker
                                log => 1,       # logarithmic graph
                                showval => 1    # show actual values
                              );
  print $graph->to_string( $dataset );

Generates the following output:

    aaaa :        (1)
      bb :.*      (22)
     ccc :..*     (43)
  dddddd :....*   (500)
      ee :.....*  (1000)
       f :....*   (300)
     ghi :..*     (50)

SEE ALSO ^

perl(1).

COPYRIGHT ^

Copyright 2002-2004 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).

syntax highlighting: