source: trunk/Jgraph/show.c@ 419

Last change on this file since 419 was 418, checked in by Nicholas Riley, 16 years ago

Jgraph 8.3 from http://www.cs.utk.edu/~plank/plank/jgraph/jgraph.tar.gz

File size: 11.5 KB
Line 
1/*
2 * $Source: /tmp_mnt/n/fs/grad1/jsp/src/jgraph/RCS/show.c,v $
3 * $Revision: 8.3 $
4 * $Date: 92/11/30 11:42:40 $
5 * $Author: jsp $
6 */
7
8#include <stdio.h>
9#include <math.h>
10#include "jgraph.h"
11
12static spaces(nsp)
13int nsp;
14{
15 while(nsp-- > 0) putchar(' ');
16}
17
18float ptoin(p)
19float p;
20{
21 return p / FCPI;
22}
23
24float ptoc(p, a)
25float p;
26Axis a;
27{
28 if (a->is_lg) {
29 return (float) exp((p / a->factor + a->logmin) * a->logfactor);
30 } else {
31 return (p / a->factor) + a->min;
32 }
33}
34
35float ptodist(p, a)
36float p;
37Axis a;
38{
39 if (a->is_lg) {
40 return p / FCPI;
41 } else {
42 return (p / a->factor);
43 }
44}
45
46static show_mltiline(s)
47char *s;
48{
49 int i;
50
51 if (s != CNULL) {
52 for (i = 0; s[i] != '\0'; i++) {
53 if (s[i] == '\n') putchar('\\');
54 putchar(s[i]);
55 }
56 }
57 putchar('\n');
58}
59
60show_string(s)
61char *s;
62{
63 int i;
64
65 if (s != CNULL) {
66 printf(": ");
67 for (i = 0; s[i] != '\0'; i++) {
68 if (s[i] == '\n') putchar('\\');
69 if (s[i] == '\\') i++;
70 putchar(s[i]);
71 }
72 }
73 putchar('\n');
74}
75
76
77show_label(l, nsp, g)
78Label l;
79int nsp;
80Graph g;
81{
82 spaces(nsp);
83 show_string(l->label);
84 spaces(nsp); printf("x %f ", ptoc(l->x, g->x_axis));
85 printf("y %f\n", ptoc(l->y, g->y_axis));
86 spaces(nsp); printf("hj%c vj%c ", l->hj, l->vj);
87 printf("rotate %f\n", l->rotate);
88 spaces(nsp); printf("font %s ", l->font);
89 printf("fontsize %f ", l->fontsize);
90 printf("linesep %f\n", l->linesep);
91 if (l->graytype == 'g') {
92 spaces(nsp);
93 printf("lgray %f\n", l->gray[0]);
94 } else if (l->graytype == 'c') {
95 spaces(nsp);
96 printf("lcolor %f %f %f\n", l->gray[0], l->gray[1], l->gray[2]);
97 }
98 return;
99}
100
101show_lmark(l, nsp, g)
102Label l;
103int nsp;
104Graph g;
105{
106 spaces(nsp); show_string(l->label);
107 spaces(nsp); printf("x %f ", ptodist(l->x, g->x_axis));
108 printf("y %f\n", ptodist(l->y, g->y_axis));
109 spaces(nsp); printf("hj%c vj%c ", l->hj, l->vj);
110 printf("rotate %f\n", l->rotate);
111 spaces(nsp); printf("font %s ", l->font);
112 printf("fontsize %f\n", l->fontsize);
113 return;
114}
115
116show_curve(c, nsp, g)
117Curve c;
118int nsp;
119Graph g;
120{
121 Point p;
122 Point px;
123 Point py;
124 int i;
125 Flist fl;
126
127 if (c->l->label != CNULL) {
128 spaces(nsp); printf("label\n");
129 spaces(nsp+2);
130 printf("(* unless <legend custom>, this label\'s x\'s and y\'s will be ignored *)\n");
131 show_label(c->l, nsp+2, g);
132 }
133
134 px = first(c->xepts);
135 py = first(c->yepts);
136 for(p = first(c->pts); p != nil(c->pts); p = next(p)) {
137 if (p->e == 'p') {
138 spaces(nsp); printf("pts %f %f\n", p->x, p->y);
139 } else if (p->e == 'x') {
140 spaces(nsp);
141 printf("x_epts %f %f %f %f\n", p->x, p->y, px->x, next(px)->x);
142 px = next(next(px));
143 } else if (p->e == 'y') {
144 spaces(nsp);
145 printf("y_epts %f %f %f %f\n", p->y, p->y, py->y, next(py)->y);
146 py = next(next(py));
147 } else {
148 fprintf(stderr, "Internal error: p->e == %c\n", p->e);
149 exit(1);
150 }
151 }
152 if (c->eps != CNULL) {
153 spaces(nsp);
154 printf("eps %s\n", c->eps);
155 }
156 if (c->postscript != CNULL) {
157 spaces(nsp);
158 printf("postscript ");
159 if (!c->postfile) printf(": ");
160 show_mltiline(c->postscript);
161 }
162 spaces(nsp); printf("marktype ");
163 for (i = 0; i < NMARKTYPES && c->marktype != MARKTYPES[i]; i++) ;
164 if (i == NMARKTYPES) {
165 error_header();
166 fprintf(stderr, "Unknown mark type %c\n", c->marktype);
167 exit(1);
168 } else printf("%s ", MARKTYPESTRS[i]);
169 if (c->marktype == 'l') {
170 show_lmark(c->lmark, nsp+2, g);
171 spaces(nsp);
172 }
173 printf("marksize %f %f ", ptodist(c->marksize[0], g->x_axis),
174 ptodist(c->marksize[1], g->y_axis));
175 printf("mrotate %f ", c->mrotate);
176 if (c->filltype == 'g') {
177 printf("fill %f\n", c->fill[0] );
178 } else if (c->filltype == 'c') {
179 printf("cfill %f %f %f\n", c->fill[0], c->fill[1], c->fill[2] );
180 }
181 if (first(c->general_marks) != c->general_marks) {
182 spaces(nsp); printf("gmarks");
183 for(p = first(c->general_marks); p != nil(c->general_marks); p = next(p))
184 printf(" %f %f ", p->x, p->y);
185 }
186 printf("\n");
187 spaces(nsp);
188 if(!c->poly) printf("no"); printf("poly ");
189 if (c->pfilltype == 'g') {
190 printf("pfill %f", c->pfill[0] );
191 } else if (c->pfilltype == 'c') {
192 printf("pcfill %f %f %f", c->pfill[0], c->pfill[1], c->pfill[2] );
193 }
194 printf("\n");
195
196 spaces(nsp); printf("linetype ");
197 if (c->linetype == '0') printf("none ");
198 else if (c->linetype == 's') printf("solid ");
199 else if (c->linetype == '.') printf("dotted ");
200 else if (c->linetype == '-') printf("dashed ");
201 else if (c->linetype == 'l') printf("longdash ");
202 else if (c->linetype == 'd') printf("dotdash ");
203 else if (c->linetype == 'D') printf("dotdotdash ");
204 else if (c->linetype == '2') printf("dotdotdashdash ");
205 else if (c->linetype == 'g') {
206 printf("general\n");
207 spaces(nsp+2);
208 printf("glines ");
209 i = 0;
210 for (fl = first(c->gen_linetype); fl != nil(c->gen_linetype);
211 fl = next(fl)) {
212 if (i == 6) {
213 printf("\n");
214 spaces(nsp + 9);
215 i = 0;
216 }
217 printf("%f ", fl->f);
218 i++;
219 }
220 printf("\n");
221 spaces(nsp);
222 }
223 printf("linethickness %f\n", c->linethick);
224 spaces(nsp);
225 if (c->graytype == 'g') {
226 printf("gray %f ", c->gray[0]);
227 } else if (c->graytype == 'c') {
228 printf("color %f %f %f ", c->gray[0], c->gray[1], c->gray[2]);
229 }
230 if(!c->clip) printf("no"); printf("clip\n");
231 spaces(nsp);
232 for (i = 0; i < NPATTERNS && PTYPES[i] != c->pattern; i++) ;
233 printf("pattern %s %f ", PATTERNS[i], c->parg);
234 for (i = 0; i < NPATTERNS && PTYPES[i] != c->ppattern; i++) ;
235 printf("ppattern %s %f ", PATTERNS[i], c->pparg);
236 for (i = 0; i < NPATTERNS && PTYPES[i] != c->apattern; i++) ;
237 printf("apattern %s %f\n", PATTERNS[i], c->aparg);
238 spaces(nsp);
239 if(!c->rarrow) printf("no"); printf("rarrow ");
240 if(!c->larrow) printf("no"); printf("larrow ");
241 if(!c->rarrows) printf("no"); printf("rarrows ");
242 if(!c->larrows) printf("no"); printf("larrows ");
243 if (c->afilltype == 'g') {
244 printf("afill %f\n", c->afill[0] );
245 } else if (c->afilltype == 'c') {
246 printf("acfill %f %f %f\n", c->afill[0], c->afill[1], c->afill[2] );
247 }
248 spaces(nsp);
249 if(!c->bezier) printf("no"); printf("bezier ");
250 printf("asize %f %f\n", ptodist(c->asize[0], g->x_axis),
251 ptodist(c->asize[1], g->y_axis) * 2.0);
252}
253
254show_axis(a, nsp, g)
255Axis a;
256int nsp;
257Graph g;
258{
259 Axis other;
260 Hash h;
261 String s;
262
263 if (a->is_x) other = g->y_axis; else other = g->x_axis;
264 spaces(nsp); printf("size %f\n", a->size);
265 spaces(nsp); printf("min %f max %f %s\n", a->min, a->max,
266 (a->is_lg) ? "log" : "linear");
267 if (!(a->draw_hash_labels || a->draw_axis_line ||
268 a->draw_hash_marks || a->draw_axis_label)) {
269 spaces(nsp);
270 printf("nodraw\n");
271 return;
272 }
273 spaces(nsp); printf("draw_at %f\n", ptoc(a->draw_at, other));
274 if (a->label->label != CNULL) {
275 spaces(nsp); printf("label\n");
276 show_label(a->label, nsp+2, g);
277 }
278 spaces(nsp);
279 printf("%sdraw_hash_labels\n", (a->draw_hash_labels) ? "" : "no_");
280 spaces(nsp);
281 printf("%sdraw_axis_line\n", (a->draw_axis_line) ? "" : "no_");
282 spaces(nsp);
283 printf("%sdraw_hash_marks\n", (a->draw_hash_marks) ? "" : "no_");
284 spaces(nsp);
285 printf("%sgrid_lines\n", (a->grid_lines) ? "" : "no_");
286 spaces(nsp);
287 printf("%smgrid_lines\n", (a->mgrid_lines) ? "" : "no_");
288 spaces(nsp);
289 printf("%sdraw_axis_label\n", (a->draw_axis_label) ? "" : "no_");
290 spaces(nsp);
291 if (a->graytype == 'g') {
292 printf("gray %f\n", a->gray[0]);
293 } else if (a->graytype == 'c') {
294 printf("color %f %f %f\n", a->gray[0], a->gray[1], a->gray[2]);
295 }
296 spaces(nsp);
297 if (a->gr_graytype == 'g') {
298 printf("gr_gray %f ", a->gr_gray[0]);
299 } else if (a->gr_graytype == 'c') {
300 printf("color %f %f %f ", a->gr_gray[0], a->gr_gray[1], a->gr_gray[2]);
301 }
302 if (a->mgr_graytype == 'g') {
303 printf("mgr_gray %f\n", a->mgr_gray[0]);
304 } else if (a->mgr_graytype == 'c') {
305 printf("color %f %f %f\n", a->mgr_gray[0], a->mgr_gray[1], a->mgr_gray[2]);
306 }
307
308 spaces(nsp);
309
310 printf("(* The real settings for generating auto_hash_labels:\n");
311 spaces(nsp+5);
312 printf("%sauto_hash_marks ", (a->auto_hash_marks) ? "" : "no_");
313 printf("%sauto_hash_labels\n", (a->auto_hash_labels) ? "" : "no_");
314 spaces(nsp+5); printf("hash %f shash %f mhash %d hash_format %c\n",
315 a->hash_interval, a->hash_start, a->minor_hashes,
316 a->hash_format);
317 spaces(nsp+5);
318 if (a->is_lg) {
319 printf("log_base %f ", a->log_base);
320 }
321 printf("hash_scale %f ", a->hash_scale);
322 printf("precision %d\n", a->precision);
323 spaces(nsp+3);
324 printf("The following are explicit and implicit hash marks and labels *)\n");
325
326 spaces(nsp);
327 printf("hash 0 draw_hash_marks_at %f draw_hash_labels_at %f\n",
328 ptoc(a->draw_hash_marks_at, other),
329 ptoc(a->draw_hash_labels_at, other));
330 spaces(nsp); printf("hash_labels (* The :, x, and y values are ignored *)\n");
331 show_label(a->hl, nsp + 2, g);
332
333 for (h = first(a->hash_lines); h != nil(a->hash_lines); h = next(h)) {
334 spaces(nsp);
335 printf("%s %f\n", ((h->size == HASH_SIZE) ? "hash_at" : "mhash_at"),
336 ptoc(h->loc, a));
337 }
338 for (s = first(a->hash_labels); s != nil(a->hash_labels); s = next(s)) {
339 spaces(nsp);
340 printf("hash_label at %f ", ptoc(s->s->x, a));
341 show_string(s->s->label);
342 }
343}
344
345show_legend(l, nsp, g)
346Legend l;
347int nsp;
348Graph g;
349{
350 if (l->type == 'c') {
351 spaces(nsp); printf("custom\n");
352 } else if (l->type == 'n') {
353 spaces(nsp); printf("off\n");
354 }
355
356 spaces(nsp); printf("linelength %f linebreak %f midspace %f\n",
357 ptodist(l->linelength, g->x_axis), ptodist(l->linebreak, g->y_axis),
358 ptodist(l->midspace, g->x_axis));
359 if (l->type == 'u') {
360 spaces(nsp); printf("defaults");
361 show_label(l->l, nsp+2, g);
362 }
363}
364
365show_graph(g, nsp)
366Graph g;
367int nsp;
368{
369
370 Curve c;
371 String s;
372 spaces(nsp); printf("x_translate %f y_translate %f\n",
373 ptoin(g->x_translate), ptoin(g->y_translate));
374 spaces(nsp); printf("xaxis\n"); show_axis(g->x_axis, nsp+2, g);
375 spaces(nsp); printf("yaxis\n"); show_axis(g->y_axis, nsp+2, g);
376 spaces(nsp); if(!g->clip) printf("no"); printf("clip ");
377 if(!g->border) printf("no"); printf("border\n");
378 for (c = first(g->curves); c != nil(g->curves); c = next(c)) {
379 spaces(nsp);
380 printf("curve %d\n", c->num);
381 show_curve(c, nsp+2, g);
382 }
383 spaces(nsp); printf("legend\n");
384 show_legend(g->legend, nsp+2, g);
385 if (g->title->label != CNULL) {
386 spaces(nsp);
387 printf("title\n");
388 show_label(g->title, nsp+2, g);
389 }
390 for (s = first(g->strings); s != nil(g->strings); s = next(s)) {
391 spaces(nsp);
392 printf("string %d\n", s->num);
393 show_label(s->s, nsp+2, g);
394 }
395}
396
397show_graphs(gs)
398Graphs gs;
399{
400 Graphs the_g;
401 Graph g;
402 char started;
403 int i;
404
405 started = 0;
406 for (the_g = first(gs); the_g != nil(gs); the_g = next(the_g)) {
407 if (started) printf("\nnewpage\n");
408 started = 1;
409 printf("X %f Y %f\n", ptoin(the_g->width), ptoin(the_g->height));
410 if (the_g->preamble != CNULL) {
411 printf("preamble ");
412 if (!the_g->prefile) printf(": ");
413 show_mltiline(the_g->preamble);
414 }
415 if (the_g->epilogue != CNULL) {
416 printf("epilogue ");
417 if (!the_g->epifile) printf(": ");
418 show_mltiline(the_g->epilogue);
419 }
420 printf("bbox");
421 for (i = 0; i < 4; i++) printf(" %d", the_g->bb[i]);
422 printf("\n");
423 for (g = first(the_g->g); g != nil(the_g->g); g = next(g)) {
424 printf("graph %d\n", g->num);
425 show_graph(g, 2);
426 }
427 }
428}
429
430
Note: See TracBrowser for help on using the repository browser.