version 1.57, 2011/03/31 16:10:07
|
version 1.67, 2011/10/19 00:20:28
|
Line 31 use strict;
|
Line 31 use strict;
|
use Apache::response(); |
use Apache::response(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
use Apache::lonnet; |
use Apache::lonnet; |
|
use Apache::run; |
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline', |
&Apache::lonxml::register('Apache::functionplotresponse',('functionplotresponse','backgroundplot','spline', |
Line 74 sub geogebra_default_parameters {
|
Line 75 sub geogebra_default_parameters {
|
<param name="image" value="/adm/lonIcons/lonanim.gif" /> |
<param name="image" value="/adm/lonIcons/lonanim.gif" /> |
<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_algos.jar, geogebra_export.jar, geogebra_javascript.jar, jlatexmath.jar, jlm_greek.jar, jlm_cyrillic.jar, geogebra_properties.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.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0, 3.9.214.0" /> |
<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="framePossible" value="false" /> |
<param name="framePossible" value="false" /> |
|
|
<param name="showResetIcon" value="false" /> |
<param name="showResetIcon" value="false" /> |
Line 333 ENDYOFFAXISLABEL
|
Line 334 ENDYOFFAXISLABEL
|
return $return; |
return $return; |
} |
} |
|
|
|
# |
|
# Subroutine to produce background and answer plots |
|
# |
|
|
sub plot_script { |
sub plot_script { |
my ($id,$function,$fixed,$label,$color,$xmin,$xmax,$thickness)=@_; |
my ($id,$function,$fixed,$label,$color,$xmin,$xmax,$thickness)=@_; |
$label=~s/\W//g; |
$label=~s/\W//g; |
Line 366 sub plot_script {
|
Line 371 sub plot_script {
|
} |
} |
|
|
# |
# |
|
# Answer spline display |
|
# |
|
# points: x,y,slope_x,slope_y |
|
|
|
sub answer_spline_script { |
|
my ($id,@points)=@_; |
|
my $order=int(($#points+1)/4); |
|
if ($order<2) { $order=2; } |
|
if ($order>8) { $order=8; } |
|
$Apache::functionplotresponse::counter++; |
|
my $label='CSpline'.$Apache::functionplotresponse::counter; |
|
my $output='document.ggbApplet_'.$id.'.evalCommand("'.$label.'=Spline'.$order.'['; |
|
for (my $i=0;$i<=$#points;$i+=4) { |
|
$output.="($points[$i],$points[$i+1]),($points[$i+2],$points[$i+3]),"; |
|
} |
|
$output=~s/\,$//; |
|
$output.=']");'."\n"; |
|
for (my $i=2; $i<2*$order; $i+=2) { |
|
$output.='document.ggbApplet_'.$id.'.setColor("'.$label.'_'.($i>=10?'{':'').$i.($i>=10?'}':'').'",0,170,0);'."\n"; |
|
} |
|
for (my $i=1; $i<2*$order; $i+=2) { |
|
$output.='document.ggbApplet_'.$id.'.setVisible("'.$label.'_'.($i>=10?'{':'').$i.($i>=10?'}':'').'",false);'."\n"; |
|
} |
|
|
|
return $output; |
|
} |
|
|
|
# |
# Subroutine that generates code for spline $label based on stored information |
# Subroutine that generates code for spline $label based on stored information |
# |
# |
|
|
Line 531 sub start_functionplotrule {
|
Line 564 sub start_functionplotrule {
|
['lt','less than'], |
['lt','less than'], |
['le','less than or equal']],$token). |
['le','less than or equal']],$token). |
$result.= &Apache::edit::select_or_text_arg('Value:','value', |
$result.= &Apache::edit::select_or_text_arg('Value:','value', |
[['undef','not defined']],$token,'8'). |
[['undef','not defined']],$token,'30'). |
&Apache::edit::text_arg('Percent error:','percenterror', |
&Apache::edit::text_arg('Percent error:','percenterror', |
$token,'8'). |
$token,'8'). |
&Apache::edit::end_row(); |
&Apache::edit::end_row(); |
Line 719 sub array_index {
|
Line 752 sub array_index {
|
# |
# |
|
|
sub populate_arrays { |
sub populate_arrays { |
my ($id,$xmin,$xmax)=@_; |
my ($id,$xmin,$xmax,$ymin,$ymax)=@_; |
for (my $i=0; $i<=400; $i++) { |
for (my $i=0; $i<=400; $i++) { |
$Apache::functionplotresponse::actualxval[$i]=undef; |
$Apache::functionplotresponse::actualxval[$i]=undef; |
$Apache::functionplotresponse::func[$i]=undef; |
$Apache::functionplotresponse::func[$i]=undef; |
Line 747 sub populate_arrays {
|
Line 780 sub populate_arrays {
|
my $xi=&array_index($xmin,$xmax,$xreal); |
my $xi=&array_index($xmin,$xmax,$xreal); |
if ($xi<$xiold) { return 'no_func'; } |
if ($xi<$xiold) { return 'no_func'; } |
if (($xi>$xiold) && ($xi>=0) && ($xi<=400)) { |
if (($xi>$xiold) && ($xi>=0) && ($xi<=400)) { |
if (defined($Apache::functionplotresponse::func[$xi])) { return 'no_func'; } |
|
$xiold=$xi; |
$xiold=$xi; |
$Apache::functionplotresponse::actualxval[$xi]=$xreal; |
$Apache::functionplotresponse::actualxval[$xi]=$xreal; |
# Function value |
# Function value |
my $funcval=&cubic_hermite($t,@yparms); |
my $funcval=&cubic_hermite($t,@yparms); |
|
|
|
# Do we already have a value for this point, and is it different from the new one? |
|
if ((defined($Apache::functionplotresponse::func[$xi])) && |
|
(abs($Apache::functionplotresponse::func[$xi]-$funcval)>($ymax-$ymin)/100.)) { |
|
return 'no_func'; |
|
} |
|
# Okay, remember the new point |
$Apache::functionplotresponse::func[$xi]=$funcval; |
$Apache::functionplotresponse::func[$xi]=$funcval; |
|
|
if (defined($funcval)) { |
if (defined($funcval)) { |
if ($xi<$Apache::functionplotresponse::functionplotrulelabels{'start'}) { |
if ($xi<$Apache::functionplotresponse::functionplotrulelabels{'start'}) { |
$Apache::functionplotresponse::functionplotrulelabels{'start'}=$xi; |
$Apache::functionplotresponse::functionplotrulelabels{'start'}=$xi; |
Line 847 sub start_functionplotresponse {
|
Line 887 sub start_functionplotresponse {
|
['yes','no'],$token).'<br />'. |
['yes','no'],$token).'<br />'. |
&Apache::edit::select_arg('Grid visible:','gridvisible', |
&Apache::edit::select_arg('Grid visible:','gridvisible', |
['yes','no'],$token).'<br />'. |
['yes','no'],$token).'<br />'. |
&Apache::edit::text_arg('Background plot(s) for answer (function:xmin:xmax,function:xmin:xmax,...):', |
&Apache::edit::text_arg('Background plot(s) for answer (function(x):xmin:xmax,function(x):xmin:xmax,x1:y1:sx1:sy1:x2:y2:sx2:sy2,...):', |
'answerdisplay',$token,'50'); |
'answerdisplay',$token,'50'). |
|
|
&Apache::edit::end_row().&Apache::edit::start_spanning_row(); |
&Apache::edit::end_row().&Apache::edit::start_spanning_row(); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
my $constructtag=&Apache::edit::get_new_args($token,$parstack, |
my $constructtag=&Apache::edit::get_new_args($token,$parstack, |
Line 934 sub compare_rel {
|
Line 973 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 941 sub actualval {
|
Line 981 sub actualval {
|
my ($i,$xmin,$xmax)=@_; |
my ($i,$xmin,$xmax)=@_; |
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 { |
|
my ($arg)=@_; |
|
return $Apache::functionplotresponse::func[&array_index($Apache::functionplotresponse::fpr_xmin, |
|
$Apache::functionplotresponse::fpr_xmax, |
|
$arg)]; |
|
} |
|
|
|
sub fpr_dfdx { |
|
my ($arg)=@_; |
|
return $Apache::functionplotresponse::dfuncdx[&array_index($Apache::functionplotresponse::fpr_xmin, |
|
$Apache::functionplotresponse::fpr_xmax, |
|
$arg)]; |
|
} |
|
|
|
sub fpr_d2fdx2 { |
|
my ($arg)=@_; |
|
return $Apache::functionplotresponse::d2funcdx2[&array_index($Apache::functionplotresponse::fpr_xmin, |
|
$Apache::functionplotresponse::fpr_xmax, |
|
$arg)]; |
|
} |
|
|
sub functionplotrulecheck { |
sub functionplotrulecheck { |
my ($rule,$xmin,$xmax,$ymin,$ymax)=@_; |
my ($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)=@_; |
|
|
my ($label,$derivative,$xinitial,$xinitiallabel,$xfinal,$xfinallabel,$minimumlength,$maximumlength,$relationship,$value,$percent) |
my ($label,$derivative,$xinitial,$xinitiallabel,$xfinal,$xfinallabel,$minimumlength,$maximumlength,$relationship,$value,$percent) |
=split(/\:/,$rule); |
=split(/\:/,$rule); |
$percent=($percent>0?$percent:5); |
$percent=($percent>0?$percent:5); |
&addlog("================="); |
&addlog("================="); |
&addlog("Rule $label for ".($derivative<0?'integral':('function itself','first derivative','second derivative')[$derivative])." $relationship $value"); |
&addlog("Rule $label for ".($derivative<0?'integral':('function itself','first derivative','second derivative')[$derivative])." $relationship $value"); |
|
# |
|
# Evaluate the value |
|
# |
|
if ($value=~/\D/) { |
|
$Apache::functionplotresponse::fpr_xmin=$xmin; |
|
$Apache::functionplotresponse::fpr_xmax=$xmax; |
|
$value=&Apache::run::run($value,$safeeval); |
|
&addlog("Value evaluated to $value"); |
|
} |
|
|
|
# |
|
# Minimum and maximum lengths of the interval |
|
# |
if ((defined($minimumlength)) || (defined($maximumlength))) { |
if ((defined($minimumlength)) || (defined($maximumlength))) { |
&addlog("Minimumlength $minimumlength Maximumlength $maximumlength"); |
&addlog("Minimumlength $minimumlength Maximumlength $maximumlength"); |
} |
} |
Line 1138 sub end_functionplotruleset {
|
Line 1219 sub end_functionplotruleset {
|
$Apache::functionplotresponse::ruleslog=''; |
$Apache::functionplotresponse::ruleslog=''; |
$Apache::functionplotresponse::functionplotrulelabels{'start'}=400; |
$Apache::functionplotresponse::functionplotrulelabels{'start'}=400; |
$Apache::functionplotresponse::functionplotrulelabels{'end'}=0; |
$Apache::functionplotresponse::functionplotrulelabels{'end'}=0; |
if (&populate_arrays($internalid,$xmin,$xmax) eq 'no_func') { |
if (&populate_arrays($internalid,$xmin,$xmax,$ymin,$ymax) eq 'no_func') { |
$ad='NOT_FUNCTION'; |
$ad='NOT_FUNCTION'; |
} else { |
} else { |
&addlog("Start of function ".&actualval($Apache::functionplotresponse::functionplotrulelabels{'start'},$xmin,$xmax)." (index ". |
&addlog("Start of function ".&actualval($Apache::functionplotresponse::functionplotrulelabels{'start'},$xmin,$xmax)." (index ". |
Line 1148 sub end_functionplotruleset {
|
Line 1229 sub end_functionplotruleset {
|
|
|
# We have a function that we can actually grade, go through the spline rules. |
# We have a function that we can actually grade, go through the spline rules. |
foreach my $rule (@Apache::functionplotresponse::functionplotrules) { |
foreach my $rule (@Apache::functionplotresponse::functionplotrules) { |
unless (&functionplotrulecheck($rule,$xmin,$xmax,$ymin,$ymax)) { |
unless (&functionplotrulecheck($rule,$xmin,$xmax,$ymin,$ymax,$safeeval)) { |
$ad='INCORRECT'; |
$ad='INCORRECT'; |
last; |
last; |
} |
} |
Line 1219 sub end_functionplotelements {
|
Line 1300 sub end_functionplotelements {
|
my $answerdisplay=&Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval,-2); |
my $answerdisplay=&Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval,-2); |
if ($answerdisplay=~/\S/s) { |
if ($answerdisplay=~/\S/s) { |
foreach my $plot (split(/\s*\,\s*/,$answerdisplay)) { |
foreach my $plot (split(/\s*\,\s*/,$answerdisplay)) { |
my ($func,$xl,$xh)=split(/\s*\:\s*/,$plot); |
my @components=split(/\s*\:\s*/,$plot); |
if ((!defined($xl)) || ($xl eq '')) { $xl=$xmin; } |
if ($#components<3) { |
if ((!defined($xh)) || ($xh eq '')) { $xh=$xmax; } |
# Just a simple plot |
$result.=&plot_script($internalid,$func,1,'','00aa00',$xl,$xh,6); |
my ($func,$xl,$xh)=@components; |
|
if ((!defined($xl)) || ($xl eq '')) { $xl=$xmin; } |
|
if ((!defined($xh)) || ($xh eq '')) { $xh=$xmax; } |
|
$result.=&plot_script($internalid,$func,1,'','00aa00',$xl,$xh,6); |
|
} else { |
|
# This is a spline |
|
$result.=&answer_spline_script($internalid,@components); |
|
} |
} |
} |
} |
} |
} |
} |