Index: trunk/Ohana/src/kapa2/src/DrawFrame.c
===================================================================
--- trunk/Ohana/src/kapa2/src/DrawFrame.c	(revision 39593)
+++ trunk/Ohana/src/kapa2/src/DrawFrame.c	(revision 39594)
@@ -138,6 +138,6 @@
     
     /* temporarily assume rectilinear axes */
-    if (naxis == 0) { dx = 0; dy = +1.0*pad; pos = 7; } // center, down justified
-    if (naxis == 2) { dx = 0; dy = -1.0*pad; pos = 1; } // center, up justified
+    if (naxis == 0) { dx = 0; dy = +1.0*pad; pos = 1; } // center, down justified
+    if (naxis == 2) { dx = 0; dy = -1.0*pad; pos = 7; } // center, up justified
 
     if (naxis == 1) { dy = 0; dx = -0.5*pad; pos = 3; } // left, center justified
Index: trunk/Ohana/src/kapa2/src/DrawObjects.c
===================================================================
--- trunk/Ohana/src/kapa2/src/DrawObjects.c	(revision 39593)
+++ trunk/Ohana/src/kapa2/src/DrawObjects.c	(revision 39594)
@@ -4,4 +4,5 @@
 # define DrawRectangle(X1,Y1,X2,Y2) (XDrawRectangle (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2)))
 # define FillRectangle(X1,Y1,X2,Y2) (XFillRectangle (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2)))
+// # define FillRectangle(X1,Y1,X2,Y2) ;
 # define DrawCircle(X,Y,R) (XDrawArc (graphic->display, graphic->window, graphic->gc, (int)(X-R), (int)(Y-R), abs(2*R), abs(2*R), 0, 23040))
 # define FillCircle(X,Y,R) (XFillArc (graphic->display, graphic->window, graphic->gc, (int)(X-R), (int)(Y-R), abs(2*R+1), abs(2*R+1), 0, 23040))
@@ -34,6 +35,8 @@
 int DrawObjectN (KapaGraphWidget *graph, Gobjects *object) {
   
-  static char dash[2] = {5,10};
-  static char dot[2] = {3,3};
+  static char dot[2] = {2,3};
+  static char short_dash[2] = {4,4};
+  static char long_dash[2] = {8,8};
+  static char dot_dash[4] = {2,4,4,4};
   int lweight;
   
@@ -59,9 +62,17 @@
       break;
     case 1:
-      XSetDashes (graphic->display, graphic->gc, 100, dash, 2);
+      XSetDashes (graphic->display, graphic->gc, 1, dot, 2);
       XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CAPSTYLE, JOINSTYLE);
       break;
     case 2:
-      XSetDashes (graphic->display, graphic->gc, 10, dot, 2);
+      XSetDashes (graphic->display, graphic->gc, 1, short_dash, 2);
+      XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CAPSTYLE, JOINSTYLE);
+      break;
+    case 3:
+      XSetDashes (graphic->display, graphic->gc, 1, long_dash, 2);
+      XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CAPSTYLE, JOINSTYLE);
+      break;
+    case 4:
+      XSetDashes (graphic->display, graphic->gc, 1, dot_dash, 4);
       XSetLineAttributes (graphic->display, graphic->gc, lweight, LineOnOffDash, CAPSTYLE, JOINSTYLE);
       break;
@@ -200,4 +211,5 @@
 /******/
 /* simplify the code abit by finding triplets, watch out for a histogram of 2 points */
+# if (1)
 void DrawHistogram (KapaGraphWidget *graph, Gobjects *object) {
 
@@ -284,6 +296,7 @@
 }
 
