--- loncom/xml/lonplot.pm 2002/01/11 16:34:06 1.39 +++ loncom/xml/lonplot.pm 2002/01/15 16:21:39 1.40 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Dynamic plot # -# $Id: lonplot.pm,v 1.39 2002/01/11 16:34:06 matthew Exp $ +# $Id: lonplot.pm,v 1.40 2002/01/15 16:21:39 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -350,9 +350,7 @@ sub end_plot { my $filename = $ENV{'user.name'}.'_'.$ENV{'user.domain'}. '_'.time.'_'.$$.int(rand(1000)).'_plot.data'; ## Write the plot description to the file - my $fh=Apache::File->new(">$tmpdir$filename"); - print $fh &write_gnuplot_file(); - close($fh); + &write_gnuplot_file($tmpdir,$filename); ## return image tag for the plot $result .= <<"ENDIMAGE"; {'function'}); } my $datatext = &Apache::lonxml::get_all_text("/data",$$parser[-1]); + # Deal with cases where we're given an array... + if ($datatext =~ /^\@/) { + $datatext = &Apache::run::run('return "'.$datatext.'"', + $safeeval,1); + } $datatext =~ s/\s+/ /g; # Need to do some error checking on the @data array - # make sure it's all numbers and make sure each array @@ -743,8 +746,10 @@ sub get_attributes{ } return ; } + ##------------------------------------------------------- write_gnuplot_file sub write_gnuplot_file { + my ($tmpdir,$filename)= @_; my $gnuplot_input = ''; my $curve; # Collect all the colors @@ -795,7 +800,6 @@ sub write_gnuplot_file { } # curves $gnuplot_input .= 'plot '; - my $datatext = ''; for (my $i = 0;$i<=$#curves;$i++) { $curve = $curves[$i]; $gnuplot_input.= ', ' if ($i > 0); @@ -805,9 +809,12 @@ sub write_gnuplot_file { $curve->{'name'}.'" with '. $curve->{'linestyle'}; } elsif (exists($curve->{'data'})) { - $gnuplot_input.= '\'-\' title "'. - $curve->{'name'}.'" with '. - $curve->{'linestyle'}; + # Store data values in $datatext + my $datatext = ''; + # get new filename + my $datafilename = "$tmpdir/$filename.$i"; + my $fh=Apache::File->new(">$datafilename"); + # Compile data my @Data = @{$curve->{'data'}}; my @Data0 = @{$Data[0]}; for (my $i =0; $i<=$#Data0; $i++) { @@ -817,11 +824,21 @@ sub write_gnuplot_file { } $datatext .= $/; } - $datatext .=$/; + # write file + print $fh $datatext; + close ($fh); + # generate gnuplot text + $gnuplot_input.= '"'.$datafilename.'" title "'. + $curve->{'name'}.'" with '. + $curve->{'linestyle'}; } } - $gnuplot_input .= $/.$datatext; - return $gnuplot_input; + # Write the output to a file. + my $fh=Apache::File->new(">$tmpdir$filename"); + print $fh $gnuplot_input; + close($fh); + # That's all folks. + return ; } #---------------------------------------------- check_inputs