Index: /branches/eam_branches/ohana.20170822/src/kapa2/include/prototypes.h
===================================================================
--- /branches/eam_branches/ohana.20170822/src/kapa2/include/prototypes.h	(revision 40122)
+++ /branches/eam_branches/ohana.20170822/src/kapa2/include/prototypes.h	(revision 40123)
@@ -36,4 +36,5 @@
 int           DrawObjectN         PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
 void          DrawPoints          PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
+void          DrawBars            PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *object, int mode));
 void          ClipLine            PROTO((Graphic *graphic, double x0, double y0, double x1, double y1, double X0, double Y0, double X1, double Y1));
 void          DrawXErrors         PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
@@ -139,4 +140,5 @@
 void	      bDrawConnect	  PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
 void	      bDrawHistogram	  PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
+void          bDrawBars           PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object, int mode));
 void	      bDrawPoints	  PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
 void	      bDrawXErrors	  PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object));
Index: /branches/eam_branches/ohana.20170822/src/kapa2/src/DrawObjects.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/kapa2/src/DrawObjects.c	(revision 40122)
+++ /branches/eam_branches/ohana.20170822/src/kapa2/src/DrawObjects.c	(revision 40123)
@@ -1,10 +1,7 @@
 # include "Ximage.h"
-
-void DrawBars (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object, int mode);
 
 # define DrawLine(X1,Y1,X2,Y2) (XDrawLine (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2)))
 # 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), abs(2*R), 0, 23040))
@@ -162,7 +159,5 @@
     sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER;
     sy1 = x[i]*myi + y[i]*myj + by + YCENTER;
-    
     ClipLine (graphic, sx0, sy0, sx1, sy1, X0, Y0, X1, Y1);
-    /* DrawLine (sx0, sy0, sx1, sy1); */
     sx0 = sx1; sy0 = sy1;
   }
@@ -225,5 +220,4 @@
 /******/
 /* simplify the code abit by finding triplets, watch out for a histogram of 2 points */
-# if (1)
 void DrawHistogram (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) {
 
@@ -309,114 +303,4 @@
   DrawLine (sxa, sy1, sxa, sya);
 }
-
-# else 
-
-void DrawHistogram (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) {
-
-  int i;
-  float *x, *y;
-  double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by;
-  double sx0, sy0, sx1, sy1, sxa, sya, sxo, syo;
-  double X0, X1, Y0, Y1;
-
-  mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0);
-  mxj = graph[0].axis[1].dfx / (object[0].y1 - object[0].y0);
-  myi = graph[0].axis[0].dfy / (object[0].x1 - object[0].x0);
-  myj = graph[0].axis[1].dfy / (object[0].y1 - object[0].y0);
-  
-  bxi  =  graph[0].axis[0].fx - object[0].x0*graph[0].axis[0].dfx/(object[0].x1 - object[0].x0);
-  bxj  =  -object[0].y0*graph[0].axis[1].dfx/(object[0].y1 - object[0].y0);
-  byi  =  -object[0].x0*graph[0].axis[0].dfy/(object[0].x1 - object[0].x0);
-  byj  =  graph[0].axis[1].fy - object[0].y0*graph[0].axis[1].dfy/(object[0].y1 - object[0].y0);
-  
-  bx = bxi + bxj;
-  by = byi + byj;
-  
-  X0 = graph[0].axis[0].fx;
-  X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;
-  Y0 = graph[0].axis[1].fy;
-  Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;
-
-  /* find the first valid datapoint */
-  x = object[0].x; y = object[0].y;
-  
-  /* 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;
-    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);
-    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 = MIN (MAX (sx1 + 0.5*(sx1 - sxo), X0), X1);
-  sya = MAX (sy1, Y0);
-  DrawLine (sx1, sy1, sxa, sy1);
-  DrawLine (sxa, sy1, sxa, sya);
-}
-# endif
 
 // uses object->color
@@ -498,14 +382,14 @@
   /* we are drawing bars which are filled rectangles of height y[i] and width 0.5*dx
      one point at a time
+
+     I need to know the distance to the next and prev points to calculate dx
+     for the first point, dx is x[1] - x[0]
+     for the last point, dx is x[-1] - x[-2] (x[-1] is the last point)
+     for the rest, dx is 0.5*(x[i+1] - x[i-1])
+    
+     rather than working out complex on-the-fly logic, I want to find the first and last
+     valid point in an initial pass, then calculate the above for the remainder.
+     TBD: make an index vector of only valid points?
   */
