[LON-CAPA-cvs] cvs: loncom /homework functionplotresponse.pm

www www@source.lon-capa.org
Tue, 23 Nov 2010 23:14:20 -0000


www		Tue Nov 23 23:14:20 2010 EDT

  Modified files:              
    /loncom/homework	functionplotresponse.pm 
  Log:
  If the axes are off screen, the axis labels are put into the corners
  
  
Index: loncom/homework/functionplotresponse.pm
diff -u loncom/homework/functionplotresponse.pm:1.44 loncom/homework/functionplotresponse.pm:1.45
--- loncom/homework/functionplotresponse.pm:1.44	Tue Nov 23 17:01:28 2010
+++ loncom/homework/functionplotresponse.pm	Tue Nov 23 23:14:20 2010
@@ -1,7 +1,7 @@
 # LearningOnline Network with CAPA
 # option list style responses
 #
-# $Id: functionplotresponse.pm,v 1.44 2010/11/23 17:01:28 www Exp $
+# $Id: functionplotresponse.pm,v 1.45 2010/11/23 23:14:20 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -295,22 +295,36 @@
 }
 
 sub axes_label {
-    my ($id,$xlabel,$ylabel)=@_;
+    my ($id,$xmin,$xmax,$ymin,$ymax,$xlabel,$ylabel)=@_;
     unless ($xlabel || $ylabel) { return ''; }
     my $return='document.ggbApplet_'.$id.'.evalCommand("topRight=Corner[3]");';
     if ($xlabel) {
+      if (($ymin<0) && ($ymax>0)) {
        $return.=(<<ENDXAXISLABELSCRIPT);
 document.ggbApplet_$id.evalCommand("Xlabel=(x(topRight)-AxisStepX[],AxisStepY[]/6)");
 document.ggbApplet_$id.setVisible("Xlabel",false);
 document.ggbApplet_$id.evalCommand("Text[\\"$xlabel\\", Xlabel]");
 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 (($xmin<0) && ($xmax>0)) {
        $return.=(<<ENDYAXISLABELSCRIPT);
 document.ggbApplet_$id.evalCommand("Ylabel=(AxisStepX[]/6,y(topRight)-AxisStepY[]/3)");
 document.ggbApplet_$id.setVisible("Ylabel",false);
 document.ggbApplet_$id.evalCommand("Text[\\"$ylabel\\", Ylabel]");
 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;
 }
@@ -1213,7 +1227,7 @@
      $result.=&start_init_script($internalid);
 # put the axis commands inside
      $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
   }
   return $result;