--- loncom/xml/lonplot.pm 2012/02/22 10:16:39 1.155 +++ loncom/xml/lonplot.pm 2012/07/03 11:29:57 1.156 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Dynamic plot # -# $Id: lonplot.pm,v 1.155 2012/02/22 10:16:39 foxr Exp $ +# $Id: lonplot.pm,v 1.156 2012/07/03 11:29:57 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1635,7 +1635,7 @@ sub write_gnuplot_file { # set output $gnuplot_input .= "set output\n"; } elsif ($target eq 'tex') { - $gnuplot_input .= "set term postscript eps enhanced $Apache::lonplot::plot{'plotcolor'} solid "; + $gnuplot_input .= "set term postscript eps enhanced $Apache::lonplot::plot{'plotcolor'} dash "; if (!$font_properties->{'tex_no_file'}) { $gnuplot_input .= 'fontfile "'.$Apache::lonnet::perlvar{'lonFontsDir'}. @@ -1835,40 +1835,31 @@ sub write_gnuplot_file { $gnuplot_input .="\n"; } # curves - $gnuplot_input .= 'plot '; + # + # Each curve will have its very own linestyle. + # (This should work just fine in web rendition I think). + # The line_xxx variables will hold the elements of the line style. + # type (solid/dashed), color, width + # + my $linestyle_index = 50; + my $line_type = ''; + my $line_color = ''; + my $line_width = ''; + + my $plot_command; + my $plot_type; + for (my $i = 0;$i<=$#curves;$i++) { $curve = $curves[$i]; - $gnuplot_input.= ', ' if ($i > 0); + $plot_command.= ', ' if ($i > 0); if ($target eq 'tex') { $curve->{'linewidth'} *= 2; } if (exists($curve->{'function'})) { - $gnuplot_input.= + $plot_type = $curve->{'function'}.' title "'. $curve->{'name'}.'" with '. $curve->{'linestyle'}; - - if (($curve->{'linestyle'} eq 'points') || - ($curve->{'linestyle'} eq 'linespoints') || - ($curve->{'linestyle'} eq 'errorbars') || - ($curve->{'linestyle'} eq 'xerrorbars') || - ($curve->{'linestyle'} eq 'yerrorbars') || - ($curve->{'linestyle'} eq 'xyerrorbars')) { - $gnuplot_input.=' pointtype '.$curve->{'pointtype'}; - $gnuplot_input.=' pointsize '.$curve->{'pointsize'}; - } elsif ($curve->{'linestyle'} eq 'filledcurves') { - $gnuplot_input.= ' '.$curve->{'limit'}; - } elsif ($curve->{'linetype'} ne '' && - $curve->{'linestyle'} eq 'lines') { - $gnuplot_input.= ' linetype '; - $gnuplot_input.= $linetypes{$curve->{'linetype'}}; - $gnuplot_input.= ' linecolor rgb "'; - # convert color from xaaaaaa to #aaaaaa - $curve->{'color'} =~ s/^x/#/; - $gnuplot_input.= $curve->{'color'}.'"'; - } - $gnuplot_input.= ' linewidth '.$curve->{'linewidth'}; - } elsif (exists($curve->{'data'})) { # Store data values in $datatext my $datatext = ''; @@ -1889,30 +1880,31 @@ sub write_gnuplot_file { print $fh $datatext; close($fh); # generate gnuplot text - $gnuplot_input.= '"'.$datafilename.'" title "'. + $plot_type = '"'.$datafilename.'" title "'. $curve->{'name'}.'" with '. $curve->{'linestyle'}; - if (($curve->{'linestyle'} eq 'points') || - ($curve->{'linestyle'} eq 'linespoints') || - ($curve->{'linestyle'} eq 'errorbars') || - ($curve->{'linestyle'} eq 'xerrorbars') || - ($curve->{'linestyle'} eq 'yerrorbars') || - ($curve->{'linestyle'} eq 'xyerrorbars')) { - $gnuplot_input.=' pointtype '.$curve->{'pointtype'}; - $gnuplot_input.=' pointsize '.$curve->{'pointsize'}; - } elsif ($curve->{'linestyle'} eq 'filledcurves') { - $gnuplot_input.= ' '.$curve->{'limit'}; - } elsif ($curve->{'linetype'} ne '' && - $curve->{'linestyle'} eq 'lines') { - $gnuplot_input.= ' linetype '; - $gnuplot_input.= $linetypes{$curve->{'linetype'}}; - $gnuplot_input.= ' linecolor rgb "'; - # convert color from xaaaaaa to #aaaaaa - $curve->{'color'} =~ s/^x/#/; - $gnuplot_input.= $curve->{'color'}.'"'; - } - $gnuplot_input.= ' linewidth '.$curve->{'linewidth'}; } + if (($curve->{'linestyle'} eq 'points') || + ($curve->{'linestyle'} eq 'linespoints') || + ($curve->{'linestyle'} eq 'errorbars') || + ($curve->{'linestyle'} eq 'xerrorbars') || + ($curve->{'linestyle'} eq 'yerrorbars') || + ($curve->{'linestyle'} eq 'xyerrorbars')) { + $plot_command.=' pointtype '.$curve->{'pointtype'}; + $plot_command.=' pointsize '.$curve->{'pointsize'}; + } elsif ($curve->{'linestyle'} eq 'filledcurves') { + $plot_command.= ' '.$curve->{'limit'}; + } elsif ($curve->{'linetype'} ne '' && + $curve->{'linestyle'} eq 'lines') { + $plot_command.= ' linetype '; + $plot_command.= $linetypes{$curve->{'linetype'}}; + $plot_command.= ' linecolor rgb "'; + # convert color from xaaaaaa to #aaaaaa + $curve->{'color'} =~ s/^x/#/; + $plot_command.= $curve->{'color'}.'"'; + } + $plot_command.= ' linewidth '.$curve->{'linewidth'}; + $gnuplot_input .= 'plot ' . $plot_type . ' ' . $plot_command . "\n"; } # Write the output to a file. open (my $fh,">$tmpdir$filename.data");