1
/* This file is part of hp2ps, a graph drawer for memory profiles.
2
Copyright (C) 2002 The University Court of the University of Glasgow.
3
This program is governed by the license contained in the file LICENSE. */
10
#include "Dimensions.h"
12
#include "Utilities.h"
17
typedef enum {MEGABYTE, KILOBYTE, BYTE} mkb;
19
static void XAxis PROTO((void)); /* forward */
20
static void YAxis PROTO((void)); /* forward */
22
static void XAxisMark PROTO((floatish, floatish)); /* forward */
23
static void YAxisMark PROTO((floatish, floatish, mkb)); /* forward */
25
static floatish Round PROTO((floatish)); /* forward */
36
floatish x; floatish num;
38
/* calibration mark */
39
fprintf(psfp, "%f %f moveto\n", xpage(x), ypage(0.0));
40
fprintf(psfp, "0 -4 rlineto\n");
41
fprintf(psfp, "stroke\n");
44
fprintf(psfp, "HE%d setfont\n", NORMAL_FONT);
45
fprintf(psfp, "(%.1f)\n", num);
46
fprintf(psfp, "dup stringwidth pop\n");
47
fprintf(psfp, "2 div\n");
48
fprintf(psfp, "%f exch sub\n", xpage(x));
49
fprintf(psfp, "%f moveto\n", borderspace);
50
fprintf(psfp, "show\n");
57
extern floatish xrange;
58
extern char *sampleunitstring;
63
floatish increment, i;
67
/* draw the x axis line */
68
fprintf(psfp, "%f %f moveto\n", xpage(0.0), ypage(0.0));
69
fprintf(psfp, "%f 0 rlineto\n", graphwidth);
70
fprintf(psfp, "%f setlinewidth\n", borderthick);
71
fprintf(psfp, "stroke\n");
73
/* draw x axis legend */
74
fprintf(psfp, "HE%d setfont\n", NORMAL_FONT);
75
fprintf(psfp, "(%s)\n", sampleunitstring);
76
fprintf(psfp, "dup stringwidth pop\n");
77
fprintf(psfp, "%f\n", xpage(0.0) + graphwidth);
78
fprintf(psfp, "exch sub\n");
79
fprintf(psfp, "%f moveto\n", borderspace);
80
fprintf(psfp, "show\n");
83
/* draw x axis scaling */
85
increment = Round(xrange / (floatish) N_X_MARKS);
87
t = graphwidth / xrange;
88
legendlen = StringSize(sampleunitstring) + (floatish) XFUDGE;
90
for (i = samplemap[0]; i < samplemap[nsamples - 1]; i += increment) {
91
x = (i - samplemap[0]) * t;
93
if (x < (graphwidth - legendlen)) {
100
YAxisMark(y, num, unit)
101
floatish y; floatish num; mkb unit;
103
/* calibration mark */
104
fprintf(psfp, "%f %f moveto\n", xpage(0.0), ypage(y));
105
fprintf(psfp, "-4 0 rlineto\n");
106
fprintf(psfp, "stroke\n");
109
fprintf(psfp, "HE%d setfont\n", NORMAL_FONT);
114
CommaPrint(psfp, (intish) (num / 1e6 + 0.5));
115
fprintf(psfp, "M)\n");
119
CommaPrint(psfp, (intish) (num / 1e3 + 0.5));
120
fprintf(psfp, "k)\n");
124
CommaPrint(psfp, (intish) (num + 0.5));
125
fprintf(psfp, ")\n");
129
fprintf(psfp, "dup stringwidth\n");
130
fprintf(psfp, "2 div\n");
131
fprintf(psfp, "%f exch sub\n", ypage(y));
133
fprintf(psfp, "exch\n");
134
fprintf(psfp, "%f exch sub\n", graphx0 - borderspace);
136
fprintf(psfp, "exch\n");
137
fprintf(psfp, "moveto\n");
138
fprintf(psfp, "show\n");
144
extern floatish yrange;
145
extern char *valueunitstring;
150
floatish increment, i;
155
/* draw the y axis line */
156
fprintf(psfp, "%f %f moveto\n", xpage(0.0), ypage(0.0));
157
fprintf(psfp, "0 %f rlineto\n", graphheight);
158
fprintf(psfp, "%f setlinewidth\n", borderthick);
159
fprintf(psfp, "stroke\n");
161
/* draw y axis legend */
162
fprintf(psfp, "gsave\n");
163
fprintf(psfp, "HE%d setfont\n", NORMAL_FONT);
164
fprintf(psfp, "(%s)\n", valueunitstring);
165
fprintf(psfp, "dup stringwidth pop\n");
166
fprintf(psfp, "%f\n", ypage(0.0) + graphheight);
167
fprintf(psfp, "exch sub\n");
168
fprintf(psfp, "%f exch\n", xpage(0.0) - borderspace);
169
fprintf(psfp, "translate\n");
170
fprintf(psfp, "90 rotate\n");
171
fprintf(psfp, "0 0 moveto\n");
172
fprintf(psfp, "show\n");
173
fprintf(psfp, "grestore\n");
175
/* draw y axis scaling */
176
increment = max( yrange / (floatish) N_Y_MARKS, 1.0);
177
increment = Round(increment);
179
if (increment >= 1e6) {
181
} else if (increment >= 1e3) {
187
t = graphheight / yrange;
188
legendlen = StringSize(valueunitstring) + (floatish) YFUDGE;
190
for (i = 0.0; i <= yrange; i += increment) {
193
if (y < (graphheight - legendlen)) {
194
YAxisMark(y, i, unit);
201
* Find a "nice round" value to use on the axis.
204
static floatish OneTwoFive PROTO((floatish)); /* forward */
213
for (i = 0; y > 10.0; y /= 10.0, i++) ;
215
for ( ; i > 0; y = y * 10.0, i--) ;
217
} else if (y < 1.0) {
218
for (i = 0; y < 1.0; y *= 10.0, i++) ;
220
for ( ; i > 0; y = y / 10.0, i--) ;
231
* OneTwoFive() -- Runciman's 1,2,5 scaling rule. Argument 1.0 <= y <= 10.0.
240
} else if (y > 1.0) {