SimpleGraph - A class for creating ASCII graphs. Example:

Values: 0.5:1:2:3:0:4:5:6:7:0:-7:-6:-5:-4:0:-3:-2:-1:-0.5.
Legend values: -6:-4:-2:0:2:4:6.
MakeSimpleASCIIGraphV3(
                {
                        screen_height => 7,
                        #roof_value => 6,
                        bottom_value => -6,
                        floor_value => 0,
                        bar_char => q{ },
                        floor_char => q{-},
                        write_floor => TRUE,
                        use_floor => TRUE,
                        write_floor_value => TRUE,
                        write_legend => 1,
                        legend_horizontal_width => 3,
                        horizontal_width => 3,
                        write_value => TRUE,
                        write_always_over_value => TRUE,
                        write_always_under_value => TRUE,
                        legend_values => \@legend_values,
                        use_legend_values => TRUE
                }, @values);
Graph:
6                        6  7                               .
4                  4  5  |  |                               .
2         2  3     |  |  |  |                               .
0  0.5 1  |  |  0  |  |  |  |  0  |  |  |  |  0  |  | -1 -0.5.
-2                                |  |  |  |    -3 -2       .
-4                                |  | -5 -4                .
-6                               -7 -6                      .

Module SimpleGraph

use 5.010;

use strict;
use utf8;
use warnings;
use diagnostics;
require Debug::SimpleOptional;

if(!defined($::DBG)) {
        $::DBG = Debug::SimpleOptional->new();
}
$::DBG->debug('DEBUG', "Debugging active in file \"" . __FILE__ . "\".\n");
#$::DBG->debug('TRACE', "Tracing active in file \"" . __FILE__ . "\".\n");
#$::DBG->debug('INFO', "Printing info active in file \"" . __FILE__ . "\".\n");
#$::DBG->debug('WARN', "Printing warnings active in file \"" . __FILE__ . "\".\n");
#$::DBG->debug('ERROR', "Printing errors active in file \"" . __FILE__ . "\".\n");
#$::DBG->debug('FATAL', "Printing fatals active in file \"" . __FILE__ . "\".\n");
$::DBG->debug('DEBUG', sub {use Data::Dumper;});

use Carp;

require "center_text.pl";

# parameters: SCREEN_HEIGHT, ROOF_VALUE (active if != 0), BOTTOM_VALUE (below floor, active if != 0), HORIZONTAL_WIDTH, VALUES
# Note: Crashes if values contain only zeroes!
sub MakeSimpleASCIIGraphV1 {
	$::DBG->enter_sub();
	$::DBG->debug('DEBUG', "Parameters: " . join(":", @_) . "\".\n");
	my $screen_height = shift @_;
	my $roof_value = shift @_;
	my $bottom_value = shift @_; # Not yet implemented.
	my $horizontal_width = shift @_;
	my @values = @_;
	my $bar_char = "|";
	my $horizontal_width_empty = "";
	for(my $i = $horizontal_width; $i > 0; $i--) {
		$horizontal_width_empty .= " ";
	}

	my @output_rows;
	if(scalar(@values) >= 1) {
		my $top_value = 0;
		if($roof_value != 0) {
			$top_value = $roof_value;
		}
		else {
			$::DBG->debug('DEBUG', "Find out the biggest value.\n");
			foreach my $value (@values) {
				if($value > $top_value) {
					$top_value = $value;
				}
			}
		}
		$::DBG->debug('DEBUG', "Var \$top_value=" . $top_value . "\".\n");
		my $rows_for_one = $screen_height / $top_value;
		$::DBG->debug('DEBUG', "Var \$rows_for_one=" . $rows_for_one . "\".\n");
		for(my $i_per_day = 0; $i_per_day < scalar(@values); $i_per_day++) {
			my $value = $values[$i_per_day];
			for(my $i_row = $screen_height - 1; $i_row >= 0; $i_row--) {
				if($value != 0) {
					if($i_row > int($rows_for_one * $value + 0.5) - 1 && $i_row == 0) {
						$output_rows[$i_row] .= CenterText($value, $horizontal_width, " ", "right");
					}
					elsif($i_row > int($rows_for_one * $value + 0.5) - 1) {
						$output_rows[$i_row] .= $horizontal_width_empty;
					}
					elsif($i_row == int($rows_for_one * $value + 0.5 - 1)) {
						$output_rows[$i_row] .= CenterText($value, $horizontal_width, " ", "right");
					}
					elsif($i_row < int($rows_for_one * $value + 0.5 - 1)) {
						$output_rows[$i_row] .= CenterText($bar_char, $horizontal_width, " ", "right");
					}
					else {
						$::DBG->debug('DEBUG', "Control has entered an if clause which is undefined. Line " . __LINE__ . "\".\n");
					}
				}
				else { # $value == 0
					$output_rows[$i_row] .= $horizontal_width_empty;
				}
			}
		}
		# Now we have to flip the order!
		my @reversed_rows;
		for(my $i = $screen_height - 1; $i >= 0; $i--) {
			push(@reversed_rows, $output_rows[$i]);
		}
		@output_rows = @reversed_rows;
	}
	$::DBG->exit_sub();
	return @output_rows;
}

