--- loncom/cgi/plot.gif 2001/12/07 22:52:38 1.1 +++ loncom/cgi/plot.gif 2001/12/10 15:45:54 1.2 @@ -1,6 +1,6 @@ #!/usr/bin/perl # -# $Id: plot.gif,v 1.1 2001/12/07 22:52:38 matthew Exp $ +# $Id: plot.gif,v 1.2 2001/12/10 15:45:54 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -24,6 +24,8 @@ # # http://www.lon-capa.org/ # +########################################################################### +# # CGI-BIN interface to GD, used for making mathematical plots. # # User specifies the following variables (given are defaults): @@ -33,6 +35,7 @@ # xmax = " 10.0" # ymin = "-10.0" # ymax = " 10.0" +# transparent (doesn't work with gif?) # frame # drawaxes # drawtics @@ -51,6 +54,7 @@ # size of a labelN is one of : # giant, large, medium, small, tiny # +########################################################################### use GD; my @inputs = split(/&/,$ENV{'QUERY_STRING'}); @@ -73,16 +77,19 @@ $axis->{'ylen'} = $axis->{'ymax'} - $axi $vtic_every = &grab('vtic_every',1.0,\%In); $htic_every = &grab('htic_every',1.0,\%In); -my $image = new GD::Image($height,$width); +my $image = new GD::Image($width,$height); # allocate standard colors my $white = $image->colorAllocate(255,255,255); my $black = $image->colorAllocate( 0, 0, 0); # Draw a black frame around the picture -&drawtics($htic_every,$vtic_every) if (exists($In{"drawtics"})); -&drawaxes($axis) if (exists($In{"drawaxis"})); -&frame(1) if (exists($In{'frame'})); +&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'})); ## Take care of labels and data series foreach (keys %In) { @@ -108,19 +115,14 @@ foreach (keys %In) { } } -# make the background transparent and interlaced -$image->transparent($white); - -# make sure we are writing to a binary stream -binmode STDOUT; -# Convert the image to PNG and print it on standard output +# Tell the browser our mime-type print <plot(\@data)->png; +my $BinaryData=$image->png; undef $image; binmode(STDOUT); open IMG,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into a gif image @@ -166,8 +168,8 @@ sub drawtics{ my ($htic_every,$vtic_every) = @_; my ($width,$height) = $image->getBounds(); - $ticwidth = ($width > 99 ? 10 : int($width /10) + 1); - $ticheight = ($height > 99 ? 10 : int($height/10)); + $ticwidth = ($width > 99 ? 5 : int($width /20) + 1); + $ticheight = ($height > 99 ? 5 : int($height/20) + 1); # Do tics along y-axis for ($ntic = 0; $ntic <=int($axis->{"ylen"}/$vtic_every); $ntic++){ @@ -196,7 +198,7 @@ sub drawcurve{ } } -sub frame{ +sub drawframe{ # Draw a frame around the picture. my ($xoffset,$yoffset) = @_; $xoffset = $xoffset || 1;