IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 3, 2010, 8:41:49 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

Location:
branches/tap_branches
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/tap_branches

  • branches/tap_branches/Ohana

  • branches/tap_branches/Ohana/src/kapa2/src/DrawFrame.c

    r18426 r27838  
    11# include "Ximage.h"
    2 # define MIN_RANGE 1e-10
     2
    33# define DrawLine(X,Y,DX,DY) (XDrawLine (graphic->display, graphic->window, graphic->gc, (int)(X), (int)(Y), (int)(X+DX), (int)(Y+DY)))
    44 
    5 static Graphic *graphic;
    6 
    7 void DrawFrame (KapaGraphWidget *graph) {
    8  
    9   int i, fx, fy, dfx, dfy, P, IsLabel, IsMajor;
    10   double range, major, minor, first, next, lweight;
     5int DrawFrame (KapaGraphWidget *graph) {
     6 
     7  int i, j, Nticks, P;
     8  double fx, fy, dfx, dfy, lweight;
     9  Graphic *graphic;
     10  TickMarkData *ticks;
     11  int color;
    1112
    1213  graphic = GetGraphic();
    1314
    14   /* each axis is drawn independently, but ticks and labels are placed according to
    15      perpendicular distance. */
     15  /* each axis is drawn independently, but ticks and labels are placed according to perpendicular distance. */
    1616  for (i = 0; i < 4; i++) {
    17     fx = graph[0].axis[i].fx;
    18     fy = graph[0].axis[i].fy;
     17    fx  = graph[0].axis[i].fx;
     18    fy  = graph[0].axis[i].fy;
    1919    dfx = graph[0].axis[i].dfx;
    2020    dfy = graph[0].axis[i].dfy;
    21     P = hypot ((double)graph[0].axis[(i+1)%2].dfx, (double)graph[0].axis[(i+1)%2].dfy);
     21    P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    2222
    2323    lweight = MAX (0, MIN (10, graph[0].axis[i].lweight));
     24    color = MAX (0, MIN (15, graph[0].axis[i].color));
     25
    2426    XSetLineAttributes (graphic->display, graphic->gc, lweight, LineSolid, CapNotLast, JoinMiter);
    25    
    26     graph[0].axis[i].color = MAX (0, MIN (15, graph[0].axis[i].color));
    27 
    28     XSetForeground (graphic->display, graphic->gc, graphic->color[graph[0].axis[i].color]);
    29     DrawRotTextInit (graphic->display, graphic->window, graphic->gc, graphic->color[graph[0].axis[i].color], graphic->back);
     27    XSetForeground (graphic->display, graphic->gc, graphic->color[color]);
     28    DrawRotTextInit (graphic->display, graphic->window, graphic->gc, graphic->color[color], graphic->back);
    3029
    3130    if (graph[0].axis[i].isaxis) {
     
    3433   
    3534    if (graph[0].axis[i].areticks) {
    36       if (isnan(graph[0].axis[i].min) || isinf(graph[0].axis[i].min)) continue;
    37       if (isnan(graph[0].axis[i].max) || isinf(graph[0].axis[i].max)) continue;
    38 
    39       range = graph[0].axis[i].max - graph[0].axis[i].min;
    40       if (fabs(range) < MIN_RANGE) continue;
    41 
    42       if (fabs(range) < MIN_RANGE) {
    43         range = (range < 0) ? -MIN_RANGE : +MIN_RANGE;
     35      ticks = CreateAxisTicks (&graph[0].axis[i], &Nticks);
     36      for (j = 0; j < Nticks; j++) {
     37        DrawTick (graphic, &graph[0].axis[i], P, &ticks[j], i);
    4438      }
    45 
    46       AxisTickScale (&graph[0].axis[i], &major, &minor);
    47 
    48       first = minor*((int)(graph[0].axis[i].min/minor));
    49       if ((range > 0) && (first < graph[0].axis[i].min)) {
    50         first += minor;
    51       }
    52       if ((range < 0) && (first > graph[0].axis[i].min)) {
    53         first -= minor;
    54       }
    55       for (next = first; ((range > 0) && (next <= graph[0].axis[i].max)) || ((range < 0) && (next >= graph[0].axis[i].max));) {
    56         IsMajor = FALSE;
    57         IsMajor |= (fabs((int)(next/major) - (next/major)) < 0.5*(minor/major));
    58         IsMajor |= (fabs((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    59         IsMajor |= (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    60         IsLabel = (IsMajor && graph[0].axis[i].islabel);
    61         DrawTick (fx, fy, dfx, dfy, P, graph[0].axis[i].min, graph[0].axis[i].max, next, IsLabel, IsMajor, i);
    62         if (range > 0)
    63           next += minor;
    64         else
    65           next -= minor;
    66       }
     39      FREE (ticks);
    6740    }
    6841  }
    69 }
    70 
    71 void DrawTick (int fx, int fy, int dfx, int dfy,
    72                int P, double min, double max,
    73                double value, int IsLabel, int IsMajor, int naxis) {
    74  
    75   int x, y, dx, dy, pos, dir, fontsize;
    76   double size, n;
     42  return (TRUE);
     43}
     44
     45void DrawTick (Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis) {
     46 
     47  double x, y, dx, dy;
     48  int pos, dir, fontsize;
     49  double size, n, pad;
    7750  char string[64], *fontname;
    7851
    79   if (IsMajor) {
     52  double fx  = axis->fx;
     53  double fy  = axis->fy;
     54  double dfx = axis->dfx;
     55  double dfy = axis->dfy;
     56
     57  double min = axis->min;
     58  double max = axis->max;
     59
     60  double value = tick->value;
     61
     62  pos = size = 0;
     63
     64  if (tick->IsMajor) {
    8065    size = MAX (0.02, 7.0 / P);
    8166  } else {
     
    8368  }
    8469 
    85   n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
     70  n = P / hypot(dfx, dfy);
    8671  x = fx + (value-min)*dfx/(max - min);
    8772  y = fy + (value-min)*dfy/(max - min);
    8873
    89   dir = +1;
    90   if ((naxis == 0) || (naxis == 1)) dir *= -1;
     74  if ((naxis == 0) || (naxis == 2)) {
     75    x = MAX(x, fx);
     76  }
     77  //   y = MAX(y, fy);
     78  // }
     79
     80  dir = ((naxis == 0) || (naxis == 1)) ? -1 : +1;
    9181  dx = dir*size*dfy*n; 
    9282  dy = dir*size*dfx*n;
     
    9484  DrawLine (x, y, dx, dy);
    9585
    96 # ifdef IN_AND_OUT_TICKS
    97 # define GAP 0.03
    98 # else
    99 # define GAP 0.01
    100 # endif
    101 
    102   if (IsLabel) {
     86  if (tick->IsLabel) {
     87    int xt, yt;
     88
    10389    fontname = GetRotFont (&fontsize);
    104     pos = 0;
     90   
     91    pad = !isnan(axis->ticktextPad) ? axis->ticktextPad*fontsize : fontsize + 4.0;
     92    // pad = !isnan(axis->ticktextPad) ? axis->ticktextPad*fontsize : 0.8*fontsize + 1.0;
    10593   
    10694    /* temporarily assume rectilinear axes */
    107     if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
    108     if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
    109 
    110     if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
    111     if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
    112 
    113     x = fx + (value-min)*dfx/(max - min) + dx;
    114     y = fy + (value-min)*dfy/(max - min) + dy;
     95    if (naxis == 0) { dx = 0; dy = +1.0*pad; pos = 7; }
     96    if (naxis == 2) { dx = 0; dy = -1.0*pad; pos = 1; }
     97
     98    if (naxis == 1) { dy = 0; dx = -0.5*pad; pos = 3; }
     99    if (naxis == 3) { dy = 0; dx = +0.5*pad; pos = 5; }
     100
     101    xt = fx + (value-min)*dfx/(max - min) + dx;
     102    yt = fy + (value-min)*dfy/(max - min) + dy;
    115103    if (fabs(value/(max-min)) < 0.001) { value = 0.0; }
    116104    sprintf (string, "%4g", value);
    117     DrawRotText (x, y, string, pos, 0.0);
    118   }
    119  
    120 }
    121 
     105    DrawRotText (xt, yt, string, pos, 0.0);
     106  }
     107}
     108
     109# define MIN_RANGE 1e-10
    122110
    123111void AxisTickScale (Axis *axis, double *major, double *minor) {
     
    183171  }
    184172}
     173
     174TickMarkData *CreateAxisTicks (Axis *axis, int *nticks) {
     175
     176  TickMarkData *ticks;
     177  double range, major, minor, first, value, dPixels, overshoot;
     178  int i, NTICKS, nPixels, done, ifirst;
     179
     180  *nticks = 0;
     181
     182  if (isnan(axis->min) || isinf(axis->min)) return NULL;
     183  if (isnan(axis->max) || isinf(axis->max)) return NULL;
     184 
     185  range = axis->max - axis->min;
     186
     187  // not sure why I skip out here instead of using the MIN_RANGE value
     188  if (fabs(range) < MIN_RANGE) return NULL;
     189 
     190  if (fabs(range) < MIN_RANGE) {
     191    range = (range < 0) ? -MIN_RANGE : +MIN_RANGE;
     192  }
     193
     194  // length of the axis in pixels
     195  nPixels = hypot(axis->dfx, axis->dfy);
     196  dPixels = nPixels / range; // axis pixel-scale
     197
     198  AxisTickScale (axis, &major, &minor);
     199
     200  // be a little generous
     201  NTICKS = (int)(fabs(range / minor)) + 2;
     202  ALLOCATE (ticks, TickMarkData, NTICKS);
     203
     204  // value of the tick mark
     205  ifirst = (axis->min < 0.0) ? (axis->min/minor - 0.05) : (axis->min/minor + 0.05);
     206  first = minor*ifirst;
     207 
     208  // allow undershoot by 1 pixel
     209  overshoot = (axis->min - first) * dPixels;
     210  // if (overshoot > 0.5) {
     211  //   if (range > 0) {
     212  //     first += minor;
     213  //   } else {
     214  //     first -= minor;
     215  //   }
     216  // }
     217
     218  // loop to find the ticks
     219  done = FALSE;
     220  value = first;
     221  for (i = 0; !done && (i < NTICKS); i++) {
     222    ticks[i].IsMajor = FALSE;
     223    ticks[i].IsMajor |= (fabs((int)(value/major) - (value/major)) < 0.5*(minor/major));
     224    ticks[i].IsMajor |= (fabs((int)((value + 0.5*minor)/major) - (value/major)) < 0.5*(minor/major));
     225    ticks[i].IsMajor |= (fabs((int)((value - 0.5*minor)/major) - (value/major)) < 0.5*(minor/major));
     226    ticks[i].IsLabel = (ticks[i].IsMajor && axis->islabel);
     227    ticks[i].value = value;
     228    if (range > 0)
     229      value += minor;
     230    else
     231      value -= minor;
     232   
     233    done |= (range > 0) && (value > axis->max);
     234    done |= (range < 0) && (value < axis->max);
     235  }
     236
     237  *nticks = i;
     238  return (ticks);
     239}
Note: See TracChangeset for help on using the changeset viewer.