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

www www at source.lon-capa.org
Fri Nov 18 11:39:22 EST 2011


www		Fri Nov 18 16:39:22 2011 EDT

  Modified files:              
    /loncom/homework	edit.pm functionplotresponse.pm insertlist.xml 
  Log:
  Work in progress: objects and vectors
  
  
Index: loncom/homework/edit.pm
diff -u loncom/homework/edit.pm:1.135 loncom/homework/edit.pm:1.136
--- loncom/homework/edit.pm:1.135	Tue Aug  9 16:12:21 2011
+++ loncom/homework/edit.pm	Fri Nov 18 16:39:22 2011
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA 
 # edit mode helpers
 #
-# $Id: edit.pm,v 1.135 2011/08/09 16:12:21 bisitz Exp $
+# $Id: edit.pm,v 1.136 2011/11/18 16:39:22 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -419,6 +419,16 @@
 <backgroundplot />';
 }
 
+sub insert_plotobject {
+    return '
+<plotobject />';
+}
+
+sub insert_plotvector {
+    return '
+<plotvector />';
+}
+
 sub insert_functionplotrule {
     return '
 <functionplotrule />';
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.69 loncom/homework/functionplotresponse.pm:1.70
--- loncom/homework/functionplotresponse.pm:1.69	Thu Oct 27 00:36:37 2011
+++ loncom/homework/functionplotresponse.pm	Fri Nov 18 16:39:22 2011
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
-# option list style responses
+# Functionplot responses
 #
-# $Id: functionplotresponse.pm,v 1.69 2011/10/27 00:36:37 www Exp $
+# $Id: functionplotresponse.pm,v 1.70 2011/11/18 16:39:22 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,6 +35,7 @@
  
 BEGIN {
   &Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline',
+                                                            'plotobject','plotvector',
                                                             'functionplotrule','functionplotruleset',
                                                             'functionplotelements'));
 }
@@ -379,6 +380,55 @@
 }
 
 #
+# Subroutine to produce objects
+#
+
+sub plotobject_script {
+   my ($id,$label,$x,$y)=@_;
+   unless ($label) {
+      $Apache::functionplotresponse::counter++;
+      $label='O'.$Apache::functionplotresponse::counter;
+   }
+   return "document.ggbApplet_$id.evalCommand('a=1');\n".
+          "document.ggbApplet_$id.setVisible('a', false);\n".
+          "document.ggbApplet_$id.setLabelVisible('a', false);\n".
+          "document.ggbApplet_$id.evalCommand('$label=a*($x,$y)');\n".
+          "document.ggbApplet_$id.setVisible('$label', true);\n".
+          "document.ggbApplet_$id.setLabelVisible('$label', true);\n";
+}
+
+#
+# Subroutine to produce vectors
+#
+
+sub plotvector_script {
+   my ($id,$label,$xs,$ys,$xe,$ye)=@_;
+   unless ($label) {
+      $Apache::functionplotresponse::counter++;
+      $label='V'.$Apache::functionplotresponse::counter;
+   }
+   return(<<ENDVECTOR);
+document.ggbApplet1.evalCommand("Gravitystart=(20,0)");
+document.ggbApplet1.setVisible("Gravitystart",false);
+document.ggbApplet1.setLabelVisible("Gravitystart",false);
+document.ggbApplet1.evalCommand("Gravityend=(20,-5)");
+document.ggbApplet1.setLabelVisible("Gravityend",false);
+document.ggbApplet1.evalCommand("Gravity=Vector[Gravitystart, Gravityend]");
+document.ggbApplet1.setLabelVisible("Gravity",true);
+document.ggbApplet1.setLineThickness("Gravity",8);
+// Displays the Angle
+document.ggbApplet1.evalCommand("Gravitypoint=(110,y(Gravitystart))"); //The x-value for this should be 2*(xmax-xmin)+xmax;
+document.ggbApplet1.evalCommand("GravityAngle=Angle[Gravitypoint,Gravitystart,Gravityend]");
+document.ggbApplet1.setLabelVisible("GravityAngle",true);
+document.ggbApplet1.setLabelStyle("GravityAngle",VALUE=2);
+// Keeps track of points we care about (This should use the same listener function we use in graph problems)
+//document.ggbApplet1.registerObjectUpdateListener('Gravitystart','updatePointCoordinates');
+//document.ggbApplet1.registerObjectUpdateListener('Gravityend','updatePointCoordinates');
+//document.ggbApplet1.registerObjectUpdateListener('GravityAngle','updatePointCoordinates');
+ENDVECTOR
+}
+
+#
 # Answer spline display
 # 
 # points: x,y,slope_x,slope_y