-
-  // I need to know the distance to the next and prev points to calculate dx
-  // for the first point, dx is x[1] - x[0]
-  // for the last point, dx is x[-1] - x[-2] (x[-1] is the last point)
-  // for the rest, dx is 0.5*(x[i+1] - x[i-1])
-
-  // rather than working out complex on-the-fly logic, I want to find the first and last
-  // valid point in an initial pass, the calculate the above for the remainder.
-  // or make an index vector of only valid points?
 
   int Ngood = 0;
@@ -522,5 +406,4 @@
     // coordinate on the screen of the point:
     double sx1r = x[i]*mxi + y[i]*mxj + bx + XCENTER;
-    // double sy1r = x[i]*myi + y[i]*myj + by + YCENTER;
 
     if (sx1r < X0) {
@@ -576,5 +459,4 @@
     n = goodPoint[1];
     double sx1r = x[n]*mxi + y[n]*mxj + bx + XCENTER;
-//  double sy1r = x[n]*myi + y[n]*myj + by + YCENTER;
 
     n = goodPoint[0];
@@ -605,11 +487,10 @@
     n = goodPoint[i + 1];
     double sx2r = x[n]*mxi + y[n]*mxj + bx + XCENTER;
-    // double sy2r = x[n]*myi + y[n]*myj + by + YCENTER;
 
     n = goodPoint[i - 1];
     double sx0r = x[n]*mxi + y[n]*mxj + bx + XCENTER;
-    // double sy0r = x[n]*myi + y[n]*myj + by + YCENTER;
-
-    double dx = 0.5*0.5*object->size*(sx2r - sx0r); // 2 factors of 0.5 (we want half of the average spacing)
+
+    // below we have 2 factors of 0.5 (we want half of the average spacing)
+    double dx = 0.5*0.5*object->size*(sx2r - sx0r);
 
     n = goodPoint[i];
@@ -642,5 +523,4 @@
     n = goodPoint[Ngood - 2];
     double sx0r = x[n]*mxi + y[n]*mxj + bx + XCENTER;
-//  double sy0r = x[n]*myi + y[n]*myj + by + YCENTER;
 
     double dx = 0.5*object->size*(sx1r - sx0r);
Index: /branches/eam_branches/ohana.20170822/src/kapa2/src/bDrawObjects.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/kapa2/src/bDrawObjects.c	(revision 40122)
+++ /branches/eam_branches/ohana.20170822/src/kapa2/src/bDrawObjects.c	(revision 40123)
@@ -2,6 +2,6 @@
 
 # define DrawLine(BUF,X1,Y1,X2,Y2) (bDrawLine (BUF, (X1), (Y1), (X2), (Y2)))
-# define DrawRectangle(BUF,X,Y,dX,dY) (bDrawRectOpen (BUF, (X-0.5*dX), (Y-0.5*dY), (X+0.5*dX), (Y+0.5*dY)))
-# define FillRectangle(BUF,X,Y,dX,dY) (bDrawRectFill (BUF, (X-0.5*dX), (Y-0.5*dY), (X+0.5*dX+1), (Y+0.5*dY+1)))
+# define DrawRectangle(BUF,X,Y,dX,dY) (bDrawRectOpen (BUF, (X), (Y), (X+dX), (Y+dY)))
+# define FillRectangle(BUF,X,Y,dX,dY) (bDrawRectFill (BUF, (X), (Y), (X+dX+1), (Y+dY+1)))
 # define DrawCircle(BUF,X1,Y1,R) (bDrawCircle (BUF, (X1), (Y1), (R)))
 # define FillCircle(BUF,X1,Y1,R) (bDrawCircleFill (BUF, (X1), (Y1), (R)))
@@ -9,8 +9,4 @@
 # define OpenTriangle(BUF,X1,Y1,X2,Y2,X3,Y3) (bDrawTriOpen (BUF, (X1), (Y1), (X2), (Y2), (X3), (Y3)))
 
-# define CONNECT 0
-# define HISTOGRAM 1
-# define POINTS 2
-
 static Graphic *graphic;
 
@@ -42,4 +38,13 @@
     case KAPA_PLOT_HISTOGRAM:
       bDrawHistogram (buffer, graph, object);
+      break;
+    case KAPA_PLOT_BARS_SOLID:
+      bDrawBars (buffer, graph, object, KAPA_PLOT_BARS_SOLID);
+      break;
+    case KAPA_PLOT_BARS_OUTLINE:
+      bDrawBars (buffer, graph, object, KAPA_PLOT_BARS_OUTLINE);
+      break;
+    case KAPA_PLOT_BARS_OUTFILL:
+      bDrawBars (buffer, graph, object, KAPA_PLOT_BARS_OUTFILL);
       break;
     case KAPA_PLOT_POINTS:
@@ -235,25 +240,246 @@
   DrawLine (buffer, sx1, sy1, sxa, sy1);
   DrawLine (buffer, sxa, sy1, sxa, sya);
-
-# if (0)
-  sx0 = x[i]*mxi + y[i]*mxj + bx;
-  sy0 = x[i]*myi + y[i]*myj + by;
-  sx0 = MIN (MAX (sx0, X0), X1);
-  sy0 = MAX (MIN (sy0, Y0), Y1);
-  
-  /* continue with rest of points */
-  for (i++; i < object[0].Npts; i++) {
+}
+
+// uses object->color
+# define HISTOGRAM_SOLID(X_VALUE, Y_VALUE, DX_VAL) {			\
+  /* histogram bar corners */						\
+  double sxmin = (X_VALUE) - 0.5*(DX_VAL);				\
+  double sxmax = (X_VALUE) + 0.5*(DX_VAL);				\
+  double symin = Xaxis;							\
+  double symax = (Y_VALUE);						\
+  /* saturated values for corner coords: */				\
+  sxmin = MIN (MAX (sxmin, X0), X1);					\
+  sxmax = MIN (MAX (sxmax, X0), X1);					\
+  symin = MAX (MIN (symin, Y0), Y1);					\
+  symax = MAX (MIN (symax, Y0), Y1);					\
+  double dy = fabs(symax - symin);					\
+  double ylow = MIN(symin, symax);					\
+  FillRectangle (buffer, sxmin, ylow, (DX_VAL), dy); }
+
+// uses object->color
+# define HISTOGRAM_OUTLINE(X_VALUE, Y_VALUE, DX_VAL) {			\
+  /* histogram bar corners */						\
+  double sxmin = (X_VALUE) - 0.5*(DX_VAL);				\
+  double sxmax = (X_VALUE) + 0.5*(DX_VAL);				\
+  double symin = Xaxis;							\
+  double symax = (Y_VALUE);						\
+  /* saturated values for corner coords: */				\
+  sxmin = MIN (MAX (sxmin, X0), X1);					\
+  sxmax = MIN (MAX (sxmax, X0), X1);					\
+  symin = MAX (MIN (symin, Y0), Y1);					\
+  symax = MAX (MIN (symax, Y0), Y1);					\
+  double dy = fabs(symax - symin);					\
+  double ylow = MIN(symin, symax);					\
+  DrawRectangle (buffer, sxmin, ylow, (DX_VAL), dy); }
+
+# define HISTOGRAM_OUTFILL(X_VALUE, Y_VALUE, DX_VAL) {			\
+  /* histogram bar corners */						\
+  double sxmin = (X_VALUE) - 0.5*(DX_VAL);				\
+  double sxmax = (X_VALUE) + 0.5*(DX_VAL);				\
+  double symin = Xaxis;							\
+  double symax = (Y_VALUE);						\
+  /* saturated values for corner coords: */				\
+  sxmin = MIN (MAX (sxmin, X0), X1);					\
+  sxmax = MIN (MAX (sxmax, X0), X1);					\
+  symin = MAX (MIN (symin, Y0), Y1);					\
+  symax = MAX (MIN (symax, Y0), Y1);					\
+  double dy = fabs(symax - symin);					\
+  double ylow = MIN(symin, symax);					\
+  FillRectangle (buffer, sxmin, ylow, (DX_VAL), dy);			\
+  bDrawSetColor (buffer, graphic->fore);				\
+  DrawRectangle (buffer, sxmin, ylow, (DX_VAL), dy);			\
+  bDrawSetColor (buffer, object[0].color); }
+
+void bDrawBars (bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object, int mode) {
+
+  double mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0); // slope of the x-axis in x-pixels
+  double mxj = graph[0].axis[1].dfx / (object[0].y1 - object[0].y0); // slope of the x-axis in y-pixels (always 0 for now)
+  double myi = graph[0].axis[0].dfy / (object[0].x1 - object[0].x0); // slope of the x-axis in x-pixels (always 0 for now)
+  double myj = graph[0].axis[1].dfy / (object[0].y1 - object[0].y0); // slope of the x-axis in x-pixels
+  
+  // intercepts of axes
+  double bxi  =  graph[0].axis[0].fx - object[0].x0*graph[0].axis[0].dfx/(object[0].x1 - object[0].x0);
+  double bxj  =  -object[0].y0*graph[0].axis[1].dfx/(object[0].y1 - object[0].y0);
+  double byi  =  -object[0].x0*graph[0].axis[0].dfy/(object[0].x1 - object[0].x0);
+  double byj  =  graph[0].axis[1].fy - object[0].y0*graph[0].axis[1].dfy/(object[0].y1 - object[0].y0);
+  
+  double bx = bxi + bxj;
+  double by = byi + byj;
+  
+  // corner coords
+  double X0 = graph[0].axis[0].fx;
+  double X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx;
+  double Y0 = graph[0].axis[1].fy;
+  double Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy;
+
+  /* find the first valid datapoint */
+  float *x = object[0].x;
+  float *y = object[0].y;
+  
+  /* we are drawing bars which are filled rectangles of height y[i] and width 0.5*dx
+     one point at a time
+
+     I need to know the distance to the next and prev points to calculate dx
+     for the first point, dx is x[1] - x[0]
+     for the last point, dx is x[-1] - x[-2] (x[-1] is the last point)
+     for the rest, dx is 0.5*(x[i+1] - x[i-1])
+    
+     rather than working out complex on-the-fly logic, I want to draw the first and last
+     valid points in an initial pass, then calculate the above for the remainder.
+
+     First, make an index vector of only valid points
+  */
+
+  int Ngood = 0;
+  ALLOCATE_PTR (goodPoint, int, object[0].Npts);
+
+  // x = ??, y = 0: this assumes the xaxis is parallel to the plot window (myi = 0)
+  // since y runs from large on bottom to small on top, this is slightly backwards
+  float Xaxis = by;
+  Xaxis = MAX (Y1, MIN (Xaxis, Y0)); // MIN & MAX reversed for neg y dir
+
+  for (int i = 0; i < object[0].Npts; i++) {
     if (!(finite(x[i]) && finite(y[i]))) continue;
-    sx1 = x[i]*mxi + y[i]*mxj + bx;
-    sy1 = x[i]*myi + y[i]*myj + by;
-    sx1 = MIN (MAX (sx1, X0), X1);
-    sy1 = MAX (MIN (sy1, Y0), Y1);
-    sxa = 0.5*(sx0 + sx1);
-    DrawLine (buffer, sx0, sy0, sxa, sy0);
-    DrawLine (buffer, sxa, sy0, sxa, sy1);
-    DrawLine (buffer, sxa, sy1, sx1, sy1);
-    sx0 = sx1; sy0 = sy1;
-  }
-# endif
+
+    // coordinate on the screen of the point:
+    double sx1r = x[i]*mxi + y[i]*mxj + bx;
+
+    if (sx1r < X0) {
+      // point to the left, skip it
+      continue;
+    }
+    if (sx1r > X1) {
+      // point to the right, skip it
+      continue;
+    }
+
+    goodPoint[Ngood] = i;
+    Ngood ++;
+  }
+    
+  if (Ngood == 0) {
+    free (goodPoint);
+    return;
+  }
+
+  // if we only have 1 point, draw bar half the width of the screen
+  // this works fine, but the auto limits for 1 value are somewhat silly
+  if (Ngood == 1) {
+    // coordinate on the screen of the point:
+    int n = goodPoint[0];
+    double sx1r = x[n]*mxi + y[n]*mxj + bx;
+    double sy1r = x[n]*myi + y[n]*myj + by;
+
+    float dx = 0.5*object->size*(X1 - X0);
+    
+    switch (mode) {
+      case KAPA_PLOT_BARS_SOLID:
+	HISTOGRAM_SOLID(sx1r, sy1r, dx);
+	break;
+      case KAPA_PLOT_BARS_OUTLINE:
+	HISTOGRAM_OUTLINE(sx1r, sy1r, dx);
+	break;
+      case KAPA_PLOT_BARS_OUTFILL:
+	HISTOGRAM_OUTFILL(sx1r, sy1r, dx);
+	break;
+      default:
+	HISTOGRAM_SOLID(sx1r, sy1r, dx);
+	break;
+    }
+
+    free (goodPoint);
+    return;
+  }
+
+  // first point:
+  {
+    int n;
+    n = goodPoint[1];
+    double sx1r = x[n]*mxi + y[n]*mxj + bx;
+
+    n = goodPoint[0];
+    double sx0r = x[n]*mxi + y[n]*mxj + bx;
+    double sy0r = x[n]*myi + y[n]*myj + by;
+
+    double dx = 0.5*object->size*(sx1r - sx0r);
+    
+    switch (mode) {
+      case KAPA_PLOT_BARS_SOLID:
+	HISTOGRAM_SOLID(sx0r, sy0r, dx);
+	break;
+      case KAPA_PLOT_BARS_OUTLINE:
+	HISTOGRAM_OUTLINE(sx0r, sy0r, dx);
+	break;
+      case KAPA_PLOT_BARS_OUTFILL:
+	HISTOGRAM_OUTFILL(sx0r, sy0r, dx);
+	break;
+      default:
+	HISTOGRAM_SOLID(sx0r, sy0r, dx);
+	break;
+    }
+  }
+
+  for (int i = 1; i < Ngood - 1; i++) {
+
+    int n;
+    n = goodPoint[i + 1];
+    double sx2r = x[n]*mxi + y[n]*mxj + bx;
+
+    n = goodPoint[i - 1];
+    double sx0r = x[n]*mxi + y[n]*mxj + bx;
+
+    // below we have 2 factors of 0.5 (we want half of the average spacing)
+    double dx = 0.5*0.5*object->size*(sx2r - sx0r);
+
+    n = goodPoint[i];
+    double sx1r = x[n]*mxi + y[n]*mxj + bx;
+    double sy1r = x[n]*myi + y[n]*myj + by;
+
+    switch (mode) {
+      case KAPA_PLOT_BARS_SOLID:
+	HISTOGRAM_SOLID(sx1r, sy1r, dx);
+	break;
+      case KAPA_PLOT_BARS_OUTLINE:
+	HISTOGRAM_OUTLINE(sx1r, sy1r, dx);
+	break;
+      case KAPA_PLOT_BARS_OUTFILL:
+	HISTOGRAM_OUTFILL(sx1r, sy1r, dx);
+	break;
+      default:
+	HISTOGRAM_SOLID(sx1r, sy1r, dx);
+	break;
+    }
+  }
+  
+  // last point:
+  {
+    int n;
+    n = goodPoint[Ngood - 1];
+    double sx1r = x[n]*mxi + y[n]*mxj + bx;
+    double sy1r = x[n]*myi + y[n]*myj + by;
+
+    n = goodPoint[Ngood - 2];
+    double sx0r = x[n]*mxi + y[n]*mxj + bx;
+
+    double dx = 0.5*object->size*(sx1r - sx0r);
+
+    switch (mode) {
+      case KAPA_PLOT_BARS_SOLID:
+	HISTOGRAM_SOLID(sx1r, sy1r, dx);
+	break;
+      case KAPA_PLOT_BARS_OUTLINE:
+	HISTOGRAM_OUTLINE(sx1r, sy1r, dx);
+	break;
+      case KAPA_PLOT_BARS_OUTFILL:
+	HISTOGRAM_OUTFILL(sx1r, sy1r, dx);
+	break;
+      default:
+	HISTOGRAM_SOLID(sx1r, sy1r, dx);
+	break;
+    }
+  }
+  free (goodPoint);
+  return;
 }
 
