version 1.6, 2010/10/05 00:10:07
|
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 214 ENDPLOTSCRIPT
|
Line 233 ENDPLOTSCRIPT
|
} |
} |
|
|
# |
# |
# Subroutine that generates spline $label based on stored information |
# Subroutine that generates code for spline $label based on stored information |
# |
# |
|
|
sub generate_spline { |
sub generate_spline { |
my ($id,$label)=@_; |
my ($id,$label)=@_; |
my $result=''; |
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; |
return $result; |
} |
} |
# |
# |
Line 255 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 273 sub start_spline {
|
Line 308 sub start_spline {
|
my $sy=&Apache::lonxml::get_param('scaley',$parstack,$safeeval); |
my $sy=&Apache::lonxml::get_param('scaley',$parstack,$safeeval); |
unless ($sy) { $sy=2; } |
unless ($sy) { $sy=2; } |
$Apache::functionplotresponse::splinescaley{$label}=$sy; |
$Apache::functionplotresponse::splinescaley{$label}=$sy; |
|
return ''; |
} |
} |
|
|
sub end_spline { |
sub end_spline { |
Line 296 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 339 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 |