source: trunk/Jgraph/show.c@ 677

Last change on this file since 677 was 420, checked in by Nicholas Riley, 17 years ago

Jgraph: my changes - ANSIfication, few minor bug fixes; works on OS X 10.5 now

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