package ChartMaker;
use lib (
'/home/raj/perl5/lib/perl5',
'/home/raj/perl-lib/ChartDirector',
);
use FindBin; # warn $FindBin::Bin;
use Modern::Perl qw(2012); # 5.14
use perlchartdir;
use autodie;
use Moo;
use MooX::Types::MooseLike::Base qw(HashRef Str);
has $_ => ( is => 'ro', isa => Str, required => 1)
for qw(data_title chart_title x_title y_title);
has data => ( is => 'ro', isa => HashRef, required => 1);
sub make_chart {
my $self = shift;
my $x_label = $self->x_title;
my $y_label = $self->y_title;
my $header = $self->chart_title;
my $data = $self->data; # href of x & y
my $img_name = $self->data_title;
$img_name =~ s/\.vcf\Z//i; # remove vcf suffix if exists
my $filename = sprintf '%s/vcf/%s.png', $FindBin::Bin, $img_name ;
my $c = new XYChart(650, 420);
$c->setPlotArea(75, 65, 550, 300, -1, -1, 0xc0c0c0, 0xc0c0c0, -1);
$c->addTitle($header, 'timesbi.ttf', 18);
$c->xAxis()->setTitle($x_label, 'arialbi.ttf', 12);
$c->yAxis()->setTitle($y_label, 'arialbi.ttf', 12);
$c->xAxis()->setWidth(2);
$c->yAxis()->setWidth(2);
$c->addScatterLayer($data->{x}, $data->{y}, undef, # data label not required
$perlchartdir::CircleShape, 4, 0xff0000);
$c->makeChart($filename);
}
1;