6 #include "Dimensions.h"
13 typedef enum {MEGABYTE, KILOBYTE, BYTE} mkb;
15 static void XAxis PROTO((void)); /* forward */
16 static void YAxis PROTO((void)); /* forward */
18 static void XAxisMark PROTO((floatish, floatish)); /* forward */
19 static void YAxisMark PROTO((floatish, floatish, mkb)); /* forward */
21 static floatish Round PROTO((floatish)); /* forward */
32 floatish x; floatish num;
34 /* calibration mark */
35 fprintf(psfp, "%f %f moveto\n", xpage(x), ypage(0.0));
36 fprintf(psfp, "0 -4 rlineto\n");
37 fprintf(psfp, "stroke\n");
40 fprintf(psfp, "HE%d setfont\n", NORMAL_FONT);
41 fprintf(psfp, "(%.1f)\n", num);
42 fprintf(psfp, "dup stringwidth pop\n");
43 fprintf(psfp, "2 div\n");
44 fprintf(psfp, "%f exch sub\n", xpage(x));
45 fprintf(psfp, "%f moveto\n", borderspace);
46 fprintf(psfp, "show\n");
53 extern floatish xrange;
54 extern char *sampleunitstring;
59 floatish increment, i;
63 /* draw the x axis line */
64 fprintf(psfp, "%f %f moveto\n", xpage(0.0), ypage(0.0));
65 fprintf(psfp, "%f 0 rlineto\n", graphwidth);
66 fprintf(psfp, "%f setlinewidth\n", borderthick);
67 fprintf(psfp, "stroke\n");
69 /* draw x axis legend */
70 fprintf(psfp, "HE%d setfont\n", NORMAL_FONT);
71 fprintf(psfp, "(%s)\n", sampleunitstring);
72 fprintf(psfp, "dup stringwidth pop\n");
73 fprintf(psfp, "%f\n", xpage(0.0) + graphwidth);
74 fprintf(psfp, "exch sub\n");
75 fprintf(psfp, "%f moveto\n", borderspace);
76 fprintf(psfp, "show\n");
79 /* draw x axis scaling */
81 increment = Round(xrange / (floatish) N_X_MARKS);
83 t = graphwidth / xrange;
84 legendlen = StringSize(sampleunitstring) + (floatish) XFUDGE;
86 for (i = samplemap[0]; i < samplemap[nsamples - 1]; i += increment) {
87 x = (i - samplemap[0]) * t;
89 if (x < (graphwidth - legendlen)) {
96 YAxisMark(y, num, unit)
97 floatish y; floatish num; mkb unit;
99 /* calibration mark */
100 fprintf(psfp, "%f %f moveto\n", xpage(0.0), ypage(y));
101 fprintf(psfp, "-4 0 rlineto\n");
102 fprintf(psfp, "stroke\n");
105 fprintf(psfp, "HE%d setfont\n", NORMAL_FONT);
110 CommaPrint(psfp, (intish) (num / 1e6 + 0.5));
111 fprintf(psfp, "M)\n");
115 CommaPrint(psfp, (intish) (num / 1e3 + 0.5));
116 fprintf(psfp, "k)\n");
120 CommaPrint(psfp, (intish) (num + 0.5));
121 fprintf(psfp, ")\n");
125 fprintf(psfp, "dup stringwidth\n");
126 fprintf(psfp, "2 div\n");
127 fprintf(psfp, "%f exch sub\n", ypage(y));
129 fprintf(psfp, "exch\n");
130 fprintf(psfp, "%f exch sub\n", graphx0 - borderspace);
132 fprintf(psfp, "exch\n");
133 fprintf(psfp, "moveto\n");
134 fprintf(psfp, "show\n");
140 extern floatish yrange;
141 extern char *valueunitstring;
146 floatish increment, i;
151 /* draw the y axis line */
152 fprintf(psfp, "%f %f moveto\n", xpage(0.0), ypage(0.0));
153 fprintf(psfp, "0 %f rlineto\n", graphheight);
154 fprintf(psfp, "%f setlinewidth\n", borderthick);
155 fprintf(psfp, "stroke\n");
157 /* draw y axis legend */
158 fprintf(psfp, "gsave\n");
159 fprintf(psfp, "HE%d setfont\n", NORMAL_FONT);
160 fprintf(psfp, "(%s)\n", valueunitstring);
161 fprintf(psfp, "dup stringwidth pop\n");
162 fprintf(psfp, "%f\n", ypage(0.0) + graphheight);
163 fprintf(psfp, "exch sub\n");
164 fprintf(psfp, "%f exch\n", xpage(0.0) - borderspace);
165 fprintf(psfp, "translate\n");
166 fprintf(psfp, "90 rotate\n");
167 fprintf(psfp, "0 0 moveto\n");
168 fprintf(psfp, "show\n");
169 fprintf(psfp, "grestore\n");
171 /* draw y axis scaling */
172 increment = max( yrange / (floatish) N_Y_MARKS, 1.0);
173 increment = Round(increment);
175 if (increment >= 1e6) {
177 } else if (increment >= 1e3) {
183 t = graphheight / yrange;
184 legendlen = StringSize(valueunitstring) + (floatish) YFUDGE;
186 for (i = 0.0; i <= yrange; i += increment) {
189 if (y < (graphheight - legendlen)) {
190 YAxisMark(y, i, unit);
197 * Find a "nice round" value to use on the axis.
200 static floatish OneTwoFive PROTO((floatish)); /* forward */
209 for (i = 0; y > 10.0; y /= 10.0, i++) ;
211 for ( ; i > 0; y = y * 10.0, i--) ;
213 } else if (y < 1.0) {
214 for (i = 0; y < 1.0; y *= 10.0, i++) ;
216 for ( ; i > 0; y = y / 10.0, i--) ;
227 * OneTwoFive() -- Runciman's 1,2,5 scaling rule. Argument 1.0 <= y <= 10.0.
236 } else if (y > 1.0) {