~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to display/d.histogram/bar.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
 */
28
28
 
29
29
#include <string.h>
 
30
 
 
31
#include <grass/raster.h>
30
32
#include <grass/display.h>
31
 
#include <grass/raster.h>
 
33
 
32
34
#include "bar.h"
33
35
 
34
36
int bar(struct stat_list *dist_stats,   /* list of distribution statistics */
52
54
    long int tic_every;         /* spacing, in units of category value, of tics */
53
55
 
54
56
    long int tic_unit;
55
 
    int t, b, l, r;
56
 
    int tt, tb, tl, tr;
57
 
    int x_line[3];              /* for border of histogram */
58
 
    int y_line[3];
59
 
    int x_box[5];               /* for histogram bar coordinates */
60
 
    int y_box[5];
 
57
    double t, b, l, r;
 
58
    double tt, tb, tl, tr;
 
59
    double x_line[3];           /* for border of histogram */
 
60
    double y_line[3];
 
61
    double x_box[5];            /* for histogram bar coordinates */
 
62
    double y_box[5];
61
63
    double height, width;
62
64
    double xscale;              /* scaling factors */
63
65
    double yscale;
65
67
    char ylabel[1024];
66
68
    char txt[1024];
67
69
    char tic_name[80];
68
 
    extern int stash_away();
69
70
 
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);
73
73
 
74
74
    /* create axis lines, to be drawn later */
75
75
    height = b - t;
76
76
    width = r - l;
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);
81
81
 
82
82
    /* figure scaling factors and offsets */
83
83
    num_cats = dist_stats->maxcat - dist_stats->mincat + 1;
86
86
        num_cats++;
87
87
        dist_stats->mincat--;
88
88
    }
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];
93
93
    else
104
104
            max_tics--;
105
105
        i = 0;
106
106
        if (is_fp) {
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");
111
111
 
112
112
            if ((range_dmax - range_dmin) < 1.0)
126
126
    }
127
127
    else {
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");
133
133
        }
134
134
        tic_every = 1;
162
162
                draw = NO;
163
163
            else {
164
164
                draw = YES;
165
 
                G_set_c_null_value(&bar_color, 1);
 
165
                Rast_set_c_null_value(&bar_color, 1);
166
166
                bar_height =
167
 
                    (int)(yoffset - yscale * (double)dist_stats->null_stat);
 
167
                    (yoffset - yscale * (double)dist_stats->null_stat);
168
168
            }
169
169
        }
170
170
        else if (ptr->cat == i) {       /* AH-HA!! found the stat */
173
173
            else {
174
174
                draw = YES;
175
175
                bar_color = ptr->cat;
176
 
                bar_height = (int)(yoffset - yscale * (double)ptr->stat);
 
176
                bar_height = (yoffset - yscale * (double)ptr->stat);
177
177
            }
178
178
            if (ptr->next != NULL)
179
179
                ptr = ptr->next;
189
189
                else {
190
190
                    draw = YES;
191
191
                    bar_color = ptr->cat;
192
 
                    bar_height = (int)(yoffset - yscale * (double)ptr->stat);
 
192
                    bar_height = (yoffset - yscale * (double)ptr->stat);
193
193
                }
194
194
                if (ptr->next != NULL)
195
195
                    ptr = ptr->next;
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) {
218
218
                    if (cat_ranges)
219
 
                        G_get_ith_d_raster_cat(&cats, bar_color,
 
219
                        Rast_get_ith_d_cat(&cats, bar_color,
220
220
                                               &dmin, &dmax);
221
221
                    else {
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;
226
224
                    }
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);
240
238
                        }
241
239
                    }
242
240
                    else {      /* 1-color bar */
250
248
                                       0.5 * xscale);
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);
254
252
                    }
255
253
                }               /* fp */
256
254
                else {          /* 1-color bar for int data or null */
264
262
                                   0.5 * xscale);
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);
268
266
                }
269
267
            }
270
268
            else {
271
269
                /* draw the bar as a line */
272
270
                if (is_fp) {
273
271
                    if (cat_ranges)
274
 
                        G_get_ith_d_raster_cat(&cats, bar_color,
 
272
                        Rast_get_ith_d_cat(&cats, bar_color,
275
273
                                               &dmin, &dmax);
276
274
                    else {
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;
281
277
                    }
282
278
                    D_d_color(dmin, colors);
283
279
                }
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]);
292
287
            }
293
288
        }
294
289
 
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)) {
 
297
 
302
298
            /* draw a numbered tic-mark */
303
 
            D_raster_use_color(color);
304
 
            R_move_abs((int)
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)));
 
299
            D_use_color(color);
 
300
            D_begin();
 
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));
 
304
            D_end();
 
305
            D_stroke();
 
306
 
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);
327
326
            }
328
 
            R_move_abs((int)
329
 
                       (xoffset + (i - dist_stats->mincat) * xscale -
330
 
                        0.5 * xscale - (tr - tl) / 2),
331
 
                       (int)(b - XNUMS_Y * (b - t)));
332
 
            R_text(txt);
 
327
            D_pos_abs(xoffset + (i - dist_stats->mincat) * xscale - 0.5 * xscale - (tr - tl) / 2,
 
328
                      b - XNUMS_Y * (b - t));
 
329
            D_text(txt);
333
330
        }
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);
337
 
            R_move_abs((int)
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)));
 
333
            D_use_color(color);
 
334
            D_begin();
 
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));
 
338
            D_end();
 
339
            D_stroke();
341
340
        }
342
341
    }
343
342
 
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);
356
 
    R_text(xlabel);
 
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));
 
354
    D_use_color(color);
 
355
    D_text(xlabel);
357
356
 
358
357
    /* DRAW Y-AXIS TIC-MARKS AND NUMBERS
359
358
     * 
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);
 
385
            D_begin();
 
386
            D_move_abs(x_line[0], yoffset - yscale * i);
 
387
            D_cont_rel((-(r - l) * BIG_TIC), 0);
 
388
            D_end();
 
389
            D_stroke();
388
390
 
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);
400
402
            }
401
 
            R_move_abs((int)(l + (r - l) * YNUMS_X - (tr - tl) / 2),
402
 
                       (int)(yoffset - (yscale * i + 0.5 * (tt - tb))));
403
 
            R_text(txt);
 
403
            D_pos_abs(l + (r - l) * YNUMS_X - (tr - tl) / 2,
 
404
                      yoffset - (yscale * i + 0.5 * (tt - tb)));
 
405
            D_text(txt);
404
406
        }
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);
 
409
            D_begin();
 
410
            D_move_abs(x_line[0], yoffset - yscale * i);
 
411
            D_cont_rel(-(r - l) * SMALL_TIC, 0);
 
412
            D_end();
 
413
            D_stroke();
409
414
        }
410
415
    }
411
416
 
425
430
 
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
 
    R_text(ylabel);
 
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));
 
437
    D_use_color(color);
 
438
    D_text(ylabel);
434
439
 
435
440
    /* draw x and y axis lines */
436
 
    D_raster_use_color(color);
437
 
    R_polyline_abs(x_line, y_line, 3);
 
441
    D_use_color(color);
 
442
    D_polyline_abs(x_line, y_line, 3);
438
443
 
439
444
    return 0;
440
445
}