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

www www@source.lon-capa.org
Tue, 05 Oct 2010 01:28:00 -0000


www		Tue Oct  5 01:28:00 2010 EDT

  Modified files:              
    /loncom/homework	functionplotresponse.pm 
  Log:
  Now draws splines
  
  
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.6 loncom/homework/functionplotresponse.pm:1.7
--- loncom/homework/functionplotresponse.pm:1.6	Tue Oct  5 00:10:07 2010
+++ loncom/homework/functionplotresponse.pm	Tue Oct  5 01:28:00 2010
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.6 2010/10/05 00:10:07 www Exp $
+# $Id: functionplotresponse.pm,v 1.7 2010/10/05 01:28:00 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -214,12 +214,27 @@
 }
 
 #
-# Subroutine that generates spline $label based on stored information
+# Subroutine that generates code for spline $label based on stored information
 #
 
 sub generate_spline {
    my ($id,$label)=@_;
    my $result='';
+   my $order=$Apache::functionplotresponse::splineorder{$label};
+   my $x=$Apache::functionplotresponse::splineinitx{$label};
+   my $y=$Apache::functionplotresponse::splineinity{$label};
+   my $sx=$Apache::functionplotresponse::splinescalex{$label};
+   my $sy=$Apache::functionplotresponse::splinescaley{$label};
+   my @coords=();
+   foreach my $i (1..$order) {
+       $result.=&new_coordinate($id,$label.'P'.$i,$x,$y);
+       $x+=$sx/$order;
+       push(@coords,$label.'P'.$i);
+       $result.=&new_coordinate($id,$label.'S'.$i,$x,$y+$sy);
+       $x+=$sx/$order;
+       push(@coords,$label.'S'.$i);
+   }
+   $result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n";
    return $result;
 }
 #
@@ -273,6 +288,7 @@
    my $sy=&Apache::lonxml::get_param('scaley',$parstack,$safeeval);
    unless ($sy) { $sy=2; }
    $Apache::functionplotresponse::splinescaley{$label}=$sy;
+   return '';
 }
 
 sub end_spline {