--- loncom/homework/functionplotresponse.pm 2010/11/23 23:55:01 1.46
+++ 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.46 2010/11/23 23:55:01 www Exp $
+# $Id: functionplotresponse.pm,v 1.47 2010/11/24 02:53:13 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -330,7 +330,7 @@ ENDYOFFAXISLABEL
}
sub plot_script {
- my ($id,$function,$fixed,$label,$color,$xmin,$xmax)=@_;
+ my ($id,$function,$fixed,$label,$color,$xmin,$xmax,$thickness)=@_;
$label=~s/\W//g;
if (($label) && ($label!~/^[A-Za-z]/)) {
$label='C'.$label;
@@ -354,7 +354,8 @@ sub plot_script {
if ($fixed) {
return "document.ggbApplet_$id.evalCommand('$label=Function[$function,$xmin,$xmax]');\n".
($visible?'':"document.ggbApplet_$id.setLabelVisible('$label', false);\n").
- ($color?"document.ggbApplet_$id.setColor('$label',$rc,$gc,$bc);\n":'');
+ ($color?"document.ggbApplet_$id.setColor('$label',$rc,$gc,$bc);\n":'').
+ ($thickness?"document.ggbApplet_$id.setLineThickness('$label',$thickness);\n":'');
} else {
return "document.ggbApplet_$id.evalCommand('y=$function');\n";
}
@@ -393,6 +394,8 @@ sub start_backgroundplot {
my $result='';
my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
my $function=&Apache::lonxml::get_param('function',$parstack,$safeeval);
+ my $xinitial=&Apache::lonxml::get_param('xinitial',$parstack,$safeeval);
+ my $xfinal=&Apache::lonxml::get_param('xfinal',$parstack,$safeeval);
my $label=&Apache::lonxml::get_param('label',$parstack,$safeeval);
my $color=&Apache::lonxml::get_param('color',$parstack,$safeeval);
$color=~s/[^a-fA-F0-9]//gs;
@@ -402,11 +405,17 @@ sub start_backgroundplot {
unless ($function) { $function="0"; }
if ($target eq 'web') {
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3);
- $result.=&plot_script($internalid,$function,$fixed,$label,$color,$xmin,$xmax);
+ unless (defined($xinitial)) { $xinitial=$xmin; }
+ unless (defined($xfinal)) { $xfinal=$xmax; }
+ $result.=&plot_script($internalid,$function,$fixed,$label,$color,$xinitial,$xfinal);
} elsif ($target eq 'edit') {
$result=&Apache::edit::tag_start($target,$token,'Background Function Plot').
&Apache::edit::text_arg('Function:','function',
$token,'16').
+ &Apache::edit::text_arg('Initial x-value (optional):','xinitial',
+ $token,'8').
+ &Apache::edit::text_arg('Final x-value (optional):','xfinal',
+ $token,'8').
&Apache::edit::text_arg('Label on Plot:','label',
$token,'8').
&Apache::edit::text_arg('Color (hex code):','color',
@@ -416,7 +425,7 @@ sub start_backgroundplot {
&Apache::edit::end_row();
} elsif ($target eq 'modified') {
my $constructtag=&Apache::edit::get_new_args($token,$parstack,
- $safeeval,'function','label','color','fixed');
+ $safeeval,'function','label','xinitial','xfinal','color','fixed');
if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
}
return $result;
@@ -826,12 +835,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') {
@@ -1162,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);
}