--- loncom/homework/functionplotresponse.pm 2010/10/05 00:10:07 1.6 +++ 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.6 2010/10/05 00:10:07 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); } @@ -214,12 +233,27 @@ ENDPLOTSCRIPT } # -# 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/(2.*($order-1)); + push(@coords,$label.'P'.$i); + $result.=&new_coordinate($id,$label.'S'.$i,$x,$y+$sy); + $x+=$sx/(2.*($order-1)); + push(@coords,$label.'S'.$i); + } + $result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n"; return $result; } # @@ -255,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); @@ -273,6 +308,7 @@ sub start_spline { my $sy=&Apache::lonxml::get_param('scaley',$parstack,$safeeval); unless ($sy) { $sy=2; } $Apache::functionplotresponse::splinescaley{$label}=$sy; + return ''; } sub end_spline { @@ -296,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); @@ -339,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