--- loncom/cgi/plot.gif 2001/12/10 15:45:54 1.2 +++ loncom/cgi/plot.gif 2001/12/11 13:47:36 1.3 @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# $Id: plot.gif,v 1.2 2001/12/10 15:45:54 matthew Exp $ +# $Id: plot.gif,v 1.3 2001/12/11 13:47:36 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -80,22 +80,24 @@ $htic_every = &grab('htic_every',1.0,\%I my $image = new GD::Image($width,$height); # allocate standard colors -my $white = $image->colorAllocate(255,255,255); -my $black = $image->colorAllocate( 0, 0, 0); +my @BGvalues = split /,/,&grab('bgcolor','255,255,255',\%In); +my @FGvalues = split /,/,&grab('fgcolor','0,0,0',\%In); +my $bgcolor = $image->colorAllocate(@BGvalues); +my $fgcolor = $image->colorAllocate(@FGvalues); -# Draw a black frame around the picture +# Draw a fgcolor frame around the picture &drawtics($htic_every,$vtic_every) if (exists($In{'drawtics'})); &drawaxes($axis) if (exists($In{'drawaxis'})); &drawframe(1) if (exists($In{'frame'})); # make the background transparent if needed (this doesn't work, at least # not for gif images, don't know if it works for png) -$image->transparent($white) if (exists($In{'transparent'})); +$image->transparent($bgcolor) if (exists($In{'transparent'})); ## Take care of labels and data series foreach (keys %In) { if (/^label/) { my ($x,$y,$size,$text) = split/,/,$In{$_}; - &drawstring($text,$x,$y,$black,$size); + &drawstring($text,$x,$y,$fgcolor,$size); delete ($In{$_}); next; } elsif (/^xseries/) { @@ -108,7 +110,7 @@ foreach (keys %In) { delete ($In{$yname}); if ($#X != $#Y) { &drawstring("size of $xname and $yname do not match", - 10,10,$black,"giant"); + 10,10,$fgcolor,"giant"); next; } &drawcurve(\@X,\@Y); @@ -158,10 +160,10 @@ sub transformPoint{ sub drawaxes{ ($x1,$y1) = &transformPoint($axis->{"xmin"},0,$image,$axis); ($x2,$y2) = &transformPoint($axis->{"xmax"},0,$image,$axis); - $image->line($x1,$y1,$x2,$y2,$black); + $image->line($x1,$y1,$x2,$y2,$fgcolor); ($x1,$y1) = &transformPoint(0,$axis->{"ymin"},$image,$axis); ($x2,$y2) = &transformPoint(0,$axis->{"ymax"},$image,$axis); - $image->line($x1,$y1,$x2,$y2,$black); + $image->line($x1,$y1,$x2,$y2,$fgcolor); } sub drawtics{ @@ -177,7 +179,7 @@ sub drawtics{ my ($x2,$y2) = &transformPoint(0,$axis->{"ymin"}+$ntic*$vtic_every); $x1 -= $ticwidth; $x2 += $ticwidth; - $image->line($x1,$y1,$x2,$y2,$black); + $image->line($x1,$y1,$x2,$y2,$fgcolor); } # Do tics along x-axis for ($ntic = 0; $ntic <=int($axis->{"xlen"}/$htic_every); $ntic++){ @@ -185,7 +187,7 @@ sub drawtics{ my ($x2,$y2) = &transformPoint( $axis->{"xmin"}+$ntic*$htic_every,0); $y1 -= $ticheight; $y2 += $ticheight; - $image->line($x1,$y1,$x2,$y2,$black); + $image->line($x1,$y1,$x2,$y2,$fgcolor); } } @@ -194,7 +196,7 @@ sub drawcurve{ for($i=0;$i< (@$X-1);$i++) { ($x1,$y1) = &transformPoint($X->[$i ],$Y->[$i ]); ($x2,$y2) = &transformPoint($X->[$i+1],$Y->[$i+1]); - $image->line($x1,$y1,$x2,$y2,$black); + $image->line($x1,$y1,$x2,$y2,$fgcolor); } } @@ -204,7 +206,7 @@ sub drawframe{ $xoffset = $xoffset || 1; $yoffset = $yoffset || $xoffset; my ($width,$height) = $image->getBounds(); - $image->rectangle($xoffset-1,$yoffset-1,$width-$xoffset,$height-$yoffset,$black); + $image->rectangle($xoffset-1,$yoffset-1,$width-$xoffset,$height-$yoffset,$fgcolor); } sub drawstring{