--- loncom/xml/lonplot.pm 2008/12/02 01:49:48 1.150 +++ loncom/xml/lonplot.pm 2012/02/13 11:24:16 1.154 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Dynamic plot # -# $Id: lonplot.pm,v 1.150 2008/12/02 01:49:48 raeburn Exp $ +# $Id: lonplot.pm,v 1.154 2012/02/13 11:24:16 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -176,14 +176,16 @@ my %gnuplot_defaults = test => $color_test, description => 'Background color of image (xffffff)', edit_type => 'entry', - size => '10' + size => '10', + class => 'colorchooser' }, fgcolor => { default => 'x000000', test => $color_test, description => 'Foreground color of image (x000000)', edit_type => 'entry', - size => '10' + size => '10', + class => 'colorchooser' }, transparent => { default => 'off', @@ -455,7 +457,7 @@ my %tic_defaults = }, ); -my @axis_edit_order = ('color','xmin','xmax','ymin','ymax','xformat', 'yformat'); +my @axis_edit_order = ('color','xmin','xmax','ymin','ymax','xformat', 'yformat', 'xzero', 'yzero'); my %axis_defaults = ( color => { @@ -463,7 +465,8 @@ my %axis_defaults = test => $color_test, description => 'Color of grid lines (x000000)', edit_type => 'entry', - size => '10' + size => '10', + class => 'colorchooser' }, xmin => { default => '-10.0', @@ -503,11 +506,26 @@ my %axis_defaults = yformat => { default => 'on', test => sub {$_[0]=~/^(on|off|\d+(f|F|e|E))$/}, - description => 'X-axis number formatting', + description => 'Y-axis number formatting', edit_type => 'choice', choices => ['on', 'off', '2e', '2f'], }, - + + xzero => { + default => 'off', + test => sub {$_[0]=~/^(off|line|thick-line|dotted)$/}, + description => 'Show x-zero (y=0) axis', + edit_type => 'choice', + choices => ['off', 'line', 'thick-line', 'dotted'], + }, + + yzero => { + default => 'off', + test => sub {$_[0]=~/^(off|line|thick-line|dotted)$/}, + description => 'Show y-zero (x=0) axis', + edit_type => 'choice', + choices => ['off', 'line', 'thick-line', 'dotted'], + }, ); my @curve_edit_order = ('color','name','linestyle','linewidth','linetype','pointtype','pointsize','limit'); @@ -519,7 +537,8 @@ my %curve_defaults = test => $color_test, description => 'Color of curve (x000000)', edit_type => 'entry', - size => '10' + size => '10', + class => 'colorchooser' }, name => { default => '', @@ -619,6 +638,8 @@ sub end_gnuplot { ('title','xlabel','ylabel','key','axis','label','curve')); my $result = ''; my $randnumber; + my $tmpdir =LONCAPA::tempdir(); # Where temporary files live: + # need to call rand everytime start_script would evaluate, as the # safe space rand number generator and the global rand generator # are not separate @@ -630,7 +651,6 @@ sub end_gnuplot { &check_inputs(); # Make sure we have all the data we need ## ## Determine filename - my $tmpdir = '/home/httpd/perl/tmp/'; my $filename = $env{'user.name'}.'_'.$env{'user.domain'}. '_'.time.'_'.$$.$randnumber.'_plot'; ## Write the plot description to the file @@ -651,7 +671,7 @@ ENDIMAGE #might be inside the safe space, register the URL for later &Apache::lonxml::register_ssi("/cgi-bin/plot.gif?file=$filename.data&output=eps"); $result = "%DYNAMICIMAGE:$Apache::lonplot::plot{'width'}:$Apache::lonplot::plot{'height'}:$Apache::lonplot::plot{'texwidth'}\n"; - $result .= '\graphicspath{{/home/httpd/perl/tmp/}}'."\n"; + $result .= '\graphicspath{{'.$tmpdir.'}}'."\n"; $result .= '\includegraphics[width='.$Apache::lonplot::plot{'texwidth'}.' mm]{'.&unescape($filename).'.eps}'; } } elsif ($target eq 'edit') { @@ -1594,7 +1614,7 @@ sub write_gnuplot_file { } $gnuplot_input .= ' "'.$font_properties->{'printname'}.'" '; $gnuplot_input .= $fontsize; - $gnuplot_input .= "\nset output \"/home/httpd/perl/tmp/". + $gnuplot_input .= "\nset output \"".$tmpdir. &unescape($filename).".eps\"\n"; $gnuplot_input .= "set encoding iso_8859_1\n"; # Get access to extended font. @@ -1735,6 +1755,26 @@ sub write_gnuplot_file { } $gnuplot_input .= "set xrange \[$axis{'xmin'}:$axis{'xmax'}\]\n"; $gnuplot_input .= "set yrange \[$axis{'ymin'}:$axis{'ymax'}\]\n"; + if ($axis{'xzero'} ne 'off') { + $gnuplot_input .= "set xzeroaxis "; + if ($axis{'xzero'} eq 'line' || $axis{'xzero'} eq 'thick-line') { + $gnuplot_input .= "lt -1 "; + if ($axis{'xzero'} eq 'thick-line') { + $gnuplot_input .= "lw 3 "; + } + } + $gnuplot_input .= "\n"; + } + if ($axis{'yzero'} ne 'off') { + $gnuplot_input .= "set yzeroaxis "; + if ($axis{'yzero'} eq 'line' || $axis{'yzero'} eq 'thick-line') { + $gnuplot_input .= "lt -1 "; + if ($axis{'yzero'} eq 'thick-line') { + $gnuplot_input .= "lw 3 "; + } + } + $gnuplot_input .= "\n"; + } } # Key if (%key) { @@ -1894,7 +1934,8 @@ sub edit_attributes { if ($defaults->{$attr}->{'edit_type'} eq 'entry') { $result .= &Apache::edit::text_arg ($description,$attr,$token, - $defaults->{$attr}->{'size'}); + $defaults->{$attr}->{'size'}, + $defaults->{$attr}->{'class'}); } elsif ($defaults->{$attr}->{'edit_type'} eq 'choice') { $result .= &Apache::edit::select_or_text_arg ($description,$attr,$defaults->{$attr}->{'choices'},$token);