--- loncom/xml/lonplot.pm 2001/12/19 19:22:52 1.8 +++ loncom/xml/lonplot.pm 2001/12/19 22:14:20 1.9 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Dynamic plot # -# $Id: lonplot.pm,v 1.8 2001/12/19 19:22:52 matthew Exp $ +# $Id: lonplot.pm,v 1.9 2001/12/19 22:14:20 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -380,74 +380,80 @@ sub write_gnuplot_file { push @Colors, $plot{'fgcolor'}; push @Colors, $axis{'color'}; push @Colors, $axis{'color'}; - foreach $curve (@Curves) { - push @Colors, ($curve{'color'} ne '' ? - $curve{'color'} : + foreach $curve (@curves) { + push @Colors, ($curve->{'color'} ne '' ? + $curve->{'color'} : $plot{'fgcolor'} ); } # set term $gnuplot_input .= 'set term gif '; $gnuplot_input .= 'transparent ' if ($plot{'transparent'} eq 'on'); $gnuplot_input .= $plot{'font'} . ' '; - $gnuplot_input .= 'size ' . $plot{'width'} . ' '; + $gnuplot_input .= 'size ' . $plot{'width'} . ','; $gnuplot_input .= $plot{'height'} . ' '; $gnuplot_input .= "@Colors\n"; # grid - $gnuplot_input .= ($plot->{'grid'} eq 'on' ? - 'set grid\n' : + $gnuplot_input .= ($plot{'grid'} eq 'on' ? + 'set grid'.$/ : '' ); # border - $gnuplot_input .= ($plot->{'border'} eq 'on'? - 'set border\n' : - 'set noborder\n' ); # title, xlabel, ylabel + $gnuplot_input .= ($plot{'border'} eq 'on'? + 'set border'.$/ : + 'set noborder'.$/ ); # title, xlabel, ylabel { - $gnuplot_input .<<"ENDLABELS"; -set title $title->{'text'} -set xlabel $xlabel->{'text'} -set ylabel $ylabel->{'text'} -set xrange $axis->{'xmin'}:$axis->{'xmax'} -set yrange $axis->{'ymin'}:$axis->{'ymax'} + $gnuplot_input .= <<"ENDLABELS"; +set output "tmp.gif" +set title "$title" +set xlabel "$xlabel" +set ylabel "$ylabel" +set xrange \[$axis{'xmin'}:$axis{'xmax'}\] +set yrange \[$axis{'ymin'}:$axis{'ymax'}\] ENDLABELS } # Key if (defined($key{'pos'})) { - $gnuplot_input .= 'set key '.$key->{'pos'}.' '; - $gnuplot_input .= ($key->{'box'} eq 'on' ? 'box ' : 'nobox '); - if ($key->{'title'} ne '') { - $gnuplot_input .= 'title "'$key->{'title'}.'"\n'; + $gnuplot_input .= 'set key '.$key{'pos'}.' '; + $gnuplot_input .= ($key{'box'} eq 'on' ? 'box ' : 'nobox '); + if ($key{'title'} ne '') { + $gnuplot_input .= 'title "'.$key{'title'}.'"'.$/; } else { - $gnuplot_input .= '\n'; + $gnuplot_input .= $/; } } else { - $gnuplot_input .= 'set nokey\n'; + $gnuplot_input .= 'set nokey'.$/; } - # axis - $gnuplot_input .= 'set xrange ['.$axis{'xmin'}.':'.$axis{'xmin'}.']\n'; - $gnuplot_input .= 'set yrange ['.$axis{'ymin'}.':'.$axis{'ymin'}.']\n'; # labels foreach $label (@labels) { $gnuplot_input .= 'set label "'.$label->{'text'}.'" at '. - $label->{'x'}.','.$label->{'y'}.'\n'; + $label->{'xpos'}.','.$label->{'ypos'}.' '.$label->{'justify'}.$/ ; } # curves $gnuplot_input .= 'plot '; my $datatext = ''; - foreach $curve (@curves) { + for (my $i = 0;$i<=$#curves;$i++) { + $curve = $curves[$i]; + $gnuplot_input.= ', ' if ($i > 0); if (exists($curve->{'function'})) { - $gnuplot_input.= $curve->{'function'}.' with '.$curve->{'linestyle'}; + $gnuplot_input.= + $curve->{'function'}.' title "'. + $curve->{'name'}.'" with '. + $curve->{'linestyle'}; } elsif (exists($curve->{'data'})) { - $gnuplot_input.= '\'-\' with '.$curve->{'linestyle'}; + $gnuplot_input.= '\'-\' title "'. + $curve->{'name'}.'" with '. + $curve->{'linestyle'}; my @Data = @{$curve->{'data'}}; - for ($i =0; $i<=$#Data; $i++) { + my @Data0 = @{$Data[0]}; + for (my $i =0; $i<=$#Data0; $i++) { foreach $dataset (@Data) { - $datatext .= $dataset[$i] . ' '; + $datatext .= $dataset->[$i] . ' '; } - $datatext .='\n'; + $datatext .= $/; } - $datatext .='\n'; + $datatext .=$/; } } - $gnuplot_input .= $datatext; + $gnuplot_input .= $/.$datatext; print $fh $gnuplot_input; }