IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 41344


Ignore:
Timestamp:
Apr 20, 2020, 1:23:21 PM (6 years ago)
Author:
eugene
Message:

add format option to tick marks

Location:
trunk/Ohana/src
Files:
1 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/kapa2/Makefile

    r41341 r41344  
    6868$(SRC)/DrawObjects.$(ARCH).o              $(SRC)/DrawFrame.$(ARCH).o          \
    6969$(SRC)/DrawTextlines.$(ARCH).o            $(SRC)/DrawLabels.$(ARCH).o         \
    70 $(SRC)/MemoryDump.$(ARCH).o           \
     70$(SRC)/MemoryDump.$(ARCH).o               $(SRC)/TickMarks.$(ARCH).o          \
    7171$(SRC)/PNGit.$(ARCH).o                    $(SRC)/PPMit.$(ARCH).o              \
    7272$(SRC)/CheckPipe.$(ARCH).o                $(SRC)/EventLoop.$(ARCH).o          \
  • trunk/Ohana/src/kapa2/include/prototypes.h

    r41341 r41344  
    4949void          DrawYErrors         PROTO((Graphic *graphic, KapaGraphWidget *graph, Gobjects *objects));
    5050void          DrawTick            PROTO((Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis));
     51
     52/* TickMark functions */
    5153void          AxisTickScale       PROTO((Axis *axis, double *range, double *major, double *minor, int *nsignif));
    5254TickMarkData *CreateAxisTicks     PROTO((Axis *axis, int *nticks));
    53 int           PrintTick           PROTO((char *string, double value, double min, double max, int nsignif));
     55int           PrintTick           PROTO((char *string, TickMarkData *tick, double min, double max));
    5456
    5557/* EventLoop */
  • trunk/Ohana/src/kapa2/include/structures.h

    r41341 r41344  
    157157
    158158typedef struct {
     159  char format[16];
    159160  double min, max;
    160161  char isaxis, areticks, islabel, islog;
     
    169170// structure to describe the ticks for an axis
    170171typedef struct {
     172  char format[16];
    171173  double value;
    172174  int IsMajor;
  • trunk/Ohana/src/kapa2/src/DrawFrame.c

    r40118 r41344  
    5858}
    5959
    60 int PrintTick (char *string, double value, double min, double max, int nsignif) {
    61 
    62   int Nexp = 0;
    63   int Nchar = 0;
    64  
    65   if (fabs(value/(max-min)) < 0.001) {
    66     value = 0.0;
    67     Nchar = sprintf (string, "%.1f", value);
    68     return Nchar;
    69   }
    70 
    71 //   double lvalue = log10(fabs(value));
    72 //   if (isfinite(lvalue)) {
    73 //     Nexp = fabs(lvalue);
    74 //   } else {
    75 //     Nexp = 0;
    76 //   }
    77  
    78   Nexp = abs(nsignif);
    79 
    80   if (Nexp > 3) {
    81     Nchar = sprintf (string, "%.1e", value);
    82   } else {
    83     if (nsignif < 0) {
    84       char format[16];
    85       snprintf (format, 16, "%%.%df", -1 * nsignif);
    86       Nchar = sprintf (string, format, value);
    87     } else {
    88       Nchar = sprintf (string, "%.1f", value);
    89     }
    90   }
    91   return Nchar;
    92 }
    93 
    9460void DrawTick (Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis) {
    9561 
     
    11884  dir = ((naxis == 0) || (naxis == 3)) ? -1 : +1;
    11985
    120   x = fx + (value-min)*dfx/(max - min);
    121   y = fy + (value-min)*dfy/(max - min);
     86  x = fx + (value - min)*dfx/(max - min);
     87  y = fy + (value - min)*dfy/(max - min);
    12288
    12389  dy = 0;
     
    153119    if (naxis == 3) { dy = 0; dx = +0.5*pad; pos = 5; } // right, center justified
    154120
    155     xt = fx + (value-min)*dfx/(max - min) + dx;
    156     yt = fy + (value-min)*dfy/(max - min) + dy;
    157 
    158     PrintTick (string, value, min, max, tick->nsignif);
     121    xt = fx + (value - min)*dfx/(max - min) + dx;
     122    yt = fy + (value - min)*dfy/(max - min) + dy;
     123
     124    PrintTick (string, tick, min, max);
    159125    DrawRotText (xt, yt, string, pos, 0.0);
    160126  }
     
    254220    if (naxis == 3) { dy = 0; dx = +0.5*pad; pos = 5; } // right, center justified
    255221
    256     xt = fx + (value-min)*dfx/(max - min) + dx;
    257     yt = fy + (value-min)*dfy/(max - min) + dy;
    258 
    259     PrintTick (string, value, min, max, tick->nsignif);
     222    xt = fx + (value - min)*dfx/(max - min) + dx;
     223    yt = fy + (value - min)*dfy/(max - min) + dy;
     224
     225    PrintTick (string, tick, min, max);
    260226    DrawRotText (xt, yt, string, pos, 0.0);
    261227  }
     
    263229# endif
    264230
    265 // do I really want this?  allow an override?
    266 # define MIN_RANGE 1e-30
    267 
    268 void AxisTickScale (Axis *axis, double *range, double *major, double *minor, int *nsignif) {
    269 
    270   double lrange, factor, mantis, fmantis, power;
    271 
    272   *range = axis->fLabelRange*(axis[0].max - axis[0].min);
    273   if (fabs(*range) < MIN_RANGE) {
    274     *range = (*range < 0) ? -MIN_RANGE : +MIN_RANGE;
    275   }
    276 
    277   lrange = log10(MAX(fabs(*range), MIN_RANGE));
    278   double truncRange = ((int) ((lrange + 0.005) * 1000)) / 1000.0;
    279   lrange = truncRange;
    280 
    281   mantis = modf (lrange, &factor);
    282   if (mantis < 0.0) {
    283     mantis += 1.0;
    284     factor -= 1.0;
    285   }
    286  
    287   // how many significant digits are needed?
    288 
    289   power = MAX(pow(10.0, factor), MIN_RANGE);
    290   fmantis = pow(10.0, mantis);
    291   *major = MAX(0.5 * power, MIN_RANGE);
    292   *minor = MAX(0.1 * power, MIN_RANGE);
    293  
    294   if ((fmantis >= 1.0) && (fmantis <  1.999)) {
    295     *major = 0.5 * power;
    296     *nsignif = factor - 1;
    297     if (axis[0].areticks == 1) {
    298       *major = 0.25 * power;
    299       *nsignif = factor - 2;
    300     }     
    301     if (axis[0].areticks == 3) {
    302       *major = 1.0 * power;
    303       *nsignif = factor - 1;
    304     }     
    305   }
    306   if ((fmantis >= 1.999) && (fmantis <  3.999)) {
    307     *major = 1.0 * power;
    308     *nsignif = factor;
    309     if (axis[0].areticks == 1) {
    310       *major = 0.5 * power;
    311       *nsignif = factor - 1;
    312     }     
    313     if (axis[0].areticks == 3) {
    314       *major = 2.0 * power;
    315       *nsignif = factor;
    316     }     
    317   }
    318   if ((fmantis >= 3.999) && (fmantis <  5.999)) {
    319     *major = 1.0 * power;
    320     *nsignif = factor;
    321     if (axis[0].areticks == 1) {
    322       *major = 1.0 * power;
    323       *nsignif = factor;
    324     }     
    325     if (axis[0].areticks == 3) {
    326       *major = 2.0 * power;
    327       *nsignif = factor;
    328     }     
    329   }
    330   if ((fmantis >= 5.999) && (fmantis <   7.999)) {
    331     *major = 2.0 * power;
    332     *nsignif = factor;
    333     if (axis[0].areticks == 1) {
    334       *major = 1.0 * power;
    335       *nsignif = factor;
    336     }     
    337     if (axis[0].areticks == 3) {
    338       *major = 4.0 * power;
    339       *nsignif = factor;
    340     }     
    341   }
    342   if ((fmantis >= 7.999) && (fmantis <  10.000)) {
    343     *major = 2.5 * power;
    344     *nsignif = factor - 1;
    345     if (axis[0].areticks == 1) {
    346       *major = 2.0 * power;
    347       *nsignif = factor;
    348     }     
    349     if (axis[0].areticks == 3) {
    350       *major = 4.0 * power;
    351       *nsignif = factor;
    352     }     
    353   }
    354   *minor = *major / axis->fMinor;
    355 }
    356 
    357 TickMarkData *CreateAxisTicks (Axis *axis, int *nticks) {
    358 
    359   TickMarkData *ticks;
    360   double range, major, minor, first, value;
    361   int i, NTICKS, done, nsignif;
    362 
    363   *nticks = 0;
    364 
    365   if (isnan(axis->min) || isinf(axis->min)) return NULL;
    366   if (isnan(axis->max) || isinf(axis->max)) return NULL;
    367  
    368   // length of the axis in pixels
    369   // int nPixels = hypot(axis->dfx, axis->dfy);
    370   // double dPixels = nPixels / range; // axis pixel-scale
    371 
    372   AxisTickScale (axis, &range, &major, &minor, &nsignif);
    373 
    374   // be a little generous
    375   NTICKS = (int)(fabs(range / minor)) + 2;
    376   ALLOCATE (ticks, TickMarkData, NTICKS);
    377 
    378   // value of the first tick mark (near axis->min)
    379   double minValue = axis->min / minor;
    380   int ifirst = (int) minValue;
    381 
    382   if ((axis->min > 0.0) && (minValue - ifirst > +0.1)) {
    383     ifirst ++;
    384   }
    385   if ((axis->min < 0.0) && (minValue - ifirst < -0.1)) {
    386     ifirst --;
    387   }
    388   first = minor*ifirst;
    389  
    390   // only write the labels for the inner fRange of the axies
    391   double minLabelValue = 0.5*(1.0 - 1.001*axis->fLabelRange)*(axis->max - axis->min) + axis->min;
    392   double maxLabelValue = 0.5*(1.0 + 1.001*axis->fLabelRange)*(axis->max - axis->min) + axis->min;
    393 
    394   // loop to find the ticks
    395   done = FALSE;
    396   value = first;
    397   for (i = 0; !done && (i < NTICKS); i++) {
    398     ticks[i].IsMajor = FALSE;
    399     ticks[i].IsMajor |= (fabs((int)(value/major) - (value/major)) < 0.5*(minor/major));
    400     ticks[i].IsMajor |= (fabs((int)((value + 0.5*minor)/major) - (value/major)) < 0.5*(minor/major));
    401     ticks[i].IsMajor |= (fabs((int)((value - 0.5*minor)/major) - (value/major)) < 0.5*(minor/major));
    402     int inLabelRange = (range > 0) ? (value >= minLabelValue) && (value <= maxLabelValue) : (value <= minLabelValue) && (value >= maxLabelValue);
    403     ticks[i].IsLabel = inLabelRange && ticks[i].IsMajor && axis->islabel;
    404     ticks[i].value = value;
    405     ticks[i].nsignif = nsignif;
    406     if (range > 0)
    407       value += minor;
    408     else
    409       value -= minor;
    410    
    411     done |= (range > 0) && (value > axis->max + 0.1*minor);
    412     done |= (range < 0) && (value < axis->max - 0.1*minor);
    413     // fprintf (stderr, "%d : %f %f %f %f\n", done, range, value, axis->max, 0.1*minor);
    414   }
    415 
    416   *nticks = i;
    417   return (ticks);
    418 }
  • trunk/Ohana/src/kapa2/src/Graphs.c

    r39652 r41344  
    2525    graph[0].axis[i].fLabelRange = 1.0;
    2626    graph[0].axis[i].fMinor = 5.0;
     27    memset (graph[0].axis[i].format, 0, 16);
    2728  }   
    2829
  • trunk/Ohana/src/kapa2/src/LoadFrame.c

    r41341 r41344  
    4646  graph[0].axis[2].fMinor = graph[0].data.fMinorXp;
    4747  graph[0].axis[3].fMinor = graph[0].data.fMinorYp;
     48
     49  strcpy (graph[0].axis[0].format, graph[0].data.formatXm);
     50  strcpy (graph[0].axis[1].format, graph[0].data.formatYm);
     51  strcpy (graph[0].axis[2].format, graph[0].data.formatXp);
     52  strcpy (graph[0].axis[3].format, graph[0].data.formatYp);
    4853
    4954  for (i = 0; i < 4; i++) {
  • trunk/Ohana/src/kapa2/src/PDF_Frame.c

    r41341 r41344  
    130130    yt = fy + (value-min)*dfy/(max - min) + dy;
    131131
    132     // PrintTick write the characters into the string
    133     PrintTick (string, value, min, max, tick->nsignif);
     132    // PrintTick writes the characters into the string
     133    PrintTick (string, tick, min, max);
    134134    PDFRotText (buffer, xt, yt, string, pos, 0.0);
    135135  }
  • trunk/Ohana/src/kapa2/src/PSFrame.c

    r40118 r41344  
    122122    yt = fy + (value-min)*dfy/(max - min) + dy;
    123123
    124     PrintTick (string, value, min, max, tick->nsignif);
     124    PrintTick (string, tick, min, max);
    125125    PSRotText (f, xt, yt, string, pos, 0.0);
    126126  }
     
    198198    yt = fy + (value-min)*dfy/(max - min) + dy;
    199199
    200     PrintTick (string, value, min, max, tick->nsignif);
     200    PrintTick (string, tick, min, max);
    201201    PSRotText (f, xt, yt, string, pos, 0.0);
    202202  }
  • trunk/Ohana/src/kapa2/src/PSit.c

    r31665 r41344  
    11# include "Ximage.h"
    2 # define XOFFSET 60
    3 # define YOFFSET 60
     2# define XOFFSET 0
     3# define YOFFSET 0
    44
    55static char *name = "$Name: not supported by cvs2svn $";
  • trunk/Ohana/src/kapa2/src/SetGraphData.c

    r38986 r41344  
    3737  graph[0].axis[2].fMinor = graph[0].data.fMinorXp;
    3838  graph[0].axis[3].fMinor = graph[0].data.fMinorYp;
     39
     40  strcpy (graph[0].axis[0].format, graph[0].data.formatXm);
     41  strcpy (graph[0].axis[1].format, graph[0].data.formatYm);
     42  strcpy (graph[0].axis[2].format, graph[0].data.formatXp);
     43  strcpy (graph[0].axis[3].format, graph[0].data.formatYp);
    3944
    4045  graph[0].axis[0].pad = graph[0].data.padXm;
  • trunk/Ohana/src/kapa2/src/SetGraphSize.c

    r38465 r41344  
    100100  GetRotFont (&fontsize);
    101101
     102  // labelPad (min -> no labels, max -> yes labels)
     103  // XXX change these defaults
    102104  minPAD = 1.0*fontsize + 0;
    103105  maxPAD = 2.0*fontsize + 4;
     
    140142  // these depend on (a) existence of tick labels and (b) auto-offset or not.
    141143  // in the auto-offset case, offset depends on the width of the tick label strings
     144  // because the y-axis labels are horizontal, the length matters
    142145  if (graph[0].axis[1].islabel && (isnan(graph[0].axis[1].labelPad) || isnan(graph[0].axis[1].pad))) {
    143146    /* check for the max size of the axis label */
     
    146149    for (i = 0; i < Nticks; i++) {
    147150      if (!ticks[i].IsMajor) continue;
    148 
    149       int Nchar = PrintTick (string, ticks[i].value, graph[0].axis[1].min, graph[0].axis[1].max, ticks[i].nsignif);
    150 
     151      int Nchar = PrintTick (string, &ticks[i], graph[0].axis[1].min, graph[0].axis[1].max);
    151152      Nc = MAX (Nc, Nchar);
    152153    }
     
    172173    for (i = 0; i < Nticks; i++) {
    173174      if (!ticks[i].IsMajor) continue;
    174       int Nchar = PrintTick (string, ticks[i].value, graph[0].axis[3].min, graph[0].axis[3].max, ticks[i].nsignif);
     175      int Nchar = PrintTick (string, &ticks[i], graph[0].axis[3].min, graph[0].axis[3].max);
    175176      Nc = MAX (Nc, Nchar);
    176177    }
  • trunk/Ohana/src/kapa2/src/bDrawFrame.c

    r40558 r41344  
    8787  dir = ((naxis == 0) || (naxis == 3)) ? -1 : +1;
    8888 
    89   x = fx + (value-min)*dfx/(max - min);
    90   y = fy + (value-min)*dfy/(max - min);
     89  x = fx + (value - min)*dfx/(max - min);
     90  y = fy + (value - min)*dfy/(max - min);
    9191
    9292  dx = 0;
     
    121121    if (naxis == 3) { dy = 0; dx = +pad; pos = 5; }
    122122
    123     xt = fx + (value-min)*dfx/(max - min) + dx;
    124     yt = fy + (value-min)*dfy/(max - min) + dy;
     123    xt = fx + (value - min)*dfx/(max - min) + dx;
     124    yt = fy + (value - min)*dfy/(max - min) + dy;
    125125
    126     PrintTick (string, value, min, max, tick->nsignif);
     126    PrintTick (string, tick, min, max);
    127127    bDrawRotText (buffer, xt, yt, string, pos, 0.0);
    128128  }
     
    190190    yt = fy + (value-min)*dfy/(max - min) + dy;
    191191
    192     PrintTick (string, value, min, max, tick->nsignif);
     192    PrintTick (string, tick, min, max);
    193193    bDrawRotText (buffer, xt, yt, string, pos, 0.0);
    194194  }
  • trunk/Ohana/src/libdvo/include/get_graphdata.h

    r40571 r41344  
    1616  int flipeast, flipnorth;
    1717  char axis[8], labels[8], ticks[8];
     18  char formatXm[16], formatXp[16], formatYm[16], formatYp[16];
    1819} Graphdata;
    1920
  • trunk/Ohana/src/libkapa/src/KapaWindow.c

    r41341 r41344  
    8888}
    8989
    90 // XXX drop this function? : kapa is responsible for the graph initialization
     90// called in kapa2/src/Graphs.c to init the graph
    9191int KapaInitGraph (Graphdata *graphdata) {
    9292
     
    109109  strcpy (graphdata[0].labels, "2222");
    110110
     111  strcpy (graphdata[0].formatXm, "auto");
     112  strcpy (graphdata[0].formatXp, "auto");
     113  strcpy (graphdata[0].formatYm, "auto");
     114  strcpy (graphdata[0].formatYp, "auto");
     115
    111116  graphdata[0].ticktextPad = NAN;
    112117
     
    182187                  data[0].fMinorYm, data[0].fMinorYp);
    183188
     189  KiiSendMessage (fd, "%s %s %s %s",
     190                  data[0].formatXm, data[0].formatXp,
     191                  data[0].formatYm, data[0].formatYp);
     192
    184193  KiiSendMessage (fd, "%g %g %g %g ",
    185194                  data[0].coords.pc1_1, data[0].coords.pc2_2,
     
    232241                  &data[0].fMinorXm, &data[0].fMinorXp,
    233242                  &data[0].fMinorYm, &data[0].fMinorYp);
     243
     244  KiiScanMessage (fd, "%s %s %s %s",
     245                  data[0].formatXm, data[0].formatXp,
     246                  data[0].formatYm, data[0].formatYp);
    234247
    235248  KiiScanMessage (fd, "%f %f %f %f",
  • trunk/Ohana/src/opihi/cmd.data/box.c

    r38986 r41344  
    200200  }
    201201
     202  if ((N = get_argument (argc, argv, "-format"))) {
     203    remove_argument (N, &argc, argv);
     204    if (strlen (argv[N]) > 15) { goto usage; }
     205    strcpy (graphmode.formatXm, argv[N]);
     206    strcpy (graphmode.formatXp, argv[N]);
     207    strcpy (graphmode.formatYm, argv[N]);
     208    strcpy (graphmode.formatYp, argv[N]);
     209    remove_argument (N, &argc, argv);
     210  }
     211
     212  if ((N = get_argument (argc, argv, "-xformat"))) {
     213    remove_argument (N, &argc, argv);
     214    if (strlen (argv[N]) > 15) { goto usage; }
     215    strcpy (graphmode.formatXm, argv[N]);
     216    remove_argument (N, &argc, argv);
     217  }
     218
     219  if ((N = get_argument (argc, argv, "-yformat"))) {
     220    remove_argument (N, &argc, argv);
     221    if (strlen (argv[N]) > 15) { goto usage; }
     222    strcpy (graphmode.formatYm, argv[N]);
     223    remove_argument (N, &argc, argv);
     224  }
     225
     226  if ((N = get_argument (argc, argv, "+xformat"))) {
     227    remove_argument (N, &argc, argv);
     228    if (strlen (argv[N]) > 15) { goto usage; }
     229    strcpy (graphmode.formatXp, argv[N]);
     230    remove_argument (N, &argc, argv);
     231  }
     232
     233  if ((N = get_argument (argc, argv, "+yformat"))) {
     234    remove_argument (N, &argc, argv);
     235    if (strlen (argv[N]) > 15) { goto usage; }
     236    strcpy (graphmode.formatYm, argv[N]);
     237    remove_argument (N, &argc, argv);
     238  }
     239
    202240  if (argc != 1) goto usage;
    203241
Note: See TracChangeset for help on using the changeset viewer.