IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Apr 28, 2010, 10:27:33 AM (16 years ago)
Author:
eugene
Message:

updates from dev branch Ohana.20100407: improvements to kapa label and tick control, creation of setphot program

Location:
trunk/Ohana
Files:
18 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/kapa2/doc/mark.issues.txt

    r25918 r27790  
     1
     2* option to set window margin
     3* option to add section outer box
     4* option to set limits based on associated image (and change dynamically...)
     5o need consistency of graph defaults : axis, tick, labels should come from kapa
     6o clear should erase current plot
     7
    18-> The "plot" command needs to be fixed so that boundaries of contours do
    29not cause it to draw excessive amounts of lines connecting unrelated
    310contours. A specific "contour line type" would be useful.
    4 
    5 -> DVO is not consistently placing the x/y axis labels, especially in
    6 user-defined sections of the plot window.
     11(-pt 100?)
    712
    813-> DVO does not plot the end-points of histograms properly (e.g., the
     
    1318relay output to the file in the same order. Also, until DVO is closed, the
    1419output does not appear in the file.
     20(fixed both issues)
    1521
     22-> DVO is not consistently placing the x/y axis labels, especially in
     23user-defined sections of the plot window.
     24(fixed)
     25* box -labelpad -labelpad[x,y] +labelpad[x,y] -
     26
     27
     28---
     29
     30
     311)You wanted me to remind you to update ~ipp-svn; this was so I could have
     32the latest version of DVO on-hand
     33
     342)The plotting of axis labels remains inconsistent; depending on section
     35dimensions and the presence/absence of tick-marks, labels will change
     36their distance from their corresponding axis. This results in labels
     37falling off the screen or overlapping with other plot sections
     38
     393)Plot section locations in the plot window shift if labels/tick-marks are
     40present or absent
     41
     424)It would be useful to have an option for the box or section command that
     43causes the background to be opaque. This will allow plots to have insets.
     44
     455)It would be useful to have a rectangle plotting command in order to
     46shade out regions on plots
     47
     486)The limits command combined with box will sometimes produce tick-marks
     49with only the zero-point labeled, making the axes difficult to interpret
     50
     517)Text is printed to a file at different times when using either the echo
     52or fprintf commands alongside the output command. Sometimes output is
     53printed to the file immediately, while other times it is printed only when
     54the file is closed for output.
     55
     568)The use of ^C as an interrupt does not always work when a macro is doing
     57for loops.
     58
     599)It would be useful for DVO to echo which line of a macro contains an
     60error, or at which line it was forced to stop. This would help debugging a
     61lot.
     62
     6310)The cgrid could use an option to print RA/DEC tick-mark labels so that
     64image plots would be more informative
  • trunk/Ohana/src/kapa2/include/prototypes.h

    r27530 r27790  
    2626
    2727/* X drawing utilities */
    28 void          DrawFrame           PROTO((KapaGraphWidget *graph));
     28int           DrawFrame           PROTO((KapaGraphWidget *graph));
    2929int           DrawObjects         PROTO((KapaGraphWidget *graph));
    3030void          DrawLabels          PROTO((KapaGraphWidget *graph));
     
    3939void          DrawXErrors         PROTO((KapaGraphWidget *graph, Gobjects *objects));
    4040void          DrawYErrors         PROTO((KapaGraphWidget *graph, Gobjects *objects));
    41 void          DrawTick            PROTO((int fx, int fy, int dfx, int dfy, int P, double min, double max, double value, int IsLabel, int IsMajor, int naxis));
     41void          DrawTick            PROTO((Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis));
    4242void          AxisTickScale       PROTO((Axis *axis, double *major, double *minor));
     43TickMarkData *CreateAxisTicks     PROTO((Axis *axis, int *nticks));
    4344
    4445/* EventLoop */
     
    4748int           Reconfig            PROTO((XEvent *event));
    4849void          Refresh             PROTO((void));
     50void          DrawSectionBG       PROTO((Graphic *graphic, Section *section));
    4951
    5052/* CheckPipe */
     
    6163int           SetSection          PROTO((int sock));
    6264int           ListSection         PROTO((int sock));
     65int           SetSectionBG        PROTO((int sock));
    6366int           MoveSection         PROTO((int sock));
    6467int           DefineSection       PROTO((int sock));
     
    8487void          FreeSection         PROTO((Section *section));
    8588void          FreeSections        PROTO((void));
    86 Section      *AddSection          PROTO((char *name, float x, float y, float dx, float dy));
     89Section      *AddSection          PROTO((char *name, float x, float y, float dx, float dy, int bg));
    8790int           DelSection          PROTO((char *name));
    8891int           GetSectionByName    PROTO((char *name));
     
    112115void          PSXErrors           PROTO((KapaGraphWidget *graph, Gobjects *objects, FILE *f));
    113116void          PSYErrors           PROTO((KapaGraphWidget *graph, Gobjects *objects, FILE *f));
    114 void          PSTick              PROTO((FILE *f, double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int IsLabel, int IsMajor, int naxis));
     117void          PSTick              PROTO((Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis, FILE *f));
    115118void          ClipLinePS          PROTO((double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0, FILE *f));
    116119int           PSimage             PROTO((KapaImageWidget *image, FILE *f));
     
    131134void          bDrawXErrors        PROTO((KapaGraphWidget *graph, Gobjects *object));
    132135void          bDrawYErrors        PROTO((KapaGraphWidget *graph, Gobjects *object));
    133 void          bDrawTick           PROTO((double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int IsLabel, int IsMajor, int naxis));
     136void          bDrawTick           PROTO((Axis *axis, int P, TickMarkData *tick, int naxis));
    134137void          bDrawClipLine       PROTO((double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0));
    135138bDrawBuffer  *bDrawIt             PROTO((void));
  • trunk/Ohana/src/kapa2/include/structures.h

    r25757 r27790  
    137137  double min, max;
    138138  char isaxis, areticks, islabel, islog;
     139  double pad, labelPad, ticktextPad;
    139140  double fx, dfx, fy, dfy;  /* axis location on graphic */
    140141  double lweight;
    141142  int color;
    142143} Axis;
     144
     145// structure to describe the ticks for an axis
     146typedef struct {
     147  double value;
     148  int IsMajor;
     149  int IsLabel;
     150} TickMarkData;
    143151
    144152// a single graph in the display window
     
    210218  float  x,  y;
    211219  float dx, dy;
     220  int bg;
    212221  char *name;
    213222} Section;
  • trunk/Ohana/src/kapa2/src/CheckPipe.c

    r25757 r27790  
    221221  }
    222222 
     223  if (!strcmp (word, "BSEC")) {
     224    status = SetSectionBG (sock);
     225    KiiSendCommand (sock, 4, "DONE");
     226    FINISHED (TRUE);
     227  }
     228 
    223229  if (!strcmp (word, "FONT")) {
    224230    status = SetFont (sock);
  • trunk/Ohana/src/kapa2/src/DefineSection.c

    r21153 r27790  
    44int DefineSection (int sock) {
    55 
    6   int N, MoveSection;
     6  int N, MoveSection, bg;
    77  char name[128];
    88  double x, y, dx, dy;
    99  Section *section;
    1010
    11   KiiScanMessage (sock, "%s %lf %lf %lf %lf", name, &x, &y, &dx, &dy);
     11  KiiScanMessage (sock, "%s %lf %lf %lf %lf %d", name, &x, &y, &dx, &dy, &bg);
    1212
    1313  MoveSection = FALSE;
     
    1515  N = GetSectionByName (name);
    1616  if (N < 0) {
    17     section = AddSection (name, x, y, dx, dy);
     17    section = AddSection (name, x, y, dx, dy, bg);
    1818    MoveSection = TRUE;
    1919  } else {
     
    3030    section[0].dx = dx;
    3131    section[0].dy = dy;
     32    section[0].bg = bg;
    3233  }
    3334
  • trunk/Ohana/src/kapa2/src/DrawFrame.c

    r27603 r27790  
    11# include "Ximage.h"
    2 # define MIN_RANGE 1e-10
    32# define DrawLine(X,Y,DX,DY) (XDrawLine (graphic->display, graphic->window, graphic->gc, (int)(X), (int)(Y), (int)(X+DX), (int)(Y+DY)))
    43 
    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;
     4int DrawFrame (KapaGraphWidget *graph) {
     5 
     6  int i, j, Nticks, P;
     7  double fx, fy, dfx, dfy, lweight;
     8  Graphic *graphic;
     9  TickMarkData *ticks;
     10  int color;
    1111
    1212  graphic = GetGraphic();
    1313
    14   /* each axis is drawn independently, but ticks and labels are placed according to
    15      perpendicular distance. */
     14  /* each axis is drawn independently, but ticks and labels are placed according to perpendicular distance. */
    1615  for (i = 0; i < 4; i++) {
    17     fx = graph[0].axis[i].fx;
    18     fy = graph[0].axis[i].fy;
     16    fx  = graph[0].axis[i].fx;
     17    fy  = graph[0].axis[i].fy;
    1918    dfx = graph[0].axis[i].dfx;
    2019    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);
     20    P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    2221
    2322    lweight = MAX (0, MIN (10, graph[0].axis[i].lweight));
     23    color = MAX (0, MIN (15, graph[0].axis[i].color));
     24
    2425    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);
    30 
    31     // fprintf (stderr, "axis: %d, color: %d, %ld, weight: %f\n", i, graph[0].axis[i].color, graphic->color[graph[0].axis[i].color], lweight);
     26    XSetForeground (graphic->display, graphic->gc, graphic->color[color]);
     27    DrawRotTextInit (graphic->display, graphic->window, graphic->gc, graphic->color[color], graphic->back);
    3228
    3329    if (graph[0].axis[i].isaxis) {
    3430      DrawLine (fx, fy, dfx, dfy);
    35       // fprintf (stderr, "%d : %d %d - %d %d\n", i, fx, fy, dfx, dfy);
    36       // if (i == 0) {
    37       //        int j;
    38       //        for (j = fx; j < fx + dfx; j+= 10) {
    39       //          DrawLine (j, fy-10, 0, 20);
    40       //        }
    41       // }
    4231    }
    4332   
    4433    if (graph[0].axis[i].areticks) {
    45       if (isnan(graph[0].axis[i].min) || isinf(graph[0].axis[i].min)) continue;
    46       if (isnan(graph[0].axis[i].max) || isinf(graph[0].axis[i].max)) continue;
    47 
    48       range = graph[0].axis[i].max - graph[0].axis[i].min;
    49       if (fabs(range) < MIN_RANGE) continue;
    50 
    51       if (fabs(range) < MIN_RANGE) {
    52         range = (range < 0) ? -MIN_RANGE : +MIN_RANGE;
     34      ticks = CreateAxisTicks (&graph[0].axis[i], &Nticks);
     35      for (j = 0; j < Nticks; j++) {
     36        DrawTick (graphic, &graph[0].axis[i], P, &ticks[j], i);
    5337      }
    54 
    55       AxisTickScale (&graph[0].axis[i], &major, &minor);
    56 
    57       first = minor*((int)(graph[0].axis[i].min/minor));
    58       if ((range > 0) && (first < graph[0].axis[i].min)) {
    59         first += minor;
    60       }
    61       if ((range < 0) && (first > graph[0].axis[i].min)) {
    62         first -= minor;
    63       }
    64       for (next = first; ((range > 0) && (next <= graph[0].axis[i].max)) || ((range < 0) && (next >= graph[0].axis[i].max));) {
    65         IsMajor = FALSE;
    66         IsMajor |= (fabs((int)(next/major) - (next/major)) < 0.5*(minor/major));
    67         IsMajor |= (fabs((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    68         IsMajor |= (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    69         IsLabel = (IsMajor && graph[0].axis[i].islabel);
    70         DrawTick (fx, fy, dfx, dfy, P, graph[0].axis[i].min, graph[0].axis[i].max, next, IsLabel, IsMajor, i);
    71         if (range > 0)
    72           next += minor;
    73         else
    74           next -= minor;
    75       }
     38      FREE (ticks);
    7639    }
    7740  }
    78 }
    79 
    80 void DrawTick (int fx, int fy, int dfx, int dfy,
    81                int P, double min, double max,
    82                double value, int IsLabel, int IsMajor, int naxis) {
    83  
    84   int x, y, dx, dy, pos, dir, fontsize;
    85   double size, n;
     41  return (TRUE);
     42}
     43
     44void DrawTick (Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis) {
     45 
     46  double x, y, dx, dy;
     47  int pos, dir, fontsize;
     48  double size, n, pad;
    8649  char string[64], *fontname;
    8750
    88   if (IsMajor) {
     51  double fx  = axis->fx;
     52  double fy  = axis->fy;
     53  double dfx = axis->dfx;
     54  double dfy = axis->dfy;
     55
     56  double min = axis->min;
     57  double max = axis->max;
     58
     59  double value = tick->value;
     60
     61  pos = size = 0;
     62
     63  if (tick->IsMajor) {
    8964    size = MAX (0.02, 7.0 / P);
    9065  } else {
     
    9267  }
    9368 
    94   n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
     69  n = P / hypot(dfx, dfy);
    9570  x = fx + (value-min)*dfx/(max - min);
    9671  y = fy + (value-min)*dfy/(max - min);
    9772
    98   dir = +1;
    99   if ((naxis == 0) || (naxis == 1)) dir *= -1;
     73  if ((naxis == 0) || (naxis == 2)) {
     74    x = MAX(x, fx);
     75  }
     76  //   y = MAX(y, fy);
     77  // }
     78
     79  dir = ((naxis == 0) || (naxis == 1)) ? -1 : +1;
    10080  dx = dir*size*dfy*n; 
    10181  dy = dir*size*dfx*n;
     
    10383  DrawLine (x, y, dx, dy);
    10484
    105 # ifdef IN_AND_OUT_TICKS
    106 # define GAP 0.03
    107 # else
    108 # define GAP 0.01
    109 # endif
    110 
    111   if (IsLabel) {
     85  if (tick->IsLabel) {
     86    int xt, yt;
     87
    11288    fontname = GetRotFont (&fontsize);
    113     pos = 0;
     89   
     90    pad = isfinite(axis->ticktextPad) ? axis->ticktextPad*fontsize : fontsize + 4.0;
     91    // pad = isfinite(axis->ticktextPad) ? axis->ticktextPad*fontsize : 0.8*fontsize + 1.0;
    11492   
    11593    /* temporarily assume rectilinear axes */
    116     if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
    117     if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
    118 
    119     if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
    120     if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
    121 
    122     x = fx + (value-min)*dfx/(max - min) + dx;
    123     y = fy + (value-min)*dfy/(max - min) + dy;
     94    if (naxis == 0) { dx = 0; dy = +1.0*pad; pos = 7; }
     95    if (naxis == 2) { dx = 0; dy = -1.0*pad; pos = 1; }
     96
     97    if (naxis == 1) { dy = 0; dx = -0.5*pad; pos = 3; }
     98    if (naxis == 3) { dy = 0; dx = +0.5*pad; pos = 5; }
     99
     100    xt = fx + (value-min)*dfx/(max - min) + dx;
     101    yt = fy + (value-min)*dfy/(max - min) + dy;
    124102    if (fabs(value/(max-min)) < 0.001) { value = 0.0; }
    125103    sprintf (string, "%4g", value);
    126     DrawRotText (x, y, string, pos, 0.0);
    127   }
    128  
    129 }
    130 
     104    DrawRotText (xt, yt, string, pos, 0.0);
     105  }
     106}
     107
     108# define MIN_RANGE 1e-10
    131109
    132110void AxisTickScale (Axis *axis, double *major, double *minor) {
     
    192170  }
    193171}
     172
     173TickMarkData *CreateAxisTicks (Axis *axis, int *nticks) {
     174
     175  TickMarkData *ticks;
     176  double range, major, minor, first, value, dPixels, overshoot;
     177  int i, NTICKS, nPixels, done, ifirst;
     178
     179  *nticks = 0;
     180
     181  if (isnan(axis->min) || isinf(axis->min)) return NULL;
     182  if (isnan(axis->max) || isinf(axis->max)) return NULL;
     183 
     184  range = axis->max - axis->min;
     185
     186  // not sure why I skip out here instead of using the MIN_RANGE value
     187  if (fabs(range) < MIN_RANGE) return NULL;
     188 
     189  if (fabs(range) < MIN_RANGE) {
     190    range = (range < 0) ? -MIN_RANGE : +MIN_RANGE;
     191  }
     192
     193  // length of the axis in pixels
     194  nPixels = hypot(axis->dfx, axis->dfy);
     195  dPixels = nPixels / range; // axis pixel-scale
     196
     197  AxisTickScale (axis, &major, &minor);
     198
     199  // be a little generous
     200  NTICKS = (int)(fabs(range / minor)) + 2;
     201  ALLOCATE (ticks, TickMarkData, NTICKS);
     202
     203  // value of the tick mark
     204  ifirst = (axis->min < 0.0) ? (axis->min/minor - 0.05) : (axis->min/minor + 0.05);
     205  first = minor*ifirst;
     206 
     207  // allow undershoot by 1 pixel
     208  overshoot = (axis->min - first) * dPixels;
     209  // if (overshoot > 0.5) {
     210  //   if (range > 0) {
     211  //     first += minor;
     212  //   } else {
     213  //     first -= minor;
     214  //   }
     215  // }
     216
     217  // loop to find the ticks
     218  done = FALSE;
     219  value = first;
     220  for (i = 0; !done && (i < NTICKS); i++) {
     221    ticks[i].IsMajor = FALSE;
     222    ticks[i].IsMajor |= (fabs((int)(value/major) - (value/major)) < 0.5*(minor/major));
     223    ticks[i].IsMajor |= (fabs((int)((value + 0.5*minor)/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].IsLabel = (ticks[i].IsMajor && axis->islabel);
     226    ticks[i].value = value;
     227    if (range > 0)
     228      value += minor;
     229    else
     230      value -= minor;
     231   
     232    done |= (range > 0) && (value > axis->max);
     233    done |= (range < 0) && (value < axis->max);
     234  }
     235
     236  *nticks = i;
     237  return (ticks);
     238}
  • trunk/Ohana/src/kapa2/src/DrawLabels.c

    r17466 r27790  
    3434      switch (i) {
    3535      case 0: pos = 7; break;
     36      case 2: pos = 1; break;
    3637      case 1: pos = 1; angle = -90; break;
    37       case 2: pos = 1; break;
    3838      case 3: pos = 1; angle =  90; break;
    3939      case 4: pos = 2; break;
  • trunk/Ohana/src/kapa2/src/EraseSections.c

    r21153 r27790  
    88 
    99  FreeSections ();
    10   AddSection ("default", 0.0, 0.0, 1.0, 1.0);
     10  AddSection ("default", 0.0, 0.0, 1.0, 1.0, -1);
    1111
    1212  if (USE_XWINDOW) XClearWindow (graphic->display, graphic->window);
  • trunk/Ohana/src/kapa2/src/Graphs.c

    r27530 r27790  
    1818    graph[0].axis[i].lweight = 0.0;
    1919    graph[0].axis[i].color = 0;
     20    graph[0].axis[i].ticktextPad = NAN;
     21    graph[0].axis[i].labelPad = NAN;
     22    graph[0].axis[i].pad = NAN;
    2023  }   
     24  graph[0].data.ticktextPad = NAN;
     25
     26  graph[0].data.labelPadXm = NAN;
     27  graph[0].data.labelPadXp = NAN;
     28  graph[0].data.labelPadYm = NAN;
     29  graph[0].data.labelPadYp = NAN;
     30
     31  graph[0].data.padXm = NAN;
     32  graph[0].data.padXp = NAN;
     33  graph[0].data.padYm = NAN;
     34  graph[0].data.padYp = NAN;
     35
    2136  for (i = 0; i < 8; i++) {
    2237    strcpy (graph[0].label[i].text, "");
     
    3752  graph[0].data.size    = 1.0;          // point size of 1.0
    3853
    39   graph[0].data.flipeast  = 1;          // +East  = -X by default
    40   graph[0].data.flipnorth = 0;          // +North = +Y by default
     54  graph[0].data.flipeast = TRUE;        // +East  = -X by default
     55  graph[0].data.flipnorth = FALSE;      // +North = +Y by default
     56
     57  graph[0].data.coords.pc1_1 = graph[0].data.coords.pc2_2 = 1.0;
     58  graph[0].data.coords.pc1_2 = graph[0].data.coords.pc2_1 = 0.0;
     59  graph[0].data.coords.crval1 = 0.0;
     60  graph[0].data.coords.crval2 = 0.0;
     61  graph[0].data.coords.crpix1 = 0.0;
     62  graph[0].data.coords.crpix2 = 0.0;
     63  graph[0].data.coords.cdelt1 = graph[0].data.coords.cdelt2 = 1.0;
     64  strcpy (graph[0].data.coords.ctype, "RA---LIN");
     65  strcpy (graph[0].data.axis, "2222");
     66  strcpy (graph[0].data.ticks, "2222");
     67  strcpy (graph[0].data.labels, "2222");
    4168
    4269  graph[0].Nobjects = 0;
  • trunk/Ohana/src/kapa2/src/Layout.c

    r14737 r27790  
    4343
    4444  /* create basic section, empty of image or graph */
    45   section = AddSection ("default", 0.0, 0.0, 1.0, 1.0);
     45  section = AddSection ("default", 0.0, 0.0, 1.0, 1.0, -1);
    4646}
  • trunk/Ohana/src/kapa2/src/LoadFrame.c

    r21153 r27790  
    33int LoadFrame (int sock) {
    44 
    5   int i, color;
    6   char Axis[16], Labels[16], Ticks[16];
    7   double lweight;
     5  int i;
    86  Section *section;
    97  KapaGraphWidget *graph;
     
    1614  graph = section->graph;
    1715
    18   KiiScanMessage (sock, "%lf %lf %lf %lf",
    19                   &graph[0].axis[0].min, &graph[0].axis[0].max,
    20                   &graph[0].axis[1].min, &graph[0].axis[1].max);
     16  KapaScanGraphData (sock, &graph[0].data);
    2117
    2218  graph[0].axis[3].min = graph[0].axis[1].min;
     
    2521  graph[0].axis[2].max = graph[0].axis[0].max;
    2622 
    27   KiiScanMessage (sock, "%lf %d", &lweight, &color);
    28   color = MAX (0, MIN (15, color));
     23  // XXX this is fragile
     24  graph[0].data.color = MAX (0, MIN (15, graph[0].data.color));
    2925
    30   KiiScanMessage (sock, "%s %s %s", Axis, Labels, Ticks);
     26  graph[0].axis[0].pad = graph[0].data.padXm;
     27  graph[0].axis[1].pad = graph[0].data.padYm;
     28  graph[0].axis[2].pad = graph[0].data.padXp;
     29  graph[0].axis[3].pad = graph[0].data.padYp;
     30
     31  graph[0].axis[0].labelPad = graph[0].data.labelPadXm;
     32  graph[0].axis[1].labelPad = graph[0].data.labelPadYm;
     33  graph[0].axis[2].labelPad = graph[0].data.labelPadXp;
     34  graph[0].axis[3].labelPad = graph[0].data.labelPadYp;
    3135
    3236  for (i = 0; i < 4; i++) {
    33     graph[0].axis[i].lweight = lweight;
    34     graph[0].axis[i].color = color;
     37    graph[0].axis[i].lweight = graph[0].data.lweight;
     38    graph[0].axis[i].color = graph[0].data.color;
    3539
    36     switch (Axis[i]) {
     40    graph[0].axis[i].ticktextPad = graph[0].data.ticktextPad;
     41
     42    switch (graph[0].data.axis[i]) {
    3743    case '0':
    3844      graph[0].axis[i].isaxis = FALSE;
     
    4551      break;
    4652    }
    47     switch (Ticks[i]) {
     53    switch (graph[0].data.ticks[i]) {
    4854    case '0':
    4955      graph[0].axis[i].areticks = FALSE;
     
    5662      break;
    5763    }
    58     switch (Labels[i]) {
     64    switch (graph[0].data.labels[i]) {
    5965    case '0':
    6066      graph[0].axis[i].islabel = FALSE;
     
    7076
    7177  SetSectionSizes (section);
    72   if (USE_XWINDOW) DrawFrame (graph);
    73   FlushDisplay ();
     78  Refresh();
     79  // if (USE_XWINDOW) DrawFrame (graph);
     80  // FlushDisplay ();
    7481
    7582  /* XXX why did I do this??? */
  • trunk/Ohana/src/kapa2/src/PSFrame.c

    r19834 r27790  
    44int PSFrame (KapaGraphWidget *graph, FILE *f) {
    55 
    6   int i, P, IsLabel, IsMajor, fontsize;
    7   double fx, fy, dfx, dfy, range, major, minor, first, next;
    8   char *fontname;
     6  int i, Nticks, P;
     7  double fx, fy, dfx, dfy, lweight;
    98  Graphic *graphic;
    10   float weight;
     9  TickMarkData *ticks;
    1110  bDrawColor color;
    1211
     
    1413
    1514  /* each axis is drawn independently */
    16   fontname = GetRotFont (&fontsize);
    1715  fprintf (f, "1 setlinewidth\n");
    1816  for (i = 0; i < 4; i++) {
    19     fx = graph[0].axis[i].fx;
    20     fy = graphic->dy - graph[0].axis[i].fy;
     17    fx  = graph[0].axis[i].fx;
     18    fy  = graphic->dy - graph[0].axis[i].fy;
    2119    dfx = graph[0].axis[i].dfx;
    2220    dfy = -graph[0].axis[i].dfy;
    23     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);
    2422
    25     weight = MAX (0, MIN (10, graph[0].axis[i].lweight));
     23    lweight = MAX (0, MIN (10, graph[0].axis[i].lweight));
    2624    color = MAX (0, MIN (15, graph[0].axis[i].color));
    27     fprintf (f, "%.1f setlinewidth\n", weight);
     25
     26    fprintf (f, "%.1f setlinewidth\n", lweight);
    2827    fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(color));
     28    // no need to init rot font
    2929
    30     if (graph[0].axis[i].isaxis) { DrawLine (fx, fy, dfx, dfy); }
     30    if (graph[0].axis[i].isaxis) {
     31      DrawLine (fx, fy, dfx, dfy);
     32    }
    3133   
    3234    if (graph[0].axis[i].areticks) {
    33       if (isnan(graph[0].axis[i].min) || isinf(graph[0].axis[i].min)) continue;
    34       if (isnan(graph[0].axis[i].max) || isinf(graph[0].axis[i].max)) continue;
    35 
    36       range = graph[0].axis[i].max - graph[0].axis[i].min;
    37       AxisTickScale (&graph[0].axis[i], &major, &minor);
    38 
    39       first = minor*((int)(graph[0].axis[i].min/minor));
    40       if ((range > 0) && (first < graph[0].axis[i].min)) {
    41         first += minor;
     35      ticks = CreateAxisTicks (&graph[0].axis[i], &Nticks);
     36      for (i = 0; i < Nticks; i++) {
     37        PSTick (graphic, &graph[0].axis[i], P, &ticks[i], i, f);
    4238      }
    43       if ((range < 0) && (first > graph[0].axis[i].min)) {
    44         first -= minor;
    45       }
    46       for (next = first; ((range > 0) && (next <= graph[0].axis[i].max)) || ((range < 0) && (next >= graph[0].axis[i].max));) {
    47         IsMajor = FALSE;
    48         IsMajor |= (fabs((int)(next/major) - (next/major)) < 0.5*(minor/major));
    49         IsMajor |= (fabs ((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    50         IsMajor |= (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    51         IsLabel = (IsMajor && graph[0].axis[i].islabel);
    52         PSTick (f, fx, fy, dfx, dfy, P, graph[0].axis[i].min, graph[0].axis[i].max, next, IsLabel, IsMajor, i);
    53         if (range > 0)
    54           next += minor;
    55         else
    56           next -= minor;
    57       }
    58     }
     39      FREE (ticks);
     40    }     
    5941  }
    6042  return (TRUE);
    6143}
    6244
    63 void PSTick (FILE *f, double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int IsLabel, int IsMajor, int naxis) {
     45void PSTick (Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis, FILE *f) {
    6446 
     47  double x, y, dx, dy;
    6548  int pos, dir, fontsize;
    66   double size, n, x, y, dx, dy;
     49  double size, n, pad;
    6750  char string[64], *fontname;
     51
     52  double fx  = axis->fx;
     53  double fy  = graphic->dy - 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;
    6861
    6962  pos = size = 0;
    7063
    71   if (IsMajor) {
     64  if (tick->IsMajor) {
    7265    size = MAX (0.02, 7.0 / P);
    7366  } else {
     
    7568  }
    7669 
    77   n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
     70  n = P / hypot(dfx, dfy);
    7871  x = fx + (value-min)*dfx/(max - min);
    7972  y = fy + (value-min)*dfy/(max - min);
    8073
    81   dir = -1;
    82   if ((naxis == 0) || (naxis == 1)) dir *= -1;
     74  dir = ((naxis == 0) || (naxis == 1)) ? -1 : +1;
    8375  dx = dir*size*dfy*n; 
    8476  dy = dir*size*dfx*n;
     
    8678  DrawLine (x, y, dx, dy);
    8779
    88   if (IsLabel) {
     80  if (tick->IsLabel) {
     81    int xt, yt;
     82
    8983    fontname = GetRotFont (&fontsize);
    9084
     85    pad = isfinite(axis->ticktextPad) ? axis->ticktextPad*fontsize : 0.8*fontsize + 1.0;
     86   
    9187    /* temporarily assume rectilinear axes */
    92     if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
    93     if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
     88    if (naxis == 0) { dx = 0; dy = +pad; pos = 1; }
     89    if (naxis == 2) { dx = 0; dy = -pad; pos = 7; }
    9490
    95     if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
    96     if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
     91    if (naxis == 1) { dy = 0; dx = -pad; pos = 3; }
     92    if (naxis == 3) { dy = 0; dx = +pad; pos = 5; }
    9793
    98     x = fx + (value-min)*dfx/(max - min) + dx;
    99     y = fy + (value-min)*dfy/(max - min) + dy;
    100     if (fabs(value) < 1e-14) { value = 0.0; }
    101     sprintf (string, "%g", value);
    102     PSRotText (f, (int)x, (int)y, string, pos, 0.0);
     94    xt = fx + (value-min)*dfx/(max - min) + dx;
     95    yt = fy + (value-min)*dfy/(max - min) + dy;
     96    if (fabs(value) < 0.001) { value = 0.0; }
     97    sprintf (string, "%4g", value);
     98    PSRotText (f, xt, yt, string, pos, 0.0);
    10399  }
    104100}
  • trunk/Ohana/src/kapa2/src/Refresh.c

    r21153 r27790  
    2121  for (i = 0; i < Nsection; i++) {
    2222      section = GetSectionByNumber (i);
     23      DrawSectionBG (graphic, section);
    2324      DrawImage (section->image);
    2425      DrawGraph (section->graph);
     
    2829}
    2930
     31void DrawSectionBG (Graphic *graphic, Section *section) {
     32
     33  int Ncolors;
     34  int X0, Y0, dX, dY;
     35
     36  if (section->bg == -1) return;
     37
     38  Ncolors = KapaColormapSize();
     39
     40  if (section->bg < 0) return;
     41  if (section->bg >= Ncolors) return;
     42
     43  XSetForeground (graphic->display, graphic->gc, graphic->color[section->bg]);
     44
     45  dY = graphic[0].dy * section[0].dy;
     46  dX = graphic[0].dx * section[0].dx;
     47  Y0 = graphic[0].dy - graphic[0].dy * section[0].y - dY;
     48  X0 = graphic[0].dx * section[0].x;
     49  // fprintf (stderr, "section: (%s) %d %d - %d %d\n", section[0].name, X0, Y0, dX, dY);
     50
     51  XFillRectangle (graphic[0].display,  graphic[0].window, graphic[0].gc, X0, Y0, dX, dY);
     52  return;
     53}
  • trunk/Ohana/src/kapa2/src/Sections.c

    r21153 r27790  
    1616  section[0].dx = 0;
    1717  section[0].dy = 0;
     18  section[0].bg = -1;
    1819
    1920  section[0].name = NULL;
     
    4243}
    4344
    44 Section *AddSection (char *name, float x, float y, float dx, float dy) {
     45Section *AddSection (char *name, float x, float y, float dx, float dy, int bg) {
    4546
    4647  int N;
     
    6162  sections[N][0].dx = dx;
    6263  sections[N][0].dy = dy;
     64  sections[N][0].bg = bg;
    6365  ActiveSection = N;
    6466  return (sections[N]);
     
    155157}
    156158
     159int SetSectionBG (int sock) {
     160
     161  int N, background;
     162  char name[128];
     163
     164  KiiScanMessage (sock, "%s %d", name, &background);
     165 
     166  N = GetSectionByName (name);
     167  if (N < 0) {
     168    fprintf (stderr, "section %s not found\n", name);
     169    return (TRUE);
     170  }
     171
     172  sections[N][0].bg = background;
     173
     174  return (TRUE);
     175}
     176
    157177// return TRUE even for nonsense cases to avoid quitting kapa
    158178int MoveSection (int sock) {
  • trunk/Ohana/src/kapa2/src/SetGraphData.c

    r21153 r27790  
    1818  graph = section->graph;
    1919 
    20   // get graph data from client
    21   KiiScanMessage (sock, "%d %d %d %d %d %d %lf %lf",
    22                   &graph[0].data.style,
    23                   &graph[0].data.ptype,
    24                   &graph[0].data.ltype,
    25                   &graph[0].data.etype,
    26                   &graph[0].data.ebar,
    27                   &graph[0].data.color,
    28                   &graph[0].data.lweight,
    29                   &graph[0].data.size);
     20  KapaScanGraphData (sock, &graph[0].data);
    3021
    31   KiiScanMessage (sock, "%lf %lf %lf %lf",
    32                   &graph[0].data.xmin,
    33                   &graph[0].data.xmax,
    34                   &graph[0].data.ymin,
    35                   &graph[0].data.ymax);
     22  for (i = 0; i < 4; i++) {
     23    graph[0].axis[i].ticktextPad = graph[0].data.ticktextPad;
     24  }   
     25  graph[0].axis[0].labelPad = graph[0].data.labelPadXm;
     26  graph[0].axis[1].labelPad = graph[0].data.labelPadYm;
     27  graph[0].axis[2].labelPad = graph[0].data.labelPadXp;
     28  graph[0].axis[3].labelPad = graph[0].data.labelPadYp;
    3629
    37   KiiScanMessage (sock, "%f %f %f %f",
    38                   &graph[0].data.coords.pc1_1, &graph[0].data.coords.pc2_2,
    39                   &graph[0].data.coords.pc1_2, &graph[0].data.coords.pc2_1);
    40 
    41   KiiScanMessage (sock, "%d %d %s",
    42                   &graph[0].data.flipeast, &graph[0].data.flipnorth,
    43                   graph[0].data.coords.ctype);
    44 
    45   KiiScanMessage (sock, "%lf %lf %f %f %f %f",
    46                   &graph[0].data.coords.crval1,
    47                   &graph[0].data.coords.crval2,
    48                   &graph[0].data.coords.crpix1,
    49                   &graph[0].data.coords.crpix2,
    50                   &graph[0].data.coords.cdelt1,
    51                   &graph[0].data.coords.cdelt2);
    52 
    53 
     30  graph[0].axis[0].pad = graph[0].data.padXm;
     31  graph[0].axis[1].pad = graph[0].data.padYm;
     32  graph[0].axis[2].pad = graph[0].data.padXp;
     33  graph[0].axis[3].pad = graph[0].data.padYp;
    5434
    5535  xmin = graph[0].data.xmin;
     
    9070  graph = section->graph;
    9171
    92   KiiSendMessage (sock, "%8d %d %d %d %d %d %f %f",
    93                   graph[0].data.style,
    94                   graph[0].data.ptype, graph[0].data.ltype,
    95                   graph[0].data.etype, graph[0].data.ebar, graph[0].data.color,
    96                   graph[0].data.lweight, graph[0].data.size);
    97 
    98   KiiSendMessage (sock, "%g %g %g %g",
    99                   graph[0].data.xmin, graph[0].data.xmax,
    100                   graph[0].data.ymin, graph[0].data.ymax);
    101 
    102   KiiSendMessage (sock, "%g %g %g %g",
    103                   graph[0].data.coords.pc1_1, graph[0].data.coords.pc2_2,
    104                   graph[0].data.coords.pc1_2, graph[0].data.coords.pc2_1);
    105 
    106   KiiSendMessage (sock, "%d %d %s",
    107                   graph[0].data.flipeast, graph[0].data.flipnorth,
    108                   graph[0].data.coords.ctype);
    109 
    110   KiiSendMessage (sock, "%g %g %g %g %g %g",
    111                   graph[0].data.coords.crval1,
    112                   graph[0].data.coords.crval2,
    113                   graph[0].data.coords.crpix1,
    114                   graph[0].data.coords.crpix2,
    115                   graph[0].data.coords.cdelt1,
    116                   graph[0].data.coords.cdelt2);
     72  KapaSendGraphData (sock, &graph[0].data);
    11773
    11874  return (TRUE);
  • trunk/Ohana/src/kapa2/src/SetGraphSize.c

    r16011 r27790  
    66void SetGraphSize (Section *section) {
    77
    8   int fontsize, bump, Nc;
     8  int i, Nticks;
     9  int fontsize, Nc;
    910  int textpad, textdY, WdY;
    10   double PADx, PADy, Dx, Dy;
    11   double PXm, PXp, PYm, PYp;
     11  int dXm, dXp, dYm, dYp;
     12  double padXm, padXp, padYm, padYp;
     13  double minPADx, maxPADx, minPADy;
     14  double minPAD, maxPAD;
    1215  double X0, Y0, dX, dY;
    1316  char string[64], *fontname;
    1417  KapaGraphWidget *graph;
    1518  Graphic *graphic;
     19  TickMarkData *ticks;
    1620
    1721  if (section == NULL) return;
     
    2226  fontname = GetRotFont (&fontsize);
    2327
    24   PADx = MAX (graphic->dx / 20.0, fontsize);
    25   PADy = MAX (graphic->dy / 20.0, fontsize);
    26   Dx = graphic->dx - 2*PADx;
    27   Dy = graphic->dy - 2*PADy;
     28  minPAD = 1.0*fontsize + 0;
     29  maxPAD = 2.0*fontsize + 4;
    2830
    29   /* each graph has a padding PXm, PXp, PYm, PYp */
    30   PXm = (graph[0].axis[1].islabel) ? 4*fontsize : 0;
    31   PXp = (graph[0].axis[3].islabel) ? 4*fontsize : 0;
    32   PYm = (graph[0].axis[0].islabel) ? 4*fontsize : 0;
    33   PYp = (graph[0].axis[2].islabel) ? 4*fontsize : 0;
    34  
     31  minPADx = 1.5*fontsize;
     32  maxPADx = 2.5*fontsize + 4.0;
     33
     34  minPADy = 1.5*fontsize;
     35
     36  // dXm : offset to label from lower x-axis, dYp : offset to label from right y-axis, etc
     37  // padXm : padding below x-axis, padYp : padding to right of y-axis, etc
     38
     39  // offset from lower x-axis to labels and tick values
     40  // these depend on (a) existence of tick labels and (b) auto-offset or not
     41  if (isnan(graph[0].axis[0].labelPad)) {
     42    dXm = (graph[0].axis[0].islabel) ? maxPAD  : minPAD;
     43  } else {
     44    dXm = graph[0].axis[0].labelPad * fontsize;
     45  }
     46  if (isnan(graph[0].axis[0].pad)) {
     47    padXm = graph[0].axis[0].islabel ? maxPADx : minPADx;
     48  } else {
     49    padXm = graph[0].axis[0].pad * fontsize;
     50  }
     51
     52  // offset from upper x-axis to labels and tick values
     53  // these depend on (a) existence of tick labels and (b) auto-offset or not
     54  if (isnan(graph[0].axis[2].labelPad)) {
     55    dXp = (graph[0].axis[2].islabel) ? maxPAD : minPAD;
     56  } else {
     57    dXp = graph[0].axis[2].labelPad * fontsize;
     58  }
     59  if (isnan(graph[0].axis[2].pad)) {
     60    padXp = graph[0].axis[2].islabel ? maxPADx : minPADx;
     61  } else {
     62    padXp = graph[0].axis[2].pad * fontsize;
     63  }
     64
     65  // offset from left y-axis to labels and tick values
     66  // these depend on (a) existence of tick labels and (b) auto-offset or not.
     67  // in the auto-offset case, offset depends on the width of the tick label strings
     68  if (graph[0].axis[1].islabel && (isnan(graph[0].axis[1].labelPad) || isnan(graph[0].axis[1].pad))) {
     69    /* check for the max size of the axis label */
     70    Nc = 0;
     71    ticks = CreateAxisTicks (&graph[0].axis[1], &Nticks);
     72    for (i = 0; i < Nticks; i++) {
     73      if (!ticks[i].IsMajor) continue;
     74      sprintf (string, "%g", ticks[i].value);
     75      Nc = MAX (Nc, strlen (string));
     76    }
     77    FREE(ticks);
     78  }
     79  if (isnan(graph[0].axis[1].labelPad)) {
     80    dYm = (graph[0].axis[1].islabel) ? (0.7*(Nc + 1.5)*fontsize) : minPAD;
     81  } else {
     82    dYm = graph[0].axis[1].labelPad * fontsize;
     83  }
     84  if (isnan(graph[0].axis[1].pad)) {
     85    padYm = graph[0].axis[1].islabel ? (0.7*(Nc + 2.5)*fontsize) : minPADy;
     86  } else {
     87    padYm = graph[0].axis[1].pad * fontsize;
     88  }
     89
     90  // offset from right y-axis to labels and tick values
     91  // these depend on (a) existence of tick labels and (b) auto-offset or not.
     92  // in the auto-offset case, offset depends on the width of the tick label strings
     93  if (graph[0].axis[3].islabel && (isnan(graph[0].axis[3].labelPad) || isnan(graph[0].axis[3].pad))) {
     94    Nc = 0;
     95    ticks = CreateAxisTicks (&graph[0].axis[3], &Nticks);
     96    for (i = 0; i < Nticks; i++) {
     97      if (!ticks[i].IsMajor) continue;
     98      sprintf (string, "%g", ticks[i].value);
     99      Nc = MAX (Nc, strlen (string));
     100    }
     101    FREE(ticks);
     102  }
     103  if (isnan(graph[0].axis[3].labelPad)) {
     104    dYp = (graph[0].axis[3].islabel) ? (0.7*(Nc + 1.5)*fontsize) : minPAD;
     105  } else {
     106    dYp = graph[0].axis[3].labelPad * fontsize;
     107  }
     108  if (isnan(graph[0].axis[3].pad)) {
     109    padYp = graph[0].axis[3].islabel ? (0.7*(Nc + 2.5)*fontsize) : minPADy;
     110  } else {
     111    padYp = graph[0].axis[3].pad * fontsize;
     112  }
     113
    35114  /* basic size of the graph in Xwindow coordinates */
    36   X0 = PADx + PXm + (Dx * section[0].x);
    37   Y0 = PADy + PYm + (Dy * section[0].y);
    38   dX = (Dx * section[0].dx) - PXp - PXm;
    39   dY = (Dy * section[0].dy) - PYp - PYm;
     115  X0 = graphic[0].dx * section[0].x + padYm;
     116  Y0 = graphic[0].dy * section[0].y + padXm;
     117  dX = graphic[0].dx * section[0].dx - padYm - padYp;
     118  dY = graphic[0].dy * section[0].dy - padXm - padXp;
    40119
    41120  // if we are tied to an image, make mods as needed
     
    47126    switch (section->image->location) {
    48127      case 1:
    49         Y0 = graphic[0].dy * section[0].y + 2*PAD1 + WdY + 2; // tied to image in Y
     128        Y0 = graphic[0].dy * section[0].y  + 2*PAD1 + WdY + 2; // tied to image in Y
    50129        dY = graphic[0].dy * section[0].dy - 5*PAD1 - WdY - COLORPAD + 1;
    51130        break;
    52131      case 3:
    53         dY = graphic[0].dy * section[0].dy - 5*PAD1 - WdY - COLORPAD - PADy - PYm;
     132        dY = graphic[0].dy * section[0].dy - 5*PAD1 - WdY - COLORPAD - padYm - padYp;
    54133        break;
    55134      case 2:
     
    58137        break;
    59138      case 4:
    60         dX = graphic[0].dx * section[0].dx - 3*PAD1 - ZOOM_X - PADx - PXm;
     139        dX = graphic[0].dx * section[0].dx - 3*PAD1 - ZOOM_X - padXm - padXp;
    61140        break;
    62141    }
     
    84163  graph[0].axis[3].dfy = -dY;
    85164
    86   PADx = 0.8*fontsize + 2;
    87   PADy = 3.0*fontsize + 4;
     165  /* define locations of axis labels */
     166  graph[0].label[LABELLL].x = graph[0].axis[0].fx;
     167  graph[0].label[LABELLL].y = graph[0].axis[0].fy + dXm;
     168  graph[0].label[LABELX0].x = graph[0].axis[0].fx + 0.5*graph[0].axis[0].dfx;
     169  graph[0].label[LABELX0].y = graph[0].axis[0].fy + dXm;
     170  graph[0].label[LABELLR].x = graph[0].axis[0].fx + graph[0].axis[0].dfx;
     171  graph[0].label[LABELLR].y = graph[0].axis[0].fy + dXm;
    88172
    89   /* define locations of axis labels */
    90   graph[0].label[LABELX0].x = graph[0].axis[0].fx + 0.5*graph[0].axis[0].dfx;
    91   bump = (graph[0].axis[0].islabel) ? PADy : PADx;
    92   graph[0].label[LABELX0].y = graph[0].axis[0].fy + bump;
    93 
     173  graph[0].label[LABELUL].x = graph[0].axis[2].fx;
     174  graph[0].label[LABELUL].y = graph[0].axis[2].fy - dXp;
    94175  graph[0].label[LABELX1].x = graph[0].axis[2].fx + 0.5*graph[0].axis[2].dfx;
    95   bump = (graph[0].axis[2].islabel) ? PADy : PADx;
    96   graph[0].label[LABELX1].y = graph[0].axis[2].fy - bump;
    97 
    98   /* check for the max size of the axis label */
    99   sprintf (string, "%4g", graph[0].axis[1].min);
    100   Nc = strlen (string);
    101   sprintf (string, "%4g", graph[0].axis[1].max);
    102   Nc = MAX (Nc, strlen (string));
     176  graph[0].label[LABELX1].y = graph[0].axis[2].fy - dXp;
     177  graph[0].label[LABELUR].x = graph[0].axis[2].fx + graph[0].axis[2].dfx;
     178  graph[0].label[LABELUR].y = graph[0].axis[2].fy - dXp;
    103179
    104180  graph[0].label[LABELY0].y = graph[0].axis[1].fy + 0.5*graph[0].axis[1].dfy;
    105   bump = (graph[0].axis[1].islabel) ? (0.8*Nc*fontsize + 1) : PADx;
    106   graph[0].label[LABELY0].x = graph[0].axis[1].fx - bump;
    107 
    108   sprintf (string, "%4g", graph[0].axis[3].min);
    109   Nc = strlen (string);
    110   sprintf (string, "%4g", graph[0].axis[3].max);
    111   Nc = MAX (Nc, strlen (string));
     181  graph[0].label[LABELY0].x = graph[0].axis[1].fx - dYm;
    112182
    113183  graph[0].label[LABELY1].y = graph[0].axis[3].fy + 0.5*graph[0].axis[3].dfy;
    114   bump = (graph[0].axis[3].islabel) ? (0.8*Nc*fontsize + 1) : PADx;
    115   graph[0].label[LABELY1].x = graph[0].axis[3].fx + bump;
     184  graph[0].label[LABELY1].x = graph[0].axis[3].fx + dYp;
    116185 
     186  // fprintf (stderr, "section %s, %f,%f : %f,%f\n", section->name, X0, Y0, dX, dY);
     187
    117188  /* these are wrong and have to be adjusted to sit in the corners */
    118189
    119   graph[0].label[LABELUL].x = graph[0].axis[2].fx - PADx;
    120   graph[0].label[LABELUL].y = graph[0].axis[2].fy - PADx;
    121   graph[0].label[LABELUR].x = graph[0].axis[2].fx + graph[0].axis[2].dfx + PADx;
    122   graph[0].label[LABELUR].y = graph[0].axis[2].fy - PADx;
    123   graph[0].label[LABELLL].x = graph[0].axis[0].fx - PADx;
    124   graph[0].label[LABELLL].y = graph[0].axis[0].fy + PADx;
    125   graph[0].label[LABELLR].x = graph[0].axis[0].fx + graph[0].axis[0].dfx + PADx;
    126   graph[0].label[LABELLR].y = graph[0].axis[0].fy + PADx;
    127 
    128190}
  • trunk/Ohana/src/kapa2/src/bDrawFrame.c

    r19837 r27790  
    11# include "Ximage.h"
     2// bDrawLine is a function, not a macro like DrawLine
    23
    34int bDrawFrame (KapaGraphWidget *graph) {
    45 
    5   int i, P, IsLabel, IsMajor, fontsize;
    6   double fx, fy, dfx, dfy, range, major, minor, first, next;
    7   char *fontname;
    8   int weight;
     6  int i, Nticks, P;
     7  double fx, fy, dfx, dfy, lweight;
     8  // Graphic graphic; is not needed
     9  TickMarkData *ticks;
    910  bDrawColor color;
    1011
     12  // don't need graphic, unlink DrawFrame
     13
    1114  /* each axis is drawn independently */
    12   fontname = GetRotFont (&fontsize);
    1315  for (i = 0; i < 4; i++) {
    1416    fx  = graph[0].axis[i].fx;
     
    1618    dfx = graph[0].axis[i].dfx;
    1719    dfy = graph[0].axis[i].dfy;
    18     P = hypot ((double)graph[0].axis[(i+1)%2].dfx, (double)graph[0].axis[(i+1)%2].dfy);
     20    P = hypot (graph[0].axis[(i+1)%2].dfx, graph[0].axis[(i+1)%2].dfy);
    1921
    20     weight = MAX (0, MIN (10, graph[0].axis[i].lweight));
     22    lweight = MAX (0, MIN (10, graph[0].axis[i].lweight));
    2123    color = MAX (0, MIN (15, graph[0].axis[i].color));
    22     bDrawSetStyle (color, weight, 0);
     24
     25    bDrawSetStyle (color, lweight, 0);
     26    // function about sets solor and weight
     27    // bDrawRotTextInit does not exist
    2328
    2429    if (graph[0].axis[i].isaxis) {
     
    2732   
    2833    if (graph[0].axis[i].areticks) {
    29       if (isnan(graph[0].axis[i].min) || isinf(graph[0].axis[i].min)) continue;
    30       if (isnan(graph[0].axis[i].max) || isinf(graph[0].axis[i].max)) continue;
    31 
    32       range = graph[0].axis[i].max - graph[0].axis[i].min;
    33 
    34       AxisTickScale (&graph[0].axis[i], &major, &minor);
    35 
    36       first = minor*((int)(graph[0].axis[i].min/minor));
    37       if ((range > 0) && (first < graph[0].axis[i].min)) {
    38         first += minor;
     34      ticks = CreateAxisTicks (&graph[0].axis[i], &Nticks);
     35      for (i = 0; i < Nticks; i++) {
     36        bDrawTick (&graph[0].axis[i], P, &ticks[i], i);
    3937      }
    40       if ((range < 0) && (first > graph[0].axis[i].min)) {
    41         first -= minor;
    42       }
    43       for (next = first; ((range > 0) && (next <= graph[0].axis[i].max)) || ((range < 0) && (next >= graph[0].axis[i].max));) {
    44         IsMajor = FALSE;
    45         IsMajor |= (fabs((int)(next/major) - (next/major)) < 0.5*(minor/major));
    46         IsMajor |= (fabs ((int)((next + 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    47         IsMajor |= (fabs ((int)((next - 0.5*minor)/major) - (next/major)) < 0.5*(minor/major));
    48         IsLabel = (IsMajor && graph[0].axis[i].islabel);
    49         bDrawTick (fx, fy, dfx, dfy, P, graph[0].axis[i].min, graph[0].axis[i].max, next, IsLabel, IsMajor, i);
    50         if (range > 0)
    51           next += minor;
    52         else
    53           next -= minor;
    54       }
     38      FREE (ticks);
    5539    }
    5640  }
     
    5842}
    5943
    60 void bDrawTick (double fx, double fy, double dfx, double dfy, int P, double min, double max, double value, int IsLabel, int IsMajor, int naxis) {
     44void bDrawTick (Axis *axis, int P, TickMarkData *tick, int naxis) {
    6145 
     46  double x, y, dx, dy;
    6247  int pos, dir, fontsize;
    63   double size, n, x, y, dx, dy;
     48  double size, n, pad;
    6449  char string[64], *fontname;
     50
     51  double fx  = axis->fx;
     52  double fy  = axis->fy;
     53  double dfx = axis->dfx;
     54  double dfy = axis->dfy;
     55
     56  double min = axis->min;
     57  double max = axis->max;
     58
     59  double value = tick->value;
    6560
    6661  pos = size = 0;
    6762
    68   if (IsMajor) {
     63  if (tick->IsMajor) {
    6964    size = MAX (0.02, 7.0 / P);
    7065  } else {
     
    7267  }
    7368 
    74   n = P / sqrt ((double)(dfx*dfx + dfy*dfy));
     69  n = P / hypot(dfx, dfy);
    7570  x = fx + (value-min)*dfx/(max - min);
    7671  y = fy + (value-min)*dfy/(max - min);
    7772
    78   dir = +1;
    79   if ((naxis == 0) || (naxis == 1)) dir *= -1;
     73  dir = ((naxis == 0) || (naxis == 1)) ? -1 : +1;
    8074  dx = dir*size*dfy*n; 
    8175  dy = dir*size*dfx*n;
     
    8377  bDrawLine (x, y, x+dx, y+dy);
    8478
    85   if (IsLabel) {
     79  if (tick->IsLabel) {
     80    int xt, yt;
     81
    8682    fontname = GetRotFont (&fontsize);
    8783
     84    pad = isfinite(axis->ticktextPad) ? axis->ticktextPad*fontsize : 0.8*fontsize + 1.0;
     85   
    8886    /* temporarily assume rectilinear axes */
    89     if (naxis == 0) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 1; }
    90     if (naxis == 2) { dx = 0; dy = -dir*(0.8*fontsize + 1); pos = 7; }
     87    if (naxis == 0) { dx = 0; dy = +pad; pos = 1; }
     88    if (naxis == 2) { dx = 0; dy = -pad; pos = 7; }
    9189
    92     if (naxis == 1) { dy = 0; dx = -(0.8*fontsize + 1); pos = 3; }
    93     if (naxis == 3) { dy = 0; dx = +(0.8*fontsize + 1); pos = 5; }
     90    if (naxis == 1) { dy = 0; dx = -pad; pos = 3; }
     91    if (naxis == 3) { dy = 0; dx = +pad; pos = 5; }
    9492
    95     x = fx + (value-min)*dfx/(max - min) + dx;
    96     y = fy + (value-min)*dfy/(max - min) + dy;
    97     if (fabs(value) < 1e-14) { value = 0.0; }
    98     sprintf (string, "%g", value);
    99     bDrawRotText ((int)x, (int)y, string, pos, 0.0);
     93    xt = fx + (value-min)*dfx/(max - min) + dx;
     94    yt = fy + (value-min)*dfy/(max - min) + dy;
     95    if (fabs(value) < 0.001) { value = 0.0; }
     96    sprintf (string, "%4g", value);
     97    bDrawRotText (xt, yt, string, pos, 0.0);
    10098  }
    10199}
Note: See TracChangeset for help on using the changeset viewer.