Diff for /loncom/homework/functionplotresponse.pm between versions 1.7 and 1.9

version 1.7, 2010/10/05 01:28:00 version 1.9, 2010/10/09 00:00:04
Line 125  sub update_script { Line 125  sub update_script {
 function updatePointCoordinates_$id(coordinateName) {  function updatePointCoordinates_$id(coordinateName) {
             var x = document.ggbApplet_$id.getXcoord(coordinateName);              var x = document.ggbApplet_$id.getXcoord(coordinateName);
             var y = document.ggbApplet_$id.getYcoord(coordinateName);              var y = document.ggbApplet_$id.getYcoord(coordinateName);
             coordinateMap_$id\[coordinateName + ".x"] = x;              document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_x"].value = x;
             coordinateMap_$id\[coordinateName + ".y"] = y;              document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_y"].value = y;
         }          }
 // ]]>  // ]]>
 </script>  </script>
Line 148  sub update_register { Line 148  sub update_register {
 sub set_coordinate {  sub set_coordinate {
    my ($id,$variable,$x,$y)=@_;     my ($id,$variable,$x,$y)=@_;
    return (<<ENDSETVARIABLE);     return (<<ENDSETVARIABLE);
 coordinateMap_$id\['$variable.x'] = $x;  document.ggbApplet_$id.evalCommand("$variable=($x,$y)");
 coordinateMap_$id\['$variable.y'] = $y;  
 document.ggbApplet_$id.evalCommand("$variable=("+coordinateMap_$id\["$variable.x"]+","+coordinateMap_$id\["$variable.y"]+")");  
 ENDSETVARIABLE  ENDSETVARIABLE
 }  }
   
 #  #
   # Input field name for a coordinate variable
   #
   
   sub field_name {
       my ($id,$variable,$name)=@_;
       return "HWVAL_$id\_$variable\_$name";
   }
   
   #
   # Generate an input field for a coordinate variable
   #
   
   sub generate_input_field {
       my ($id,$variable,$x,$y)=@_;
       $Apache::functionplotresponse::inputfields.=
          "<input type='hidden' name='".&field_name($id,$variable,'x')."' value='$x' />\n".
          "<input type='hidden' name='".&field_name($id,$variable,'y')."' value='$y' />\n";
   }
   
   #
 # Initialize a new coordinate variable at set a listener on it  # Initialize a new coordinate variable at set a listener on it
 #  #
 sub new_coordinate {  sub new_coordinate {
     my ($id,$variable,$x,$y)=@_;      my ($id,$variable,$x,$y)=@_;
       &generate_input_field($id,$variable,$x,$y);
     return &set_coordinate($id,$variable,$x,$y).&update_register($id,$variable);      return &set_coordinate($id,$variable,$x,$y).&update_register($id,$variable);
 }  }
   
Line 228  sub generate_spline { Line 247  sub generate_spline {
    my @coords=();     my @coords=();
    foreach my $i (1..$order) {     foreach my $i (1..$order) {
        $result.=&new_coordinate($id,$label.'P'.$i,$x,$y);         $result.=&new_coordinate($id,$label.'P'.$i,$x,$y);
        $x+=$sx/$order;         $x+=$sx/(2.*($order-1));
        push(@coords,$label.'P'.$i);         push(@coords,$label.'P'.$i);
        $result.=&new_coordinate($id,$label.'S'.$i,$x,$y+$sy);         $result.=&new_coordinate($id,$label.'S'.$i,$x,$y+$sy);
        $x+=$sx/$order;         $x+=$sx/(2.*($order-1));
        push(@coords,$label.'S'.$i);         push(@coords,$label.'S'.$i);
    }     }
    $result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n";     $result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n";
Line 270  sub start_spline { Line 289  sub start_spline {
    unless ($label) { $label='S'.$Apache::functionplotresponse::counter; }     unless ($label) { $label='S'.$Apache::functionplotresponse::counter; }
   
    my $order=&Apache::lonxml::get_param('order',$parstack,$safeeval);     my $order=&Apache::lonxml::get_param('order',$parstack,$safeeval);
    if (($order<2) || ($order>4)) { $order=2; }     if ($order<2) { $order=2; }
      if ($order>8) { $order=8; }
    $Apache::functionplotresponse::splineorder{$label}=$order;     $Apache::functionplotresponse::splineorder{$label}=$order;
   
    my $x=&Apache::lonxml::get_param('initx',$parstack,$safeeval);     my $x=&Apache::lonxml::get_param('initx',$parstack,$safeeval);
Line 312  sub start_functionplotresponse { Line 332  sub start_functionplotresponse {
   undef %Apache::functionplotresponse::splineinity;    undef %Apache::functionplotresponse::splineinity;
   undef %Apache::functionplotresponse::splinescalex;    undef %Apache::functionplotresponse::splinescalex;
   undef %Apache::functionplotresponse::splinescaley;    undef %Apache::functionplotresponse::splinescaley;
     $Apache::functionplotresponse::inputfields='';
   $Apache::functionplotresponse::counter=0;    $Apache::functionplotresponse::counter=0;
 # Internal ID to mark the applet and its coordinates  # Internal ID to mark the applet and its coordinates
   my $internalid = $Apache::inputtags::part.'_'.&Apache::response::start_response($parstack,$safeeval);    my $internalid = $Apache::inputtags::part.'_'.&Apache::response::start_response($parstack,$safeeval);
Line 355  sub end_functionplotresponse { Line 376  sub end_functionplotresponse {
      }       }
 # close the init script  # close the init script
      $result.=&end_init_script();       $result.=&end_init_script();
   # generate the input fields
        $result.=$Apache::functionplotresponse::inputfields;
 # actually start the <applet>-tag  # actually start the <applet>-tag
      $result.=&geogebra_startcode($internalid);       $result.=&geogebra_startcode($internalid);
 # load the spline bytecode  # load the spline bytecode

Removed from v.1.7  
changed lines
  Added in v.1.9


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>