1 | /*
|
---|
2 | * $Source: /tmp_mnt/n/fs/grad1/jsp/src/jgraph/RCS/draw.c,v $
|
---|
3 | * $Revision: 8.3 $
|
---|
4 | * $Date: 92/11/30 11:42:10 $
|
---|
5 | * $Author: jsp $
|
---|
6 | */
|
---|
7 |
|
---|
8 | #include "jgraph.h"
|
---|
9 | #include <stdio.h>
|
---|
10 | #include <math.h>
|
---|
11 |
|
---|
12 | static char real_eof = EOF;
|
---|
13 |
|
---|
14 | float ctop(val, axis)
|
---|
15 | float val;
|
---|
16 | Axis axis;
|
---|
17 | {
|
---|
18 | if (axis->is_lg) {
|
---|
19 | if (val <= 0.0) {
|
---|
20 | error_header();
|
---|
21 | fprintf(stderr,
|
---|
22 | "Value of %f is at negative infinity with logrhythmic %c axis\n",
|
---|
23 | val, (axis->is_x) ? 'x' : 'y');
|
---|
24 | exit(1);
|
---|
25 | }
|
---|
26 | return (log(val) / axis->logfactor - axis->logmin) * axis->factor;
|
---|
27 | } else {
|
---|
28 | return (val - axis->min) * axis->factor;
|
---|
29 | }
|
---|
30 | }
|
---|
31 |
|
---|
32 | float disttop(val, axis)
|
---|
33 | float val;
|
---|
34 | Axis axis;
|
---|
35 | {
|
---|
36 | if (axis->is_lg) {
|
---|
37 | return FCPI * val;
|
---|
38 | } else {
|
---|
39 | return (val) * axis->factor;
|
---|
40 | }
|
---|
41 | }
|
---|
42 |
|
---|
43 | float intop(val)
|
---|
44 | float val;
|
---|
45 | {
|
---|
46 | return FCPI * val;
|
---|
47 | }
|
---|
48 |
|
---|
49 | #define MAXIMUM(a,b) ((a > b) ? a : b)
|
---|
50 |
|
---|
51 | draw_axis(a, other)
|
---|
52 | Axis a, other;
|
---|
53 | {
|
---|
54 | char orientation;
|
---|
55 | Hash h;
|
---|
56 | String s;
|
---|
57 |
|
---|
58 | orientation = (a->is_x) ? 'x' : 'y';
|
---|
59 | setlinewidth(1.0);
|
---|
60 | comment("Drawing Axis");
|
---|
61 | if (a->grid_lines) {
|
---|
62 | comment("Drawing Grid lines");
|
---|
63 | gsave();
|
---|
64 | setgray(a->gr_graytype, a->gr_gray);
|
---|
65 | for (h = first(a->hash_lines); h != nil(a->hash_lines); h = next(h)) {
|
---|
66 | if (h->major) {
|
---|
67 | printline(h->loc, 0.0, h->loc, other->psize, orientation);
|
---|
68 | }
|
---|
69 | }
|
---|
70 | grestore();
|
---|
71 | }
|
---|
72 | if (a->mgrid_lines) {
|
---|
73 | comment("Drawing Minor Grid lines");
|
---|
74 | gsave();
|
---|
75 | setgray(a->mgr_graytype, a->mgr_gray);
|
---|
76 | for (h = first(a->hash_lines); h != nil(a->hash_lines); h = next(h)) {
|
---|
77 | if (!h->major) {
|
---|
78 | printline(h->loc, 0.0, h->loc, other->psize, orientation);
|
---|
79 | }
|
---|
80 | }
|
---|
81 | grestore();
|
---|
82 | }
|
---|
83 | gsave();
|
---|
84 | setgray(a->graytype, a->gray);
|
---|
85 | if (a->draw_axis_line) {
|
---|
86 | printline(0.0, a->draw_at, a->psize, a->draw_at, orientation);
|
---|
87 | }
|
---|
88 | if (a->draw_hash_marks) {
|
---|
89 | comment("Drawing Hash Marks");
|
---|
90 | for (h = first(a->hash_lines); h != nil(a->hash_lines); h = next(h)) {
|
---|
91 | printline(h->loc, a->draw_hash_marks_at, h->loc,
|
---|
92 | a->draw_hash_marks_at + (h->size * a->hash_scale),
|
---|
93 | orientation);
|
---|
94 | }
|
---|
95 | }
|
---|
96 | if (a->draw_hash_labels) {
|
---|
97 | comment("Drawing Hash Labels");
|
---|
98 | for (s = first(a->hash_labels); s != nil(a->hash_labels); s = next(s)) {
|
---|
99 | a->hl->label = s->s->label;
|
---|
100 | if (a->is_x) {
|
---|
101 | a->hl->x = s->s->x;
|
---|
102 | } else {
|
---|
103 | a->hl->y = s->s->y;
|
---|
104 | }
|
---|
105 | draw_label(a->hl);
|
---|
106 | }
|
---|
107 | }
|
---|
108 | if (a->draw_axis_label) {
|
---|
109 | comment("Drawing Axis Label");
|
---|
110 | draw_label(a->label);
|
---|
111 | }
|
---|
112 | grestore();
|
---|
113 | printf("\n");
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | draw_label(l)
|
---|
118 | Label l;
|
---|
119 | {
|
---|
120 | if (l->label == CNULL) return;
|
---|
121 | comment(l->label);
|
---|
122 | print_label(l);
|
---|
123 | }
|
---|
124 |
|
---|
125 | set_clip(g)
|
---|
126 | Graph g;
|
---|
127 | {
|
---|
128 | comment("Setting Clip");
|
---|
129 | printf("newpath\n");
|
---|
130 | printf(" 0 0 moveto 0 %f lineto %f %f lineto %f 0 lineto\n",
|
---|
131 | g->y_axis->psize, g->x_axis->psize,
|
---|
132 | g->y_axis->psize, g->x_axis->psize);
|
---|
133 | printf(" closepath clip newpath\n");
|
---|
134 | }
|
---|
135 |
|
---|
136 | draw_curves(g)
|
---|
137 | Graph g;
|
---|
138 | {
|
---|
139 | Curve c;
|
---|
140 |
|
---|
141 | gsave();
|
---|
142 | printf("\n");
|
---|
143 | if (g->clip) set_clip(g);
|
---|
144 | for(c = first(g->curves); c != nil(g->curves); c = next(c)) {
|
---|
145 | draw_curve(c, g);
|
---|
146 | }
|
---|
147 | grestore();
|
---|
148 | printf("\n");
|
---|
149 | }
|
---|
150 |
|
---|
151 | draw_curve(c, g)
|
---|
152 | Curve c;
|
---|
153 | Graph g;
|
---|
154 | {
|
---|
155 | Point p, px, py;
|
---|
156 | int i, j;
|
---|
157 | float this_x, this_y, last_x, last_y, x, y;
|
---|
158 |
|
---|
159 | gsave();
|
---|
160 | setgray(c->graytype, c->gray);
|
---|
161 | if (c->clip) set_clip(g);
|
---|
162 | if (first(c->xepts) != nil(c->xepts) ||
|
---|
163 | first(c->yepts) != nil(c->yepts)) {
|
---|
164 | comment("Drawing Epts");
|
---|
165 | px = first(c->xepts);
|
---|
166 | py = first(c->yepts);
|
---|
167 | setlinewidth(c->linethick);
|
---|
168 | setlinestyle('s', (Flist)0);
|
---|
169 | for (p = first(c->pts); p != nil(c->pts); p = next(p)) {
|
---|
170 | if (p->e == 'x') {
|
---|
171 | x = ctop(p->x, g->x_axis);
|
---|
172 | y = ctop(p->y, g->y_axis);
|
---|
173 | print_ebar(x, y, ctop(px->x, g->x_axis), c->marksize[1]/2.0, 'x');
|
---|
174 | px = next(px);
|
---|
175 | print_ebar(x, y, ctop(px->x, g->x_axis), c->marksize[1]/2.0, 'x');
|
---|
176 | px = next(px);
|
---|
177 | } else if (p->e == 'y') {
|
---|
178 | x = ctop(p->x, g->x_axis);
|
---|
179 | y = ctop(p->y, g->y_axis);
|
---|
180 | print_ebar(y, x, ctop(py->y, g->y_axis), c->marksize[0]/2.0, 'y');
|
---|
181 | py = next(py);
|
---|
182 | print_ebar(y, x, ctop(py->y, g->y_axis), c->marksize[0]/2.0, 'y');
|
---|
183 | py = next(py);
|
---|
184 | }
|
---|
185 | }
|
---|
186 | }
|
---|
187 |
|
---|
188 | comment("Drawing Curve");
|
---|
189 | if (c->linetype != '0' || c->poly) {
|
---|
190 | if (c->bezier) {
|
---|
191 | i = 0;
|
---|
192 | j = 0;
|
---|
193 | if (c->poly) printf("newpath ");
|
---|
194 | for (p = first(c->pts); p != nil(c->pts); p = next(p)) {
|
---|
195 | if (j == 0 && i == 0) {
|
---|
196 | start_line(ctop(p->x, g->x_axis), ctop(p->y, g->y_axis), c);
|
---|
197 | j++;
|
---|
198 | } else if (i != 0) {
|
---|
199 | bezier_control(ctop(p->x, g->x_axis), ctop(p->y, g->y_axis));
|
---|
200 | } else {
|
---|
201 | bezier_end(ctop(p->x, g->x_axis), ctop(p->y, g->y_axis));
|
---|
202 | j++;
|
---|
203 | }
|
---|
204 | if (!c->poly && j == 30 && i == 0) {
|
---|
205 | end_line();
|
---|
206 | p = prev(p);
|
---|
207 | j = 0;
|
---|
208 | i = 0;
|
---|
209 | } else i = (i + 1) % 3;
|
---|
210 | }
|
---|
211 | if (j != 0) {
|
---|
212 | if (c->poly) {
|
---|
213 | printf("closepath ");
|
---|
214 | setfill(0.0, 0.0, c->pfilltype, c->pfill, c->ppattern, c->pparg);
|
---|
215 | }
|
---|
216 | end_line();
|
---|
217 | }
|
---|
218 | } else {
|
---|
219 | i = 0;
|
---|
220 | if (c->poly) printf("newpath ");
|
---|
221 | for (p = first(c->pts);
|
---|
222 | p != nil(c->pts);
|
---|
223 | p = next(p)) {
|
---|
224 | if (i == 0) {
|
---|
225 | start_line(ctop(p->x, g->x_axis), ctop(p->y, g->y_axis), c);
|
---|
226 | } else {
|
---|
227 | cont_line(ctop(p->x, g->x_axis), ctop(p->y, g->y_axis));
|
---|
228 | }
|
---|
229 | if (!c->poly && i == 100 && next(p)) {
|
---|
230 | end_line();
|
---|
231 | p = prev(p);
|
---|
232 | i = 0;
|
---|
233 | } else i++;
|
---|
234 | }
|
---|
235 | if (i != 0) {
|
---|
236 | if (c->poly) {
|
---|
237 | printf("closepath ");
|
---|
238 | setfill(0.0, 0.0, c->pfilltype, c->pfill, c->ppattern, c->pparg);
|
---|
239 | }
|
---|
240 | end_line();
|
---|
241 | }
|
---|
242 | }
|
---|
243 | }
|
---|
244 | comment("Drawing Curve points");
|
---|
245 | i = 0;
|
---|
246 | for (p = first(c->pts);
|
---|
247 | p != nil(c->pts);
|
---|
248 | p = next(p)) {
|
---|
249 | this_x = ctop(p->x, g->x_axis);
|
---|
250 | this_y = ctop(p->y, g->y_axis);
|
---|
251 | if (!c->bezier || i == 0) draw_mark(this_x, this_y, c, g);
|
---|
252 | if (p != first(c->pts)) {
|
---|
253 | if (c->rarrows || (c->rarrow && p == last(c->pts))) {
|
---|
254 | if (!c->bezier || i == 0)
|
---|
255 | draw_arrow(this_x, this_y, last_x, last_y, c);
|
---|
256 | }
|
---|
257 | if (c->larrows || (c->larrow && prev(p) == first(c->pts))) {
|
---|
258 | if (!c->bezier || i == 1)
|
---|
259 | draw_arrow(last_x, last_y, this_x, this_y, c);
|
---|
260 | }
|
---|
261 | }
|
---|
262 | last_x = this_x;
|
---|
263 | last_y = this_y;
|
---|
264 | i = (i + 1) % 3;
|
---|
265 | }
|
---|
266 | grestore();
|
---|
267 | printf("\n");
|
---|
268 | }
|
---|
269 |
|
---|
270 | draw_mark(x, y, c, g)
|
---|
271 | float x, y;
|
---|
272 | Curve c;
|
---|
273 | Graph g;
|
---|
274 | {
|
---|
275 | Point p;
|
---|
276 | float ms0, ms1, scx, scy, trx, try;
|
---|
277 | int i, j;
|
---|
278 | FILE *f;
|
---|
279 | char ch;
|
---|
280 | int done, newline;
|
---|
281 | char inp[100];
|
---|
282 | int bb[4];
|
---|
283 |
|
---|
284 | if (c->marktype == 'n') return;
|
---|
285 | ms0 = c->marksize[0] / 2.0;
|
---|
286 | ms1 = c->marksize[1] / 2.0;
|
---|
287 |
|
---|
288 | gsave();
|
---|
289 | printf(" %f %f translate %f rotate\n", x, y, c->mrotate);
|
---|
290 |
|
---|
291 | switch (c->marktype) {
|
---|
292 | case 'n': break;
|
---|
293 | case 'E': if (c->eps == CNULL) break;
|
---|
294 | f = fopen(c->eps, "r");
|
---|
295 | if (f == NULL) {
|
---|
296 | fprintf(stderr, "Error: eps file %s couldn't be opened\n",
|
---|
297 | c->eps);
|
---|
298 | exit(1);
|
---|
299 | }
|
---|
300 | /* Get bbox */
|
---|
301 | newline = 1;
|
---|
302 | done = 0;
|
---|
303 | while(!done) {
|
---|
304 | while(!newline) {
|
---|
305 | ch = getc(f);
|
---|
306 | if (ch == real_eof) {
|
---|
307 | fprintf(stderr, "Error: Eps file '%s' has %s\n",
|
---|
308 | c->eps, "no bounding box");
|
---|
309 | exit(1);
|
---|
310 | }
|
---|
311 | newline = (ch == '\n');
|
---|
312 | }
|
---|
313 | fscanf(f, "%s", inp);
|
---|
314 | if (strcmp(inp, "%%BoundingBox:") == 0) done = 1;
|
---|
315 | }
|
---|
316 | for (i = 0; i < 4; i++) {
|
---|
317 | if (fscanf(f, "%d", &(bb[i])) != 1) {
|
---|
318 | fprintf(stderr, "Error: Eps file '%s': eof in %s\n",
|
---|
319 | c->eps, "bounding box");
|
---|
320 | exit(1);
|
---|
321 | }
|
---|
322 | }
|
---|
323 | if (bb[2] - bb[0] == 0) {
|
---|
324 | scx = ms0;
|
---|
325 | trx = 0.0;
|
---|
326 | } else {
|
---|
327 | scx = ms0 * 2.0/(float)(bb[2] - bb[0]);
|
---|
328 | trx = -(float)(bb[2] - bb[0])/2.0 - bb[0];
|
---|
329 | }
|
---|
330 | if (bb[3] - bb[1] == 0) {
|
---|
331 | scy = ms1;
|
---|
332 | try = 0.0;
|
---|
333 | } else {
|
---|
334 | scy = ms1 * 2.0/(float)(bb[3] - bb[1]);
|
---|
335 | try = -(float)(bb[3] - bb[1])/2.0 - bb[1];
|
---|
336 | }
|
---|
337 | /* Don't scale if ms == 0 0 */
|
---|
338 | if (ms0 == 0.0 && ms1 == 0.0) {
|
---|
339 | scx = 1.0;
|
---|
340 | scy = 1.0;
|
---|
341 | }
|
---|
342 |
|
---|
343 | sprintf(inp, "Including eps file %s", c->eps);
|
---|
344 | comment(inp);
|
---|
345 | /* Use bbox to scale and translate */
|
---|
346 |
|
---|
347 | printf("%f %f scale %f %f translate\n", scx, scy, trx, try);
|
---|
348 | /* Include the rest of the file */
|
---|
349 | for (ch = getc(f); ch != real_eof; ch = getc(f)) putchar(ch);
|
---|
350 | putchar('\n');
|
---|
351 | fclose(f);
|
---|
352 | break;
|
---|
353 | case 'p': if (c->postscript == CNULL) break;
|
---|
354 | if (ms0 != 0.0 || ms1 != 0.0) {
|
---|
355 | printf("%f %f scale\n", ms0, ms1);
|
---|
356 | }
|
---|
357 | if (!c->postfile) {
|
---|
358 | printf("%s\n", c->postscript);
|
---|
359 | } else {
|
---|
360 | f = fopen(c->postscript, "r");
|
---|
361 | if (f == NULL) {
|
---|
362 | fprintf(stderr,
|
---|
363 | "Error: postscript file %s couldn't be opened\n",
|
---|
364 | c->postscript);
|
---|
365 | exit(1);
|
---|
366 | }
|
---|
367 | for (ch = getc(f); ch != real_eof; ch = getc(f)) putchar(ch);
|
---|
368 | putchar('\n');
|
---|
369 | fclose(f);
|
---|
370 | }
|
---|
371 | break;
|
---|
372 | case 'c': printline(-ms0, 0.0, ms0, 0.0, 'x');
|
---|
373 | printline(-ms1, 0.0, ms1, 0.0, 'y');
|
---|
374 | break;
|
---|
375 | case 'b': start_poly(-ms0, -ms1);
|
---|
376 | cont_poly(ms0, -ms1);
|
---|
377 | cont_poly(ms0, ms1);
|
---|
378 | cont_poly(-ms0, ms1);
|
---|
379 | end_poly(x, y, c->filltype, c->fill, c->pattern, c->parg);
|
---|
380 | break;
|
---|
381 | case 'd': start_poly(-ms0, 0.0);
|
---|
382 | cont_poly(0.0, -ms1);
|
---|
383 | cont_poly(ms0, 0.0);
|
---|
384 | cont_poly(0.0, ms1);
|
---|
385 | end_poly(x, y, c->filltype, c->fill, c->pattern, c->parg);
|
---|
386 | break;
|
---|
387 | case 'g': p = first(c->general_marks);
|
---|
388 | if (p == nil(c->general_marks)) break;
|
---|
389 | if (next(p) == nil(c->general_marks)) break;
|
---|
390 | start_poly(p->x*ms0, p->y*ms1);
|
---|
391 | for(p = next(p); p != nil(c->general_marks); p = next(p))
|
---|
392 | cont_poly(p->x*ms0, p->y*ms1);
|
---|
393 | end_poly(x, y, c->filltype, c->fill, c->pattern, c->parg);
|
---|
394 | break;
|
---|
395 | case 'G': i = 0;
|
---|
396 | for (p = first(c->general_marks);
|
---|
397 | p != nil(c->general_marks);
|
---|
398 | p = next(p)) {
|
---|
399 | if (i == 0) {
|
---|
400 | printf("%f %f moveto ", p->x*ms0, p->y*ms1);
|
---|
401 | } else {
|
---|
402 | printf("%f %f lineto\n", p->x*ms0, p->y*ms1);
|
---|
403 | }
|
---|
404 | if (i == 100) {
|
---|
405 | printf("stroke\n");
|
---|
406 | p = prev(p);
|
---|
407 | i = 0;
|
---|
408 | } else i++;
|
---|
409 | }
|
---|
410 | if (i != 0) printf("stroke\n");
|
---|
411 | break;
|
---|
412 | case 'B': i = 0;
|
---|
413 | j = 0;
|
---|
414 | for (p = first(c->general_marks);
|
---|
415 | p != nil(c->general_marks);
|
---|
416 | p = next(p)) {
|
---|
417 | if (j == 0 && i == 0) {
|
---|
418 | printf("%f %f moveto ", p->x*ms0, p->y*ms1);
|
---|
419 | j++;
|
---|
420 | } else if (i != 0) {
|
---|
421 | printf("%f %f ", p->x*ms0, p->y*ms1);
|
---|
422 | } else {
|
---|
423 | printf("%f %f curveto\n", p->x*ms0, p->y*ms1);
|
---|
424 | j++;
|
---|
425 | }
|
---|
426 | if (j == 30 && i == 0) {
|
---|
427 | printf(" stroke\n");
|
---|
428 | p = prev(p);
|
---|
429 | j = 0;
|
---|
430 | i = 0;
|
---|
431 | } else i = (i + 1) % 3;
|
---|
432 | }
|
---|
433 | if (j != 0) printf(" stroke\n");
|
---|
434 | if (! ((i == 1) || (i == 0 && j == 0))) {
|
---|
435 | fprintf(stderr, "Error: curve %d, %s\n", c->num,
|
---|
436 | "wrong number of points for bezier marktype\n");
|
---|
437 | exit(1);
|
---|
438 | }
|
---|
439 | break;
|
---|
440 |
|
---|
441 | case 'Z': i = 0;
|
---|
442 | j = 0;
|
---|
443 | for (p = first(c->general_marks);
|
---|
444 | p != nil(c->general_marks);
|
---|
445 | p = next(p)) {
|
---|
446 | if (i == 0 && j == 0) {
|
---|
447 | printf("newpath %f %f moveto ", p->x*ms0, p->y*ms1);
|
---|
448 | j++;
|
---|
449 | } else if (i != 0) {
|
---|
450 | printf("%f %f ", p->x*ms0, p->y*ms1);
|
---|
451 | } else {
|
---|
452 | printf("%f %f curveto\n", p->x*ms0, p->y*ms1);
|
---|
453 | }
|
---|
454 | i = (i + 1) % 3;
|
---|
455 | }
|
---|
456 | printf("closepath ");
|
---|
457 | setfill(x, y, c->filltype, c->fill, c->pattern, c->parg);
|
---|
458 | printf("stroke\n");
|
---|
459 |
|
---|
460 | if (i != 1) {
|
---|
461 | fprintf(stderr, "Error: curve %d, %s\n", c->num,
|
---|
462 | "wrong number of points for bezier marktype\n");
|
---|
463 | exit(1);
|
---|
464 | }
|
---|
465 | break;
|
---|
466 |
|
---|
467 | case 'x': printline(-ms0, -ms1, ms0, ms1, 'x');
|
---|
468 | printline(-ms0, ms1, ms0, -ms1, 'x');
|
---|
469 | break;
|
---|
470 | case 'o': printellipse(x, y, ms0, ms0,
|
---|
471 | c->filltype, c->fill, c->pattern, c->parg);
|
---|
472 | break;
|
---|
473 | case 'e': printellipse(x, y, ms0, ms1,
|
---|
474 | c->filltype, c->fill, c->pattern, c->parg);
|
---|
475 | break;
|
---|
476 | case 't': start_poly(ms0, -ms1);
|
---|
477 | cont_poly(0.0, ms1);
|
---|
478 | cont_poly(-ms0, -ms1);
|
---|
479 | end_poly(x, y, c->filltype, c->fill, c->pattern, c->parg);
|
---|
480 | break;
|
---|
481 | case 'X': start_poly(ms0, 0.0);
|
---|
482 | cont_poly(-ms0, 0.0);
|
---|
483 | cont_poly(-ms0, g->x_axis->draw_at - y);
|
---|
484 | cont_poly(ms0, g->x_axis->draw_at - y);
|
---|
485 | end_poly(x, y, c->filltype, c->fill, c->pattern, c->parg);
|
---|
486 | break;
|
---|
487 | case 'Y': start_poly(0.0, ms1);
|
---|
488 | cont_poly(0.0, -ms1);
|
---|
489 | cont_poly(g->y_axis->draw_at - x, -ms1);
|
---|
490 | cont_poly(g->y_axis->draw_at - x, ms1);
|
---|
491 | end_poly(x, y, c->filltype, c->fill, c->pattern, c->parg);
|
---|
492 | break;
|
---|
493 | case 'l': draw_label(c->lmark);
|
---|
494 | break;
|
---|
495 | default: error_header();
|
---|
496 | fprintf(stderr, "Unknown mark: %c\n", c->marktype);
|
---|
497 | break;
|
---|
498 | }
|
---|
499 | grestore();
|
---|
500 | }
|
---|
501 |
|
---|
502 | draw_arrow(x1, y1, x2, y2, c)
|
---|
503 | float x1, y1, x2, y2;
|
---|
504 | Curve c;
|
---|
505 | {
|
---|
506 | float dx, dy;
|
---|
507 | float ms0;
|
---|
508 | float theta, ct, st;
|
---|
509 |
|
---|
510 |
|
---|
511 | if (c->marktype == 'o') {
|
---|
512 | dx = x1 - x2;
|
---|
513 | dy = y1 - y2;
|
---|
514 | if (dx == 0.0 && dy == 0.0) return;
|
---|
515 |
|
---|
516 | ms0 = c->marksize[0] / 2.0;
|
---|
517 | if (dx == 0.0) theta = asin(1.0); else theta = atan(dy/dx);
|
---|
518 | if (theta < 0.0) theta = -theta;
|
---|
519 | ct = cos(theta)*ms0;
|
---|
520 | st = sin(theta)*ms0;
|
---|
521 | x1 = x1 + ct*(dx > 0.0 ? -1.0 : 1.0);
|
---|
522 | y1 = y1 + st*(dy > 0.0 ? -1.0 : 1.0);
|
---|
523 |
|
---|
524 | if ( ((x1 - x2 > 0) != (dx > 0)) ||
|
---|
525 | ((y1 - y2 > 0) != (dy > 0)) ) return;
|
---|
526 | }
|
---|
527 |
|
---|
528 | dx = x1 - x2;
|
---|
529 | dy = y1 - y2;
|
---|
530 | if (dx == 0.0 && dy == 0.0) return;
|
---|
531 |
|
---|
532 | gsave();
|
---|
533 | printf("%f %f translate %f %f atan rotate\n", x1, y1, dy, dx);
|
---|
534 | start_poly(0.0, 0.0);
|
---|
535 | cont_poly(-(c->asize[0]), (c->asize[1]));
|
---|
536 | cont_poly(-(c->asize[0]), -(c->asize[1]));
|
---|
537 | end_poly(0.0, 0.0, c->afilltype, c->afill, c->apattern, c->aparg);
|
---|
538 | grestore();
|
---|
539 | printf("\n");
|
---|
540 | }
|
---|
541 |
|
---|
542 | draw_legend(g)
|
---|
543 | Graph g;
|
---|
544 | {
|
---|
545 | Curve c;
|
---|
546 | Legend l;
|
---|
547 | float x, y;
|
---|
548 | char tmpmktype;
|
---|
549 |
|
---|
550 | l = g->legend;
|
---|
551 | comment("Drawing legend");
|
---|
552 | if (l->type == 'n' || l->anylines < 0) return;
|
---|
553 | gsave();
|
---|
554 | if (l->type == 'u') {
|
---|
555 | printf("%f %f translate %f rotate\n", l->l->x, l->l->y, l->l->rotate);
|
---|
556 | }
|
---|
557 | for (c = first(g->curves); c != nil(g->curves); c = next(c)) {
|
---|
558 | if (c->l->label != CNULL) {
|
---|
559 | gsave();
|
---|
560 | setgray(c->graytype, c->gray);
|
---|
561 | y = (c->l->ymax + c->l->ymin) / 2.0;
|
---|
562 | if (l->anylines) {
|
---|
563 | if (c->linetype != '0' && l->linelength != 0) {
|
---|
564 | if (l->type == 'c' && c->l->hj == 'r') {
|
---|
565 | x = c->l->x + l->midspace;
|
---|
566 | } else {
|
---|
567 | x = c->l->x - l->midspace - l->linelength;
|
---|
568 | }
|
---|
569 | start_line(x, y, c);
|
---|
570 | cont_line(x+l->linelength, y);
|
---|
571 | end_line();
|
---|
572 | }
|
---|
573 | tmpmktype = c->marktype;
|
---|
574 | c->marktype = 'n';
|
---|
575 | if (c->larrows || c->larrow) draw_arrow(x, y, x+l->linelength, y, c);
|
---|
576 | if (c->rarrows || c->rarrow) draw_arrow(x+l->linelength, y, x, y, c);
|
---|
577 | c->marktype = tmpmktype;
|
---|
578 | if (l->type == 'c' && c->l->hj == 'r') {
|
---|
579 | x = c->l->x + l->midspace + l->linelength / 2.0;
|
---|
580 | } else {
|
---|
581 | x = c->l->x - l->midspace - l->linelength / 2.0;
|
---|
582 | }
|
---|
583 | } else if (l->type == 'c' && c->l->hj == 'r') {
|
---|
584 | x = c->l->x + l->midspace;
|
---|
585 | } else {
|
---|
586 | x = c->l->x - l->midspace;
|
---|
587 | }
|
---|
588 | if (c->marktype == 'X' || c->marktype == 'Y') {
|
---|
589 | char old;
|
---|
590 | old = c->marktype;
|
---|
591 | c->marktype = 'b';
|
---|
592 | draw_mark(x, y, c, g);
|
---|
593 | c->marktype = old;
|
---|
594 | } else {
|
---|
595 | draw_mark(x, y, c, g);
|
---|
596 | }
|
---|
597 | grestore();
|
---|
598 | printf("\n");
|
---|
599 | draw_label(c->l);
|
---|
600 | }
|
---|
601 | }
|
---|
602 | grestore();
|
---|
603 | printf("\n");
|
---|
604 | }
|
---|
605 |
|
---|
606 | draw_strings(g)
|
---|
607 | Graph g;
|
---|
608 | {
|
---|
609 | String s;
|
---|
610 |
|
---|
611 | comment("Drawing strings");
|
---|
612 | for (s = first(g->strings); s != nil(g->strings); s = next(s))
|
---|
613 | draw_label(s->s);
|
---|
614 | }
|
---|
615 |
|
---|
616 | draw_graph(g)
|
---|
617 | Graph g;
|
---|
618 | {
|
---|
619 | comment("Drawing New Graph");
|
---|
620 | printf("%f %f translate\n", g->x_translate, g->y_translate);
|
---|
621 | if (g->border) {
|
---|
622 | printline(0.0, 0.0, 0.0, g->y_axis->psize, 'x');
|
---|
623 | printline(0.0, 0.0, 0.0, g->x_axis->psize, 'y');
|
---|
624 | printline(g->x_axis->psize, 0.0, g->x_axis->psize, g->y_axis->psize, 'x');
|
---|
625 | printline(g->y_axis->psize, 0.0, g->y_axis->psize, g->x_axis->psize, 'y');
|
---|
626 | }
|
---|
627 | draw_axis(g->x_axis, g->y_axis);
|
---|
628 | draw_axis(g->y_axis, g->x_axis);
|
---|
629 | draw_label(g->title);
|
---|
630 | draw_curves(g);
|
---|
631 | draw_legend(g);
|
---|
632 | draw_strings(g);
|
---|
633 | printf("%f %f translate\n", - g->x_translate, - g->y_translate);
|
---|
634 |
|
---|
635 | }
|
---|
636 |
|
---|
637 | draw_graphs(gs, pp, landscape)
|
---|
638 | Graphs gs;
|
---|
639 | int pp;
|
---|
640 | int landscape;
|
---|
641 | {
|
---|
642 | Graphs gs_p;
|
---|
643 | Graph g;
|
---|
644 |
|
---|
645 | for (gs_p = first(gs); gs_p != nil(gs); gs_p = next(gs_p)) {
|
---|
646 | draw_header(gs_p, pp, landscape);
|
---|
647 | for (g = first(gs_p->g); g != nil(gs_p->g); g = next(g)) {
|
---|
648 | draw_graph(g);
|
---|
649 | }
|
---|
650 | draw_footer(gs_p, pp);
|
---|
651 | }
|
---|
652 | }
|
---|
653 |
|
---|
654 | draw_header(gs, pp, landscape)
|
---|
655 | Graphs gs;
|
---|
656 | int pp;
|
---|
657 | int landscape;
|
---|
658 | {
|
---|
659 | FILE *f;
|
---|
660 | char c;
|
---|
661 |
|
---|
662 | if (gs->page == 1) printf("%%!PS-Adobe-2.0 EPSF-1.2\n");
|
---|
663 | printf("%%%%Page: %d %d\n", gs->page, gs->page);
|
---|
664 | if (landscape) {
|
---|
665 | printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[1], gs->bb[0],
|
---|
666 | gs->bb[3], gs->bb[2]);
|
---|
667 | } else {
|
---|
668 | printf("%%%%BoundingBox: %d %d %d %d\n", gs->bb[0], gs->bb[1],
|
---|
669 | gs->bb[2], gs->bb[3]);
|
---|
670 | }
|
---|
671 |
|
---|
672 | printf("%%%%EndComments\n");
|
---|
673 | if (landscape) {
|
---|
674 | printf("-90 rotate\n");
|
---|
675 | }
|
---|
676 | if (pp) {
|
---|
677 | if (landscape) {
|
---|
678 | printf("%f 0 translate\n", -(11.0 * FCPI));
|
---|
679 | printf("%f %f translate\n",
|
---|
680 | (((11.0 * FCPI) - (gs->bb[2] - gs->bb[0])) / 2.0) - gs->bb[0],
|
---|
681 | (((8.5 * FCPI) - (gs->bb[3] - gs->bb[1])) / 2.0) - gs->bb[1]);
|
---|
682 | } else {
|
---|
683 | printf("%f %f translate\n",
|
---|
684 | (((8.5 * FCPI) - (gs->bb[2] - gs->bb[0])) / 2.0) - gs->bb[0],
|
---|
685 | (((11.0 * FCPI) - (gs->bb[3] - gs->bb[1])) / 2.0) - gs->bb[1]);
|
---|
686 | }
|
---|
687 | } else if (landscape) {
|
---|
688 | printf("%f 0 translate\n", -gs->bb[2] - gs->bb[0]);
|
---|
689 | }
|
---|
690 | printf("1 setlinecap 1 setlinejoin\n");
|
---|
691 | printf("0.700 setlinewidth\n");
|
---|
692 | printf("0.00 setgray\n");
|
---|
693 |
|
---|
694 | printf("\n");
|
---|
695 | printf("/Jrnd { exch cvi exch cvi dup 3 1 roll idiv mul } def\n");
|
---|
696 |
|
---|
697 | printf("/JDEdict 8 dict def\n");
|
---|
698 | printf("JDEdict /mtrx matrix put\n");
|
---|
699 | printf("/JDE {\n");
|
---|
700 | printf(" JDEdict begin\n");
|
---|
701 | printf(" /yrad exch def\n");
|
---|
702 | printf(" /xrad exch def\n");
|
---|
703 | printf(" /savematrix mtrx currentmatrix def\n");
|
---|
704 | printf(" xrad yrad scale\n");
|
---|
705 | printf(" 0 0 1 0 360 arc\n");
|
---|
706 | printf(" savematrix setmatrix\n");
|
---|
707 | printf(" end\n");
|
---|
708 | printf("} def\n");
|
---|
709 |
|
---|
710 | printf("/JSTR {\n");
|
---|
711 | printf(" gsave 1 eq { gsave 1 setgray fill grestore } if\n");
|
---|
712 | printf(" exch neg exch neg translate \n");
|
---|
713 | printf(" clip \n");
|
---|
714 | printf(" rotate \n");
|
---|
715 | printf(" 4 dict begin\n");
|
---|
716 | printf(" pathbbox /&top exch def\n");
|
---|
717 | printf(" /&right exch def\n");
|
---|
718 | printf(" /&bottom exch def\n");
|
---|
719 | printf(" &right sub /&width exch def\n");
|
---|
720 | printf(" newpath\n");
|
---|
721 | printf(" currentlinewidth mul round dup \n");
|
---|
722 | printf(" &bottom exch Jrnd exch &top \n");
|
---|
723 | printf(" 4 -1 roll currentlinewidth mul setlinewidth \n");
|
---|
724 | printf(" { &right exch moveto &width 0 rlineto stroke } for \n");
|
---|
725 | printf(" end\n");
|
---|
726 | printf(" grestore\n");
|
---|
727 | printf(" newpath\n");
|
---|
728 | printf("} bind def\n");
|
---|
729 |
|
---|
730 | gsave();
|
---|
731 | setfont("Times-Roman", 9.00);
|
---|
732 | if (gs->preamble != CNULL) {
|
---|
733 | if (gs->prefile) {
|
---|
734 | f = fopen(gs->preamble, "r");
|
---|
735 | if (f == NULL) {
|
---|
736 | fprintf(stderr, "Error: preamble file %s couldn't be opened\n",
|
---|
737 | gs->preamble);
|
---|
738 | exit(1);
|
---|
739 | }
|
---|
740 | for (c = getc(f); c != real_eof; c = getc(f)) putchar(c);
|
---|
741 | putchar('\n');
|
---|
742 | fclose(f);
|
---|
743 | } else {
|
---|
744 | printf("%s\n", gs->preamble);
|
---|
745 | }
|
---|
746 | }
|
---|
747 | }
|
---|
748 |
|
---|
749 | draw_footer(gs, pp)
|
---|
750 | Graphs gs;
|
---|
751 | int pp;
|
---|
752 | {
|
---|
753 | FILE *f;
|
---|
754 | char c;
|
---|
755 |
|
---|
756 | if (gs->epilogue != CNULL) {
|
---|
757 | if (gs->epifile) {
|
---|
758 | f = fopen(gs->epilogue, "r");
|
---|
759 | if (f == NULL) {
|
---|
760 | fprintf(stderr, "Error: epilogue file %s couldn't be opened\n",
|
---|
761 | gs->epilogue);
|
---|
762 | exit(1);
|
---|
763 | }
|
---|
764 | for (c = getc(f); c != real_eof; c = getc(f)) putchar(c);
|
---|
765 | putchar('\n');
|
---|
766 | fclose(f);
|
---|
767 | } else {
|
---|
768 | printf("%s\n", gs->epilogue);
|
---|
769 | }
|
---|
770 | }
|
---|
771 | grestore();
|
---|
772 | if (pp) printf("showpage\n"); else printf("\n");
|
---|
773 | }
|
---|
774 |
|
---|