NAME

Text::BarGraph - Text Bar graph generator

SYNOPSIS

use Text::BarGraph;

$graph = Text::BarGraph->new();

ABSTRACT

A module to create text bar graphs

DESCRIPTION

This module takes as input a hash, where the keys are labels for bars on a graph and the values are the magnitudes of those bars.

EXAMPLE

$graph = Text::BarGraph->new();

%hash = (
  alpha => 30,
  beta  => 40,
  gamma => 25
);

print $g->graph(\%hash);

METHODS

new
$graph = Text::BarGraph->new();

The constructor.

graph
$graph_text = $graph->graph(\%data);

Return a graph of the data in the supplied hash. The keys in the hash are labels, and the values are the magnitudes.

dot
$graph->dot('.')

Set the character used in the graph.

Default: #

num
$graph->num(0);

Whether to display the numerical value of each bar

Default: 1

sortvalue
$graph->sortvalue("data");

Set what to use to sort the graph. Valid values are "data" and "key". Key sorts by the bar's label, data sorts by the bar's magnitude.

Default: key

sorttype
$graph->sorttype("string");

Whether to sort bar labels as strings or numerically. Valid values are "string" and "numeric". This option is ignored when sorting by 'data'

Default: string

zero
$graph->zero(20);

Sets the initial value (far left) of the graph. Ignored if autozero is set. When zero is non-zero, an extra row will be printed to identify the minimum value.

Default: 0

autozero
$graph->autozero(1);

Automatically choose the initial value (far left) of the graph. Overrides any value set with zero.

Default: 0

max_data
$graph->max_data(1000);

Forces the end of the graph (right side) to be larger than the maximum value in the graph. If the supplied value is less than the maximum value, it will be ignored.

Default: 0

columns
$graph->columns(120);

Set the number of columns to use when displaying the graph. This value is ignored if autosize is used.

Default: 80

autosize
$graph->autosize(0);

Automatically determine the size of the display. Only works if Term::ReadKey is installed and a terminal is detected. Otherwise, the value set by columns is used.

Default: 1

enable_color
$graph->enable_color(1);

Whether to use ANSI color on the bargraph. Uses Term::ANSIColor if it is present.

Default: 0

AUTHOR

Kirk Baucom <kbaucom@schizoid.com>

COPYRIGHT

Copyright (c) 2011 Kirk Baucom. All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself.