52
54
long int tic_every; /* spacing, in units of category value, of tics */
57
int x_line[3]; /* for border of histogram */
59
int x_box[5]; /* for histogram bar coordinates */
58
double tt, tb, tl, tr;
59
double x_line[3]; /* for border of histogram */
61
double x_box[5]; /* for histogram bar coordinates */
61
63
double height, width;
62
64
double xscale; /* scaling factors */
68
extern int stash_away();
70
/* get coordinates of current screen window, in pixels */
71
D_get_screen_window(&t, &b, &l, &r);
72
R_set_window(t, b, l, r);
71
/* get coordinates of current screen window */
72
D_get_src(&t, &b, &l, &r);
74
74
/* create axis lines, to be drawn later */
77
x_line[0] = x_line[1] = l + (int)(ORIGIN_X * width);
78
x_line[2] = l + (int)(XAXIS_END * width);
79
y_line[0] = b - (int)(YAXIS_END * height);
80
y_line[1] = y_line[2] = b - (int)(ORIGIN_Y * height);
77
x_line[0] = x_line[1] = l + (ORIGIN_X * width);
78
x_line[2] = l + (XAXIS_END * width);
79
y_line[0] = b - (YAXIS_END * height);
80
y_line[1] = y_line[2] = b - (ORIGIN_Y * height);
82
82
/* figure scaling factors and offsets */
83
83
num_cats = dist_stats->maxcat - dist_stats->mincat + 1;
87
87
dist_stats->mincat--;
89
xscale = ((double)(x_line[2] - x_line[1]) / ((double)num_cats));
90
yscale = ((double)(y_line[1] - y_line[0])) / dist_stats->maxstat;
89
xscale = ((x_line[2] - x_line[1]) / ((double)num_cats));
90
yscale = ((y_line[1] - y_line[0])) / dist_stats->maxstat;
91
91
if (num_cats >= x_line[2] - x_line[1])
92
92
xoffset = (long int)x_line[1];
107
G_get_fp_range_min_max(&fp_range, &range_dmin, &range_dmax);
108
if (G_is_d_null_value(&range_dmin) ||
109
G_is_d_null_value(&range_dmax))
107
Rast_get_fp_range_min_max(&fp_range, &range_dmin, &range_dmax);
108
if (Rast_is_d_null_value(&range_dmin) ||
109
Rast_is_d_null_value(&range_dmax))
110
110
G_fatal_error("Floating point data range is empty");
112
112
if ((range_dmax - range_dmin) < 1.0)
128
128
if (is_fp && !cat_ranges) {
129
G_get_fp_range_min_max(&fp_range, &range_dmin, &range_dmax);
130
if (G_is_d_null_value(&range_dmin) ||
131
G_is_d_null_value(&range_dmax))
129
Rast_get_fp_range_min_max(&fp_range, &range_dmin, &range_dmax);
130
if (Rast_is_d_null_value(&range_dmin) ||
131
Rast_is_d_null_value(&range_dmax))
132
132
G_fatal_error("Floating point data range is empty");
165
G_set_c_null_value(&bar_color, 1);
165
Rast_set_c_null_value(&bar_color, 1);
167
(int)(yoffset - yscale * (double)dist_stats->null_stat);
167
(yoffset - yscale * (double)dist_stats->null_stat);
170
170
else if (ptr->cat == i) { /* AH-HA!! found the stat */
214
214
if (draw == YES) {
215
215
if (xscale != 1) {
216
216
/* draw the bar as a box */
217
if (!G_is_c_null_value(&bar_color) && is_fp) {
217
if (!Rast_is_c_null_value(&bar_color) && is_fp) {
219
G_get_ith_d_raster_cat(&cats, bar_color,
219
Rast_get_ith_d_cat(&cats, bar_color,
222
dmin = range_dmin + (double)i *
223
(range_dmax - range_dmin) / (double)nsteps;
224
dmax = range_dmin + (double)(i + 1) *
225
(range_dmax - range_dmin) / (double)nsteps;
222
dmin = range_dmin + i * (range_dmax - range_dmin) / nsteps;
223
dmax = range_dmin + (i + 1) * (range_dmax - range_dmin) / nsteps;
227
225
if (dmin != dmax) {
228
226
for (j = 0; j < xscale; j++) {
236
234
0.5 * xscale + j + 1);
237
235
y_box[0] = y_box[3] = yoffset;
238
236
y_box[1] = y_box[2] = bar_height;
239
R_polygon_abs(x_box, y_box, 4);
237
D_polygon_abs(x_box, y_box, 4);
242
240
else { /* 1-color bar */
251
249
y_box[0] = y_box[3] = yoffset;
252
250
y_box[1] = y_box[2] = bar_height;
253
R_polygon_abs(x_box, y_box, 4);
251
D_polygon_abs(x_box, y_box, 4);
256
254
else { /* 1-color bar for int data or null */
265
263
y_box[0] = y_box[3] = yoffset;
266
264
y_box[1] = y_box[2] = bar_height;
267
R_polygon_abs(x_box, y_box, 4);
265
D_polygon_abs(x_box, y_box, 4);
271
269
/* draw the bar as a line */
274
G_get_ith_d_raster_cat(&cats, bar_color,
272
Rast_get_ith_d_cat(&cats, bar_color,
277
dmin = range_dmin + (double)i *
278
(range_dmax - range_dmin) / (double)nsteps;
279
dmax = range_dmin + (double)(i + 1) *
280
(range_dmax - range_dmin) / (double)nsteps;
275
dmin = range_dmin + i * (range_dmax - range_dmin) / nsteps;
276
dmax = range_dmin + (i + 1) * (range_dmax - range_dmin) / nsteps;
282
278
D_d_color(dmin, colors);
287
283
xoffset + (i - dist_stats->mincat) * xscale;
288
284
y_box[0] = yoffset;
289
285
y_box[1] = bar_height;
290
R_move_abs((int)x_box[0], (int)y_box[0]);
291
R_cont_abs((int)x_box[1], (int)y_box[1]);
286
D_line_abs(x_box[0], y_box[0], x_box[1], y_box[1]);
299
294
if (((rem((long int)i, tic_every) == 0L) ||
300
295
((i == dist_stats->mincat) && nodata))
301
296
&& !(nodata && i == dist_stats->mincat + 1)) {
302
298
/* draw a numbered tic-mark */
303
D_raster_use_color(color);
305
(xoffset + (i - dist_stats->mincat) * xscale -
306
0.5 * xscale), (int)(b - ORIGIN_Y * (b - t)));
307
R_cont_rel((int)0, (int)(BIG_TIC * (b - t)));
301
D_move_abs(xoffset + (i - dist_stats->mincat) * xscale - 0.5 * xscale,
302
b - ORIGIN_Y * (b - t));
303
D_cont_rel(0, BIG_TIC * (b - t));
308
307
if (nodata && i == dist_stats->mincat)
309
308
sprintf(txt, "null");
310
309
else if (is_fp) {
317
316
sprintf(txt, "%d", (int)(i / tic_unit));
318
317
text_height = (b - t) * TEXT_HEIGHT;
319
318
text_width = (r - l) * TEXT_WIDTH;
320
R_text_size(text_width, text_height);
321
R_get_text_box(txt, &tt, &tb, &tl, &tr);
319
D_text_size(text_width, text_height);
320
D_get_text_box(txt, &tt, &tb, &tl, &tr);
322
321
while ((tr - tl) > XTIC_DIST) {
323
322
text_width *= 0.75;
324
323
text_height *= 0.75;
325
R_text_size(text_width, text_height);
326
R_get_text_box(txt, &tt, &tb, &tl, &tr);
324
D_text_size(text_width, text_height);
325
D_get_text_box(txt, &tt, &tb, &tl, &tr);
329
(xoffset + (i - dist_stats->mincat) * xscale -
330
0.5 * xscale - (tr - tl) / 2),
331
(int)(b - XNUMS_Y * (b - t)));
327
D_pos_abs(xoffset + (i - dist_stats->mincat) * xscale - 0.5 * xscale - (tr - tl) / 2,
328
b - XNUMS_Y * (b - t));
334
else if (rem(i, tic_unit) == (float)0) {
331
else if (rem(i, tic_unit) == 0.0) {
335
332
/* draw a tic-mark */
336
D_raster_use_color(color);
338
(xoffset + (i - dist_stats->mincat) * xscale -
339
0.5 * xscale), (int)(b - ORIGIN_Y * (b - t)));
340
R_cont_rel((int)0, (int)(SMALL_TIC * (b - t)));
335
D_move_abs(xoffset + (i - dist_stats->mincat) * xscale - 0.5 * xscale,
336
b - ORIGIN_Y * (b - t));
337
D_cont_rel(0, SMALL_TIC * (b - t));
348
347
sprintf(xlabel, "X-AXIS: Cell Values");
349
348
text_height = (b - t) * TEXT_HEIGHT;
350
349
text_width = (r - l) * TEXT_WIDTH;
351
R_text_size(text_width, text_height);
352
R_get_text_box(xlabel, &tt, &tb, &tl, &tr);
353
R_move_abs((int)(l + (r - l) / 2 - (tr - tl) / 2),
354
(int)(b - LABEL_1 * (b - t)));
355
D_raster_use_color(color);
350
D_text_size(text_width, text_height);
351
D_get_text_box(xlabel, &tt, &tb, &tl, &tr);
352
D_pos_abs(l + (r - l) / 2 - (tr - tl) / 2,
353
b - LABEL_1 * (b - t));
358
357
/* DRAW Y-AXIS TIC-MARKS AND NUMBERS
383
382
for (i = stat_start; i <= stat_finis; i += tic_unit) {
384
383
if (rem(i, tic_every) == (float)0) {
385
384
/* draw a tic-mark */
386
R_move_abs((int)x_line[0], (int)(yoffset - yscale * i));
387
R_cont_rel((int)(-(r - l) * BIG_TIC), (int)0);
386
D_move_abs(x_line[0], yoffset - yscale * i);
387
D_cont_rel((-(r - l) * BIG_TIC), 0);
389
391
/* draw a tic-mark number */
390
392
sprintf(txt, "%d", (int)(i / tic_unit));
391
393
text_height = (b - t) * TEXT_HEIGHT;
392
394
text_width = (r - l) * TEXT_WIDTH;
393
R_text_size(text_width, text_height);
394
R_get_text_box(txt, &tt, &tb, &tl, &tr);
395
D_text_size(text_width, text_height);
396
D_get_text_box(txt, &tt, &tb, &tl, &tr);
395
397
while ((tt - tb) > YTIC_DIST) {
396
398
text_width *= 0.75;
397
399
text_height *= 0.75;
398
R_text_size(text_width, text_height);
399
R_get_text_box(txt, &tt, &tb, &tl, &tr);
400
D_text_size(text_width, text_height);
401
D_get_text_box(txt, &tt, &tb, &tl, &tr);
401
R_move_abs((int)(l + (r - l) * YNUMS_X - (tr - tl) / 2),
402
(int)(yoffset - (yscale * i + 0.5 * (tt - tb))));
403
D_pos_abs(l + (r - l) * YNUMS_X - (tr - tl) / 2,
404
yoffset - (yscale * i + 0.5 * (tt - tb)));
405
else if (rem(i, tic_unit) == (float)0) {
407
else if (rem(i, tic_unit) == 0.0) {
406
408
/* draw a tic-mark */
407
R_move_abs((int)x_line[0], (int)(yoffset - yscale * i));
408
R_cont_rel((int)(-(r - l) * SMALL_TIC), (int)0);
410
D_move_abs(x_line[0], yoffset - yscale * i);
411
D_cont_rel(-(r - l) * SMALL_TIC, 0);
426
431
text_height = (b - t) * TEXT_HEIGHT;
427
432
text_width = (r - l) * TEXT_WIDTH;
428
R_text_size(text_width, text_height);
429
R_get_text_box(ylabel, &tt, &tb, &tl, &tr);
430
R_move_abs((int)(l + (r - l) / 2 - (tr - tl) / 2),
431
(int)(b - LABEL_2 * (b - t)));
432
D_raster_use_color(color);
433
D_text_size(text_width, text_height);
434
D_get_text_box(ylabel, &tt, &tb, &tl, &tr);
435
D_pos_abs(l + (r - l) / 2 - (tr - tl) / 2,
436
b - LABEL_2 * (b - t));
435
440
/* draw x and y axis lines */
436
D_raster_use_color(color);
437
R_polyline_abs(x_line, y_line, 3);
442
D_polyline_abs(x_line, y_line, 3);