Changeset 40123

Show
Ignore:
Timestamp:
08/22/2017 10:02:36 AM (5 weeks ago)
Author:
eugene
Message:

add bDrawBars function; clean up DrawObjects? a bit

Location:
branches/eam_branches/ohana.20170822/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20170822/src/kapa2/include/prototypes.h

    r39926 r40123  
    3636int           DrawObjectN         PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects)); 
    3737void          DrawPoints          PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects)); 
     38void          DrawBars            PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *object, int mode)); 
    3839void          ClipLine            PROTO((Graphic *graphic, double x0, double y0, double x1, double y1, double X0, double Y0, double X1, double Y1)); 
    3940void          DrawXErrors         PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects)); 
     
    139140void          bDrawConnect        PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object)); 
    140141void          bDrawHistogram      PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object)); 
     142void          bDrawBars           PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object, int mode)); 
    141143void          bDrawPoints         PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object)); 
    142144void          bDrawXErrors        PROTO((bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object)); 
  • branches/eam_branches/ohana.20170822/src/kapa2/src/DrawObjects.c

    r40116 r40123  
    11# include "Ximage.h" 
    2  
    3 void DrawBars (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object, int mode); 
    42 
    53# define DrawLine(X1,Y1,X2,Y2) (XDrawLine (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2))) 
    64# define DrawRectangle(X1,Y1,X2,Y2) (XDrawRectangle (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2))) 
    75# define FillRectangle(X1,Y1,X2,Y2) (XFillRectangle (graphic->display, graphic->window, graphic->gc, (int)(X1), (int)(Y1), (int)(X2), (int)(Y2))) 
    8 // # define FillRectangle(X1,Y1,X2,Y2) ; 
    96# 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)) 
    107# 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)) 
     
    162159    sx1 = x[i]*mxi + y[i]*mxj + bx + XCENTER; 
    163160    sy1 = x[i]*myi + y[i]*myj + by + YCENTER; 
    164      
    165161    ClipLine (graphic, sx0, sy0, sx1, sy1, X0, Y0, X1, Y1); 
    166     /* DrawLine (sx0, sy0, sx1, sy1); */ 
    167162    sx0 = sx1; sy0 = sy1; 
    168163  } 
     
    225220/******/ 
    226221/* simplify the code abit by finding triplets, watch out for a histogram of 2 points */ 
    227 # if (1) 
    228222void DrawHistogram (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) { 
    229223 
     
    309303  DrawLine (sxa, sy1, sxa, sya); 
    310304} 
    311  
    312 # else  
    313  
    314 void DrawHistogram (Graphic *graphic, KapaGraphWidget *graph, Gobjects *object) { 
    315  
    316   int i; 
    317   float *x, *y; 
    318   double mxi, mxj, myi, myj, bxi, bxj, byi, byj, bx, by; 
    319   double sx0, sy0, sx1, sy1, sxa, sya, sxo, syo; 
    320   double X0, X1, Y0, Y1; 
    321  
    322   mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0); 
    323   mxj = graph[0].axis[1].dfx / (object[0].y1 - object[0].y0); 
    324   myi = graph[0].axis[0].dfy / (object[0].x1 - object[0].x0); 
    325   myj = graph[0].axis[1].dfy / (object[0].y1 - object[0].y0); 
    326    
    327   bxi  =  graph[0].axis[0].fx - object[0].x0*graph[0].axis[0].dfx/(object[0].x1 - object[0].x0); 
    328   bxj  =  -object[0].y0*graph[0].axis[1].dfx/(object[0].y1 - object[0].y0); 
    329   byi  =  -object[0].x0*graph[0].axis[0].dfy/(object[0].x1 - object[0].x0); 
    330   byj  =  graph[0].axis[1].fy - object[0].y0*graph[0].axis[1].dfy/(object[0].y1 - object[0].y0); 
    331    
    332   bx = bxi + bxj; 
    333   by = byi + byj; 
    334    
    335   X0 = graph[0].axis[0].fx; 
    336   X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx; 
    337   Y0 = graph[0].axis[1].fy; 
    338   Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy; 
    339  
    340   /* find the first valid datapoint */ 
    341   x = object[0].x; y = object[0].y; 
    342    
    343   /* we only worry about pairs of points of which one is on the screen.  for each such 
    344     pair, we draw the connecting lines from sx0,sy0 to sx1,sy1, passing through the point 
    345     halfway between.   
    346  
    347     if, for a given point, there was no valid x0,y0, then we call this the first point 
    348     save both the current and previous points. 
    349   */ 
    350  
    351   int firstPair = TRUE; 
    352   sx0r = sy0r = NAN; 
    353   sxPr = syPr = NAN; 
    354   for (i = 0; i < object[0].Npts; i++) { 
    355     if (!(finite(x[i]) && finite(y[i]))) continue; 
    356     sx1r = x[i]*mxi + y[i]*mxj + bx + XCENTER; 
    357     sy1r = x[i]*myi + y[i]*myj + by + YCENTER; 
    358  
    359     // we have hit the first valid point, but not yet the second one 
    360     if (!isfinite (sx0r)) { 
    361       sx0r = sx1r; sy0r = sy1r; 
    362       continue; 
    363     } 
    364  
    365     if ((sx1r < X0) && (sx0r < X0)) { 
    366       // both points to left, skip the pair 
    367       sxPr = sx0r; syPr = sy0r; 
    368       sx0r = sx1r; sy0r = sy1r; 
    369       continue; 
    370     } 
    371     if ((sx1r > X0) && (sx0r > X0)) { 
    372       // both points to right, skip the pair 
    373       sxPr = sx0r; syPr = sy0r; 
    374       sx0r = sx1r; sy0r = sy1r; 
    375       continue; 
    376     } 
    377  
    378     // saturated values for sx0,sy0 
    379     sx0 = MIN (MAX (sx0r, X0), X1); 
    380     sy0 = MAX (MIN (sy0r, Y0), Y1); 
    381  
    382     // saturated values for sx1,sy1 
    383     sx1 = MIN (MAX (sx1r, X0), X1); 
    384     sy1 = MAX (MIN (sy1r, Y0), Y1); 
    385  
    386     if (firstPair) { 
    387       /* draw segment equal distance behind first point and down to x-axis */ 
    388       sxar = sx0r - 0.5*(sx1r - sx0r); 
    389       sxa = MIN (MAX (sxar, X0), X1); 
    390       sya = MAX (sy0r, Y0); 
    391       XSetForeground (graphic->display, graphic->gc, graphic->fore); 
    392       DrawLine (sx0, sy0, sxa, sy0); 
    393       DrawLine (sxa, sy0, sxa, sya); 
    394       XSetForeground (graphic->display, graphic->gc, graphic->color[object[0].color]); 
    395       FillRectangle (sxa + 3, sy0 + 3, sx0 - sxa - 6, sya - sy0 - 6); 
    396       firstPair = FALSE; 
    397     } 
    398  
    399     // midpoint & saturated version 
    400     sxar = 0.5*(sx0r + sx1r); 
    401     sxa = MIN (MAX (sxar, X0), X1); 
    402  
    403     XSetForeground (graphic->display, graphic->gc, graphic->fore); 
    404     DrawLine (sx0, sy0, sxa, sy0); 
    405     DrawLine (sxa, sy0, sxa, sy1); 
    406     DrawLine (sxa, sy1, sx1, sy1); 
    407     XSetForeground (graphic->display, graphic->gc, graphic->color[object[0].color]); 
    408     FillRectangle (sx0 + 3, sy0 + 3, sxa - sx0 - 6, Y0 - sy0 - 6); 
    409     FillRectangle (sxa + 3, sy1 + 3, sx1 - sxa - 6, Y0 - sy1 - 6); 
    410     sxPr = sx0r; syPr = sy0r; 
    411     sx0r = sx1r; sy0r = sy1r; 
    412   } 
    413    
    414   /* draw segment equal distance after last point and down to x-axis */ 
    415   sxa = MIN (MAX (sx1 + 0.5*(sx1 - sxo), X0), X1); 
    416   sya = MAX (sy1, Y0); 
    417   DrawLine (sx1, sy1, sxa, sy1); 
    418   DrawLine (sxa, sy1, sxa, sya); 
    419 } 
    420 # endif 
    421305 
    422306// uses object->color 
     
    498382  /* we are drawing bars which are filled rectangles of height y[i] and width 0.5*dx 
    499383     one point at a time 
     384 
     385     I need to know the distance to the next and prev points to calculate dx 
     386     for the first point, dx is x[1] - x[0] 
     387     for the last point, dx is x[-1] - x[-2] (x[-1] is the last point) 
     388     for the rest, dx is 0.5*(x[i+1] - x[i-1]) 
     389     
     390     rather than working out complex on-the-fly logic, I want to find the first and last 
     391     valid point in an initial pass, then calculate the above for the remainder. 
     392     TBD: make an index vector of only valid points? 
    500393  */ 
    501  
    502   // I need to know the distance to the next and prev points to calculate dx 
    503   // for the first point, dx is x[1] - x[0] 
    504   // for the last point, dx is x[-1] - x[-2] (x[-1] is the last point) 
    505   // for the rest, dx is 0.5*(x[i+1] - x[i-1]) 
    506  
    507   // rather than working out complex on-the-fly logic, I want to find the first and last 
    508   // valid point in an initial pass, the calculate the above for the remainder. 
    509   // or make an index vector of only valid points? 
    510394 
    511395  int Ngood = 0; 
     
    522406    // coordinate on the screen of the point: 
    523407    double sx1r = x[i]*mxi + y[i]*mxj + bx + XCENTER; 
    524     // double sy1r = x[i]*myi + y[i]*myj + by + YCENTER; 
    525408 
    526409    if (sx1r < X0) { 
     
    576459    n = goodPoint[1]; 
    577460    double sx1r = x[n]*mxi + y[n]*mxj + bx + XCENTER; 
    578 //  double sy1r = x[n]*myi + y[n]*myj + by + YCENTER; 
    579461 
    580462    n = goodPoint[0]; 
     
    605487    n = goodPoint[i + 1]; 
    606488    double sx2r = x[n]*mxi + y[n]*mxj + bx + XCENTER; 
    607     // double sy2r = x[n]*myi + y[n]*myj + by + YCENTER; 
    608489 
    609490    n = goodPoint[i - 1]; 
    610491    double sx0r = x[n]*mxi + y[n]*mxj + bx + XCENTER; 
    611     // double sy0r = x[n]*myi + y[n]*myj + by + YCENTER; 
    612  
    613     double dx = 0.5*0.5*object->size*(sx2r - sx0r); // 2 factors of 0.5 (we want half of the average spacing) 
     492 
     493    // below we have 2 factors of 0.5 (we want half of the average spacing) 
     494    double dx = 0.5*0.5*object->size*(sx2r - sx0r); 
    614495 
    615496    n = goodPoint[i]; 
     
    642523    n = goodPoint[Ngood - 2]; 
    643524    double sx0r = x[n]*mxi + y[n]*mxj + bx + XCENTER; 
    644 //  double sy0r = x[n]*myi + y[n]*myj + by + YCENTER; 
    645525 
    646526    double dx = 0.5*object->size*(sx1r - sx0r); 
  • branches/eam_branches/ohana.20170822/src/kapa2/src/bDrawObjects.c

    r39926 r40123  
    22 
    33# define DrawLine(BUF,X1,Y1,X2,Y2) (bDrawLine (BUF, (X1), (Y1), (X2), (Y2))) 
    4 # 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))) 
    5 # 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))) 
     4# define DrawRectangle(BUF,X,Y,dX,dY) (bDrawRectOpen (BUF, (X), (Y), (X+dX), (Y+dY))) 
     5# define FillRectangle(BUF,X,Y,dX,dY) (bDrawRectFill (BUF, (X), (Y), (X+dX+1), (Y+dY+1))) 
    66# define DrawCircle(BUF,X1,Y1,R) (bDrawCircle (BUF, (X1), (Y1), (R))) 
    77# define FillCircle(BUF,X1,Y1,R) (bDrawCircleFill (BUF, (X1), (Y1), (R))) 
     
    99# define OpenTriangle(BUF,X1,Y1,X2,Y2,X3,Y3) (bDrawTriOpen (BUF, (X1), (Y1), (X2), (Y2), (X3), (Y3))) 
    1010 
    11 # define CONNECT 0 
    12 # define HISTOGRAM 1 
    13 # define POINTS 2 
    14  
    1511static Graphic *graphic; 
    1612 
     
    4238    case KAPA_PLOT_HISTOGRAM: 
    4339      bDrawHistogram (buffer, graph, object); 
     40      break; 
     41    case KAPA_PLOT_BARS_SOLID: 
     42      bDrawBars (buffer, graph, object, KAPA_PLOT_BARS_SOLID); 
     43      break; 
     44    case KAPA_PLOT_BARS_OUTLINE: 
     45      bDrawBars (buffer, graph, object, KAPA_PLOT_BARS_OUTLINE); 
     46      break; 
     47    case KAPA_PLOT_BARS_OUTFILL: 
     48      bDrawBars (buffer, graph, object, KAPA_PLOT_BARS_OUTFILL); 
    4449      break; 
    4550    case KAPA_PLOT_POINTS: 
     
    235240  DrawLine (buffer, sx1, sy1, sxa, sy1); 
    236241  DrawLine (buffer, sxa, sy1, sxa, sya); 
    237  
    238 # if (0) 
    239   sx0 = x[i]*mxi + y[i]*mxj + bx; 
    240   sy0 = x[i]*myi + y[i]*myj + by; 
    241   sx0 = MIN (MAX (sx0, X0), X1); 
    242   sy0 = MAX (MIN (sy0, Y0), Y1); 
    243    
    244   /* continue with rest of points */ 
    245   for (i++; i < object[0].Npts; i++) { 
     242} 
     243 
     244// uses object->color 
     245# define HISTOGRAM_SOLID(X_VALUE, Y_VALUE, DX_VAL) {                    \ 
     246  /* histogram bar corners */                                           \ 
     247  double sxmin = (X_VALUE) - 0.5*(DX_VAL);                              \ 
     248  double sxmax = (X_VALUE) + 0.5*(DX_VAL);                              \ 
     249  double symin = Xaxis;                                                 \ 
     250  double symax = (Y_VALUE);                                             \ 
     251  /* saturated values for corner coords: */                             \ 
     252  sxmin = MIN (MAX (sxmin, X0), X1);                                    \ 
     253  sxmax = MIN (MAX (sxmax, X0), X1);                                    \ 
     254  symin = MAX (MIN (symin, Y0), Y1);                                    \ 
     255  symax = MAX (MIN (symax, Y0), Y1);                                    \ 
     256  double dy = fabs(symax - symin);                                      \ 
     257  double ylow = MIN(symin, symax);                                      \ 
     258  FillRectangle (buffer, sxmin, ylow, (DX_VAL), dy); } 
     259 
     260// uses object->color 
     261# define HISTOGRAM_OUTLINE(X_VALUE, Y_VALUE, DX_VAL) {                  \ 
     262  /* histogram bar corners */                                           \ 
     263  double sxmin = (X_VALUE) - 0.5*(DX_VAL);                              \ 
     264  double sxmax = (X_VALUE) + 0.5*(DX_VAL);                              \ 
     265  double symin = Xaxis;                                                 \ 
     266  double symax = (Y_VALUE);                                             \ 
     267  /* saturated values for corner coords: */                             \ 
     268  sxmin = MIN (MAX (sxmin, X0), X1);                                    \ 
     269  sxmax = MIN (MAX (sxmax, X0), X1);                                    \ 
     270  symin = MAX (MIN (symin, Y0), Y1);                                    \ 
     271  symax = MAX (MIN (symax, Y0), Y1);                                    \ 
     272  double dy = fabs(symax - symin);                                      \ 
     273  double ylow = MIN(symin, symax);                                      \ 
     274  DrawRectangle (buffer, sxmin, ylow, (DX_VAL), dy); } 
     275 
     276# define HISTOGRAM_OUTFILL(X_VALUE, Y_VALUE, DX_VAL) {                  \ 
     277  /* histogram bar corners */                                           \ 
     278  double sxmin = (X_VALUE) - 0.5*(DX_VAL);                              \ 
     279  double sxmax = (X_VALUE) + 0.5*(DX_VAL);                              \ 
     280  double symin = Xaxis;                                                 \ 
     281  double symax = (Y_VALUE);                                             \ 
     282  /* saturated values for corner coords: */                             \ 
     283  sxmin = MIN (MAX (sxmin, X0), X1);                                    \ 
     284  sxmax = MIN (MAX (sxmax, X0), X1);                                    \ 
     285  symin = MAX (MIN (symin, Y0), Y1);                                    \ 
     286  symax = MAX (MIN (symax, Y0), Y1);                                    \ 
     287  double dy = fabs(symax - symin);                                      \ 
     288  double ylow = MIN(symin, symax);                                      \ 
     289  FillRectangle (buffer, sxmin, ylow, (DX_VAL), dy);                    \ 
     290  bDrawSetColor (buffer, graphic->fore);                                \ 
     291  DrawRectangle (buffer, sxmin, ylow, (DX_VAL), dy);                    \ 
     292  bDrawSetColor (buffer, object[0].color); } 
     293 
     294void bDrawBars (bDrawBuffer *buffer, KapaGraphWidget *graph, Gobjects *object, int mode) { 
     295 
     296  double mxi = graph[0].axis[0].dfx / (object[0].x1 - object[0].x0); // slope of the x-axis in x-pixels 
     297  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) 
     298  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) 
     299  double myj = graph[0].axis[1].dfy / (object[0].y1 - object[0].y0); // slope of the x-axis in x-pixels 
     300   
     301  // intercepts of axes 
     302  double bxi  =  graph[0].axis[0].fx - object[0].x0*graph[0].axis[0].dfx/(object[0].x1 - object[0].x0); 
     303  double bxj  =  -object[0].y0*graph[0].axis[1].dfx/(object[0].y1 - object[0].y0); 
     304  double byi  =  -object[0].x0*graph[0].axis[0].dfy/(object[0].x1 - object[0].x0); 
     305  double byj  =  graph[0].axis[1].fy - object[0].y0*graph[0].axis[1].dfy/(object[0].y1 - object[0].y0); 
     306   
     307  double bx = bxi + bxj; 
     308  double by = byi + byj; 
     309   
     310  // corner coords 
     311  double X0 = graph[0].axis[0].fx; 
     312  double X1 = graph[0].axis[0].fx + graph[0].axis[0].dfx; 
     313  double Y0 = graph[0].axis[1].fy; 
     314  double Y1 = graph[0].axis[1].fy + graph[0].axis[1].dfy; 
     315 
     316  /* find the first valid datapoint */ 
     317  float *x = object[0].x; 
     318  float *y = object[0].y; 
     319   
     320  /* we are drawing bars which are filled rectangles of height y[i] and width 0.5*dx 
     321     one point at a time 
     322 
     323     I need to know the distance to the next and prev points to calculate dx 
     324     for the first point, dx is x[1] - x[0] 
     325     for the last point, dx is x[-1] - x[-2] (x[-1] is the last point) 
     326     for the rest, dx is 0.5*(x[i+1] - x[i-1]) 
     327     
     328     rather than working out complex on-the-fly logic, I want to draw the first and last 
     329     valid points in an initial pass, then calculate the above for the remainder. 
     330 
     331     First, make an index vector of only valid points 
     332  */ 
     333 
     334  int Ngood = 0; 
     335  ALLOCATE_PTR (goodPoint, int, object[0].Npts); 
     336 
     337  // x = ??, y = 0: this assumes the xaxis is parallel to the plot window (myi = 0) 
     338  // since y runs from large on bottom to small on top, this is slightly backwards 
     339  float Xaxis = by; 
     340  Xaxis = MAX (Y1, MIN (Xaxis, Y0)); // MIN & MAX reversed for neg y dir 
     341 
     342  for (int i = 0; i < object[0].Npts; i++) { 
    246343    if (!(finite(x[i]) && finite(y[i]))) continue; 
    247     sx1 = x[i]*mxi + y[i]*mxj + bx; 
    248     sy1 = x[i]*myi + y[i]*myj + by; 
    249     sx1 = MIN (MAX (sx1, X0), X1); 
    250     sy1 = MAX (MIN (sy1, Y0), Y1); 
    251     sxa = 0.5*(sx0 + sx1); 
    252     DrawLine (buffer, sx0, sy0, sxa, sy0); 
    253     DrawLine (buffer, sxa, sy0, sxa, sy1); 
    254     DrawLine (buffer, sxa, sy1, sx1, sy1); 
    255     sx0 = sx1; sy0 = sy1; 
    256   } 
    257 # endif 
     344 
     345    // coordinate on the screen of the point: 
     346    double sx1r = x[i]*mxi + y[i]*mxj + bx; 
     347 
     348    if (sx1r < X0) { 
     349      // point to the left, skip it 
     350      continue; 
     351    } 
     352    if (sx1r > X1) { 
     353      // point to the right, skip it 
     354      continue; 
     355    } 
     356 
     357    goodPoint[Ngood] = i; 
     358    Ngood ++; 
     359  } 
     360     
     361  if (Ngood == 0) { 
     362    free (goodPoint); 
     363    return; 
     364  } 
     365 
     366  // if we only have 1 point, draw bar half the width of the screen 
     367  // this works fine, but the auto limits for 1 value are somewhat silly 
     368  if (Ngood == 1) { 
     369    // coordinate on the screen of the point: 
     370    int n = goodPoint[0]; 
     371    double sx1r = x[n]*mxi + y[n]*mxj + bx; 
     372    double sy1r = x[n]*myi + y[n]*myj + by; 
     373 
     374    float dx = 0.5*object->size*(X1 - X0); 
     375     
     376    switch (mode) { 
     377      case KAPA_PLOT_BARS_SOLID: 
     378        HISTOGRAM_SOLID(sx1r, sy1r, dx); 
     379        break; 
     380      case KAPA_PLOT_BARS_OUTLINE: 
     381        HISTOGRAM_OUTLINE(sx1r, sy1r, dx); 
     382        break; 
     383      case KAPA_PLOT_BARS_OUTFILL: 
     384        HISTOGRAM_OUTFILL(sx1r, sy1r, dx); 
     385        break; 
     386      default: 
     387        HISTOGRAM_SOLID(sx1r, sy1r, dx); 
     388        break; 
     389    } 
     390 
     391    free (goodPoint); 
     392    return; 
     393  } 
     394 
     395  // first point: 
     396  { 
     397    int n; 
     398    n = goodPoint[1]; 
     399    double sx1r = x[n]*mxi + y[n]*mxj + bx; 
     400 
     401    n = goodPoint[0]; 
     402    double sx0r = x[n]*mxi + y[n]*mxj + bx; 
     403    double sy0r = x[n]*myi + y[n]*myj + by; 
     404 
     405    double dx = 0.5*object->size*(sx1r - sx0r); 
     406     
     407    switch (mode) { 
     408      case KAPA_PLOT_BARS_SOLID: 
     409        HISTOGRAM_SOLID(sx0r, sy0r, dx); 
     410        break; 
     411      case KAPA_PLOT_BARS_OUTLINE: 
     412        HISTOGRAM_OUTLINE(sx0r, sy0r, dx); 
     413        break; 
     414      case KAPA_PLOT_BARS_OUTFILL: 
     415        HISTOGRAM_OUTFILL(sx0r, sy0r, dx); 
     416        break; 
     417      default: 
     418        HISTOGRAM_SOLID(sx0r, sy0r, dx); 
     419        break; 
     420    } 
     421  } 
     422 
     423  for (int i = 1; i < Ngood - 1; i++) { 
     424 
     425    int n; 
     426    n = goodPoint[i + 1]; 
     427    double sx2r = x[n]*mxi + y[n]*mxj + bx; 
     428 
     429    n = goodPoint[i - 1]; 
     430    double sx0r = x[n]*mxi + y[n]*mxj + bx; 
     431 
     432    // below we have 2 factors of 0.5 (we want half of the average spacing) 
     433    double dx = 0.5*0.5*object->size*(sx2r - sx0r); 
     434 
     435    n = goodPoint[i]; 
     436    double sx1r = x[n]*mxi + y[n]*mxj + bx; 
     437    double sy1r = x[n]*myi + y[n]*myj + by; 
     438 
     439    switch (mode) { 
     440      case KAPA_PLOT_BARS_SOLID: 
     441        HISTOGRAM_SOLID(sx1r, sy1r, dx); 
     442        break; 
     443      case KAPA_PLOT_BARS_OUTLINE: 
     444        HISTOGRAM_OUTLINE(sx1r, sy1r, dx); 
     445        break; 
     446      case KAPA_PLOT_BARS_OUTFILL: 
     447        HISTOGRAM_OUTFILL(sx1r, sy1r, dx); 
     448        break; 
     449      default: 
     450        HISTOGRAM_SOLID(sx1r, sy1r, dx); 
     451        break; 
     452    } 
     453  } 
     454   
     455  // last point: 
     456  { 
     457    int n; 
     458    n = goodPoint[Ngood - 1]; 
     459    double sx1r = x[n]*mxi + y[n]*mxj + bx; 
     460    double sy1r = x[n]*myi + y[n]*myj + by; 
     461 
     462    n = goodPoint[Ngood - 2]; 
     463    double sx0r = x[n]*mxi + y[n]*mxj + bx; 
     464 
     465    double dx = 0.5*object->size*(sx1r - sx0r); 
     466 
     467    switch (mode) { 
     468      case KAPA_PLOT_BARS_SOLID: 
     469        HISTOGRAM_SOLID(sx1r, sy1r, dx); 
     470        break; 
     471      case KAPA_PLOT_BARS_OUTLINE: 
     472        HISTOGRAM_OUTLINE(sx1r, sy1r, dx); 
     473        break; 
     474      case KAPA_PLOT_BARS_OUTFILL: 
     475        HISTOGRAM_OUTFILL(sx1r, sy1r, dx); 
     476        break; 
     477      default: 
     478        HISTOGRAM_SOLID(sx1r, sy1r, dx); 
     479        break; 
     480    } 
     481  } 
     482  free (goodPoint); 
     483  return; 
    258484} 
    259485 
     
    280506  by = byi + byj; 
    281507   
     508  // scaled colors use the colormap defined for the graphic 
    282509  Graphic *graphic = GetGraphic(); 
    283510 
     
    317544          } 
    318545          D = scaleSize ? dz*z[i] : ds; 
    319           DrawRectangle (buffer, sx, sy, 2*D, 2*D); 
     546          DrawRectangle (buffer, sx - D, sy - D, 2*D, 2*D); // DrawRectangle takes corner point 
    320547          // plot range saturated by bDrawRectOpen 
    321548        } 
     
    611838          } 
    612839          D = scaleSize ? dz*z[i] : ds; 
    613           FillRectangle (buffer, sx, sy, 2*D, 2*D); 
     840          FillRectangle (buffer, sx - D, sy - D, 2*D, 2*D); 
    614841          // plot range saturated by bDrawRectFill 
    615842        } 
  • branches/eam_branches/ohana.20170822/src/libkapa/include/kapa.h

    r40106 r40123  
    292292void bDrawBufferFree (bDrawBuffer *buffer); 
    293293void bDrawSetBuffer (bDrawBuffer *buffer); 
     294void bDrawSetColor (bDrawBuffer *buffer, bDrawColor color); 
    294295void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt); 
    295296void bDrawPoint (bDrawBuffer *buffer, int x, int y); 
  • branches/eam_branches/ohana.20170822/src/libkapa/src/bDrawFuncs.c

    r39926 r40123  
    7676// } 
    7777 
    78 void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt) { 
     78// "bDrawColor color" is one of the hardwired colors in KapaColors.c 
     79void bDrawSetColor (bDrawBuffer *buffer, bDrawColor color) { 
     80  fprintf (stderr, "set color %d\n", color); 
    7981  buffer->bColor = color; 
    8082  buffer->bColor_R = buffer->palette[color].red; 
    8183  buffer->bColor_G = buffer->palette[color].green; 
    8284  buffer->bColor_B = buffer->palette[color].blue; 
     85 
     86  return; 
     87} 
     88 
     89void bDrawSetStyle (bDrawBuffer *buffer, bDrawColor color, int lw, int lt) { 
     90  bDrawSetColor (buffer, color); 
    8391 
    8492  buffer->bWeight = lw; 
     
    121129} 
    122130 
     131// x1,y1 is lower-left corner, x2,y2 is upper-right corner 
    123132void bDrawRectOpen (bDrawBuffer *buffer, double x1, double y1, double x2, double y2) { 
    124133