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

www www@source.lon-capa.org
Fri, 19 Nov 2010 17:20:45 -0000


www		Fri Nov 19 17:20:45 2010 EDT

  Modified files:              
    /loncom/homework	functionplotresponse.pm 
  Log:
  New interface code
  
  
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.39 loncom/homework/functionplotresponse.pm:1.40
--- loncom/homework/functionplotresponse.pm:1.39	Fri Nov 19 15:41:28 2010
+++ loncom/homework/functionplotresponse.pm	Fri Nov 19 17:20:44 2010
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.39 2010/11/19 15:41:28 www Exp $
+# $Id: functionplotresponse.pm,v 1.40 2010/11/19 17:20:44 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -47,7 +47,7 @@
     my ($id)=@_;
     return (<<ENDSTARTCODE);
 <applet name="ggbApplet_$id" code="geogebra.GeoGebraApplet" archive="geogebra.jar"
-         codebase="/adm/geogebra/"  width="714" height="447" MAYSCRIPT>
+         codebase="/adm/geogebra/"  width="722" height="447" MAYSCRIPT>
        <param name="java_arguments" value="-Xmx512m -Djnlp.packEnabled=true"/>
 ENDSTARTCODE
 }
@@ -74,7 +74,6 @@
         <param name="image" value="/adm/lonIcons/lonanim.gif"  />
         <param name="boxborder" value="false"  />
         <param name="centerimage" value="true"  />
-        <param name="java_arguments" value="-Xmx512m -Djnlp.packEnabled=true" />
 	<param name="cache_archive" value="geogebra.jar, geogebra_main.jar, geogebra_gui.jar, geogebra_cas.jar, geogebra_algos.jar, geogebra_export.jar, geogebra_javascript.jar, jlatexmath.jar, jlm_greek.jar, jlm_cyrillic.jar, geogebra_properties.jar" />
 	<param name="cache_version" value="3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0, 3.9.115.0" />
         <param name="framePossible" value="false" />
@@ -159,16 +158,40 @@
 }
 
 #
-# Set a coordinate variable
+# Set a point coordinate variable
 #
-sub set_coordinate {
+sub set_point_coordinate {
    my ($id,$variable,$x,$y)=@_;
    return (<<ENDSETVARIABLE);
 document.ggbApplet_$id.evalCommand("$variable=($x,$y)");
+document.ggbApplet_$id.setLabelVisible("$variable",false);
 ENDSETVARIABLE
 }
 
 #
+# Set a slope coordinate variable
+#
+sub set_slope_coordinate {
+   my ($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname)=@_;
+   my $xvariable=$variable.'x';
+   my $yvariable=$variable.'y';
+   my $domain=$xmax-$xmin;
+   my $range=$ymax-$ymin;
+   my $xinterval=$domain/100.;
+   my $yinterval=$range/200.;
+   return (<<ENDSETSVARIABLE);
+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.setLabelVisible("$variable", false);
+ENDSETSVARIABLE
+}
+
+#
 # Input field name for a coordinate variable
 #
 
@@ -189,9 +212,9 @@
 }
 
 #
-# Initialize a new coordinate variable at set a listener on it
+# Initialize a new point coordinate variable at set a listener on it
 #
-sub new_coordinate {
+sub new_point_coordinate {
     my ($id,$variable,$x,$y)=@_;
     if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'x')})) {
        $x=$Apache::functionplotresponse::previous{&field_name($id,$variable,'x')};
@@ -200,7 +223,37 @@
        $y=$Apache::functionplotresponse::previous{&field_name($id,$variable,'y')};
     }
     &generate_input_field($id,$variable,$x,$y);
-    return &set_coordinate($id,$variable,$x,$y).&update_register($id,$variable);
+    return &set_point_coordinate($id,$variable,$x,$y).&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)=@_;
+#
+# $variable: name of the slope point
+# $x, $y: coordinates of the slope point
+# $pointname: name of the associated point point
+# $xp $yp: coordinates of the point point
+#
+    if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'x')})) {
+       $x=$Apache::functionplotresponse::previous{&field_name($id,$variable,'x')};
+    }
+    if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'y')})) {
+       $y=$Apache::functionplotresponse::previous{&field_name($id,$variable,'y')};
+    }
+    if (defined($Apache::functionplotresponse::previous{&field_name($id,$pointname,'x')})) {
+       $xp=$Apache::functionplotresponse::previous{&field_name($id,$pointname,'x')};
+    }
+    if (defined($Apache::functionplotresponse::previous{&field_name($id,$pointname,'y')})) {
+       $yp=$Apache::functionplotresponse::previous{&field_name($id,$pointname,'y')};
+    }
+
+    &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);
 }
 
 #
@@ -284,7 +337,7 @@
 #
 
 sub generate_spline {
-   my ($id,$label)=@_;
+   my ($id,$label,$xmin,$xmax,$ymin,$ymax)=@_;
    my $result='';
    my $order=$Apache::functionplotresponse::splineorder{$label};
    my $x=$Apache::functionplotresponse::splineinitx{$label};
@@ -293,10 +346,11 @@
    my $sy=$Apache::functionplotresponse::splinescaley{$label};
    my @coords=();
    foreach my $i (1..$order) {
-       $result.=&new_coordinate($id,$label.'P'.$i,$x,$y);
+       $result.=&new_point_coordinate($id,$label.'P'.$i,$x,$y);
+       my $xp=$x;
        $x+=$sx/(2.*($order-1));
        push(@coords,$label.'P'.$i);
-       $result.=&new_coordinate($id,$label.'S'.$i,$x,$y+$sy);
+       $result.=&new_slope_coordinate($id,$label.'S'.$i,$x,$y+$sy,$label.'P'.$i,$xp,$y,$xmin,$xmax,$ymin,$ymax);
        $x+=$sx/(2.*($order-1));
        push(@coords,$label.'S'.$i);
    }
@@ -1068,8 +1122,22 @@
      $result=&Apache::edit::end_table();
   } elsif ($target eq 'web') {
 # Now is the time to render all of the stored splines
+      my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval,-2);
+      $xmin=(defined($xmin)?$xmin:-10);
+      my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval,-2);
+      $xmax=(defined($xmax)?$xmax:10);
+      my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval,-2);
+      $ymin=(defined($ymin)?$ymin:-10);
+      my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval,-2);
+      $ymax=(defined($ymax)?$ymax:10);
+      if ($xmax<=$xmin) {
+        $xmax=$xmin+20;
+      }
+      if ($ymax<=$ymin) {
+         $ymax=$ymin+20;
+      }
      foreach my $label (keys(%Apache::functionplotresponse::splineorder)) {
-        $result.=&generate_spline($internalid,$label);
+        $result.=&generate_spline($internalid,$label,$xmin,$xmax,$ymin,$ymax);
      }
 # close the init script
      $result.=&end_init_script();