@@ -431,6 +481,52 @@
    $result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',', at coords).']");'."\n";
    return $result;
 }
+
+#
+# Object
+#
+
+sub start_plotobject {
+   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+   my $result='';
+   my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
+   my $x=&Apache::lonxml::get_param('x',$parstack,$safeeval);
+   my $y=&Apache::lonxml::get_param('y',$parstack,$safeeval);
+   my $label=&Apache::lonxml::get_param('label',$parstack,$safeeval);
+   $label=~s/\W//gs;
+   $label=ucfirst($label);
+   unless ($label) { $label="NewObject"; }
+   if ($target eq 'web') {
+      my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3);
+      unless (defined($x)) { $x=$xmin; }
+      unless (defined($y)) { $y=$ymin; }
+      $result.=&plotobject_script($internalid,$label,$x,$y);
+   } elsif ($target eq 'edit') {
+        $result=&Apache::edit::tag_start($target,$token,'Plot Object').
+             &Apache::edit::text_arg('Label on Plot:','label',
+                                     $token,'16').
+             &Apache::edit::text_arg('x:','x',
+                                     $token,'8').
+             &Apache::edit::text_arg('y:','y',
+                                     $token,'8').
+             &Apache::edit::end_row();
+  } elsif ($target eq 'modified') {
+    my $constructtag=&Apache::edit::get_new_args($token,$parstack,$safeeval,'label','x','y');
+    if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
+  }
+  return $result;
+}
+
+sub end_plotobject {
+   my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
+   my $result='';
+   if ($target eq 'edit') {
+       $result=&Apache::edit::end_table();
+   }
+   return $result;
+}
+
+
 #
 # <backgroundplot function="..." fixed="yes/no" />
 #
Index: loncom/homework/insertlist.xml
diff -u loncom/homework/insertlist.xml:1.24 loncom/homework/insertlist.xml:1.25
--- loncom/homework/insertlist.xml:1.24	Fri Jan 14 01:56:32 2011
+++ loncom/homework/insertlist.xml	Fri Nov 18 16:39:22 2011
@@ -44,6 +44,18 @@
                 </help>
 
         </tag>
+        <tag name="plotobject">
+                <description>Plot Object</description>
+                <color>#DDDD55</color>
+                <insert_sub>insert_plotobject</insert_sub>
+                <allow></allow>
+        </tag>
+        <tag name="plotvector">
+                <description>Plot Vector</description>
+                <color>#DDDD55</color>
+                <insert_sub>insert_plotvector</insert_sub>
+                <allow></allow>
+        </tag>
         <tag name="functionplotruleset">
                 <description>Function Plot Rule Set</description>
                 <color>#99ff88</color>
@@ -54,7 +66,7 @@
                 <description>Function Plot Elements</description>
                 <color>#99ff88</color>
                 <insert_sub>insert_functionplotelements</insert_sub>
-                <allow>spline,backgroundplot</allow>
+                <allow>spline,backgroundplot,plotobject,plotvector</allow>
         <tag>
 
         <tag name="functionplotrule">




More information about the LON-CAPA-cvs mailing list