Chart
view release on metacpan or search on metacpan
lib/Chart/Bars.pm view on Meta::CPAN
# vertical bars
use v5.12;
package Chart::Bars;
our @ISA = qw(Chart::Base);
our $VERSION = 'v2.403.9';
use Chart::Base;
use GD;
use Carp;
#>>>>>>>>>>>>>>>>>>>>>>>>>>#
# public methods #
#<<<<<<<<<<<<<<<<<<<<<<<<<<#
#>>>>>>>>>>>>>>>>>>>>>>>>>>>#
# private methods #
#<<<<<<<<<<<<<<<<<<<<<<<<<<<#
## _draw_data : plotting the data for (vertical) bars
#
# The user may define the kind of labelling the data by setting
# 'label_values' to 'value' if she wants to have the absolut values
# 'label_values' to 'none' if she wants to have no values (default)
#
sub _draw_data {
my $self = shift;
my $data = $self->{'dataref'};
my $misccolor = $self->_color_role_to_index('misc');
my ( $x1, $x2, $x3, $y1, $y2, $y3 );
my ( $width, $height, $delta1, $delta2, $map, $mod, $cut, $pink );
my ( $i, $j, $color );
my $temp = 0;
my $font = $self->{'legend_font'};
my $fontW = $self->{'legend_font'}->width;
my $fontH = $self->{'legend_font'}->height;
my $textcolor = $self->_color_role_to_index('text');
# init the imagemap data field if they wanted it
if ( $self->true( $self->{'imagemap'} ) )
{
$self->{'imagemap_data'} = [];
}
# find the longest label
# first we need the length of the values
# draw the bars
my $max_label_len = 0;
for $i ( 1 .. $self->{'num_datasets'} )
{
for $j ( 0 .. $self->{'num_datapoints'} )
{
# don't try to draw anything if there's no data
if ( defined( $data->[$i][$j] )
&& $data->[$i][$j] =~ /^[\-\+]{0,1}\s*[\d\.eE\-\+]+/ )
{
if ( defined $self->{'label_values'} && $self->{'label_values'} =~ /^value$/i )
{
my $label = sprintf( "%.2f", $data->[$i][$j] );
my $label_length = length($label);
$max_label_len = $label_length if ( $max_label_len < $label_length );
}
}
}
}
$max_label_len *= $fontH;
# find both delta values ($delta1 for stepping between different
# datapoint names, $delta2 for stepping between datasets for that
# point) and the mapping constant
$width = $self->{'curr_x_max'} - $self->{'curr_x_min'};
$height = $self->{'curr_y_max'} - $self->{'curr_y_min'};
$delta1 =
( $self->{'num_datapoints'} > 0 )
? $width / ( $self->{'num_datapoints'} * 1 )
: $width;
$map =
( ( $self->{'max_val'} - $self->{'min_val'} ) > 0 )
? $height / ( $self->{'max_val'} - $self->{'min_val'} )
: $height;
if ( $self->true( $self->{'spaced_bars'} ) )
{
#OLD: $delta2 = $delta1 / ($self->{'num_datasets'} + 2);
$delta2 =
( ( $self->{'num_datasets'} + 2 ) > 0 )
? $delta1 / ( $self->{'num_datasets'} + 2 )
: $delta1;
}
else
{
$delta2 =
( $self->{'num_datasets'} > 0 )
( run in 0.592 second using v1.01-cache-2.11-cpan-e1769b4cff6 )