1 /*
2 * Copyright (C) 1992 Board of Regents of the University of Wisconsin
3 * on behalf of the Department of Electrical Engineering and Computer
4 * Science, University of Wisconsin-Milwaukee, Milwaukee, WI 53201.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * a copy of which is included here in file "GNU_GENERAL"
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 *
21 * The programs in this directory were developed by software engineering
22 * teams as part of the course "Introduction to Software Engineering"
23 * under the supervision of Professor G. Davida.
24 * This is a modification of a program written or modified by
25 * others. The original copyrights, as per GNU General Public License,
26 * may still be applicable. The UWM copyright is applicable only
27 * the those parts generated at UWM.
28 *
29 * Please send all changes, enhancements, and other comments about this
30 * software to
31 * soft-eng@cs.uwm.edu
32 *
33 * No Warranty, expressed or implied, comes with this software.
34 * This software is intended to be used by not-for-profit
35 * organizations or by individuals for personal HOME use.
36 * This software, or any of its parts, may not be used by for-profit
37 * organization, regardless of application or intended product or
38 * customer, without the permission of the Board of Regents of the
39 * University of Wisconsin.
40 *
41 * Contact: soft-eng@cs.uwm.edu
42 * or
43 *
44 * Software Engineering Coordinator
45 * Computer Science
46 * Department of EECS
47 * University of Wisconsin - Milwaukee
48 * Milwaukee, WI 53201
49 * 414-229-4677
50 *
51 * HISTORY,CLAIMS and CONTRIBUTIONS
52 */
53 /*
54 ******************************************************************************
55 * This procedure will display the line graph given the values provided by *
56 * the user. It evenly spaces out the columns depending on the number of *
57 * X-Values which are used.
58 * Dan Gruber - October 1991 *
59 * Modified 5/94 by Dan Coppersmith to improve user friendliness of
60 * error messages.
61 ****************************************************************************
62 */
63 #include <config.h>
64
65 #ifdef HAVE_X11_X_H /* this code for now is X specific */
66
67 #include <math.h>
68 #include <curses.h>
69 #include <X11/Xlib.h>
70 #include <X11/Xutil.h>
71 #include "plot.h"
72 #include "graphic_gvar.h"
73 #include "sc.h"
74 #include "scXstuff.h"
75 #define TITLE "XSPREAD-Grapher (Line Plot)"
76 #define PIX_SEP 3
77
78 #ifndef irint
79 #define irint(x) floor((x)+0.5)
80 #endif
81
82 /*
83 * This structure forms the WM_HINTS property of the window,
84 * letting the window manager know how to handle this window.
85 * See Section 9.1 of the Xlib manual.
86 */
87
88 XWMHints XWMH = {
89 (InputHint|StateHint), /* flags */
90 False, /* input */
91 NormalState, /* initial_state */
92 0, /* icon pixmap */
93 0, /* icon window */
94 0, 0, /* icon location */
95 0, /* icon mask */
96 0, /* Window group */
97 };
98
99
100 void
plot_line()101 plot_line()
102 { double max_y, min_y;
103 double Y_Range;
104 double y_power /*, x_power */;
105 double grid_w;
106
107 int i, j /*,k*/, len;
108 int first_y_datum=1;
109 int grid_l_x, grid_l_y, grid_h;
110 int /* font_w, */ text_w;
111 int legend_n;
112 int x, y, x1, y1;
113 int looping = 1; /* true if we shouldn't exit yet */
114 int draw = 0; /* true if we should paint the window */
115 char format; /* graph format specifier, (L)ine, (S)ymbol, (B)oth */
116 int first_point; /* true when getting coords for 1st point in curve */
117 struct ent *p;
118 struct ent *yent; /* table entries y values */
119 int cells=0;
120 int items=0;
121 int number_of_items=0;
122 int width; /* used to calculate the Labelsize */
123 int labelsize; /* The size of the Label to be drawn */
124
125 char str[100];
126 /* register int c; */
127
128 int argc = 0;
129 char **argv = 0;
130
131 /*---- Colors and fonts added by Rama Devi ---------*/
132 Colormap cmap;
133 XColor exactBlack, exactOrange;
134 XColor exactGreen, exactGreenYellow, exactOrchid;
135 XColor exactYellow, exactAquamarine, exactGoldenrod;
136
137 XColor Black, Orange;
138 XColor Green, GreenYellow, Orchid, Yellow, Aquamarine, Goldenrod;
139
140 extern XFontStruct *curfont; /* Font descriptor struct for current font */
141 extern Font curfontid; /* resource id of current font */
142 extern int curfontwidth,
143 curfontheight; /* pixel dimensions of current font */
144
145 /* check that we have enough valid x values. While we are looping,
146 * determine the minimum and maximum x values, in case we need them
147 */
148
149 for (i=graphic_range[0].r1; i <= graphic_range[0].r2; i++) {
150 p = lookat( i, graphic_range[0].c);
151 if (!(p->label)) continue;
152 cells++;
153 } /* for i */
154
155 if (cells < 2) {
156 fprintf(stderr,"\007");
157 if (graphic_range[0].r2 - graphic_range[0].r1 > 1)
158 message("x values must be strings");
159 else message("Not enough valid X values");
160 return;
161 }
162
163 number_of_items = cells;
164
165 /*
166 * The plotting job now
167 */
168
169 /*
170 * Decide the scale for x and y axes
171 */
172
173 /* calculate y limits automatically or manually */
174 if (g_auto_man[1] == 'M'){
175 max_y = graphic_scale[1][1];
176 min_y = graphic_scale[1][0];
177 } else {
178 first_y_datum = 1;
179 for (j = 1; j < GRAPHRANGES; j++) {
180
181 if (*(graphic_range[j].col) == '\0') continue;
182
183 for (i=graphic_range[j].r1; i <= graphic_range[j].r2; i++) {
184 p = lookat(i, graphic_range[j].c);
185 if ( !(p->flags & is_valid)) continue; /* ignore invalid */
186 if (first_y_datum) {
187 max_y = p->v;
188 min_y = p->v;
189 first_y_datum = 0;
190 } else {
191 max_y = Max(max_y, p->v);
192 min_y = Min(min_y, p->v);
193 }
194 }
195 }
196 }
197 /* protection for the case max == min */
198 if (min_y == max_y) {
199 max_y = 1.01 * max_y;
200 min_y = 0.99 * min_y;
201 }
202
203 y_power = - floor(log10((max_y - min_y)));
204 y_power = pow10(y_power);
205
206 min_y = floor(min_y * y_power) / y_power;
207 max_y = ceil(max_y * y_power) / y_power;
208 Y_Range = max_y - min_y;
209
210 /*
211 * Open a new display window
212 */
213
214 /*
215 * Select colors for the border, the window background, and the
216 * foreground.
217 */
218
219
220 /*---- Colors fonts added by Rama Devi --*/
221 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
222 if ((XAllocNamedColor(dpy, cmap, "Black", &exactBlack,
223 &Black) != 0) && (XAllocNamedColor (dpy, cmap,
224 "Orange", &exactOrange, &Orange) != 0))
225 {
226 bd = Orange.pixel;
227 bg = Black.pixel;
228 fg = Orange.pixel;
229 }
230 else
231 {
232 bd = WhitePixel(dpy, DefaultScreen(dpy));
233 bg = BlackPixel(dpy, DefaultScreen(dpy));
234 fg = WhitePixel(dpy, DefaultScreen(dpy));
235 }
236
237 if (userfont == NULL)
238 curfont = XLoadQueryFont(dpy, SC_FONT);
239 else
240 curfont = XLoadQueryFont(dpy, userfont);
241 if (curfont == NULL)
242 {
243 fprintf(stderr, "%s: Display %s doesn't know font \"%s\" \n",
244 progname, DisplayString(dpy), userfont == NULL ? SC_FONT : userfont);
245 exit(1);
246 }
247 /* initialize the font-related globals */
248 /* usefont(curfont); */
249 curfontid = curfont->fid;
250 curfontheight = curfont->max_bounds.ascent + curfont->max_bounds.descent;
251 curfontwidth = curfont->max_bounds.width;
252
253 /*
254 * Set the border width of the window, and the gap between the text
255 * and the edge of the window, "pad".
256 */
257
258 pad = BORDER;
259 bw = 1;
260
261 /*
262 * Deal with providing the window with an initial position & size.
263 * Fill out the XSizeHints struct to inform the window manager.
264 */
265
266 xsh.width = XTextWidth(curfont, TITLE, 80 + pad * 2);
267
268 xsh.flags = (PPosition | PSize);
269 xsh.height = WIN_H;
270 xsh.width = WIN_W;
271 xsh.x = (DisplayWidth(dpy, DefaultScreen(dpy)) - xsh.width) / 2;
272 xsh.y = (DisplayHeight(dpy, DefaultScreen(dpy)) - xsh.height) / 2;
273
274 /*
275 * Create the Window with the information in the XSizeHints, the
276 * border width, and the border & background pixels.
277 */
278
279 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
280 xsh.x, xsh.y, xsh.width, xsh.height,
281 /*--- bw, bd, bg); ---*/
282 bw, fg, bg);
283
284 /*
285 * Set the standard properties for the window managers.
286 */
287
288 XSetStandardProperties(dpy, win, TITLE, TITLE,
289 None, argv, argc, &xsh);
290 XSetWMHints(dpy, win, &XWMH);
291
292 /*
293 * Ensure that the window's colormap field points to the default
294 * colormap, so that the window manager knows the correct colormap to
295 * use for the window. Also, set the window's Bit Gravity to reduce
296 * Expose events.
297 */
298
299 xswa.colormap = DefaultColormap(dpy, DefaultScreen(dpy));
300 xswa.bit_gravity = CenterGravity;
301 XChangeWindowAttributes(dpy, win, (CWColormap | CWBitGravity), &xswa);
302
303
304 /*--- The following statement is added by Rama Devi ---*/
305 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
306 if ((XAllocNamedColor (dpy, cmap, "Orange", &exactOrange, &Orange) != 0))
307 {
308 maingcreversed = XCreateGC(dpy, win, 0,0);
309 XSetFont(dpy, maingcreversed, curfontid);
310 XSetForeground (dpy, maingcreversed, Orange.pixel);
311 XSetBackground (dpy, maingcreversed, Black.pixel);
312 }
313 else
314 {
315 maingcreversed = XCreateGC(dpy, win, 0,0);
316 XSetFont(dpy, maingcreversed, curfontid);
317 XSetForeground (dpy, maingcreversed, fg);
318 XSetBackground (dpy, maingcreversed, bg);
319 } /*---*/
320
321 /*
322 * Map the window to make it visible.
323 */
324
325 XMapWindow(dpy, win);
326
327 /*
328 * Find out the dimension of the window.
329 */
330
331 if (XGetWindowAttributes(dpy, win, &xwa) == 0){
332 fprintf(stderr,"plot_XY: Can't access attributes for graph window\n");
333 exit(1);
334 }
335
336 XClearWindow(dpy, win);
337 XSelectInput(dpy,win, ButtonPressMask|KeyPressMask|ExposureMask);
338
339 while(looping)
340 {
341
342 XEvent event;
343
344 XNextEvent(dpy,&event);
345 switch (event.type){
346 case KeyPress:
347 case ButtonPress: looping = 0;
348 break;
349 case Expose: draw = 1;
350 }
351
352
353 /* if not drawing, go back and get another event */
354 if (!draw) continue;
355
356 /*
357 * Draw the coordinate box
358 */
359
360 XDrawRectangle(dpy, win, maingcreversed, RECT_X, RECT_Y, RECT_W, RECT_H);
361
362 /* grid_l_y and grid_l_x are the length of the grid lines.
363 * Only tick marks are drawn when the value is '8'.
364 */
365
366 if (graphic_grid == 'H') { /* horizontal grid */
367 grid_l_x = RECT_W;
368 grid_l_y = 8;
369 }
370 else if (graphic_grid == 'V') { /* vertical grid */
371 grid_l_x = 8;
372 grid_l_y = RECT_H;
373 }
374 else if (graphic_grid == 'B') { /* both direction grid */
375 grid_l_x = RECT_W;
376 grid_l_y = RECT_H;
377 }
378 else {
379 grid_l_x = 8; /* no grid */
380 grid_l_y = 8;
381 }
382
383
384 grid_w = RECT_W / (double)(number_of_items + 1); /* grid seperation */
385 grid_h = RECT_H / 10;
386
387 /*
388 * Draw grids along with the labels on the Y-Axis
389 */
390
391 for (i = 0; i < 11; i++) {
392 XDrawLine(dpy, win, maingcreversed,
393 RECT_X, RECT_Y + i * grid_h,
394 RECT_X + grid_l_x, RECT_Y + i * grid_h);
395 XDrawLine(dpy, win, maingcreversed,
396 RECT_X + RECT_W, RECT_Y + i * grid_h,
397 RECT_X + RECT_W - grid_l_x, RECT_Y + i * grid_h);
398
399 sprintf(str,"%.1f",(max_y - Y_Range*i/10));
400 len = strlen(str);
401 text_w = XTextWidth(curfont,str,len+2);
402 XDrawImageString(dpy,win,maingcreversed,
403 RECT_X - text_w,
404 RECT_Y + i*grid_h + curfontheight/3,
405 str,len);
406
407 } /*end for loop*/
408
409
410 for (i = 1; i < (number_of_items + 1); i++) {
411 x = RECT_X + i * grid_w;
412 XDrawLine(dpy, win, maingcreversed,
413 x, RECT_Y,
414 x, RECT_Y + grid_l_y);
415 XDrawLine(dpy, win, maingcreversed,
416 x, RECT_Y + RECT_H,
417 x, RECT_Y + RECT_H - grid_l_y);
418 }
419
420 /*
421 * Draw titles
422 */
423
424 /* first graph title */
425 len = strlen(graphic_title[0]);
426 text_w= XTextWidth(curfont, graphic_title[0], len);
427 XDrawImageString(dpy, win, maingcreversed, (WIN_W - text_w)/2, RECT_Y/3,
428 graphic_title[0], len);
429
430 /* second graph title */
431 len = strlen(graphic_title[1]);
432 text_w= XTextWidth(curfont, graphic_title[1], len);
433 XDrawImageString(dpy, win, maingcreversed, (WIN_W - text_w)/2, RECT_Y*2/3,
434 graphic_title[1], len);
435
436 /* x-axis title */
437 len = strlen(graphic_title[2]);
438 text_w= XTextWidth(curfont, graphic_title[2], len);
439 XDrawImageString(dpy, win, maingcreversed,
440 (WIN_W - text_w)/2, RECT_H + RECT_Y * 3/2,
441 graphic_title[2], len);
442
443 /* y-axis title */
444 len = strlen(graphic_title[3]);
445 text_w=XTextWidth(curfont,graphic_title[3],len);
446 if ((RECT_X-text_w) < 0)
447 x = curfontwidth;
448 else
449 x = RECT_X-text_w;
450 XDrawImageString(dpy, win, maingcreversed,
451 x, RECT_Y - curfontheight,
452 graphic_title[3],len);
453
454
455 /*
456 * Draw Labels on the X-Axis
457 */
458
459 width = (RECT_W - (PIX_SEP * (number_of_items + 1)))/number_of_items;
460 labelsize = irint(floor(width/(double)curfontwidth)-1);
461 y = RECT_Y + RECT_H + curfontheight;
462 items = 0;
463 for (i=graphic_range[0].r1; i<=graphic_range[0].r2; i++)
464 {
465 p = lookat(i,graphic_range[0].c);
466 if (!(p->label)) continue;
467
468 x1 = RECT_X + ((items+1)*(grid_w));
469 items++;
470 strncpy(str, p->label, labelsize);
471 str[labelsize] = '\0';
472 len = strlen(str);
473 text_w = XTextWidth(curfont, str, len);
474
475 x = x1-(text_w / 2);
476 XDrawImageString(dpy,win,maingcreversed,
477 x,y,str,len);
478 }
479
480
481 /*
482 * Draw legends
483 */
484
485 legend_n = 0;
486 for (i = 0; i < GRAPHLEGENDS; i++) {
487
488 /* ---- the following switch statement added by Rama Devi ----*/
489 switch (i+1) {
490 case 1 :
491 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
492 if ((XAllocNamedColor (dpy, cmap, "Green", &exactGreen, &Green) != 0))
493 {
494 XSetForeground (dpy, maingcreversed, Green.pixel);
495 XSetBackground (dpy, maingcreversed, Black.pixel);
496 }
497 else
498 {
499 XSetForeground (dpy, maingcreversed, fg);
500 XSetBackground (dpy, maingcreversed, bg);
501 }
502 break;
503
504 case 2 :
505 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
506 if ((XAllocNamedColor (dpy, cmap, "Orchid", &exactOrchid, &Orchid) != 0))
507 {
508 XSetForeground (dpy, maingcreversed, Orchid.pixel);
509 }
510 else
511 {
512 XSetForeground (dpy, maingcreversed, fg);
513 }
514 break;
515
516 case 3 :
517 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
518 if ((XAllocNamedColor (dpy, cmap, "GreenYellow", &exactGreenYellow, &GreenYellow) != 0))
519 {
520 XSetForeground (dpy, maingcreversed, GreenYellow.pixel);
521 }
522 else
523 {
524 XSetForeground (dpy, maingcreversed, fg);
525 }
526 break;
527
528 case 4 :
529 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
530 if ((XAllocNamedColor (dpy, cmap, "Goldenrod", &exactGoldenrod, &Goldenrod) != 0))
531 {
532 XSetForeground (dpy, maingcreversed, Goldenrod.pixel);
533 }
534 else
535 {
536 XSetForeground (dpy, maingcreversed, fg);
537 }
538 break;
539
540 case 5 :
541 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
542
543 if ((XAllocNamedColor (dpy, cmap, "Aquamarine", &exactAquamarine, &Aquamarine) != 0))
544 {
545 XSetForeground (dpy, maingcreversed, Aquamarine.pixel);
546 }
547 else
548 {
549 XSetForeground (dpy, maingcreversed, fg);
550 }
551 break;
552 case 6 :
553 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
554 if ((XAllocNamedColor (dpy, cmap, "Yellow", &exactYellow, &Yellow) != 0))
555 {
556 XSetForeground (dpy, maingcreversed, Yellow.pixel);
557 }
558 else
559 {
560 XSetForeground (dpy, maingcreversed, fg);
561
562 }
563 break; } /* --switch --- */
564
565 if ((*(graphic_range[i + 1].col) == '\0') || (curves_n < 1) ||
566 (graphic_legend[i][0] == '\0'))
567 continue;
568
569 len = strlen(graphic_legend[i]);
570 text_w = XTextWidth(curfont, graphic_legend[i], len);
571 if (curves_n == 1) {
572 /* Draw the legend symble */
573 if (graphic_format[i] == 'L') {
574 XDrawLine(dpy, win, maingcreversed,
575 RECT_X +(RECT_W - text_w) / 2 - 15,
576 RECT_Y * 7 / 4 +RECT_H, RECT_X +(RECT_W - text_w) / 2 - 5,
577 RECT_Y * 7 / 4 +RECT_H);
578 }
579 else if ((graphic_format[i] == 'S') || (graphic_format[i] == 'B')) {
580 x = RECT_X + (RECT_W - text_w) / 2 - 10;
581 y = RECT_Y * 7 / 4 + RECT_H;
582 switch (i) {
583 case 0: LDrawOpenSquare(x,y); break;
584 case 1: LDrawOpenTriangle(x,y); break;
585 case 2: LDrawOpenDiamon(x,y); break;
586 case 3: LDrawCross(x,y); break;
587 case 4: LDrawCloseSquare(x,y); break;
588 case 5: LDrawCloseDiamon(x,y); break;
589 }
590 if (graphic_format[i] == 'B')
591 XDrawLine(dpy, win, maingcreversed,
592 x-5, y,
593 x+5, y);
594 }
595 /* Draw the legend title */
596
597 XDrawImageString(dpy, win, maingcreversed,
598 RECT_X + (RECT_W - text_w)/2, RECT_Y*7/4 + RECT_H,
599 graphic_legend[i], len);
600 break;
601 }
602 else {
603
604 /* Draw the legend symbols */
605
606 if (graphic_format[i] == 'L') {
607 XDrawLine(dpy, win, maingcreversed ,
608 RECT_X/2 + legend_n*(WIN_W/curves_n - 10) - 15,
609 RECT_Y * 7 / 4 + RECT_H,
610 RECT_X / 2 + legend_n * (WIN_W / curves_n - 10) - 5,
611 RECT_Y *7 / 4 + RECT_H);
612 }
613 else if ((graphic_format[i] == 'S') || (graphic_format[i] == 'B')) {
614 switch (i) {
615 case 0:
616 LDrawOpenSquare(RECT_X/2 + legend_n*(WIN_W / curves_n - 10) - 10,
617 RECT_Y * 7 / 4 + RECT_H);
618 break;
619 case 1:
620 LDrawOpenTriangle(RECT_X/2 + legend_n*(WIN_W/curves_n - 10) - 10,
621 RECT_Y * 7 / 4 + RECT_H);
622 break;
623 case 2:
624 LDrawOpenDiamon(RECT_X/2 + legend_n * (WIN_W/curves_n - 10) - 10,
625 RECT_Y*7/4 + RECT_H);
626 break;
627 case 3:
628 LDrawCross(RECT_X/2 + legend_n*(WIN_W/curves_n - 10) - 10,
629 RECT_Y*7/4 + RECT_H);
630 break;
631 case 4:
632 LDrawCloseSquare(RECT_X/2 + legend_n*(WIN_W/curves_n - 10) - 10,
633 RECT_Y*7/4 + RECT_H);
634 break;
635 case 5:
636 LDrawCloseDiamon(RECT_X/2 + legend_n*(WIN_W/curves_n - 10) - 10,
637 RECT_Y*7/4 + RECT_H);
638 break;
639 }
640 if (graphic_format[i] == 'B')
641 XDrawLine(dpy, win, maingcreversed ,
642 RECT_X/2 + legend_n*(WIN_W/curves_n - 10) - 15,
643 RECT_Y*7/4 + RECT_H,
644 RECT_X/2 + legend_n*(WIN_W/curves_n - 10) - 5,
645 RECT_Y*7/4 + RECT_H);
646
647 }
648
649 /* Draw the legend titles */
650 XDrawImageString(dpy, win, maingcreversed,
651 RECT_X/2 + legend_n*(WIN_W/curves_n - 10),
652 RECT_Y*7/4 + RECT_H,
653 graphic_legend[i], len);
654 legend_n ++;
655 }
656 }
657
658
659 /*
660 * Draw curves
661 */
662 for (i = 1; i < GRAPHRANGES; i++) {
663 if (*(graphic_range[i].col) == '\0') continue;
664
665 /* ---- the following switch statement added by Rama Devi ----*/
666 switch (i) {
667 case 1 :
668 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
669 if ((XAllocNamedColor (dpy, cmap, "Green", &exactGreen, &Green) != 0))
670 {
671 XSetForeground (dpy, maingcreversed, Green.pixel);
672 XSetBackground (dpy, maingcreversed, Black.pixel);
673 }
674 else
675 {
676 XSetForeground (dpy, maingcreversed, fg);
677 XSetBackground (dpy, maingcreversed, bg);
678 }
679 break;
680
681 case 2 :
682 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
683 if ((XAllocNamedColor (dpy, cmap, "Orchid", &exactOrchid, &Orchid) != 0))
684 {
685 XSetForeground (dpy, maingcreversed, Orchid.pixel);
686 }
687 else
688 {
689 XSetForeground (dpy, maingcreversed, fg);
690 }
691 break;
692
693 case 3 :
694 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
695 if ((XAllocNamedColor (dpy, cmap, "GreenYellow", &exactGreenYellow, &GreenYellow) != 0))
696 {
697 XSetForeground (dpy, maingcreversed, GreenYellow.pixel);
698 }
699 else
700 {
701 XSetForeground (dpy, maingcreversed, fg);
702 }
703 break;
704
705 case 4 :
706 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
707 if ((XAllocNamedColor (dpy, cmap, "Goldenrod", &exactGoldenrod, &Goldenrod) != 0))
708 {
709 XSetForeground (dpy, maingcreversed, Goldenrod.pixel);
710 }
711 else
712 {
713 XSetForeground (dpy, maingcreversed, fg);
714 }
715 break;
716
717 case 5 :
718 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
719
720 if ((XAllocNamedColor (dpy, cmap, "Aquamarine", &exactAquamarine, &Aquamarine) != 0))
721 {
722 XSetForeground (dpy, maingcreversed, Aquamarine.pixel);
723 }
724 else
725 {
726 XSetForeground (dpy, maingcreversed, fg);
727 }
728 break;
729 case 6 :
730 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
731 if ((XAllocNamedColor (dpy, cmap, "Yellow", &exactYellow, &Yellow) != 0))
732 {
733 XSetForeground (dpy, maingcreversed, Yellow.pixel);
734 }
735 else
736 {
737 XSetForeground (dpy, maingcreversed, fg);
738
739 }
740 break; } /* --switch --- */
741
742 first_point = 1;
743 format = graphic_format[i];
744 items = 0;
745
746 /*--------The following is commented by Rama Devi -----------
747
748 ------ for (j = graphic_range[0].r1, k = graphic_range[i].r1;
749 (j <= graphic_range[0].r2) && (k <= graphic_range[i].r2); j++, k++) {---
750
751 if graphic_range[i].r1 is greater than graphic_range[0].r1 and the
752 difference between graphic_range[i].r1 and graphic_range[i].r2 is
753 less tahn the difference between graphic_range[0].r1 and graphic_
754 range[0].r2 then the loop is executed only the difference between
755 graphic_range[0].r1 and graphic_range[0].r2 teimes and comes out
756 without drawing the graphs for the specified ranges
757 -----------------------------------------------------------*/
758 /*--------- The following for loop added by Rama Devi ------- */
759
760 for (j = graphic_range[0].r1; j <= graphic_range[0].r2; j++) {
761
762 if (!((p=lookat(j,graphic_range[0].c))->label)) continue;
763 x = RECT_X + (items+1)*grid_w ;
764 items++;
765
766 /*------ the following if statement added by Rama Devi --*/
767 if ((j >= graphic_range[i].r1) && (j <= graphic_range[i].r2))
768 {
769
770 yent = lookat(j, graphic_range[i].c);
771 if (!(yent->flags & is_valid) || (yent->v < min_y)
772 || (yent->v > max_y))
773 continue;
774
775 if (first_point){
776 x1 = x;
777 y1 = RECT_Y + RECT_H - RECT_H * (yent->v - min_y) / Y_Range;
778 if ((format == 'S') || (format == 'B'))
779 switch(i){
780 case 1: LDrawOpenSquare(x1, y1); break;
781 case 2: LDrawOpenTriangle(x1, y1); break;
782 case 3: LDrawOpenDiamon(x1, y1); break;
783 case 4: LDrawCross(x1, y1); break;
784 case 5: LDrawCloseSquare(x1, y1); break;
785 case 6: LDrawCloseDiamon(x1, y1); break;
786 }
787 first_point = 0;
788 continue;
789 }
790
791 y = RECT_Y + RECT_H - RECT_H * (yent->v - min_y) / Y_Range;
792
793 if ((format == 'L') || (format == 'B'))
794 XDrawLine(dpy, win, maingcreversed, x1, y1, x, y);
795 if ((format == 'S') || (format == 'B'))
796 switch(i){
797 case 1: LDrawOpenSquare(x, y); break;
798 case 2: LDrawOpenTriangle(x, y); break;
799 case 3: LDrawOpenDiamon(x, y); break;
800 case 4: LDrawCross(x, y); break;
801 case 5: LDrawCloseSquare(x, y); break;
802 case 6: LDrawCloseDiamon(x, y); break;
803 }
804 x1 = x;
805 y1 = y;
806
807 } /*-----*/
808 }
809 }
810
811 /*---- The following two statements added by Rama Devi ----*/
812 cmap = DefaultColormap(dpy, DefaultScreen(dpy));
813 if ((XAllocNamedColor (dpy, cmap, "Orange", &exactOrange, &Orange) != 0))
814 {
815 XSetForeground (dpy, maingcreversed, Orange.pixel);
816 XSetBackground (dpy, maingcreversed, Black.pixel);
817 }
818 else
819 {
820 XSetForeground (dpy, maingcreversed, fg);
821 XSetBackground (dpy, maingcreversed, bg);
822 }
823
824 } /* end of while */
825
826
827 /*---- The following statements added by Rama Devi ----*/
828 cmap = DefaultColormap (dpy, DefaultScreen (dpy));
829 if (backg && (XAllocNamedColor (dpy, cmap, backg, &exactOrange, &Orange) != 0))
830 {
831 bg = Orange.pixel;
832 }
833 else
834 {
835 bg = WhitePixel(dpy, DefaultScreen(dpy)); /* background */
836 }
837 if (foreg && (XAllocNamedColor (dpy, cmap, foreg, &exactBlack, &Black) != 0))
838 {
839 fg = Black.pixel;
840 }
841 else
842 {
843 fg = BlackPixel(dpy, DefaultScreen(dpy)); /* foreground */
844 }
845
846 XSetForeground (dpy, maingc, fg);
847 XSetBackground (dpy, maingc, bg);
848 XSetForeground (dpy, maingcreversed, bg);
849 XSetBackground (dpy, maingcreversed, fg);
850
851
852 XUnmapWindow(dpy, win);
853 XDestroyWindow(dpy, win);
854 /*XCloseDisplay(dpy); */ /* NO. don't do this anymore */
855 } /* end of plot_line */
856
857
858 /*
859 * The following Drawing functions draw diffrent symbols.
860 */
861
LDrawOpenDiamon(x,y)862 void LDrawOpenDiamon(x, y)
863 short x, y;
864 {
865 XPoint points[5];
866
867 points[0].x = x;
868 points[0].y = y - 3;
869 points[1].x = 3;
870 points[1].y = 3;
871 points[2].x = -3;
872 points[2].y = 3;
873 points[3].x = -3;
874 points[3].y = -3;
875 points[4].x = 3;
876 points[4].y = -3;
877 XDrawLines(dpy, win, maingcreversed, points, 5, CoordModePrevious);
878 }
879
LDrawCloseDiamon(x,y)880 void LDrawCloseDiamon(x, y)
881 short x, y;
882 {
883 XPoint points[12];
884
885 points[0].x = x;
886 points[0].y = y;
887 points[1].x = -2;
888 points[1].y = 0;
889 points[2].x = 4;
890 points[2].y = 0;
891 points[3].x = -2;
892 points[3].y = 0;
893 points[4].x = 0;
894 points[4].y = -2;
895 points[5].x = 0;
896 points[5].y = 4;
897 points[6].x = 0;
898 points[6].y = -2;
899 points[7].x = 1;
900 points[7].y = 1;
901 points[8].x = -2;
902 points[8].y = -2;
903 points[9].x = 1;
904 points[9].y = 1;
905 points[10].x = -1;
906 points[10].y = 1;
907 points[11].x = 2;
908 points[11].y = -2;
909 XDrawLines(dpy, win, maingcreversed, points, 12, CoordModePrevious);
910 }
911
LDrawOpenSquare(x,y)912 void LDrawOpenSquare(x, y)
913 short x, y;
914 {
915 XPoint points[5];
916 points[0].x = x - 2;
917 points[0].y = y - 2;
918 points[1].x = 4;
919 points[1].y = 0;
920 points[2].x = 0;
921 points[2].y = 4;
922 points[3].x = -4;
923 points[3].y = 0;
924 points[4].x = 0;
925 points[4].y = -4;
926 XDrawLines(dpy, win, maingcreversed, points, 5, CoordModePrevious);
927 }
928
LDrawCloseSquare(x,y)929 void LDrawCloseSquare(x, y)
930 short x, y;
931 {
932 XPoint points[9];
933
934 points[0].x = x - 2;
935 points[0].y = y - 2;
936 points[1].x = 4;
937 points[1].y = 0;
938 points[2].x = 0;
939 points[2].y = 4;
940 points[3].x = -4;
941 points[3].y = 0;
942 points[4].x = 0;
943 points[4].y = -4;
944 points[5].x = 4;
945 points[5].y = 4;
946 points[6].x = -2;
947 points[6].y = -2;
948 points[7].x = -2;
949 points[7].y = 2;
950 points[8].x = 4;
951 points[8].y = -4;
952 XDrawLines(dpy, win, maingcreversed, points, 9, CoordModePrevious);
953 }
954
LDrawOpenTriangle(x,y)955 void LDrawOpenTriangle(x, y)
956 short x, y;
957 {
958 XPoint points[4];
959
960 points[0].x = x;
961 points[0].y = y - 3;
962 points[1].x = 2;
963 points[1].y = 5;
964 points[2].x = -4;
965 points[2].y = 0;
966 points[3].x = 2;
967 points[3].y = -5;
968 XDrawLines(dpy, win, maingcreversed, points, 4, CoordModePrevious);
969 }
970
971
LDrawCross(x,y)972 void LDrawCross(x, y)
973 short x, y;
974 {
975 XPoint points[6];
976
977 points[0].x = x;
978 points[0].y = y;
979 points[1].x = -2;
980 points[1].y = 0;
981 points[2].x = 4;
982 points[2].y = 0;
983 points[3].x = -2;
984 points[3].y = 0;
985 points[4].x = 0;
986 points[4].y = -2;
987 points[5].x = 0;
988 points[5].y = 4;
989 XDrawLines(dpy, win, maingcreversed, points, 6, CoordModePrevious);
990 }
991
992
993 #ifdef NOTUSED
994 /*
995 * Lrm_tail_zero removes heading Black spaces, trailing Black spaces,
996 * zero '0' and '.' of a string for nice printing of graph lable
997 *
998 */
999
Lrm_tail_zero(s)1000 char *Lrm_tail_zero(s)
1001 char *s;
1002 {
1003 char *t;
1004 /* Get rid of heading Black spaces */
1005 for (t = s; *t == ' ' || *t == '\t'; t++);
1006 strcpy(s, t);
1007
1008 /* Get rid of trailing Black spaces and zeros */
1009 t = s;
1010 while ((*t) && (*t != '\n')) /* while not null or newline */
1011 t++;
1012 t--;
1013 while ((t != s) && ((*t == ' ') || (*t == '0')))
1014 t--;
1015 if (*t != '.') /* Get rid of trailing '.' */
1016 t++;
1017 *t = '\0';
1018 return s;
1019 }
1020 #endif /* NOTUSED */
1021
1022 #endif /* HAVE_X11_X_H this code for now is X specific */
1023