version 1.43, 2010/11/20 21:35:53
|
version 1.49, 2010/12/03 00:52:59
|
Line 161 sub update_register {
|
Line 161 sub update_register {
|
# Set a point coordinate variable |
# Set a point coordinate variable |
# |
# |
sub set_point_coordinate { |
sub set_point_coordinate { |
my ($id,$variable,$x,$y)=@_; |
my ($id,$variable,$x,$y,$fixed)=@_; |
|
my $mult=($fixed?'a*':''); |
return (<<ENDSETVARIABLE); |
return (<<ENDSETVARIABLE); |
document.ggbApplet_$id.evalCommand("$variable=($x,$y)"); |
document.ggbApplet_$id.evalCommand("a=1"); |
|
document.ggbApplet_$id.evalCommand("$variable=$mult($x,$y)"); |
document.ggbApplet_$id.setLabelVisible("$variable",false); |
document.ggbApplet_$id.setLabelVisible("$variable",false); |
ENDSETVARIABLE |
ENDSETVARIABLE |
} |
} |
Line 172 ENDSETVARIABLE
|
Line 174 ENDSETVARIABLE
|
# Set a slope coordinate variable |
# Set a slope coordinate variable |
# |
# |
sub set_slope_coordinate { |
sub set_slope_coordinate { |
my ($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname)=@_; |
my ($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname,$fixed)=@_; |
my $xvariable=$variable.'x'; |
my $xvariable=$variable.'x'; |
my $yvariable=$variable.'y'; |
my $yvariable=$variable.'y'; |
my $domain=$xmax-$xmin; |
my $domain=$xmax-$xmin; |
my $range=$ymax-$ymin; |
my $range=$ymax-$ymin; |
my $xinterval=$domain/100.; |
my $xinterval=$domain/100.; |
my $yinterval=$range/200.; |
my $yinterval=$range/200.; |
|
my $mult=($fixed?'a*':''); |
return (<<ENDSETSVARIABLE); |
return (<<ENDSETSVARIABLE); |
|
document.ggbApplet_$id.evalCommand("a=1"); |
document.ggbApplet_$id.evalCommand("$xvariable=Slider[0,$domain,$xinterval]"); |
document.ggbApplet_$id.evalCommand("$xvariable=Slider[0,$domain,$xinterval]"); |
document.ggbApplet_$id.setVisible("$xvariable", false); |
document.ggbApplet_$id.setVisible("$xvariable", false); |
document.ggbApplet_$id.evalCommand("$xvariable=$xrel"); |
document.ggbApplet_$id.evalCommand("$xvariable=$xrel"); |
document.ggbApplet_$id.evalCommand("$yvariable=Slider[-$range,$range,$yinterval]"); |
document.ggbApplet_$id.evalCommand("$yvariable=Slider[-$range,$range,$yinterval]"); |
document.ggbApplet_$id.setVisible("$yvariable", false); |
document.ggbApplet_$id.setVisible("$yvariable", false); |
document.ggbApplet_$id.evalCommand("$yvariable=$yrel"); |
document.ggbApplet_$id.evalCommand("$yvariable=$yrel"); |
document.ggbApplet_$id.evalCommand("$variable=($xvariable+x($pointname),$yvariable+y($pointname))"); |
document.ggbApplet_$id.evalCommand("$variable=$mult($xvariable+x($pointname),$yvariable+y($pointname))"); |
document.ggbApplet_$id.setLabelVisible("$variable", false); |
document.ggbApplet_$id.setLabelVisible("$variable", false); |
ENDSETSVARIABLE |
ENDSETSVARIABLE |
} |
} |
Line 215 sub generate_input_field {
|
Line 219 sub generate_input_field {
|
# Initialize a new point coordinate variable at set a listener on it |
# Initialize a new point coordinate variable at set a listener on it |
# |
# |
sub new_point_coordinate { |
sub new_point_coordinate { |
my ($id,$variable,$x,$y)=@_; |
my ($id,$variable,$x,$y,$fixed)=@_; |
if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'x')})) { |
if (defined($Apache::functionplotresponse::previous{&field_name($id,$variable,'x')})) { |
$x=$Apache::functionplotresponse::previous{&field_name($id,$variable,'x')}; |
$x=$Apache::functionplotresponse::previous{&field_name($id,$variable,'x')}; |
} |
} |
Line 223 sub new_point_coordinate {
|
Line 227 sub new_point_coordinate {
|
$y=$Apache::functionplotresponse::previous{&field_name($id,$variable,'y')}; |
$y=$Apache::functionplotresponse::previous{&field_name($id,$variable,'y')}; |
} |
} |
&generate_input_field($id,$variable,$x,$y); |
&generate_input_field($id,$variable,$x,$y); |
return &set_point_coordinate($id,$variable,$x,$y).&update_register($id,$variable); |
return &set_point_coordinate($id,$variable,$x,$y,$fixed).&update_register($id,$variable); |
} |
} |
|
|
# |
# |
# Initialize a new slope coordinate variable at set a listener on it |
# Initialize a new slope coordinate variable at set a listener on it |
# |
# |
sub new_slope_coordinate { |
sub new_slope_coordinate { |
my ($id,$variable,$x,$y,$pointname,$xp,$yp,$xmin,$xmax,$ymin,$ymax)=@_; |
my ($id,$variable,$x,$y,$pointname,$xp,$yp,$xmin,$xmax,$ymin,$ymax,$fixed)=@_; |
# |
# |
# $variable: name of the slope point |
# $variable: name of the slope point |
# $x, $y: coordinates of the slope point |
# $x, $y: coordinates of the slope point |
Line 253 sub new_slope_coordinate {
|
Line 257 sub new_slope_coordinate {
|
&generate_input_field($id,$variable,$x,$y); |
&generate_input_field($id,$variable,$x,$y); |
my $xrel=$x-$xp; |
my $xrel=$x-$xp; |
my $yrel=$y-$yp; |
my $yrel=$y-$yp; |
return &set_slope_coordinate($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname).&update_register($id,$variable); |
return &set_slope_coordinate($id,$variable,$xrel,$yrel,$xmin,$xmax,$ymin,$ymax,$pointname,$fixed).&update_register($id,$variable); |
} |
} |
|
|
# |
# |
Line 295 ENDAXESSCRIPT
|
Line 299 ENDAXESSCRIPT
|
} |
} |
|
|
sub axes_label { |
sub axes_label { |
my ($id,$xlabel,$ylabel)=@_; |
my ($id,$xmin,$xmax,$ymin,$ymax,$xlabel,$ylabel)=@_; |
unless ($xlabel || $ylabel) { return ''; } |
unless ($xlabel || $ylabel) { return ''; } |
my $return='document.ggbApplet_'.$id.'.evalCommand("topRight=Corner[3]");'; |
my $return='document.ggbApplet_'.$id.'.evalCommand("topRight=Corner[3]");'; |
if ($xlabel) { |
if ($xlabel) { |
|
if (($ymin<0) && ($ymax>0)) { |
$return.=(<<ENDXAXISLABELSCRIPT); |
$return.=(<<ENDXAXISLABELSCRIPT); |
document.ggbApplet_$id.evalCommand("Xlabel=(x(topRight)-AxisStepX[],AxisStepY[]/6)"); |
document.ggbApplet_$id.evalCommand("Xlabel=(x(topRight)-AxisStepX[],AxisStepY[]/6)"); |
document.ggbApplet_$id.setVisible("Xlabel",false); |
document.ggbApplet_$id.setVisible("Xlabel",false); |
document.ggbApplet_$id.evalCommand("Text[\\"$xlabel\\", Xlabel]"); |
document.ggbApplet_$id.evalCommand("Text[\\"$xlabel\\", Xlabel]"); |
ENDXAXISLABELSCRIPT |
ENDXAXISLABELSCRIPT |
|
} else { |
|
$return.=(<<ENDXOFFAXISLABEL); |
|
document.ggbApplet_$id.evalCommand("LowerRight=Corner[2]"); |
|
document.ggbApplet_$id.evalCommand("Text[\\"$xlabel\\", (x(LowerRight) - AxisStepX[], y(LowerRight) + AxisStepY[] / 2)]"); |
|
ENDXOFFAXISLABEL |
|
} |
} |
} |
if ($ylabel) { |
if ($ylabel) { |
|
if (($xmin<0) && ($xmax>0)) { |
$return.=(<<ENDYAXISLABELSCRIPT); |
$return.=(<<ENDYAXISLABELSCRIPT); |
document.ggbApplet_$id.evalCommand("Ylabel=(AxisStepX[]/6,y(topRight)-AxisStepY[]/3)"); |
document.ggbApplet_$id.evalCommand("Ylabel=(AxisStepX[]/6,y(topRight)-AxisStepY[]/3)"); |
document.ggbApplet_$id.setVisible("Ylabel",false); |
document.ggbApplet_$id.setVisible("Ylabel",false); |
document.ggbApplet_$id.evalCommand("Text[\\"$ylabel\\", Ylabel]"); |
document.ggbApplet_$id.evalCommand("Text[\\"$ylabel\\", Ylabel]"); |
ENDYAXISLABELSCRIPT |
ENDYAXISLABELSCRIPT |
|
} else { |
|
$return.=(<<ENDYOFFAXISLABEL); |
|
document.ggbApplet_$id.evalCommand("UpperLeft=Corner[4]"); |
|
document.ggbApplet_$id.evalCommand("Text[\\"$ylabel\\", (x(UpperLeft) + AxisStepX[] / 5, y(UpperLeft) - AxisStepY[] / 1.8)]"); |
|
ENDYOFFAXISLABEL |
|
} |
} |
} |
return $return; |
return $return; |
} |
} |
|
|
sub plot_script { |
sub plot_script { |
my ($id,$function,$fixed,$label,$xmin,$xmax)=@_; |
my ($id,$function,$fixed,$label,$color,$xmin,$xmax,$thickness)=@_; |
$label=~s/\W//g; |
$label=~s/\W//g; |
if (($label) && ($label!~/^[A-Za-z]/)) { |
if (($label) && ($label!~/^[A-Za-z]/)) { |
$label='C'.$label; |
$label='C'.$label; |
Line 328 sub plot_script {
|
Line 346 sub plot_script {
|
$Apache::functionplotresponse::counter++; |
$Apache::functionplotresponse::counter++; |
$label='C'.$Apache::functionplotresponse::counter; |
$label='C'.$Apache::functionplotresponse::counter; |
} |
} |
|
my $rc=0; |
|
my $gc=0; |
|
my $bc=0; |
|
if ($color) { |
|
my ($rh,$gh,$bh)=($color=~/(..)(..)(..)/); |
|
$rc=hex($rh); |
|
$gc=hex($gh); |
|
$bc=hex($bh); |
|
} |
if ($fixed) { |
if ($fixed) { |
return "document.ggbApplet_$id.evalCommand('$label=Function[$function,$xmin,$xmax]');\n". |
return "document.ggbApplet_$id.evalCommand('$label=Function[$function,$xmin,$xmax]');\n". |
($visible?'':"document.ggbApplet_$id.setLabelVisible('$label', false);\n"); |
($visible?'':"document.ggbApplet_$id.setLabelVisible('$label', false);\n"). |
|
($color?"document.ggbApplet_$id.setColor('$label',$rc,$gc,$bc);\n":''). |
|
($thickness?"document.ggbApplet_$id.setLineThickness('$label',$thickness);\n":''); |
} else { |
} else { |
return "document.ggbApplet_$id.evalCommand('y=$function')"; |
return "document.ggbApplet_$id.evalCommand('y=$function');\n"; |
} |
} |
} |
} |
|
|
Line 341 sub plot_script {
|
Line 370 sub plot_script {
|
# |
# |
|
|
sub generate_spline { |
sub generate_spline { |
my ($id,$label,$xmin,$xmax,$ymin,$ymax)=@_; |
my ($id,$label,$xmin,$xmax,$ymin,$ymax,$fixed)=@_; |
my $result=''; |
my $result=''; |
my $order=$Apache::functionplotresponse::splineorder{$label}; |
my $order=$Apache::functionplotresponse::splineorder{$label}; |
my $x=$Apache::functionplotresponse::splineinitx{$label}; |
my $x=$Apache::functionplotresponse::splineinitx{$label}; |
Line 350 sub generate_spline {
|
Line 379 sub generate_spline {
|
my $sy=$Apache::functionplotresponse::splinescaley{$label}; |
my $sy=$Apache::functionplotresponse::splinescaley{$label}; |
my @coords=(); |
my @coords=(); |
foreach my $i (1..$order) { |
foreach my $i (1..$order) { |
$result.=&new_point_coordinate($id,$label.'P'.$i,$x,$y); |
$result.=&new_point_coordinate($id,$label.'P'.$i,$x,$y,$fixed); |
my $xp=$x; |
my $xp=$x; |
$x+=$sx/(2.*($order-1)); |
$x+=$sx/(2.*($order-1)); |
push(@coords,$label.'P'.$i); |
push(@coords,$label.'P'.$i); |
$result.=&new_slope_coordinate($id,$label.'S'.$i,$x,$y+$sy,$label.'P'.$i,$xp,$y,$xmin,$xmax,$ymin,$ymax); |
$result.=&new_slope_coordinate($id,$label.'S'.$i,$x,$y+$sy,$label.'P'.$i,$xp,$y,$xmin,$xmax,$ymin,$ymax,$fixed); |
$x+=$sx/(2.*($order-1)); |
$x+=$sx/(2.*($order-1)); |
push(@coords,$label.'S'.$i); |
push(@coords,$label.'S'.$i); |
} |
} |
Line 369 sub start_backgroundplot {
|
Line 398 sub start_backgroundplot {
|
my $result=''; |
my $result=''; |
my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1]; |
my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1]; |
my $function=&Apache::lonxml::get_param('function',$parstack,$safeeval); |
my $function=&Apache::lonxml::get_param('function',$parstack,$safeeval); |
|
my $xinitial=&Apache::lonxml::get_param('xinitial',$parstack,$safeeval); |
|
my $xfinal=&Apache::lonxml::get_param('xfinal',$parstack,$safeeval); |
my $label=&Apache::lonxml::get_param('label',$parstack,$safeeval); |
my $label=&Apache::lonxml::get_param('label',$parstack,$safeeval); |
|
my $color=&Apache::lonxml::get_param('color',$parstack,$safeeval); |
|
$color=~s/[^a-fA-F0-9]//gs; |
|
unless (length($color)==6) { $color=''; } |
my $fixed=(&Apache::lonxml::get_param('fixed',$parstack,$safeeval)=~/on|true|yes|1/i?1:0); |
my $fixed=(&Apache::lonxml::get_param('fixed',$parstack,$safeeval)=~/on|true|yes|1/i?1:0); |
|
|
unless ($function) { $function="0"; } |
unless ($function) { $function="0"; } |
if ($target eq 'web') { |
if ($target eq 'web') { |
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3); |
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3); |
$result.=&plot_script($internalid,$function,$fixed,$label,$xmin,$xmax); |
unless (defined($xinitial)) { $xinitial=$xmin; } |
|
unless (defined($xfinal)) { $xfinal=$xmax; } |
|
$result.=&plot_script($internalid,$function,$fixed,$label,$color,$xinitial,$xfinal); |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
$result=&Apache::edit::tag_start($target,$token,'Background Function Plot'). |
$result=&Apache::edit::tag_start($target,$token,'Background Function Plot'). |
&Apache::edit::text_arg('Function:','function', |
&Apache::edit::text_arg('Function:','function', |
$token,'16'). |
$token,'16'). |
|
&Apache::edit::text_arg('Initial x-value (optional):','xinitial', |
|
$token,'8'). |
|
&Apache::edit::text_arg('Final x-value (optional):','xfinal', |
|
$token,'8'). |
&Apache::edit::text_arg('Label on Plot:','label', |
&Apache::edit::text_arg('Label on Plot:','label', |
$token,'8'). |
$token,'8'). |
|
&Apache::edit::text_arg('Color (hex code):','color', |
|
$token,'8'). |
&Apache::edit::select_arg('Fixed location:','fixed', |
&Apache::edit::select_arg('Fixed location:','fixed', |
['yes','no'],$token). |
['yes','no'],$token). |
&Apache::edit::end_row(); |
&Apache::edit::end_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, |
$safeeval,'function','label','fixed'); |
$safeeval,'function','label','xinitial','xfinal','color','fixed'); |
if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); } |
if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); } |
} |
} |
return $result; |
return $result; |
Line 467 sub start_functionplotrule {
|
Line 509 sub start_functionplotrule {
|
['1','First derivative'], |
['1','First derivative'], |
['2','Second derivative'], |
['2','Second derivative'], |
['-1','Integral']],$token).'<br />'. |
['-1','Integral']],$token).'<br />'. |
&Apache::edit::text_arg('(Initial) x-value:','xinitial', |
&Apache::edit::text_arg('Initial x-value:','xinitial', |
$token,'8'). |
$token,'8'). |
&Apache::edit::select_or_text_arg('(Initial) x-value label:','xinitiallabel', |
&Apache::edit::select_or_text_arg('Initial x-value label:','xinitiallabel', |
[['start','Start of Plot']],$token,'8').'<br />'. |
[['start','Start of Plot'], |
|
['end','End of Plot']],$token,'8').'<br />'. |
|
|
&Apache::edit::text_arg('Optional final x-value for ranges:','xfinal', |
&Apache::edit::text_arg('Final x-value (optional):','xfinal', |
$token,'8'). |
$token,'8'). |
&Apache::edit::select_or_text_arg('Optional final x-value label:','xfinallabel', |
&Apache::edit::select_or_text_arg('Final x-value label (optional):','xfinallabel', |
[['end','End of Plot']],$token,'8').'<br />'. |
[['end','End of Plot']],$token,'8').'<br />'. |
&Apache::edit::text_arg('Optional minimum length for range:','minimumlength', |
&Apache::edit::text_arg('Minimum length for range (optional):','minimumlength', |
$token,'8'). |
$token,'8'). |
&Apache::edit::text_arg('Optional maximum length for range:','maximumlength', |
&Apache::edit::text_arg('Maximum length for range (optional):','maximumlength', |
$token,'8').'<br />'. |
$token,'8').'<br />'. |
&Apache::edit::select_or_text_arg(&mt('Relationship:'),'relationship', |
&Apache::edit::select_or_text_arg(&mt('Relationship:'),'relationship', |
[['eq','equal'], |
[['eq','equal'], |
Line 562 sub start_spline {
|
Line 605 sub start_spline {
|
&Apache::edit::text_arg('Index:','index', |
&Apache::edit::text_arg('Index:','index', |
$token,'4').' '. |
$token,'4').' '. |
&Apache::edit::select_arg('Order:','order', |
&Apache::edit::select_arg('Order:','order', |
['2','3','4','5','6','7','8','9'],$token).' '. |
['2','3','4','5','6','7','8'],$token).' '. |
&Apache::edit::text_arg('Initial x-value:','initx', |
&Apache::edit::text_arg('Initial x-value:','initx', |
$token,'4').' '. |
$token,'4').' '. |
&Apache::edit::text_arg('Initial y-value:','inity', |
&Apache::edit::text_arg('Initial y-value:','inity', |
Line 796 sub start_functionplotresponse {
|
Line 839 sub start_functionplotresponse {
|
&Apache::edit::select_arg('y-axis visible:','yaxisvisible', |
&Apache::edit::select_arg('y-axis visible:','yaxisvisible', |
['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). |
['yes','no'],$token).'<br />'. |
|
&Apache::edit::text_arg('Background plot(s) for answer (function:xmin:xmax,function:xmin:xmax,...):', |
|
'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, |
$safeeval,'xlabel','xmin','xmax','ylabel','ymin','ymax', |
$safeeval,'xlabel','xmin','xmax','ylabel','ymin','ymax', |
'xaxisvisible','yaxisvisible','gridvisible'); |
'xaxisvisible','yaxisvisible','gridvisible','answerdisplay'); |
if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } |
if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); } |
|
|
} elsif ($target eq 'meta') { |
} elsif ($target eq 'meta') { |
Line 897 sub functionplotrulecheck {
|
Line 943 sub functionplotrulecheck {
|
$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"); |
|
if ((defined($minimumlength)) || (defined($maximumlength))) { |
|
&addlog("Minimumlength $minimumlength Maximumlength $maximumlength"); |
|
} |
my $li=0; |
my $li=0; |
my $lh=400; |
my $lh=400; |
|
|
Line 991 sub functionplotrulecheck {
|
Line 1040 sub functionplotrulecheck {
|
&addlog("Actual value ".(defined($val)?$val:'undef').", expected $value, tolerance $tol"); |
&addlog("Actual value ".(defined($val)?$val:'undef').", expected $value, tolerance $tol"); |
&addlog("Condition not fulfilled at x=".&actualval($i,$xmin,$xmax)." (".$Apache::functionplotresponse::actualxval[$i]."; index $i)"); |
&addlog("Condition not fulfilled at x=".&actualval($i,$xmin,$xmax)." (".$Apache::functionplotresponse::actualxval[$i]."; index $i)"); |
if (($findupper) && ($i>$li)) { |
if (($findupper) && ($i>$li)) { |
# check for minimum and maximum lengths |
# Check lengths |
my $length=&actualval($i,$xmin,$xmax)-&actualval($li,$xmin,$xmax); |
unless (&checklength($i,$li,$minimumlength,$maximumlength,$xmin,$xmax,$label)) { return 0; } |
if ($minimumlength) { |
# Successfully found a new label, set it |
if ($length<$minimumlength) { |
|
&addlog("Rule $label failed, actual length $length, minimum length $minimumlength"); |
|
return 0; |
|
} |
|
} |
|
if ($maximumlength) { |
|
if ($length>$maximumlength) { |
|
&addlog("Rule $label failed, actual length $length, maximum length $maximumlength"); |
|
return 0; |
|
} |
|
} |
|
$Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$i; |
$Apache::functionplotresponse::functionplotrulelabels{$xfinallabel}=$i; |
&addlog("Rule $label passed, setting label $xfinallabel"); |
&addlog("Rule $label passed, setting label $xfinallabel"); |
return 1; |
return 1; |
} else { |
} else { |
&addlog("Rule $label failed."); |
&addlog("Rule $label failed."); |
my $hintlabel=$label; |
&setfailed($label); |
$hintlabel=~s/^R//; |
|
push(@Apache::functionplotresponse::failedrules,$hintlabel); |
|
&addlog("Set hint condition $hintlabel"); |
|
return 0; |
return 0; |
} |
} |
} |
} |
} |
} |
} |
} |
|
# Corner case where this makes sense: using start or stop as defined labels |
|
unless (&checklength($lh,$li,$minimumlength,$maximumlength,$xmin,$xmax,$label)) { return 0; } |
&addlog("Rule $label passed."); |
&addlog("Rule $label passed."); |
return 1; |
return 1; |
} |
} |
|
|
|
# |
|
# check for minimum and maximum lengths |
|
# |
|
|
|
sub checklength { |
|
my ($i,$li,$minimumlength,$maximumlength,$xmin,$xmax,$label)=@_; |
|
unless (($minimumlength) || ($maximumlength)) { return 1; } |
|
my $length=&actualval($i,$xmin,$xmax)-&actualval($li,$xmin,$xmax); |
|
if ($minimumlength) { |
|
if ($length<$minimumlength) { |
|
&addlog("Rule $label failed, actual length $length, minimum length $minimumlength"); |
|
&setfailed($label); |
|
return 0; |
|
} |
|
} |
|
if ($maximumlength) { |
|
if ($length>$maximumlength) { |
|
&addlog("Rule $label failed, actual length $length, maximum length $maximumlength"); |
|
&setfailed($label); |
|
return 0; |
|
} |
|
} |
|
return 1; |
|
} |
|
|
|
sub setfailed { |
|
my ($label)=@_; |
|
my $hintlabel=$label; |
|
$hintlabel=~s/^R//; |
|
push(@Apache::functionplotresponse::failedrules,$hintlabel); |
|
&addlog("Set hint condition $hintlabel"); |
|
} |
|
|
sub start_functionplotruleset { |
sub start_functionplotruleset { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
if ($target eq 'edit') { |
if ($target eq 'edit') { |
Line 1132 sub end_functionplotelements {
|
Line 1202 sub end_functionplotelements {
|
if ($target eq 'edit' ) { |
if ($target eq 'edit' ) { |
$result=&Apache::edit::end_table(); |
$result=&Apache::edit::end_table(); |
} elsif ($target eq 'web') { |
} elsif ($target eq 'web') { |
# Now is the time to render all of the stored splines |
|
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2); |
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2); |
|
|
|
# Are we in show answer mode? |
|
my $showanswer=&Apache::response::show_answer(); |
|
if ($showanswer) { |
|
# Render answerdisplay |
|
my $answerdisplay=&Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval,-2); |
|
if ($answerdisplay=~/\S/s) { |
|
foreach my $plot (split(/\s*\,\s*/,$answerdisplay)) { |
|
my ($func,$xl,$xh)=split(/\s*\:\s*/,$plot); |
|
if ((!defined($xl)) || ($xl eq '')) { $xl=$xmin; } |
|
if ((!defined($xh)) || ($xh eq '')) { $xh=$xmax; } |
|
$result.=&plot_script($internalid,$func,1,'','00aa00',$xl,$xh,6); |
|
} |
|
} |
|
} |
|
my $fixed=0; |
|
if (($showanswer) || (&Apache::response::check_status()>=2)) { $fixed=1; } |
|
# Now is the time to render all of the stored splines |
foreach my $label (keys(%Apache::functionplotresponse::splineorder)) { |
foreach my $label (keys(%Apache::functionplotresponse::splineorder)) { |
$result.=&generate_spline($internalid,$label,$xmin,$xmax,$ymin,$ymax); |
$result.=&generate_spline($internalid,$label,$xmin,$xmax,$ymin,$ymax,$fixed); |
} |
} |
# close the init script |
# close the init script |
$result.=&end_init_script(); |
$result.=&end_init_script(); |
Line 1212 sub start_functionplotelements {
|
Line 1299 sub start_functionplotelements {
|
$result.=&start_init_script($internalid); |
$result.=&start_init_script($internalid); |
# put the axis commands inside |
# put the axis commands inside |
$result.=&axes_script($internalid,$xmin,$xmax,$ymin,$ymax,$xaxisvisible,$yaxisvisible,$gridvisible); |
$result.=&axes_script($internalid,$xmin,$xmax,$ymin,$ymax,$xaxisvisible,$yaxisvisible,$gridvisible); |
$result.=&axes_label($internalid,$xlabel,$ylabel); |
$result.=&axes_label($internalid,$xmin,$xmax,$ymin,$ymax,$xlabel,$ylabel); |
# init script is left open |
# init script is left open |
} |
} |
return $result; |
return $result; |