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

www www@source.lon-capa.org
Wed, 24 Nov 2010 15:30:45 -0000


www		Wed Nov 24 15:30:45 2010 EDT

  Modified files:              
    /loncom/homework	functionplotresponse.pm 
  Log:
  Lock down entered spline when problem cannot be answered anymore
  
  
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.47 loncom/homework/functionplotresponse.pm:1.48
--- loncom/homework/functionplotresponse.pm:1.47	Wed Nov 24 02:53:13 2010
+++ loncom/homework/functionplotresponse.pm	Wed Nov 24 15:30:45 2010
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.47 2010/11/24 02:53:13 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 @@
 # 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 (<<ENDSETVARIABLE);
-document.ggbApplet_$id.evalCommand("$variable=($x,$y)");
+document.ggbApplet_$id.evalCommand("a=1");
+document.ggbApplet_$id.evalCommand("$variable=$mult($x,$y)");
 document.ggbApplet_$id.setLabelVisible("$variable",false);
 ENDSETVARIABLE
 }
@@ -172,21 +174,23 @@
 # Set a slope coordinate variable
 #
 sub set_slope_coordinate {
-   my ($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname)=@_;
+   my ($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname,$fixed)=@_;
    my $xvariable=$variable.'x';
    my $yvariable=$variable.'y';
    my $domain=$xmax-$xmin;
    my $range=$ymax-$ymin;
    my $xinterval=$domain/100.;
    my $yinterval=$range/200.;
+   my $mult=($fixed?'a*':'');
    return (<<ENDSETSVARIABLE);
+document.ggbApplet_$id.evalCommand("a=1");
 document.ggbApplet_$id.evalCommand("$xvariable=Slider[0,$domain,$xinterval]");
 document.ggbApplet_$id.setVisible("$xvariable", false);
 document.ggbApplet_$id.evalCommand("$xvariable=$xrel");
 document.ggbApplet_$id.evalCommand("$yvariable=Slider[-$range,$range,$yinterval]");
 document.ggbApplet_$id.setVisible("$yvariable", false);
 document.ggbApplet_$id.evalCommand("$yvariable=$yrel");
-document.ggbApplet_$id.evalCommand("$variable=($xvariable+x($pointname),$yvariable+y($pointname))");
+document.ggbApplet_$id.evalCommand("$variable=$mult($xvariable+x($pointname),$yvariable+y($pointname))");
 document.ggbApplet_$id.setLabelVisible("$variable", false);
 ENDSETSVARIABLE
 }
@@ -215,7 +219,7 @@
 # Initialize a new point coordinate variable at set a listener on it
 #
 sub new_point_coordinate {
-    my ($id,$variable,$x,$y)=@_;
+    my ($id,$variable,$x,$y,$fixed)=@_;
     if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'x')})) {
        $x=$Apache::functionplotresponse::previous{&field_name($id,$variable,'x')};
     }
@@ -223,14 +227,14 @@
        $y=$Apache::functionplotresponse::previous{&field_name($id,$variable,'y')};
     }
     &generate_input_field($id,$variable,$x,$y);
-    return &set_point_coordinate($id,$variable,$x,$y).&update_register($id,$variable);
+    return &set_point_coordinate($id,$variable,$x,$y,$fixed).&update_register($id,$variable);
 }
 
 #
 # Initialize a new slope coordinate variable at set a listener on it
 #
 sub new_slope_coordinate {
-    my ($id,$variable,$x,$y,$pointname,$xp,$yp,$xmin,$xmax,$ymin,$ymax)=@_;
+    my ($id,$variable,$x,$y,$pointname,$xp,$yp,$xmin,$xmax,$ymin,$ymax,$fixed)=@_;
 #
 # $variable: name of the slope point
 # $x, $y: coordinates of the slope point
@@ -253,7 +257,7 @@
     &generate_input_field($id,$variable,$x,$y);
     my $xrel=$x-$xp;
     my $yrel=$y-$yp;
-    return &set_slope_coordinate($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname).&update_register($id,$variable);
+    return &set_slope_coordinate($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname,$fixed).&update_register($id,$variable);
 }
 
 #
@@ -366,7 +370,7 @@
 #
 
 sub generate_spline {
-   my ($id,$label,$xmin,$xmax,$ymin,$ymax)=@_;
+   my ($id,$label,$xmin,$xmax,$ymin,$ymax,$fixed)=@_;
    my $result='';
    my $order=$Apache::functionplotresponse::splineorder{$label};
    my $x=$Apache::functionplotresponse::splineinitx{$label};
@@ -375,11 +379,11 @@
    my $sy=$Apache::functionplotresponse::splinescaley{$label};
    my @coords=();
    foreach my $i (1..$order) {
-       $result.=&new_point_coordinate($id,$label.'P'.$i,$x,$y);
+       $result.=&new_point_coordinate($id,$label.'P'.$i,$x,$y,$fixed);
        my $xp=$x;
        $x+=$sx/(2.*($order-1));
        push(@coords,$label.'P'.$i);
-       $result.=&new_slope_coordinate($id,$label.'S'.$i,$x,$y+$sy,$label.'P'.$i,$xp,$y,$xmin,$xmax,$ymin,$ymax);
+       $result.=&new_slope_coordinate($id,$label.'S'.$i,$x,$y+$sy,$label.'P'.$i,$xp,$y,$xmin,$xmax,$ymin,$ymax,$fixed);
        $x+=$sx/(2.*($order-1));
        push(@coords,$label.'S'.$i);
    }
@@ -1190,10 +1194,11 @@
            }
         }
      }
-
+     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();