-# if (0)
-void FillHistogram (KapaGraphWidget *graph, Gobjects *object) {
+# else 
+
+void DrawHistogram (KapaGraphWidget *graph, Gobjects *object) {
 
   int i;
@@ -313,54 +326,78 @@
   /* find the first valid datapoint */
   x = object[0].x; y = object[0].y;
-  for (i = 0; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
-  if (i >= object[0].Npts) return;
-
-  /* first valid data point */
-  sx0 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
-  sy0 = x[i]*myi + y[i]*myj + by + YCENTER;
-  sx0 = MIN (MAX (sx0, X0), X1);
-  sy0 = MAX (MIN (sy0, Y0), Y1);
-  
-  /* find the second valid datapoint */
-  for (i++; (i < object[0].Npts) && !(finite(x[i]) && finite(y[i])); i++);
-  if (i >= object[0].Npts) return;
-
-  /* second valid data point */
-  sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
-  sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
-  sx1 = MIN (MAX (sx1, X0), X1);
-  sy1 = MAX (MIN (sy1, Y0), Y1);
-  
-  /* connect first point to second point */
-  sxa = sx0 - 0.5*(sx1 - sx0);
-  sya = MAX (sy0, Y0);
-  DrawLine (sx0, sy0, sxa, sy0);
-  DrawLine (sxa, sy0, sxa, sya);
-  
-  /* draw segment equal distance behind first point and down to x-axis */
-  sxa = 0.5*(sx0 + sx1);
-  DrawLine (sx0, sy0, sxa, sy0);
-  DrawLine (sxa, sy0, sxa, sy1);
-  DrawLine (sxa, sy1, sx1, sy1);
-  sx0 = sx1;
-  sy0 = sy1;
-  
-  /* continue with rest of points */
-  for (i++; i < object[0].Npts; i++) {
+  
+  /* we only worry about pairs of points of which one is on the screen.  for each such
+    pair, we draw the connecting lines from sx0,sy0 to sx1,sy1, passing through the point
+    halfway between.  
+
+    if, for a given point, there was no valid x0,y0, then we call this the first point
+    save both the current and previous points.
+  */
+
+  int firstPair = TRUE;
+  sx0r = sy0r = NAN;
+  sxPr = syPr = NAN;
+  for (i = 0; i < object[0].Npts; i++) {
     if (!(finite(x[i]) && finite(y[i]))) continue;
-    sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
-    sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
-    sx1 = MIN (MAX (sx1, X0), X1);
-    sy1 = MAX (MIN (sy1, Y0), Y1);
-    sxa = 0.5*(sx0 + sx1);
+    sx1r = x[i]*mxi + y[i]*mxj + bx + XCENTER;
+    sy1r = x[i]*myi + y[i]*myj + by + YCENTER;
+
+    // we have hit the first valid point, but not yet the second one
+    if (!isfinite (sx0r)) {
+      sx0r = sx1r; sy0r = sy1r;
+      continue;
+    }
+
+    if ((sx1r < X0) && (sx0r < X0)) {
+      // both points to left, skip the pair
+      sxPr = sx0r; syPr = sy0r;
+      sx0r = sx1r; sy0r = sy1r;
+      continue;
+    }
+    if ((sx1r > X0) && (sx0r > X0)) {
+      // both points to right, skip the pair
+      sxPr = sx0r; syPr = sy0r;
+      sx0r = sx1r; sy0r = sy1r;
+      continue;
+    }
+
+    // saturated values for sx0,sy0
+    sx0 = MIN (MAX (sx0r, X0), X1);
+    sy0 = MAX (MIN (sy0r, Y0), Y1);
+
+    // saturated values for sx1,sy1
+    sx1 = MIN (MAX (sx1r, X0), X1);
+    sy1 = MAX (MIN (sy1r, Y0), Y1);
+
+    if (firstPair) {
+      /* draw segment equal distance behind first point and down to x-axis */
+      sxar = sx0r - 0.5*(sx1r - sx0r);
+      sxa = MIN (MAX (sxar, X0), X1);
+      sya = MAX (sy0r, Y0);
+      XSetForeground (graphic->display, graphic->gc, graphic->fore);
+      DrawLine (sx0, sy0, sxa, sy0);
+      DrawLine (sxa, sy0, sxa, sya);
+      XSetForeground (graphic->display, graphic->gc, graphic->color[object[0].color]);
+      FillRectangle (sxa + 3, sy0 + 3, sx0 - sxa - 6, sya - sy0 - 6);
+      firstPair = FALSE;
+    }
+
+    // midpoint & saturated version
+    sxar = 0.5*(sx0r + sx1r);
+    sxa = MIN (MAX (sxar, X0), X1);
+
+    XSetForeground (graphic->display, graphic->gc, graphic->fore);
     DrawLine (sx0, sy0, sxa, sy0);
     DrawLine (sxa, sy0, sxa, sy1);
     DrawLine (sxa, sy1, sx1, sy1);
-    sxo = sx0; syo = sy0;
-    sx0 = sx1; sy0 = sy1;
+    XSetForeground (graphic->display, graphic->gc, graphic->color[object[0].color]);
+    FillRectangle (sx0 + 3, sy0 + 3, sxa - sx0 - 6, Y0 - sy0 - 6);
+    FillRectangle (sxa + 3, sy1 + 3, sx1 - sxa - 6, Y0 - sy1 - 6);
+    sxPr = sx0r; syPr = sy0r;
+    sx0r = sx1r; sy0r = sy1r;
   }
   
   /* draw segment equal distance after last point and down to x-axis */
-  sxa = sx1 + 0.5*(sx1 - sxo);
+  sxa = MIN (MAX (sx1 + 0.5*(sx1 - sxo), X0), X1);
   sya = MAX (sy1, Y0);
   DrawLine (sx1, sy1, sxa, sy1);
