Index: /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/include/prototypes.h
===================================================================
--- /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/include/prototypes.h	(revision 38705)
+++ /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/include/prototypes.h	(revision 38706)
@@ -40,5 +40,5 @@
 void          DrawYErrors         PROTO((KapaGraphWidget *graph, Gobjects *objects));
 void	      DrawTick		  PROTO((Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis));
-void	      AxisTickScale	  PROTO((Axis *axis, double *major, double *minor, int *nsignif));
+void	      AxisTickScale	  PROTO((Axis *axis, double *range, double *major, double *minor, int *nsignif));
 TickMarkData *CreateAxisTicks     PROTO((Axis *axis, int *nticks));
 int           PrintTick           PROTO((char *string, double value, double min, double max, int nsignif));
Index: /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/src/DrawFrame.c
===================================================================
--- /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/src/DrawFrame.c	(revision 38705)
+++ /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/src/DrawFrame.c	(revision 38706)
@@ -116,8 +116,9 @@
 
   if ((naxis == 0) || (naxis == 2)) {
-    x = MAX(x, fx);
-  }
-  //   y = MAX(y, fy);
-  // }
+    x = MIN(MAX(x, fx),fx+dfx);
+  }
+  if ((naxis == 1) || (naxis == 3)) {
+    y = MAX(MIN(y, fy),fy+dfy);
+  }
 
   dir = ((naxis == 0) || (naxis == 1)) ? -1 : +1;
@@ -154,14 +155,17 @@
 # define MIN_RANGE 1e-30
 
-void AxisTickScale (Axis *axis, double *major, double *minor, int *nsignif) {
-
-  double range, lrange, factor, mantis, fmantis, power;
-
-  range = axis[0].max - axis[0].min;
-  if (fabs(range) < MIN_RANGE) {
-    range = (range < 0) ? -MIN_RANGE : +MIN_RANGE;
-  }
-
-  lrange = log10(MAX(fabs(range), MIN_RANGE));
+void AxisTickScale (Axis *axis, double *range, double *major, double *minor, int *nsignif) {
+
+  double lrange, factor, mantis, fmantis, power;
+
+  *range = (axis[0].max - axis[0].min);
+  if (fabs(*range) < MIN_RANGE) {
+    *range = (*range < 0) ? -MIN_RANGE : +MIN_RANGE;
+  }
+
+  lrange = log10(MAX(fabs(*range), MIN_RANGE));
+  double truncRange = ((int) ((lrange + 0.005) * 1000)) / 1000.0;
+  lrange = truncRange;
+
   mantis = modf (lrange, &factor);
   if (mantis < 0.0) {
@@ -240,18 +244,9 @@
   if (isnan(axis->max) || isinf(axis->max)) return NULL;
   
-  range = axis->max - axis->min;
-
-  // not sure why I skip out here instead of using the MIN_RANGE value
-  if (fabs(range) < MIN_RANGE) return NULL;
-  
-  if (fabs(range) < MIN_RANGE) {
-    range = (range < 0) ? -MIN_RANGE : +MIN_RANGE;
-  }
-
   // length of the axis in pixels
   // int nPixels = hypot(axis->dfx, axis->dfy);
   // double dPixels = nPixels / range; // axis pixel-scale
 
-  AxisTickScale (axis, &major, &minor, &nsignif);
+  AxisTickScale (axis, &range, &major, &minor, &nsignif);
 
   // be a little generous 
@@ -260,5 +255,20 @@
 
   // value of the tick mark
-  ifirst = (axis->min < 0.0) ? (axis->min/minor - 0.05) : (axis->min/minor + 0.05);
+  if (axis->min > 0.0) {
+    double minValue = axis->min / minor;
+    if (minValue - (int)minValue < +0.1) {
+      ifirst = (int) minValue;
+    } else {
+      ifirst = (int) (minValue + 1);
+    }
+  } else {
+    double minValue = axis->min / minor;
+    if (minValue - (int)minValue > -0.1) {
+      ifirst = (int) minValue;
+    } else {
+      ifirst = (int) (minValue - 1);
+    }
+  }
+  // ifirst = (axis->min < 0.0) ? (axis->min/minor - 0.01) : (axis->min/minor + 0.01);
   first = minor*ifirst;
   
@@ -292,6 +302,7 @@
       value -= minor;
     
-    done |= (range > 0) && (value > axis->max);
-    done |= (range < 0) && (value < axis->max);
+    done |= (range > 0) && (value > axis->max + 0.1*minor);
+    done |= (range < 0) && (value < axis->max - 0.1*minor);
+    // fprintf (stderr, "%d : %f %f %f %f\n", done, range, value, axis->max, 0.1*minor);
   }
 
Index: /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/src/PSFrame.c
===================================================================
--- /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/src/PSFrame.c	(revision 38705)
+++ /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/src/PSFrame.c	(revision 38706)
@@ -81,4 +81,11 @@
   y = fy + (value-min)*dfy/(max - min);
 
+  if ((naxis == 0) || (naxis == 2)) {
+    x = MIN(MAX(x, fx),fx+dfx);
+  }
+  if ((naxis == 1) || (naxis == 3)) {
+    y = MIN(MAX(y, fy),fy+dfy);
+  }
+
   dir = ((naxis == 0) || (naxis == 1)) ? +1 : -1;
   dx = dir*size*dfy*n;	
Index: /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/src/bDrawFrame.c
===================================================================
--- /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/src/bDrawFrame.c	(revision 38705)
+++ /branches/eam_branches/ipp-20150625/Ohana/src/kapa2/src/bDrawFrame.c	(revision 38706)
@@ -84,4 +84,11 @@
   y = fy + (value-min)*dfy/(max - min);
 
+  if ((naxis == 0) || (naxis == 2)) {
+    x = MIN(MAX(x, fx),fx+dfx);
+  }
+  if ((naxis == 1) || (naxis == 3)) {
+    y = MAX(MIN(y, fy),fy+dfy);
+  }
+
   dir = ((naxis == 0) || (naxis == 1)) ? -1 : +1;
   dx = dir*size*dfy*n;	