# parameters: SCREEN_HEIGHT, ROOF_VALUE (active if != 0), BOTTOM_VALUE (below floor, active if != 0), LEGEND_HORIZONTAL_WIDTH, HORIZONTAL_WIDTH, WRITE_VALUE (YES = 1, NO = 0), VALUES
# Note: Crashes if values contain only zeroes!
sub MakeSimpleASCIIGraphV2 {
	$::DBG->enter_sub();
	$::DBG->debug('DEBUG', "Parameters: " . join(":", @_) . "\".\n");
	my $screen_height = shift @_;
	my $roof_value = shift @_;
	my $bottom_value = shift @_; # Not yet implemented.
	my $legend_horizontal_width = shift @_;
	my $write_value = shift @_;
	my $horizontal_width = shift @_;
	my @values = @_;
	my $bar_char = "|";
	my $horizontal_width_empty = "";
	for(my $i = $horizontal_width; $i > 0; $i--) {
		$horizontal_width_empty .= " ";
	}

	my @output_rows;
	if(scalar(@values) >= 1) {
		my $top_value = 0;
		if($roof_value != 0) {
			$top_value = $roof_value;
		}
		else {
			$::DBG->debug('DEBUG', "Find out the biggest value.\n");
			foreach my $value (@values) {
				if($value > $top_value) {
					$top_value = $value;
				}
			}
		}
		$::DBG->debug('DEBUG', "Var \$top_value=" . $top_value . "\".\n");
		my $rows_for_one = $screen_height / $top_value;
		$::DBG->debug('DEBUG', "Var \$rows_for_one=" . $rows_for_one . "\".\n");
		my $amount_per_row = $top_value / $screen_height;
		$::DBG->debug('DEBUG', "Var \$amount_per_row=" . $amount_per_row . "\".\n");
		# Make a legend of top value on each row
		my $sprf_format = "\%-" . $legend_horizontal_width . "s";
		$::DBG->debug('DEBUG', "Var \$sprf_format=" . $sprf_format . "\".\n");
		for(my $i_row = $screen_height - 1; $i_row >= 0; $i_row--) {
			$output_rows[$i_row] .= sprintf $sprf_format, int(($i_row + 1) * $amount_per_row + 0.5);
		}
		# Now the values
		for(my $i_per_day = 0; $i_per_day < scalar(@values); $i_per_day++) {
			my $value = $values[$i_per_day];
			for(my $i_row = $screen_height - 1; $i_row >= 0; $i_row--) {
				if($value != 0) {
					if($i_row > int($rows_for_one * $value + 0.5) - 1 && $i_row == 0) {
						$output_rows[$i_row] .= CenterText($write_value ? $value : $bar_char, $horizontal_width, " ", "right");
					}
					elsif($i_row > int($rows_for_one * $value + 0.5) - 1) {
						$output_rows[$i_row] .= $horizontal_width_empty;
					}
					elsif($i_row == int($rows_for_one * $value + 0.5 - 1)) {
						$output_rows[$i_row] .= CenterText($write_value ? $value : $bar_char, $horizontal_width, " ", "right");
					}
					elsif($i_row < int($rows_for_one * $value + 0.5 - 1)) {
						$output_rows[$i_row] .= CenterText($bar_char, $horizontal_width, " ", "right");
					}
					else {
						$::DBG->debug('DEBUG', "Control has entered an if clause which is undefined. Line " . __LINE__ . "\".\n");
					}
				}
				else { # $value == 0
					$output_rows[$i_row] .= $horizontal_width_empty;
				}
			}
		}
		# Now we have to flip the order!
		my @reversed_rows;
		for(my $i = $screen_height - 1; $i >= 0; $i--) {
			push(@reversed_rows, $output_rows[$i]);
		}
		@output_rows = @reversed_rows;
	}
	$::DBG->exit_sub();
	return @output_rows;
}


