version 1.40, 2010/11/19 17:20:44
|
version 1.41, 2010/11/19 20:03:13
|
Line 316 ENDYAXISLABELSCRIPT
|
Line 316 ENDYAXISLABELSCRIPT
|
} |
} |
|
|
sub plot_script { |
sub plot_script { |
my ($id,$function,$fixed)=@_; |
my ($id,$function,$fixed,$label,$xmin,$xmax)=@_; |
|
$label=~s/\W//g; |
|
if (($label) && ($label!~/^[A-Za-z]/)) { |
|
$label='C'.$label; |
|
} |
|
my $visible=0; |
|
if ($label) { |
|
$visible="1"; |
|
} else { |
|
$Apache::functionplotresponse::counter++; |
|
$label='C'.$Apache::functionplotresponse::counter; |
|
} |
if ($fixed) { |
if ($fixed) { |
# Use stupid trick to nail this to a location |
return "document.ggbApplet_$id.evalCommand('$label=Function[$function,$xmin,$xmax]')". |
# Oddly, it seems like only one plot cannot be nailed to a location |
($visible?'':"document.ggbApplet.setLabelVisible('$label', false);"); |
# Non-nailed-down plots apparently get overwritten |
|
return (<<ENDPLOTSCRIPT); |
|
document.ggbApplet_$id.evalCommand("a=1"); |
|
document.ggbApplet_$id.setVisible("a",false); |
|
// This MUST be a DEPENDENT OBJECT in order to be locked down: |
|
document.ggbApplet_$id.evalCommand("y=a*($function)"); |
|
ENDPLOTSCRIPT |
|
} else { |
} else { |
return "document.ggbApplet_$id.evalCommand('y=$function')"; |
return "document.ggbApplet_$id.evalCommand('y=$function')"; |
} |
} |
Line 365 sub start_backgroundplot {
|
Line 369 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 $label=&Apache::lonxml::get_param('label',$parstack,$safeeval); |
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') { |
$result.=&plot_script($internalid,$function,$fixed); |
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3); |
|
$result.=&plot_script($internalid,$function,$fixed,$label,$xmin,$xmax); |
} 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('Label on Plot:','label', |
|
$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','fixed'); |
$safeeval,'function','label','fixed'); |
if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); } |
if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); } |
} |
} |
return $result; |
return $result; |
Line 753 sub start_functionplotresponse {
|
Line 761 sub start_functionplotresponse {
|
&decode_previous_answer($Apache::lonhomework::history{"resource.$partid.$id.submission"}); |
&decode_previous_answer($Apache::lonhomework::history{"resource.$partid.$id.submission"}); |
|
|
# Parameters of <functionplotresponse> |
# Parameters of <functionplotresponse> |
my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval); |
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval); |
$xmin=(defined($xmin)?$xmin:-10); |
|
my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval); |
|
$xmax=(defined($xmax)?$xmax:10); |
|
my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval); |
|
$ymin=(defined($ymin)?$ymin:-10); |
|
my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval); |
|
$ymax=(defined($ymax)?$ymax:10); |
|
if ($xmax<=$xmin) { |
|
&Apache::lonxml::warning('Maximum x-value needs to be larger than minimum value.'); |
|
$xmax=$xmin+20; |
|
} |
|
if ($ymax<=$ymin) { |
|
&Apache::lonxml::warning('Maximum y-value needs to be larger than minimum value.'); |
|
$ymax=$ymin+20; |
|
} |
|
my $xaxisvisible=(&Apache::lonxml::get_param('xaxisvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false'); |
my $xaxisvisible=(&Apache::lonxml::get_param('xaxisvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false'); |
my $yaxisvisible=(&Apache::lonxml::get_param('yaxisvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false'); |
my $yaxisvisible=(&Apache::lonxml::get_param('yaxisvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false'); |
my $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false'); |
my $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false'); |
Line 1035 sub end_functionplotruleset {
|
Line 1028 sub end_functionplotruleset {
|
# |
# |
# Actually grade |
# Actually grade |
# |
# |
my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval,-2); |
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2); |
$xmin=(defined($xmin)?$xmin:-10); |
|
my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval,-2); |
|
$xmax=(defined($xmax)?$xmax:10); |
|
my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval,-2); |
|
$ymin=(defined($ymin)?$ymin:-10); |
|
my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval,-2); |
|
$ymax=(defined($ymax)?$ymax:10); |
|
|
|
my $ad=''; |
my $ad=''; |
undef %Apache::functionplotresponse::functionplotrulelabels; |
undef %Apache::functionplotresponse::functionplotrulelabels; |
Line 1122 sub end_functionplotelements {
|
Line 1108 sub end_functionplotelements {
|
$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 |
# Now is the time to render all of the stored splines |
my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval,-2); |
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2); |
$xmin=(defined($xmin)?$xmin:-10); |
|
my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval,-2); |
|
$xmax=(defined($xmax)?$xmax:10); |
|
my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval,-2); |
|
$ymin=(defined($ymin)?$ymin:-10); |
|
my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval,-2); |
|
$ymax=(defined($ymax)?$ymax:10); |
|
if ($xmax<=$xmin) { |
|
$xmax=$xmin+20; |
|
} |
|
if ($ymax<=$ymin) { |
|
$ymax=$ymin+20; |
|
} |
|
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); |
} |
} |
Line 1162 sub end_functionplotelements {
|
Line 1135 sub end_functionplotelements {
|
return $result; |
return $result; |
} |
} |
|
|
|
sub boundaries { |
|
my ($parstack,$safeeval,$level)=@_; |
|
my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval,$level); |
|
$xmin=(defined($xmin)?$xmin:-10); |
|
my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval,$level); |
|
$xmax=(defined($xmax)?$xmax:10); |
|
my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval,$level); |
|
$ymin=(defined($ymin)?$ymin:-10); |
|
my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval,$level); |
|
$ymax=(defined($ymax)?$ymax:10); |
|
if ($xmax<=$xmin) { |
|
$xmax=$xmin+20; |
|
} |
|
if ($ymax<=$ymin) { |
|
$ymax=$ymin+20; |
|
} |
|
return ($xmin,$xmax,$ymin,$ymax); |
|
} |
|
|
sub start_functionplotelements { |
sub start_functionplotelements { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result=''; |
my $result=''; |
Line 1181 sub start_functionplotelements {
|
Line 1173 sub start_functionplotelements {
|
.&Apache::edit::start_spanning_row() |
.&Apache::edit::start_spanning_row() |
."\n"; |
."\n"; |
} elsif ($target eq 'web') { |
} elsif ($target eq 'web') { |
my $xmin=&Apache::lonxml::get_param('xmin',$parstack,$safeeval,-2); |
my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2); |
$xmin=(defined($xmin)?$xmin:-10); |
|
my $xmax=&Apache::lonxml::get_param('xmax',$parstack,$safeeval,-2); |
|
$xmax=(defined($xmax)?$xmax:10); |
|
my $ymin=&Apache::lonxml::get_param('ymin',$parstack,$safeeval,-2); |
|
$ymin=(defined($ymin)?$ymin:-10); |
|
my $ymax=&Apache::lonxml::get_param('ymax',$parstack,$safeeval,-2); |
|
$ymax=(defined($ymax)?$ymax:10); |
|
if ($xmax<=$xmin) { |
|
$xmax=$xmin+20; |
|
} |
|
if ($ymax<=$ymin) { |
|
$ymax=$ymin+20; |
|
} |
|
my $xaxisvisible=(&Apache::lonxml::get_param('xaxisvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false'); |
my $xaxisvisible=(&Apache::lonxml::get_param('xaxisvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false'); |
my $yaxisvisible=(&Apache::lonxml::get_param('yaxisvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false'); |
my $yaxisvisible=(&Apache::lonxml::get_param('yaxisvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false'); |
my $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false'); |
my $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false'); |