--- loncom/homework/functionplotresponse.pm 2010/10/05 01:28:00 1.7 +++ loncom/homework/functionplotresponse.pm 2010/10/09 00:00:04 1.9 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # option list style responses # -# $Id: functionplotresponse.pm,v 1.7 2010/10/05 01:28:00 www Exp $ +# $Id: functionplotresponse.pm,v 1.9 2010/10/09 00:00:04 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -125,8 +125,8 @@ sub update_script { function updatePointCoordinates_$id(coordinateName) { var x = document.ggbApplet_$id.getXcoord(coordinateName); var y = document.ggbApplet_$id.getYcoord(coordinateName); - coordinateMap_$id\[coordinateName + ".x"] = x; - coordinateMap_$id\[coordinateName + ".y"] = y; + document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_x"].value = x; + document.lonhomework.elements["HWVAL_$id\_" + coordinateName + "_y"].value = y; } // ]]> @@ -148,17 +148,36 @@ sub update_register { sub set_coordinate { my ($id,$variable,$x,$y)=@_; return (<\n". + "\n"; +} + +# # Initialize a new coordinate variable at set a listener on it # sub new_coordinate { my ($id,$variable,$x,$y)=@_; + &generate_input_field($id,$variable,$x,$y); return &set_coordinate($id,$variable,$x,$y).&update_register($id,$variable); } @@ -228,10 +247,10 @@ sub generate_spline { my @coords=(); foreach my $i (1..$order) { $result.=&new_coordinate($id,$label.'P'.$i,$x,$y); - $x+=$sx/$order; + $x+=$sx/(2.*($order-1)); push(@coords,$label.'P'.$i); $result.=&new_coordinate($id,$label.'S'.$i,$x,$y+$sy); - $x+=$sx/$order; + $x+=$sx/(2.*($order-1)); push(@coords,$label.'S'.$i); } $result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n"; @@ -270,7 +289,8 @@ sub start_spline { unless ($label) { $label='S'.$Apache::functionplotresponse::counter; } 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; my $x=&Apache::lonxml::get_param('initx',$parstack,$safeeval); @@ -312,6 +332,7 @@ sub start_functionplotresponse { undef %Apache::functionplotresponse::splineinity; undef %Apache::functionplotresponse::splinescalex; undef %Apache::functionplotresponse::splinescaley; + $Apache::functionplotresponse::inputfields=''; $Apache::functionplotresponse::counter=0; # Internal ID to mark the applet and its coordinates my $internalid = $Apache::inputtags::part.'_'.&Apache::response::start_response($parstack,$safeeval); @@ -355,6 +376,8 @@ sub end_functionplotresponse { } # close the init script $result.=&end_init_script(); +# generate the input fields + $result.=$Apache::functionplotresponse::inputfields; # actually start the -tag $result.=&geogebra_startcode($internalid); # load the spline bytecode