# parameters: 
# SCREEN_HEIGHT, (height reserved for the graph.)
# ROOF_VALUE (active if != 0), # Arbitrarily squeeze or extend the size (height) of bars (not screen)
# BOTTOM_VALUE (below floor, active if != 0), # Not yet implemented.
# FLOOR_VALUE (default zero, )
# BAR_CHAR (default '|')
# FLOOR_CHAR (default '-' )
# WRITE_FLOOR
# USE_FLOOR
# WRITE_FLOOR_VALUE # If value == floor_value, then write value (mostly "0").
# WRITE_LEGEND (Prepend legend to each row.)
# LEGEND_HORIZONTAL_WIDTH, 
# HORIZONTAL_WIDTH, 
# WRITE_VALUE (YES = 1, NO = 0, default: no),
# WRITE_ALWAYS_OVER_VALUE (YES = 1, NO = 0, default: yes),
# WRITE_ALWAYS_UNDER_VALUE (YES = 1, NO = 0, default: yes),
# LEGEND_VALUES (pointer to array)
# USE_LEGEND_VALUES
# VALUES (the rest of parameter array)
# Note: Crashes if values contain only zeroes!

# Always create the legend first so you know which rows have which values!
# If user gives the legend values (parameter LEGEND_VALUES) 
# and demands their use (parameter USE_LEGEND_VALUES),
# then all the better for you (no need to calculate the legend yourself).
# But only print the legend if user demands it (parameter WRITE_LEGEND).

