[LON-CAPA-cvs] cvs: loncom /homework functionplotresponse.pm

www www@source.lon-capa.org
Mon, 04 Apr 2011 15:44:37 -0000


www		Mon Apr  4 15:44:37 2011 EDT

  Modified files:              
    /loncom/homework	functionplotresponse.pm 
  Log:
  Work in progress on using splines as answers
  
  
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.57 loncom/homework/functionplotresponse.pm:1.58
--- loncom/homework/functionplotresponse.pm:1.57	Thu Mar 31 16:10:07 2011
+++ loncom/homework/functionplotresponse.pm	Mon Apr  4 15:44:37 2011
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.57 2011/03/31 16:10:07 www Exp $
+# $Id: functionplotresponse.pm,v 1.58 2011/04/04 15:44:37 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -333,6 +333,10 @@
     return $return;
 }
 
+#
+# Subroutine to produce background and answer plots
+#
+
 sub plot_script {
    my ($id,$function,$fixed,$label,$color,$xmin,$xmax,$thickness)=@_;
    $label=~s/\W//g;
@@ -366,6 +370,20 @@
 }
 
 #
+# Answer spline display
+# 
+# points: x,y,slope_x,slope_y
+
+sub answer_spline_script {
+   my ($id,@points)=@_;
+   my $order=int(($#points+1)/4);
+   if ($order<2) { $order=2; }
+   if ($order>8) { $order=8; }
+   $Apache::functionplotresponse::counter++;
+   my $label='C'.$Apache::functionplotresponse::counter;
+}
+
+#
 # Subroutine that generates code for spline $label based on stored information
 #
 
@@ -847,7 +865,7 @@
                                   ['yes','no'],$token).'<br />'.
              &Apache::edit::select_arg('Grid visible:','gridvisible',
                                   ['yes','no'],$token).'<br />'.
-             &Apache::edit::text_arg('Background plot(s) for answer (function:xmin:xmax,function:xmin:xmax,...):',
+             &Apache::edit::text_arg('Background plot(s) for answer (function(x):xmin:xmax,function(x):xmin:xmax,x1:y1:sx1:sy1:x2:y2:sx2:sy2,...):',
                                          'answerdisplay',$token,'50');
 
              &Apache::edit::end_row().&Apache::edit::start_spanning_row();
@@ -1219,10 +1237,17 @@
         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 @components=split(/\s*\:\s*/,$plot);
+              if ($#components<3) {
+# Just a simple plot
+                 my ($func,$xl,$xh)=@components;
+                 if ((!defined($xl)) || ($xl eq '')) { $xl=$xmin; }
+                 if ((!defined($xh)) || ($xh eq '')) { $xh=$xmax; }
+                 $result.=&plot_script($internalid,$func,1,'','00aa00',$xl,$xh,6);
+              } else {
+# This is a spline
+                 $result.=&answer_spline_script(@components);
+              }
            }
         }
      }