@@ -280,4 +506,5 @@
   by = byi + byj;
   
+  // scaled colors use the colormap defined for the graphic
   Graphic *graphic = GetGraphic();
 
@@ -317,5 +544,5 @@
 	  }
 	  D = scaleSize ? dz*z[i] : ds;
-	  DrawRectangle (buffer, sx, sy, 2*D, 2*D);
+	  DrawRectangle (buffer, sx - D, sy - D, 2*D, 2*D); // DrawRectangle takes corner point
 	  // plot range saturated by bDrawRectOpen
 	}
@@ -611,5 +838,5 @@
 	  }
 	  D = scaleSize ? dz*z[i] : ds;
-	  FillRectangle (buffer, sx, sy, 2*D, 2*D);
+	  FillRectangle (buffer, sx - D, sy - D, 2*D, 2*D);
 	  // plot range saturated by bDrawRectFill
 	}
Index: /branches/eam_branches/ohana.20170822/src/libkapa/include/kapa.h
===================================================================
--- /branches/eam_branches/ohana.20170822/src/libkapa/include/kapa.h	(revision 40122)
+++ /branches/eam_branches/ohana.20170822/src/libkapa/include/kapa.h	(revision 40123)
@@ -292,4 +292,5 @@
 void bDrawBufferFree (bDrawBuffer *buffer);
 void bDrawSetBuffer (bDrawBuffer *buffer);