sub MakeSimpleASCIIGraphV3 {
	$::DBG->enter_sub();

	my $parameter_tags = shift @_;

	my $screen_height = 10;
	if(exists $parameter_tags->{'screen_height'}) {
		$screen_height = $parameter_tags->{'screen_height'};
	}
	$::DBG->debug('DEBUG', "Var \$screen_height=" . $screen_height . "\".\n");

	my $roof_value = 0;
	if(exists $parameter_tags->{'roof_value'}) {
		$roof_value = $parameter_tags->{'roof_value'};
	}
	$::DBG->debug('DEBUG', "Var \$roof_value=" . $roof_value . "\".\n");

	my $bottom_value = 0;
	if(exists $parameter_tags->{'bottom_value'}) {
		$roof_value = $parameter_tags->{'bottom_value'};
	}
	$::DBG->debug('DEBUG', "Var \$bottom_value=" . $bottom_value . "\".\n");

	my $floor_value = 0;
	if(exists $parameter_tags->{'floor_value'}) {
		$roof_value = $parameter_tags->{'floor_value'};
	}
	$::DBG->debug('DEBUG', "Var \$floor_value=" . $floor_value . "\".\n");

	my $write_floor = 0;
	if(exists $parameter_tags->{'write_floor'}) {
		$write_floor = $parameter_tags->{'write_floor'};
	}
	$::DBG->debug('DEBUG', "Var \$write_floor=" . $write_floor . "\".\n");

	my $use_floor = 0;
	if(exists $parameter_tags->{'use_floor'}) {
		$use_floor = $parameter_tags->{'use_floor'};
	}
	$::DBG->debug('DEBUG', "Var \$use_floor=" . $use_floor . "\".\n");

	my $write_floor_value = 0;
	if(exists $parameter_tags->{'write_floor_value'}) {
		$write_floor_value = $parameter_tags->{'write_floor_value'};
	}
	$::DBG->debug('DEBUG', "Var \$write_floor_value=" . $write_floor_value . "\".\n");

	my $write_legend = 0;
	if(exists $parameter_tags->{'write_legend'}) {
		$write_legend = $parameter_tags->{'write_legend'};
	}
	$::DBG->debug('DEBUG', "Var \$write_legend=" . $write_legend . "\".\n");

	my $legend_horizontal_width = 5;
	if(exists $parameter_tags->{'legend_horizontal_width'}) {
		$legend_horizontal_width = $parameter_tags->{'legend_horizontal_width'};
	}
	$::DBG->debug('DEBUG', "Var \$legend_horizontal_width=" . $legend_horizontal_width . "\".\n");

	my $horizontal_width = 5;
	if(exists $parameter_tags->{'horizontal_width'}) {
		$horizontal_width = $parameter_tags->{'horizontal_width'};
	}
	$::DBG->debug('DEBUG', "Var \$horizontal_width=" . $horizontal_width . "\".\n");

	my $write_value = 0;
	if(exists $parameter_tags->{'write_value'}) {
		$write_value = $parameter_tags->{'write_value'};
	}
	$::DBG->debug('DEBUG', "Var \$write_value=" . $write_value . "\".\n");

	my $write_always_over_value = 0;
	if(exists $parameter_tags->{'write_always_over_value'}) {
		$write_always_over_value = $parameter_tags->{'write_always_over_value'};
	}
	$::DBG->debug('DEBUG', "Var \$write_always_over_value=" . $write_always_over_value . "\".\n");

	my $write_always_under_value = 0;
	if(exists $parameter_tags->{'write_always_under_value'}) {
		$write_always_under_value = $parameter_tags->{'write_always_under_value'};
	}
	$::DBG->debug('DEBUG', "Var \$write_always_under_value=" . $write_always_under_value . "\".\n");

	my $legend_values_p = 0;
	if(exists $parameter_tags->{'legend_values'}) {
		$legend_values_p = $parameter_tags->{'legend_values'};
	}
	$::DBG->debug('DEBUG', "Var \$legend_values_p=" . $legend_values_p . "\".\n");

	my $use_legend_values = 0;
	if(exists $parameter_tags->{'use_legend_values'}) {
		$use_legend_values = $parameter_tags->{'use_legend_values'};
	}
	$::DBG->debug('DEBUG', "Var \$use_legend_values=" . $use_legend_values . "\".\n");

	my $bar_char = "|";
	if(exists $parameter_tags->{'bar_char'}) {
		$bar_char = $parameter_tags->{'bar_char'};
	}
	$::DBG->debug('DEBUG', "Var \$bar_char=" . $bar_char . "\".\n");

	my $floor_char = "-";
	if(exists $parameter_tags->{'floor_char'}) {
		$floor_char = $parameter_tags->{'floor_char'};
	}
	$::DBG->debug('DEBUG', "Var \$floor_char=" . $floor_char . "\".\n");

	my @values = @_;
	my @legend_values = ();
	if($legend_values_p) {
		foreach my $legend_value (@{$legend_values_p}) {
			# $::DBG->debug('DEBUG', "Var \$legend_value=" . $legend_value . "\".\n");
			push @legend_values, $legend_value
		}
	}
	my $horizontal_width_empty = "";
	for(my $i = $horizontal_width; $i > 0; $i--) {
		$horizontal_width_empty .= " ";
	}

	my @output_rows;
	# If user wants, write only the legend.

	my $sprf_format = "\%-" . $legend_horizontal_width . "s";
	$::DBG->debug('DEBUG', "Var \$sprf_format=" . $sprf_format . ".\n");
	if($use_legend_values == 1) {
		if(scalar(@legend_values) != $screen_height) {
			croak("Screen height must be equal to number of legend values!");
		}
		@legend_values = sort {$a <=> $b} @legend_values; # Sort them to be sure
	}
	else {
		my $highest_value = 0;
		if($roof_value != 0) {
			$highest_value = $roof_value;
		}
		else {
			$::DBG->debug('DEBUG', "Find out the highest value.\n");
			foreach my $value (@values) {
				if($value > $highest_value) {
					$highest_value = $value;
				}
			}
		}
		my $lowest_value = 0;
		if($bottom_value != 0) {
			$lowest_value = $bottom_value;
		}
		else {
			$::DBG->debug('DEBUG', "Find out the lowest value.\n");
			foreach my $value (@values) {
				if($value < $lowest_value) {
					$lowest_value = $value;
				}
			}
		}
		$::DBG->debug('DEBUG', "Var \$highest_value=" . $highest_value . ".\n");
		my $rows_for_one = $screen_height / $highest_value;
		$::DBG->debug('DEBUG', "Var \$rows_for_one=" . $rows_for_one . ".\n");
		my $amount_per_row = $highest_value / $screen_height;
		$::DBG->debug('DEBUG', "Var \$amount_per_row=" . $amount_per_row . ".\n");

		# Make a legend based on lowest and highest value in @values
		my $screen_top_row = $screen_height - 1;
		my $screen_bottom_row = 0;
		for(my $i_row = $screen_bottom_row; $i_row <= $screen_top_row; $i_row++) {
			push @legend_values, (sprintf $sprf_format, int(($i_row + 1) * $amount_per_row + 0.5));
		}
	}
	$::DBG->debug('DEBUG', sub {print "[DEBUG] Var \@legend_values=" . (join ":", @legend_values) . ".\n"});
	if($write_legend == 1) {
		for(my $i_row = $screen_height - 1; $i_row >= 0; $i_row--) {
			#$output_rows[$i_row] .= $legend_values[$i_row];
			#$output_rows[$i_row] .= CenterText($legend_values[$i_row], $legend_horizontal_width, " ", "right");
			#$output_rows[$i_row] .= CenterText($bar_char, $horizontal_width, " ", "right");
			$output_rows[$i_row] .= sprintf $sprf_format, int($legend_values[$i_row]);
			$::DBG->debug('DEBUG', sub {$output_rows[$i_row] .=  ".";});
			
		}
	}

	# Now the values
	# We write one pillar at a time: one value = one pillar!
	# So, we write from left to right, one pillar at a time!
	# We write the pillar starting from the bottom.
	my $screen_top_row = $screen_height - 1;
	my $screen_bottom_row = 0;
	my $screen_floor_row = $screen_bottom_row;
	if($use_floor == 1) {
		for(my $i_legend_row = 0; $i_legend_row < @legend_values; $i_legend_row++) {
			if($legend_values[$i_legend_row] == $floor_value) {
				$screen_floor_row = $i_legend_row;
			}
		}
	}
	$::DBG->debug('DEBUG', "Var \$screen_floor_row=" . $screen_floor_row . ".\n");
	foreach my $value (@values) {
		$::DBG->debug('DEBUG', "Var \$value=" . $value . ".\n");
		for(my $i_row = $screen_bottom_row; $i_row <= $screen_top_row; $i_row++) {
			if($value != $floor_value) { # If value == 0, just write spaces. TODO
				#$::DBG->debug('DEBUG', "Var \$i_row=" . $i_row . ".\n");
				if($i_row == $screen_bottom_row) { # Bottom row
					$::DBG->debug('DEBUG', "Screen Bottom row.\n");
					if($i_row < $screen_floor_row) {
						$::DBG->debug('DEBUG', 'Var $i_row < $screen_floor_row' . ":". $i_row ."<". $screen_floor_row . ".\n");
						if($value > $legend_values[$i_row]) { # Write empty space
							$::DBG->debug('DEBUG', 'Var $value > $legend_values[$i_row] && $value < $floor_value' . ":". $value .">". $legend_values[$i_row] .  "&&" . $value ."<". $floor_value . ".\n");
							$output_rows[$i_row] .= $horizontal_width_empty;
						}
						elsif($value <= $legend_values[$i_row]) { # Write value
							$::DBG->debug('DEBUG', '$value <= $legend_values[$i_row]' . ":". $value ."<=". $legend_values[$i_row] . ".\n");
							$output_rows[$i_row] .= CenterText($write_value ? $value : $bar_char, $horizontal_width, " ", "right");
						}
						else {
							$::DBG->debug('DEBUG', "Control has entered an if clause which is undefined. Line " . __LINE__ . "\".\n");
						}
					}
					elsif($i_row >= $screen_floor_row) {
						$::DBG->debug('DEBUG', 'Var $i_row > $screen_floor_row' . ":". $i_row .">". $screen_floor_row . ".\n");
						if($value >= $legend_values[$i_row + 1]) { # Write bar char
							$::DBG->debug('DEBUG', 'Var $value >= $legend_values[\$i_row + 1]' . ":". $value .">=". $legend_values[$i_row + 1] . ".\n");
							$output_rows[$i_row] .= CenterText($bar_char, $horizontal_width, " ", "right");
						}
						elsif($value >= $legend_values[$i_row] && $value < $legend_values[$i_row + 1]) { # Write value
							$::DBG->debug('DEBUG', '$value >= $legend_values[$i_row - 1] && $value < $legend_values[$i_row]' . ":". $value .">=". $legend_values[$i_row - 1] ."&&". $value ."<". $legend_values[$i_row] . ".\n");
							$output_rows[$i_row] .= CenterText($write_value ? $value : $bar_char, $horizontal_width, " ", "right");
						}
						elsif($value < $legend_values[$i_row] && $value >= $floor_value) { # Write value maybe
							$::DBG->debug('DEBUG', 'Var $value < $legend_values[\$i_row] && $value >= $floor_value' . ":". $value ."<". $legend_values[$i_row] ."&&". $value .">=". $floor_value . ".\n");
							$output_rows[$i_row] .= CenterText(
									$write_always_under_value ? $value : '',
									$horizontal_width, " ", "right");
						}
						elsif($value < $legend_values[$i_row] && $value < $floor_value) { # Write value
							$::DBG->debug('DEBUG', 'Var $value < $legend_values[\$i_row] && $value >= $floor_value' . ":". $value ."<". $legend_values[$i_row] ."&&". $value .">=". $floor_value . ".\n");
							$output_rows[$i_row] .= CenterText($write_value ? $value : $bar_char, $horizontal_width, " ", "right");
						}
						else {
							$::DBG->debug('DEBUG', "Control has entered an if clause which is undefined. Line " . __LINE__ . "\".\n");
						}
					}
					else {
						$::DBG->debug('DEBUG', "Control has entered an if clause which is undefined. Line " . __LINE__ . "\".\n");
					}
				}

				# (Possible) middle rows (floor down)
				elsif($i_row < $screen_floor_row && $i_row > $screen_bottom_row) {
					$::DBG->debug('DEBUG', "Screen Middle row (floor down).\n");
					if($value <= $legend_values[$i_row - 1]) { # Write bar char
						$::DBG->debug('DEBUG', 'Var $value <= $legend_values[\$i_row + 1]' . ":". $value ."<=". $legend_values[$i_row + 1] . ".\n");
						$output_rows[$i_row] .= CenterText($bar_char, $horizontal_width, " ", "right");
					}
					elsif($value <= $legend_values[$i_row] && $value > $legend_values[$i_row - 1]) { # Write value
						$::DBG->debug('DEBUG', '$value <= $legend_values[$i_row - 1] && $value > $legend_values[$i_row]' . ":". $value ."<=". $legend_values[$i_row - 1] ."&&". $value .">". $legend_values[$i_row] . ".\n");
						$output_rows[$i_row] .= CenterText($write_value ? $value : $bar_char, $horizontal_width, " ", "right");
					}
					elsif($value > $legend_values[$i_row]) { # Write white space
						$::DBG->debug('DEBUG', 'Var $value > $legend_values[\$i_row]' . ":". $value .">". $legend_values[$i_row] . ".\n");
						$output_rows[$i_row] .= $horizontal_width_empty;
					}
					else {
						$::DBG->debug('DEBUG', "Control has entered an if clause which is undefined. Line " . __LINE__ . "\".\n");
					}
				}

				# Floor row
				elsif($i_row == $screen_floor_row) {
					$::DBG->debug('DEBUG', "Screen Middle row (floor up).\n");
					if($write_floor == 1) {
						$output_rows[$i_row] .= CenterText('-', $horizontal_width, "-", "right");
					}
					else {
						if($value > $legend_values[$i_row - 1] && $value < $legend_values[$i_row + 1]) { # Write value
							$::DBG->debug('DEBUG', '$value >= $legend_values[$i_row - 1] && $value < $legend_values[$i_row]' . ":". $value .">=". $legend_values[$i_row - 1] ."&&". $value ."<". $legend_values[$i_row] . ".\n");
							$output_rows[$i_row] .= CenterText($write_value ? $value : $bar_char, $horizontal_width, " ", "right");
						}
						else { # Write bar char
							$::DBG->debug('DEBUG', 'Var $value >= $legend_values[\$i_row + 1]' . ":". $value .">=". $legend_values[$i_row + 1] . ".\n");
							$output_rows[$i_row] .= CenterText($bar_char, $horizontal_width, " ", "right");
						}
					}
				}

				# (Possible) middle rows (floor up)
				elsif($i_row > $screen_floor_row && $i_row < $screen_top_row) {
					$::DBG->debug('DEBUG', "Screen Middle row (floor up).\n");
					if($value >= $legend_values[$i_row + 1]) { # Write bar char
						$::DBG->debug('DEBUG', 'Var $value >= $legend_values[\$i_row + 1]' . ":". $value .">=". $legend_values[$i_row + 1] . ".\n");
						$output_rows[$i_row] .= CenterText($bar_char, $horizontal_width, " ", "right");
					}
					elsif($value >= $legend_values[$i_row] && $value < $legend_values[$i_row + 1]) { # Write value
						$::DBG->debug('DEBUG', '$value >= $legend_values[$i_row - 1] && $value < $legend_values[$i_row]' . ":". $value .">=". $legend_values[$i_row - 1] ."&&". $value ."<". $legend_values[$i_row] . ".\n");
						$output_rows[$i_row] .= CenterText($write_value ? $value : $bar_char, $horizontal_width, " ", "right");
					}
					elsif($value < $legend_values[$i_row]) { # Write white space
						$::DBG->debug('DEBUG', 'Var $value < $legend_values[\$i_row]' . ":". $value ."<". $legend_values[$i_row] . ".\n");
						$output_rows[$i_row] .= $horizontal_width_empty;
					}
					else {
						$::DBG->debug('DEBUG', "Control has entered an if clause which is undefined. Line " . __LINE__ . "\".\n");
					}
				}

				# Top row, here value is only >= or debug('DEBUG', "Screen Top row.\n");
					if($value >= $legend_values[$i_row]) { # Write value or bar char
						$::DBG->debug('DEBUG', 'Var $value >= $legend_values[\$i_row]' . ":". $value .">=". $legend_values[$i_row] . ".\n");
						$output_rows[$i_row] .= CenterText(
								$write_always_over_value ? $value : ($write_value ? $value : $bar_char),
								$horizontal_width, " ", "right");
					}
					elsif($value < $legend_values[$i_row]) { # Write white space
						$::DBG->debug('DEBUG', 'Var $value < $legend_values[\$i_row] && $value >= $floor_value' . ":". $value ."<". $legend_values[$i_row] ."&&". $value .">=". $floor_value . ".\n");
						$output_rows[$i_row] .= $horizontal_width_empty;
					}
					else {
						$::DBG->debug('DEBUG', "Control has entered an if clause which is undefined. Line " . __LINE__ . "\".\n");
					}
				}
				else {
					$::DBG->debug('DEBUG', "Control has entered an if clause which is undefined. Line " . __LINE__ . "\".\n");
				}
			}
			else { # $value == $floor_value
				if($floor_value == $legend_values[$i_row]) { # This is the floor row, the "0" row.
					if($write_floor_value == 1) {
						$output_rows[$i_row] .= CenterText($value, $horizontal_width, " ", "right");
					}
					elsif($write_floor) {
						$output_rows[$i_row] .= CenterText($floor_char, $horizontal_width, " ", "right");
					}
					else {
						$output_rows[$i_row] .= $horizontal_width_empty;
					}
				}
				else {
					$output_rows[$i_row] .= $horizontal_width_empty;
				}
			}
		}
	}
	# Now we have to flip the order!
	my @reversed_rows;
	for(my $i = $screen_height - 1; $i >= 0; $i--) {
		push(@reversed_rows, $output_rows[$i]);
	}
	@output_rows = @reversed_rows;

	$::DBG->exit_sub(@output_rows);
	return @output_rows;
}




=head1 BUGS

=cut

=head1 AUTHOR

        Mikko Koivunalho

=cut

=head1 OWNER

        Copyright (C) Mikko Koivunalho

=head1 CHANGES

=cut


Copyright © Mikko Johannes Koivunalho 2008-2010
email: mikko.koivunalho@iki.fi, homepage: http://koivunalho.kapsi.fi/mikko/index.html

This page last updated or changed 14.01.2010.