--- loncom/homework/functionplotresponse.pm 2010/11/23 17:01:28 1.44 +++ loncom/homework/functionplotresponse.pm 2010/11/24 02:53:13 1.47 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # option list style responses # -# $Id: functionplotresponse.pm,v 1.44 2010/11/23 17:01:28 www Exp $ +# $Id: functionplotresponse.pm,v 1.47 2010/11/24 02:53:13 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -295,28 +295,42 @@ ENDAXESSCRIPT } sub axes_label { - my ($id,$xlabel,$ylabel)=@_; + my ($id,$xmin,$xmax,$ymin,$ymax,$xlabel,$ylabel)=@_; unless ($xlabel || $ylabel) { return ''; } my $return='document.ggbApplet_'.$id.'.evalCommand("topRight=Corner[3]");'; if ($xlabel) { + if (($ymin<0) && ($ymax>0)) { $return.=(<0)) { $return.=(<'. &Apache::edit::select_arg('Grid visible:','gridvisible', - ['yes','no'],$token). + ['yes','no'],$token).'
'. + &Apache::edit::text_arg('Background plot(s) for answer (function:xmin:xmax,function:xmin:xmax,...):', + 'answerdisplay',$token,'50'); + &Apache::edit::end_row().&Apache::edit::start_spanning_row(); } elsif ($target eq 'modified') { my $constructtag=&Apache::edit::get_new_args($token,$parstack, $safeeval,'xlabel','xmin','xmax','ylabel','ymin','ymax', - 'xaxisvisible','yaxisvisible','gridvisible'); + 'xaxisvisible','yaxisvisible','gridvisible','answerdisplay'); if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } } elsif ($target eq 'meta') { @@ -1133,8 +1174,24 @@ sub end_functionplotelements { if ($target eq 'edit' ) { $result=&Apache::edit::end_table(); } elsif ($target eq 'web') { -# Now is the time to render all of the stored splines my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2); + +# Are we in show answer mode? + my $showanswer=&Apache::response::show_answer(); + if ($showanswer) { +# Render answerdisplay + my $answerdisplay=&Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval,-2); + if ($answerdisplay=~/\S/s) { + foreach my $plot (split(/\s*\,\s*/,$answerdisplay)) { + my ($func,$xl,$xh)=split(/\s*\:\s*/,$plot); + if ((!defined($xl)) || ($xl eq '')) { $xl=$xmin; } + if ((!defined($xh)) || ($xh eq '')) { $xh=$xmax; } + $result.=&plot_script($internalid,$func,1,'','00aa00',$xl,$xh,6); + } + } + } + +# Now is the time to render all of the stored splines foreach my $label (keys(%Apache::functionplotresponse::splineorder)) { $result.=&generate_spline($internalid,$label,$xmin,$xmax,$ymin,$ymax); } @@ -1213,7 +1270,7 @@ sub start_functionplotelements { $result.=&start_init_script($internalid); # put the axis commands inside $result.=&axes_script($internalid,$xmin,$xmax,$ymin,$ymax,$xaxisvisible,$yaxisvisible,$gridvisible); - $result.=&axes_label($internalid,$xlabel,$ylabel); + $result.=&axes_label($internalid,$xmin,$xmax,$ymin,$ymax,$xlabel,$ylabel); # init script is left open } return $result;