[LON-CAPA-cvs] cvs: loncom /homework functionplotresponse.pm
www
www@source.lon-capa.org
Fri, 19 Nov 2010 20:03:13 -0000
This is a MIME encoded message
--www1290196993
Content-Type: text/plain
www Fri Nov 19 20:03:13 2010 EDT
Modified files:
/loncom/homework functionplotresponse.pm
Log:
Code cleanup
--www1290196993
Content-Type: text/plain
Content-Disposition: attachment; filename="www-20101119200313.txt"
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.40 loncom/homework/functionplotresponse.pm:1.41
--- loncom/homework/functionplotresponse.pm:1.40 Fri Nov 19 17:20:44 2010
+++ loncom/homework/functionplotresponse.pm Fri Nov 19 20:03:13 2010
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: functionplotresponse.pm,v 1.40 2010/11/19 17:20:44 www Exp $
+# $Id: functionplotresponse.pm,v 1.41 2010/11/19 20:03:13 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -316,17 +316,21 @@
}
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) {
-# Use stupid trick to nail this to a location
-# Oddly, it seems like only one plot cannot be nailed to a location
-# 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
+ return "document.ggbApplet_$id.evalCommand('$label=Function[$function,$xmin,$xmax]')".
+ ($visible?'':"document.ggbApplet.setLabelVisible('$label', false);");
} else {
return "document.ggbApplet_$id.evalCommand('y=$function')";
}
@@ -365,21 +369,25 @@
my $result='';
my $internalid = $Apache::inputtags::part.'_'.$Apache::inputtags::response[-1];
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);
unless ($function) { $function="0"; }
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') {
$result=&Apache::edit::tag_start($target,$token,'Background Function Plot').
&Apache::edit::text_arg('Function:','function',
$token,'16').
+ &Apache::edit::text_arg('Label on Plot:','label',
+ $token,'8').
&Apache::edit::select_arg('Fixed location:','fixed',
['yes','no'],$token).
&Apache::edit::end_row();
} elsif ($target eq 'modified') {
my $constructtag=&Apache::edit::get_new_args($token,$parstack,
- $safeeval,'function','fixed');
+ $safeeval,'function','label','fixed');
if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); }
}
return $result;
@@ -753,22 +761,7 @@
&decode_previous_answer($Apache::lonhomework::history{"resource.$partid.$id.submission"});
# Parameters of <functionplotresponse>
- my $xmin=&Apache::lonxml::get_param('xmin',$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 ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval);
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 $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval)=~/on|true|yes|1/i?'true':'false');
@@ -1035,14 +1028,7 @@
#
# Actually grade
#
- my $xmin=&Apache::lonxml::get_param('xmin',$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 ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2);
my $ad='';
undef %Apache::functionplotresponse::functionplotrulelabels;
@@ -1122,20 +1108,7 @@
$result=&Apache::edit::end_table();
} elsif ($target eq 'web') {
# Now is the time to render all of the stored splines
- my $xmin=&Apache::lonxml::get_param('xmin',$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 ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2);
foreach my $label (keys(%Apache::functionplotresponse::splineorder)) {
$result.=&generate_spline($internalid,$label,$xmin,$xmax,$ymin,$ymax);
}
@@ -1162,6 +1135,25 @@
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 {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result='';
@@ -1181,20 +1173,7 @@
.&Apache::edit::start_spanning_row()
."\n";
} elsif ($target eq 'web') {
- my $xmin=&Apache::lonxml::get_param('xmin',$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 ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-2);
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 $gridvisible=(&Apache::lonxml::get_param('gridvisible',$parstack,$safeeval,-2)=~/on|true|yes|1/i?'true':'false');
--www1290196993--