### ====================================================== ### UTIL: plot (using GD::Graph::$type) ### ====================================================== sub plot { ### Set options for graph, cf params and default my ($rOpt, $rData, $type, $x, $y) = @_; # %Opt, @data, ... $type ||= 'hb'; # Default horiz. bars $x ||= max(scalar(@{$rData->[1]})*20, 150); # Scale to num. data.pts $y ||= 400; # Fixed (dyn: max(ceil($s/2), 400);) my @opt = %{$rOpt}; # Flatten option hash to array my $graph; # (width:y, height:x) if ($type eq 'lp') { $graph = GD::Graph::linespoints->new($y, $x); } if ($type eq 'hb') { $graph = GD::Graph::hbars->new($y, $x); } $graph->set_x_axis_font(gdTinyFont); $graph->set(logo => ".\\KMD.gif", logo_resize => 0.5, logo_position => "LL", ); $graph->set(@opt) or die $graph->error; ### Plot graph, cf @$rData array my $gd = $graph->plot($rData) or die $graph->error; my $dir = Win32::GetCwd() . "\\plot"; unless (-e $dir and -d $dir) { mkdir($dir) or die "can't mkdir $dir: $!"; } open(IMG, ">$dir\\$rOpt->{title}.png") or die "can't open $dir\\$t.png: $!"; binmode IMG; print IMG $gd->png; }