+void bDrawSetColor (bDrawBuffer *buffer, bDrawColor color);
 void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt);
 void bDrawPoint (bDrawBuffer *buffer, int x, int y);
Index: /branches/eam_branches/ohana.20170822/src/libkapa/src/bDrawFuncs.c
===================================================================
--- /branches/eam_branches/ohana.20170822/src/libkapa/src/bDrawFuncs.c	(revision 40122)
+++ /branches/eam_branches/ohana.20170822/src/libkapa/src/bDrawFuncs.c	(revision 40123)
@@ -76,9 +76,17 @@
 // }
 
-void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt) {
+// "bDrawColor color" is one of the hardwired colors in KapaColors.c
+void bDrawSetColor (bDrawBuffer *buffer, bDrawColor color) {
+  fprintf (stderr, "set color %d\n", color);
   buffer->bColor = color;
   buffer->bColor_R = buffer->palette[color].red;
   buffer->bColor_G = buffer->palette[color].green;
   buffer->bColor_B = buffer->palette[color].blue;
+
+  return;
+}
+
+void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt) {
+  bDrawSetColor (buffer, color);
 
   buffer->bWeight = lw;
@@ -121,4 +129,5 @@
 }
 
+// x1,y1 is lower-left corner, x2,y2 is upper-right corner
 void bDrawRectOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2) {
 
