Diff for /loncom/homework/functionplotresponse.pm between versions 1.46 and 1.47

version 1.46, 2010/11/23 23:55:01 version 1.47, 2010/11/24 02:53:13
Line 330  ENDYOFFAXISLABEL Line 330  ENDYOFFAXISLABEL
 }  }
   
 sub plot_script {  sub plot_script {
    my ($id,$function,$fixed,$label,$color,$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 354  sub plot_script { Line 354  sub plot_script {
    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":'');               ($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');\n";         return "document.ggbApplet_$id.evalCommand('y=$function');\n";
    }     }
Line 393  sub start_backgroundplot { Line 394  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);     my $color=&Apache::lonxml::get_param('color',$parstack,$safeeval);
    $color=~s/[^a-fA-F0-9]//gs;     $color=~s/[^a-fA-F0-9]//gs;
Line 402  sub start_backgroundplot { Line 405  sub start_backgroundplot {
    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,$color,$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',               &Apache::edit::text_arg('Color (hex code):','color',
Line 416  sub start_backgroundplot { Line 425  sub start_backgroundplot {
              &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','color','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 826  sub start_functionplotresponse { Line 835  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 1162  sub end_functionplotelements { Line 1174  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);
              }
           }
        }
   
   # 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);
      }       }

Removed from v.1.46  
changed lines
  Added in v.1.47


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>