package NGS::ChartMaker; use lib ( '/home/raj/perl5/lib/perl5', '/home/raj/perl-lib/ChartDirector', '/home/raj/perl-lib', ); use Modern::Perl qw(2012); # 5.14 use perlchartdir; use autodie; use Moo; use FindBin; # warn $FindBin::Bin; use Local::MooX::Types qw(HashReference VarChar Integer); has data => ( is => 'ro', isa => HashReference, required => 1); has $_ => ( is => 'ro', isa => VarChar[25], required => 1) # VarChar max 25 chars for qw(data_title chart_title x_title y_title); has $_ => ( is => 'ro', isa => Integer, required => 0 ) for qw(max_x_val max_y_val); 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/analysis/%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); if (my $x_max = $self->max_x_val ) { # warn $x_max; $c->xAxis()->setLinearScale(0, $x_max); } if (my $y_max = $self->max_y_val ) { # warn $y_max; $c->yAxis()->setLinearScale(0, $y_max); } $c->addScatterLayer($data->{x}, $data->{y}, undef, # data label not required $perlchartdir::CircleShape, 4, 0xff0000); $c->makeChart($filename); } 1;