App-Basis-ConvertText2
view release on metacpan or search on metacpan
lib/App/Basis/ConvertText2/Plugin/Chart.pm view on Meta::CPAN
=head1 NAME
App::Basis::ConvertText2::Plugin::Chart
=head1 SYNOPSIS
my $content = "apples,bananas,cake,cabbage,edam,fromage,tomatoes,chips
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
1,2,3,5,11,22,33,55
" ;
my $params = {
size => "600x480",
title => "chart1",
xaxis => 'things xways',
yaxis => 'Vertical things',
format => 'pie',
legends => 'a,b,c,d,e,f,g,h'
} ;
my $obj = App::Basis::ConvertText2::Plugin::Chart->new() ;
my $out = $obj->process( 'chart', $content, $params) ;
=head1 DESCRIPTION
Convert comma separated text strings into charts image PNG
=cut
# ----------------------------------------------------------------------------
package App::Basis::ConvertText2::Plugin::Chart;
$App::Basis::ConvertText2::Plugin::Chart::VERSION = '0.4';
use 5.10.0;
use strict;
use warnings;
# the different graph types
use GD::Graph::lines;
use GD::Graph::lines3d;
use GD::Graph::bars;
use GD::Graph::bars3d;
use GD::Graph::pie;
use GD::Graph::points;
use GD::Graph::linespoints;
use GD::Graph::area;
use GD::Graph::mixed;
use GD;
use Capture::Tiny qw(capture);
use Path::Tiny;
use Moo;
use App::Basis;
use App::Basis::ConvertText2::Support;
use namespace::autoclean;
has handles => (
is => 'ro',
init_arg => undef,
default => sub { [qw{chart}] }
);
# BEGIN {
# load up the X11 colour names
GD::Graph::colour::read_rgb("/etc/X11/rgb.txt");
# }
# ----------------------------------------------------------------------------
my %_chart_formats = (
mixed => 'GD::Graph::mixed',
area => 'GD::Graph::area',
lines => 'GD::Graph::lines',
points => 'GD::Graph::points',
linespoints => 'GD::Graph::linespoints',
bars => 'GD::Graph::bars',
lines3d => 'GD::Graph::lines3d',
pie => 'GD::Graph::pie'
);
# ----------------------------------------------------------------------------
sub chart_formats {
my @charts = sort keys %_chart_formats;
return @charts;
}
# ----------------------------------------------------------------------------
sub _split_csv_data {
my $data = shift;
my @d = ();
my $j = 0;
foreach my $line ( split( /\n/, $data ) ) {
last if ( !$line );
my @row = split( /,/, $line );
for ( my $i = 0; $i <= $#row; $i++ ) {
undef $row[$i] if ( $row[$i] eq 'undef' );
# dont' bother with any zero values either
undef $row[$i] if ( $row[$i] =~ /^0\.?0?$/ );
push @{ $d[$j] }, $row[$i];
}
$j++;
}
return @d;
}
# ----------------------------------------------------------------------------
=item chart
( run in 0.908 second using v1.01-cache-2.11-cpan-39bf76dae61 )