Changeset 27790 for trunk/Ohana/src/kapa2
- Timestamp:
- Apr 28, 2010, 10:27:33 AM (16 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 18 edited
- 1 copied
-
. (modified) (1 prop)
-
src/kapa2/doc/mark.issues.txt (modified) (2 diffs)
-
src/kapa2/doc/notes.txt (copied) (copied from branches/eam_branches/Ohana.20100407/src/kapa2/doc/notes.txt )
-
src/kapa2/include/prototypes.h (modified) (7 diffs)
-
src/kapa2/include/structures.h (modified) (2 diffs)
-
src/kapa2/src/CheckPipe.c (modified) (1 diff)
-
src/kapa2/src/DefineSection.c (modified) (3 diffs)
-
src/kapa2/src/DrawFrame.c (modified) (4 diffs)
-
src/kapa2/src/DrawLabels.c (modified) (1 diff)
-
src/kapa2/src/EraseSections.c (modified) (1 diff)
-
src/kapa2/src/Graphs.c (modified) (2 diffs)
-
src/kapa2/src/Layout.c (modified) (1 diff)
-
src/kapa2/src/LoadFrame.c (modified) (6 diffs)
-
src/kapa2/src/PSFrame.c (modified) (4 diffs)
-
src/kapa2/src/Refresh.c (modified) (2 diffs)
-
src/kapa2/src/Sections.c (modified) (4 diffs)
-
src/kapa2/src/SetGraphData.c (modified) (2 diffs)
-
src/kapa2/src/SetGraphSize.c (modified) (5 diffs)
-
src/kapa2/src/bDrawFrame.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana
-
Property svn:mergeinfo
set to
/branches/eam_branches/Ohana.20100407 merged eligible
-
Property svn:mergeinfo
set to
-
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...) 5 o need consistency of graph defaults : axis, tick, labels should come from kapa 6 o clear should erase current plot 7 1 8 -> The "plot" command needs to be fixed so that boundaries of contours do 2 9 not cause it to draw excessive amounts of lines connecting unrelated 3 10 contours. 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?) 7 12 8 13 -> DVO does not plot the end-points of histograms properly (e.g., the … … 13 18 relay output to the file in the same order. Also, until DVO is closed, the 14 19 output does not appear in the file. 20 (fixed both issues) 15 21 22 -> DVO is not consistently placing the x/y axis labels, especially in 23 user-defined sections of the plot window. 24 (fixed) 25 * box -labelpad -labelpad[x,y] +labelpad[x,y] - 26 27 28 --- 29 30 31 1)You wanted me to remind you to update ~ipp-svn; this was so I could have 32 the latest version of DVO on-hand 33 34 2)The plotting of axis labels remains inconsistent; depending on section 35 dimensions and the presence/absence of tick-marks, labels will change 36 their distance from their corresponding axis. This results in labels 37 falling off the screen or overlapping with other plot sections 38 39 3)Plot section locations in the plot window shift if labels/tick-marks are 40 present or absent 41 42 4)It would be useful to have an option for the box or section command that 43 causes the background to be opaque. This will allow plots to have insets. 44 45 5)It would be useful to have a rectangle plotting command in order to 46 shade out regions on plots 47 48 6)The limits command combined with box will sometimes produce tick-marks 49 with only the zero-point labeled, making the axes difficult to interpret 50 51 7)Text is printed to a file at different times when using either the echo 52 or fprintf commands alongside the output command. Sometimes output is 53 printed to the file immediately, while other times it is printed only when 54 the file is closed for output. 55 56 8)The use of ^C as an interrupt does not always work when a macro is doing 57 for loops. 58 59 9)It would be useful for DVO to echo which line of a macro contains an 60 error, or at which line it was forced to stop. This would help debugging a 61 lot. 62 63 10)The cgrid could use an option to print RA/DEC tick-mark labels so that 64 image plots would be more informative -
trunk/Ohana/src/kapa2/include/prototypes.h
r27530 r27790 26 26 27 27 /* X drawing utilities */ 28 voidDrawFrame PROTO((KapaGraphWidget *graph));28 int DrawFrame PROTO((KapaGraphWidget *graph)); 29 29 int DrawObjects PROTO((KapaGraphWidget *graph)); 30 30 void DrawLabels PROTO((KapaGraphWidget *graph)); … … 39 39 void DrawXErrors PROTO((KapaGraphWidget *graph, Gobjects *objects)); 40 40 void 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));41 void DrawTick PROTO((Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis)); 42 42 void AxisTickScale PROTO((Axis *axis, double *major, double *minor)); 43 TickMarkData *CreateAxisTicks PROTO((Axis *axis, int *nticks)); 43 44 44 45 /* EventLoop */ … … 47 48 int Reconfig PROTO((XEvent *event)); 48 49 void Refresh PROTO((void)); 50 void DrawSectionBG PROTO((Graphic *graphic, Section *section)); 49 51 50 52 /* CheckPipe */ … … 61 63 int SetSection PROTO((int sock)); 62 64 int ListSection PROTO((int sock)); 65 int SetSectionBG PROTO((int sock)); 63 66 int MoveSection PROTO((int sock)); 64 67 int DefineSection PROTO((int sock)); … … 84 87 void FreeSection PROTO((Section *section)); 85 88 void FreeSections PROTO((void)); 86 Section *AddSection PROTO((char *name, float x, float y, float dx, float dy ));89 Section *AddSection PROTO((char *name, float x, float y, float dx, float dy, int bg)); 87 90 int DelSection PROTO((char *name)); 88 91 int GetSectionByName PROTO((char *name)); … … 112 115 void PSXErrors PROTO((KapaGraphWidget *graph, Gobjects *objects, FILE *f)); 113 116 void 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));117 void PSTick PROTO((Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis, FILE *f)); 115 118 void ClipLinePS PROTO((double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0, FILE *f)); 116 119 int PSimage PROTO((KapaImageWidget *image, FILE *f)); … … 131 134 void bDrawXErrors PROTO((KapaGraphWidget *graph, Gobjects *object)); 132 135 void 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));136 void bDrawTick PROTO((Axis *axis, int P, TickMarkData *tick, int naxis)); 134 137 void bDrawClipLine PROTO((double x0, double y0, double x1, double y1, double X0, double Y1, double X1, double Y0)); 135 138 bDrawBuffer *bDrawIt PROTO((void)); -
trunk/Ohana/src/kapa2/include/structures.h
r25757 r27790 137 137 double min, max; 138 138 char isaxis, areticks, islabel, islog; 139 double pad, labelPad, ticktextPad; 139 140 double fx, dfx, fy, dfy; /* axis location on graphic */ 140 141 double lweight; 141 142 int color; 142 143 } Axis; 144 145 // structure to describe the ticks for an axis 146 typedef struct { 147 double value; 148 int IsMajor; 149 int IsLabel; 150 } TickMarkData; 143 151 144 152 // a single graph in the display window … … 210 218 float x, y; 211 219 float dx, dy; 220 int bg; 212 221 char *name; 213 222 } Section; -
trunk/Ohana/src/kapa2/src/CheckPipe.c
r25757 r27790 221 221 } 222 222 223 if (!strcmp (word, "BSEC")) { 224 status = SetSectionBG (sock); 225 KiiSendCommand (sock, 4, "DONE"); 226 FINISHED (TRUE); 227 } 228 223 229 if (!strcmp (word, "FONT")) { 224 230 status = SetFont (sock); -
trunk/Ohana/src/kapa2/src/DefineSection.c
r21153 r27790 4 4 int DefineSection (int sock) { 5 5 6 int N, MoveSection ;6 int N, MoveSection, bg; 7 7 char name[128]; 8 8 double x, y, dx, dy; 9 9 Section *section; 10 10 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); 12 12 13 13 MoveSection = FALSE; … … 15 15 N = GetSectionByName (name); 16 16 if (N < 0) { 17 section = AddSection (name, x, y, dx, dy );17 section = AddSection (name, x, y, dx, dy, bg); 18 18 MoveSection = TRUE; 19 19 } else { … … 30 30 section[0].dx = dx; 31 31 section[0].dy = dy; 32 section[0].bg = bg; 32 33 } 33 34 -
trunk/Ohana/src/kapa2/src/DrawFrame.c
r27603 r27790 1 1 # include "Ximage.h" 2 # define MIN_RANGE 1e-103 2 # define DrawLine(X,Y,DX,DY) (XDrawLine (graphic->display, graphic->window, graphic->gc, (int)(X), (int)(Y), (int)(X+DX), (int)(Y+DY))) 4 3 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; 4 int 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; 11 11 12 12 graphic = GetGraphic(); 13 13 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. */ 16 15 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; 19 18 dfx = graph[0].axis[i].dfx; 20 19 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); 22 21 23 22 lweight = MAX (0, MIN (10, graph[0].axis[i].lweight)); 23 color = MAX (0, MIN (15, graph[0].axis[i].color)); 24 24 25 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); 32 28 33 29 if (graph[0].axis[i].isaxis) { 34 30 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 // }42 31 } 43 32 44 33 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); 53 37 } 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); 76 39 } 77 40 } 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 44 void 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; 86 49 char string[64], *fontname; 87 50 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) { 89 64 size = MAX (0.02, 7.0 / P); 90 65 } else { … … 92 67 } 93 68 94 n = P / sqrt ((double)(dfx*dfx + dfy*dfy));69 n = P / hypot(dfx, dfy); 95 70 x = fx + (value-min)*dfx/(max - min); 96 71 y = fy + (value-min)*dfy/(max - min); 97 72 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; 100 80 dx = dir*size*dfy*n; 101 81 dy = dir*size*dfx*n; … … 103 83 DrawLine (x, y, dx, dy); 104 84 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 112 88 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; 114 92 115 93 /* 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; 124 102 if (fabs(value/(max-min)) < 0.001) { value = 0.0; } 125 103 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 131 109 132 110 void AxisTickScale (Axis *axis, double *major, double *minor) { … … 192 170 } 193 171 } 172 173 TickMarkData *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 34 34 switch (i) { 35 35 case 0: pos = 7; break; 36 case 2: pos = 1; break; 36 37 case 1: pos = 1; angle = -90; break; 37 case 2: pos = 1; break;38 38 case 3: pos = 1; angle = 90; break; 39 39 case 4: pos = 2; break; -
trunk/Ohana/src/kapa2/src/EraseSections.c
r21153 r27790 8 8 9 9 FreeSections (); 10 AddSection ("default", 0.0, 0.0, 1.0, 1.0 );10 AddSection ("default", 0.0, 0.0, 1.0, 1.0, -1); 11 11 12 12 if (USE_XWINDOW) XClearWindow (graphic->display, graphic->window); -
trunk/Ohana/src/kapa2/src/Graphs.c
r27530 r27790 18 18 graph[0].axis[i].lweight = 0.0; 19 19 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; 20 23 } 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 21 36 for (i = 0; i < 8; i++) { 22 37 strcpy (graph[0].label[i].text, ""); … … 37 52 graph[0].data.size = 1.0; // point size of 1.0 38 53 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"); 41 68 42 69 graph[0].Nobjects = 0; -
trunk/Ohana/src/kapa2/src/Layout.c
r14737 r27790 43 43 44 44 /* 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); 46 46 } -
trunk/Ohana/src/kapa2/src/LoadFrame.c
r21153 r27790 3 3 int LoadFrame (int sock) { 4 4 5 int i, color; 6 char Axis[16], Labels[16], Ticks[16]; 7 double lweight; 5 int i; 8 6 Section *section; 9 7 KapaGraphWidget *graph; … … 16 14 graph = section->graph; 17 15 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); 21 17 22 18 graph[0].axis[3].min = graph[0].axis[1].min; … … 25 21 graph[0].axis[2].max = graph[0].axis[0].max; 26 22 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)); 29 25 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; 31 35 32 36 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; 35 39 36 switch (Axis[i]) { 40 graph[0].axis[i].ticktextPad = graph[0].data.ticktextPad; 41 42 switch (graph[0].data.axis[i]) { 37 43 case '0': 38 44 graph[0].axis[i].isaxis = FALSE; … … 45 51 break; 46 52 } 47 switch ( Ticks[i]) {53 switch (graph[0].data.ticks[i]) { 48 54 case '0': 49 55 graph[0].axis[i].areticks = FALSE; … … 56 62 break; 57 63 } 58 switch ( Labels[i]) {64 switch (graph[0].data.labels[i]) { 59 65 case '0': 60 66 graph[0].axis[i].islabel = FALSE; … … 70 76 71 77 SetSectionSizes (section); 72 if (USE_XWINDOW) DrawFrame (graph); 73 FlushDisplay (); 78 Refresh(); 79 // if (USE_XWINDOW) DrawFrame (graph); 80 // FlushDisplay (); 74 81 75 82 /* XXX why did I do this??? */ -
trunk/Ohana/src/kapa2/src/PSFrame.c
r19834 r27790 4 4 int PSFrame (KapaGraphWidget *graph, FILE *f) { 5 5 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; 9 8 Graphic *graphic; 10 float weight;9 TickMarkData *ticks; 11 10 bDrawColor color; 12 11 … … 14 13 15 14 /* each axis is drawn independently */ 16 fontname = GetRotFont (&fontsize);17 15 fprintf (f, "1 setlinewidth\n"); 18 16 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; 21 19 dfx = graph[0].axis[i].dfx; 22 20 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); 24 22 25 weight = MAX (0, MIN (10, graph[0].axis[i].lweight));23 lweight = MAX (0, MIN (10, graph[0].axis[i].lweight)); 26 24 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); 28 27 fprintf (f, "%s setrgbcolor\n", KapaColorRGBString(color)); 28 // no need to init rot font 29 29 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 } 31 33 32 34 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); 42 38 } 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 } 59 41 } 60 42 return (TRUE); 61 43 } 62 44 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) {45 void PSTick (Graphic *graphic, Axis *axis, int P, TickMarkData *tick, int naxis, FILE *f) { 64 46 47 double x, y, dx, dy; 65 48 int pos, dir, fontsize; 66 double size, n, x, y, dx, dy;49 double size, n, pad; 67 50 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; 68 61 69 62 pos = size = 0; 70 63 71 if ( IsMajor) {64 if (tick->IsMajor) { 72 65 size = MAX (0.02, 7.0 / P); 73 66 } else { … … 75 68 } 76 69 77 n = P / sqrt ((double)(dfx*dfx + dfy*dfy));70 n = P / hypot(dfx, dfy); 78 71 x = fx + (value-min)*dfx/(max - min); 79 72 y = fy + (value-min)*dfy/(max - min); 80 73 81 dir = -1; 82 if ((naxis == 0) || (naxis == 1)) dir *= -1; 74 dir = ((naxis == 0) || (naxis == 1)) ? -1 : +1; 83 75 dx = dir*size*dfy*n; 84 76 dy = dir*size*dfx*n; … … 86 78 DrawLine (x, y, dx, dy); 87 79 88 if (IsLabel) { 80 if (tick->IsLabel) { 81 int xt, yt; 82 89 83 fontname = GetRotFont (&fontsize); 90 84 85 pad = isfinite(axis->ticktextPad) ? axis->ticktextPad*fontsize : 0.8*fontsize + 1.0; 86 91 87 /* 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; } 94 90 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; } 97 93 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); 103 99 } 104 100 } -
trunk/Ohana/src/kapa2/src/Refresh.c
r21153 r27790 21 21 for (i = 0; i < Nsection; i++) { 22 22 section = GetSectionByNumber (i); 23 DrawSectionBG (graphic, section); 23 24 DrawImage (section->image); 24 25 DrawGraph (section->graph); … … 28 29 } 29 30 31 void 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 16 16 section[0].dx = 0; 17 17 section[0].dy = 0; 18 section[0].bg = -1; 18 19 19 20 section[0].name = NULL; … … 42 43 } 43 44 44 Section *AddSection (char *name, float x, float y, float dx, float dy ) {45 Section *AddSection (char *name, float x, float y, float dx, float dy, int bg) { 45 46 46 47 int N; … … 61 62 sections[N][0].dx = dx; 62 63 sections[N][0].dy = dy; 64 sections[N][0].bg = bg; 63 65 ActiveSection = N; 64 66 return (sections[N]); … … 155 157 } 156 158 159 int 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 157 177 // return TRUE even for nonsense cases to avoid quitting kapa 158 178 int MoveSection (int sock) { -
trunk/Ohana/src/kapa2/src/SetGraphData.c
r21153 r27790 18 18 graph = section->graph; 19 19 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); 30 21 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; 36 29 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; 54 34 55 35 xmin = graph[0].data.xmin; … … 90 70 graph = section->graph; 91 71 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); 117 73 118 74 return (TRUE); -
trunk/Ohana/src/kapa2/src/SetGraphSize.c
r16011 r27790 6 6 void SetGraphSize (Section *section) { 7 7 8 int fontsize, bump, Nc; 8 int i, Nticks; 9 int fontsize, Nc; 9 10 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; 12 15 double X0, Y0, dX, dY; 13 16 char string[64], *fontname; 14 17 KapaGraphWidget *graph; 15 18 Graphic *graphic; 19 TickMarkData *ticks; 16 20 17 21 if (section == NULL) return; … … 22 26 fontname = GetRotFont (&fontsize); 23 27 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; 28 30 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 35 114 /* 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; 40 119 41 120 // if we are tied to an image, make mods as needed … … 47 126 switch (section->image->location) { 48 127 case 1: 49 Y0 = graphic[0].dy * section[0].y + 2*PAD1 + WdY + 2; // tied to image in Y128 Y0 = graphic[0].dy * section[0].y + 2*PAD1 + WdY + 2; // tied to image in Y 50 129 dY = graphic[0].dy * section[0].dy - 5*PAD1 - WdY - COLORPAD + 1; 51 130 break; 52 131 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; 54 133 break; 55 134 case 2: … … 58 137 break; 59 138 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; 61 140 break; 62 141 } … … 84 163 graph[0].axis[3].dfy = -dY; 85 164 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; 88 172 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; 94 175 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; 103 179 104 180 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; 112 182 113 183 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; 116 185 186 // fprintf (stderr, "section %s, %f,%f : %f,%f\n", section->name, X0, Y0, dX, dY); 187 117 188 /* these are wrong and have to be adjusted to sit in the corners */ 118 189 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 128 190 } -
trunk/Ohana/src/kapa2/src/bDrawFrame.c
r19837 r27790 1 1 # include "Ximage.h" 2 // bDrawLine is a function, not a macro like DrawLine 2 3 3 4 int bDrawFrame (KapaGraphWidget *graph) { 4 5 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; 9 10 bDrawColor color; 10 11 12 // don't need graphic, unlink DrawFrame 13 11 14 /* each axis is drawn independently */ 12 fontname = GetRotFont (&fontsize);13 15 for (i = 0; i < 4; i++) { 14 16 fx = graph[0].axis[i].fx; … … 16 18 dfx = graph[0].axis[i].dfx; 17 19 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); 19 21 20 weight = MAX (0, MIN (10, graph[0].axis[i].lweight));22 lweight = MAX (0, MIN (10, graph[0].axis[i].lweight)); 21 23 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 23 28 24 29 if (graph[0].axis[i].isaxis) { … … 27 32 28 33 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); 39 37 } 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); 55 39 } 56 40 } … … 58 42 } 59 43 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) {44 void bDrawTick (Axis *axis, int P, TickMarkData *tick, int naxis) { 61 45 46 double x, y, dx, dy; 62 47 int pos, dir, fontsize; 63 double size, n, x, y, dx, dy;48 double size, n, pad; 64 49 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; 65 60 66 61 pos = size = 0; 67 62 68 if ( IsMajor) {63 if (tick->IsMajor) { 69 64 size = MAX (0.02, 7.0 / P); 70 65 } else { … … 72 67 } 73 68 74 n = P / sqrt ((double)(dfx*dfx + dfy*dfy));69 n = P / hypot(dfx, dfy); 75 70 x = fx + (value-min)*dfx/(max - min); 76 71 y = fy + (value-min)*dfy/(max - min); 77 72 78 dir = +1; 79 if ((naxis == 0) || (naxis == 1)) dir *= -1; 73 dir = ((naxis == 0) || (naxis == 1)) ? -1 : +1; 80 74 dx = dir*size*dfy*n; 81 75 dy = dir*size*dfx*n; … … 83 77 bDrawLine (x, y, x+dx, y+dy); 84 78 85 if (IsLabel) { 79 if (tick->IsLabel) { 80 int xt, yt; 81 86 82 fontname = GetRotFont (&fontsize); 87 83 84 pad = isfinite(axis->ticktextPad) ? axis->ticktextPad*fontsize : 0.8*fontsize + 1.0; 85 88 86 /* 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; } 91 89 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; } 94 92 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); 100 98 } 101 99 }
Note:
See TracChangeset
for help on using the changeset viewer.
