--- loncom/homework/functionplotresponse.pm 2010/11/20 21:35:53 1.43 +++ loncom/homework/functionplotresponse.pm 2010/11/24 15:30:45 1.48 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # option list style responses # -# $Id: functionplotresponse.pm,v 1.43 2010/11/20 21:35:53 www Exp $ +# $Id: functionplotresponse.pm,v 1.48 2010/11/24 15:30:45 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -161,9 +161,11 @@ sub update_register { # Set a point coordinate variable # sub set_point_coordinate { - my ($id,$variable,$x,$y)=@_; + my ($id,$variable,$x,$y,$fixed)=@_; + my $mult=($fixed?'a*':''); return (<0)) { $return.=(<0)) { $return.=(<'. - &Apache::edit::text_arg('(Initial) x-value:','xinitial', + &Apache::edit::text_arg('Initial x-value:','xinitial', $token,'8'). - &Apache::edit::select_or_text_arg('(Initial) x-value label:','xinitiallabel', - [['start','Start of Plot']],$token,'8').'
'. + &Apache::edit::select_or_text_arg('Initial x-value label:','xinitiallabel', + [['start','Start of Plot'], + ['end','End of Plot']],$token,'8').'
'. - &Apache::edit::text_arg('Optional final x-value for ranges:','xfinal', + &Apache::edit::text_arg('Final x-value (optional):','xfinal', $token,'8'). - &Apache::edit::select_or_text_arg('Optional final x-value label:','xfinallabel', + &Apache::edit::select_or_text_arg('Final x-value label (optional):','xfinallabel', [['end','End of Plot']],$token,'8').'
'. - &Apache::edit::text_arg('Optional minimum length for range:','minimumlength', + &Apache::edit::text_arg('Minimum length for range (optional):','minimumlength', $token,'8'). - &Apache::edit::text_arg('Optional maximum length for range:','maximumlength', + &Apache::edit::text_arg('Maximum length for range (optional):','maximumlength', $token,'8').'
'. &Apache::edit::select_or_text_arg(&mt('Relationship:'),'relationship', [['eq','equal'], @@ -562,7 +605,7 @@ sub start_spline { &Apache::edit::text_arg('Index:','index', $token,'4').' '. &Apache::edit::select_arg('Order:','order', - ['2','3','4','5','6','7','8','9'],$token).' '. + ['2','3','4','5','6','7','8'],$token).' '. &Apache::edit::text_arg('Initial x-value:','initx', $token,'4').' '. &Apache::edit::text_arg('Initial y-value:','inity', @@ -796,12 +839,15 @@ sub start_functionplotresponse { &Apache::edit::select_arg('y-axis visible:','yaxisvisible', ['yes','no'],$token).'
'. &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') { @@ -1132,10 +1178,27 @@ 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); + } + } + } + my $fixed=0; + if (($showanswer) || (&Apache::response::check_status()>=2)) { $fixed=1; } +# 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); + $result.=&generate_spline($internalid,$label,$xmin,$xmax,$ymin,$ymax,$fixed); } # close the init script $result.=&end_init_script(); @@ -1212,7 +1275,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;