version 1.65, 2011/10/13 01:54:12
|
version 1.70, 2011/11/18 16:39:22
|
Line 1
|
Line 1
|
# LearningOnline Network with CAPA |
# LearningOnline Network with CAPA |
# option list style responses |
# Functionplot responses |
# |
# |
# $Id$ |
# $Id$ |
# |
# |
Line 35 use Apache::run;
|
Line 35 use Apache::run;
|
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline', |
&Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline', |
|
'plotobject','plotvector', |
'functionplotrule','functionplotruleset', |
'functionplotrule','functionplotruleset', |
'functionplotelements')); |
'functionplotelements')); |
} |
} |
Line 76 sub geogebra_default_parameters {
|
Line 77 sub geogebra_default_parameters {
|
<param name="boxborder" value="false" /> |
<param name="boxborder" value="false" /> |
<param name="centerimage" value="true" /> |
<param name="centerimage" value="true" /> |
<param name="cache_archive" value="geogebra.jar, geogebra_main.jar, geogebra_gui.jar, geogebra_cas.jar, geogebra_export.jar, geogebra_algos.jar, geogebra_javascript.jar, geogebra_properties.jar, jlatexmath.jar, jlm_cyrillic.jar, jlm_greek.jar" /> |
<param name="cache_archive" value="geogebra.jar, geogebra_main.jar, geogebra_gui.jar, geogebra_cas.jar, geogebra_export.jar, geogebra_algos.jar, geogebra_javascript.jar, geogebra_properties.jar, jlatexmath.jar, jlm_cyrillic.jar, jlm_greek.jar" /> |
<param name="cache_version" value="3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0, 3.9.219.0" /> |
<param name="cache_version" value="4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0,4.0.1.0" /> |
<param name="framePossible" value="false" /> |
<param name="framePossible" value="false" /> |
|
|
<param name="showResetIcon" value="false" /> |
<param name="showResetIcon" value="false" /> |
Line 164 sub update_register {
|
Line 165 sub update_register {
|
sub set_point_coordinate { |
sub set_point_coordinate { |
my ($id,$variable,$x,$y,$fixed)=@_; |
my ($id,$variable,$x,$y,$fixed)=@_; |
my $mult=($fixed?'a*':''); |
my $mult=($fixed?'a*':''); |
|
# Get rid of wild exponents, make sure it's a number |
|
$x=1.*$x; |
|
$y=1.*$y; |
|
# GeoGebra does not understand "E" |
|
$x=~s/[e|E]/\*10\^/; |
|
$x=~s/\+//; |
|
$y=~s/[e|E]/\*10\^/; |
|
$y=~s/\+//; |
return (<<ENDSETVARIABLE); |
return (<<ENDSETVARIABLE); |
document.ggbApplet_$id.evalCommand("a=1"); |
document.ggbApplet_$id.evalCommand("a=1"); |
document.ggbApplet_$id.evalCommand("$variable=$mult($x,$y)"); |
document.ggbApplet_$id.evalCommand("$variable=$mult($x,$y)"); |
Line 371 sub plot_script {
|
Line 380 sub plot_script {
|
} |
} |
|
|
# |
# |
|
# 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 |
# Answer spline display |
# |
# |
# points: x,y,slope_x,slope_y |
# points: x,y,slope_x,slope_y |
Line 423 sub generate_spline {
|
Line 481 sub generate_spline {
|
$result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n"; |
$result.='document.ggbApplet_'.$id.'.evalCommand("Spline'.$order.'['.join(',',@coords).']");'."\n"; |
return $result; |
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" /> |
# <backgroundplot function="..." fixed="yes/no" /> |
# |
# |
Line 973 sub compare_rel {
|
Line 1077 sub compare_rel {
|
|
|
sub addlog { |
sub addlog { |
my ($text)=@_; |
my ($text)=@_; |
|
$text=~s/\'/\\\'/g; |
$Apache::functionplotresponse::ruleslog.=$text.'<br />'; |
$Apache::functionplotresponse::ruleslog.=$text.'<br />'; |
} |
} |
|
|
Line 981 sub actualval {
|
Line 1086 sub actualval {
|
return $xmin+$i/400.*($xmax-$xmin); |
return $xmin+$i/400.*($xmax-$xmin); |
} |
} |
|
|
|
sub fpr_val { |
|
my ($arg)=@_; |
|
return &actualval($Apache::functionplotresponse::functionplotrulelabels{$arg}, |
|
$Apache::functionplotresponse::fpr_xmin, |
|
$Apache::functionplotresponse::fpr_xmax); |
|
} |
|
|
sub fpr_f { |
sub fpr_f { |
my ($arg)=@_; |
my ($arg)=@_; |
return $Apache::functionplotresponse::func[&array_index($Apache::functionplotresponse::fpr_xmin, |
return $Apache::functionplotresponse::func[&array_index($Apache::functionplotresponse::fpr_xmin, |