--- loncom/homework/functionplotresponse.pm 2010/11/23 23:14:20 1.45 +++ loncom/homework/functionplotresponse.pm 2010/11/23 23:55:01 1.46 @@ -1,7 +1,7 @@ # LearningOnline Network with CAPA # option list style responses # -# $Id: functionplotresponse.pm,v 1.45 2010/11/23 23:14:20 www Exp $ +# $Id: functionplotresponse.pm,v 1.46 2010/11/23 23:55:01 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -330,7 +330,7 @@ ENDYOFFAXISLABEL } sub plot_script { - my ($id,$function,$fixed,$label,$xmin,$xmax)=@_; + my ($id,$function,$fixed,$label,$color,$xmin,$xmax)=@_; $label=~s/\W//g; if (($label) && ($label!~/^[A-Za-z]/)) { $label='C'.$label; @@ -342,11 +342,21 @@ sub plot_script { $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) { 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":''); } else { - return "document.ggbApplet_$id.evalCommand('y=$function')"; + return "document.ggbApplet_$id.evalCommand('y=$function');\n"; } } @@ -384,24 +394,29 @@ sub start_backgroundplot { 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 $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); unless ($function) { $function="0"; } if ($target eq 'web') { my ($xmin,$xmax,$ymin,$ymax)=&boundaries($parstack,$safeeval,-3); - $result.=&plot_script($internalid,$function,$fixed,$label,$xmin,$xmax); + $result.=&plot_script($internalid,$function,$fixed,$label,$color,$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::text_arg('Color (hex code):','color', + $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','label','fixed'); + $safeeval,'function','label','color','fixed'); if ($constructtag) { $result=&Apache::edit::rebuild_tag($token); } } return $result;