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

version 1.42, 2010/11/20 00:14:44 version 1.46, 2010/11/23 23:55:01
Line 295  ENDAXESSCRIPT Line 295  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)=@_;
    $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 342  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]')".        return "document.ggbApplet_$id.evalCommand('$label=Function[$function,$xmin,$xmax]');\n".
              ($visible?'':"document.ggbApplet.setLabelVisible('$label', false);");               ($visible?'':"document.ggbApplet_$id.setLabelVisible('$label', false);\n").
                ($color?"document.ggbApplet_$id.setColor('$label',$rc,$gc,$bc);\n":'');
    } else {     } else {
        return "document.ggbApplet_$id.evalCommand('y=$function')";         return "document.ggbApplet_$id.evalCommand('y=$function');\n";
    }     }
 }  }
   
Line 370  sub start_backgroundplot { Line 394  sub start_backgroundplot {
    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 $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);        $result.=&plot_script($internalid,$function,$fixed,$label,$color,$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',               &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','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 496  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 592  sub start_spline {
              &Apache::edit::text_arg('Index:','index',               &Apache::edit::text_arg('Index:','index',
                                      $token,'4').'&nbsp;'.                                       $token,'4').'&nbsp;'.
              &Apache::edit::select_arg('Order:','order',               &Apache::edit::select_arg('Order:','order',
                                   ['2','3','4','5','6','7','8','9'],$token).'&nbsp;'.                                    ['2','3','4','5','6','7','8'],$token).'&nbsp;'.
              &Apache::edit::text_arg('Initial x-value:','initx',               &Apache::edit::text_arg('Initial x-value:','initx',
                                      $token,'4').'&nbsp;'.                                       $token,'4').'&nbsp;'.
              &Apache::edit::text_arg('Initial y-value:','inity',               &Apache::edit::text_arg('Initial y-value:','inity',
Line 1212  sub start_functionplotelements { Line 1242  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;

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


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