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

« back to all changes in this revision

Viewing changes to display/d.histogram/pie.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:
29
29
 */
30
30
 
31
31
#include <string.h>
 
32
 
 
33
#include <grass/raster.h>
32
34
#include <grass/display.h>
33
 
#include <grass/raster.h>
 
35
 
34
36
#include "pie.h"
35
37
 
36
38
/*#define DEBUG */
56
58
    long int num_cats;
57
59
    long int tic_every;         /* spacing, in units of category value, of tics */
58
60
    long int tic_unit;
59
 
    int t, b, l, r;
60
 
    int tt, tb, tl, tr;
61
 
    int x_line[5];              /* for border of histogram */
62
 
    int y_line[5];
63
 
    int x_box[6];               /* for histogram bar coordinates */
64
 
    int y_box[6];
 
61
    double t, b, l, r;
 
62
    double tt, tb, tl, tr;
 
63
    double x_line[5];           /* for border of histogram */
 
64
    double y_line[5];
 
65
    double x_box[6];            /* for histogram bar coordinates */
 
66
    double y_box[6];
65
67
    double height, width;
66
68
    double xscale;              /* scaling factors */
67
69
    double yscale;
70
72
    char tic_name[80];
71
73
    DCELL dmin, dmax, range_dmin, range_dmax, dval;
72
74
 
73
 
    /* get coordinates of current screen window, in pixels */
74
 
    D_get_screen_window(&t, &b, &l, &r);
75
 
    R_set_window(t, b, l, r);
 
75
    /* get coordinates of current screen window */
 
76
    D_get_src(&t, &b, &l, &r);
76
77
 
77
78
    /* create legend box border, to be drawn later */
78
79
    height = b - t;
79
80
    width = r - l;
80
 
    x_line[4] = x_line[0] = x_line[1] = l + (int)(BAR_X1 * width);
81
 
    y_line[4] = y_line[0] = y_line[3] = b - (int)(BAR_Y1 * height);
82
 
    x_line[2] = x_line[3] = l + (int)(BAR_X2 * width);
83
 
    bar_height = y_line[1] = y_line[2] = b - (int)(BAR_Y2 * height);
 
81
    x_line[4] = x_line[0] = x_line[1] = l + (BAR_X1 * width);
 
82
    y_line[4] = y_line[0] = y_line[3] = b - (BAR_Y1 * height);
 
83
    x_line[2] = x_line[3] = l + (BAR_X2 * width);
 
84
    bar_height = y_line[1] = y_line[2] = b - (BAR_Y2 * height);
84
85
 
85
86
    /* figure scaling factors and offsets */
86
87
    num_cats = dist_stats->maxcat - dist_stats->mincat + 1;
109
110
        max_tics = (x_line[2] - x_line[1]) / XTIC_DIST;
110
111
        i = 0;
111
112
        if (is_fp) {
112
 
            G_get_fp_range_min_max(&fp_range, &range_dmin, &range_dmax);
113
 
            if (G_is_d_null_value(&range_dmin) ||
114
 
                G_is_d_null_value(&range_dmax))
 
113
            Rast_get_fp_range_min_max(&fp_range, &range_dmin, &range_dmax);
 
114
            if (Rast_is_d_null_value(&range_dmin) ||
 
115
                Rast_is_d_null_value(&range_dmax))
115
116
                G_fatal_error("Floating point data range is empty");
116
117
 
117
118
            while ((range_dmax - range_dmin) / tics[i].every > max_tics)
126
127
    }
127
128
    else {
128
129
        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))
 
130
            Rast_get_fp_range_min_max(&fp_range, &range_dmin, &range_dmax);
 
131
            if (Rast_is_d_null_value(&range_dmin) ||
 
132
                Rast_is_d_null_value(&range_dmax))
132
133
                G_fatal_error("Floating point data range is empty");
133
134
        }
134
135
        tic_every = 1;
146
147
    ptr = dist_stats->ptr;
147
148
    arc_counter = 0;
148
149
    for (i = dist_stats->mincat; i <= dist_stats->maxcat; i++) {
149
 
        text_height = (height) * 0.7 * TEXT_HEIGHT;
150
 
        text_width = (width) * 0.7 * TEXT_WIDTH;
151
 
        R_text_size(text_width, text_height);
 
150
        text_height = height * 0.7 * TEXT_HEIGHT;
 
151
        text_width = width * 0.7 * TEXT_WIDTH;
 
152
        D_text_size(text_width, text_height);
152
153
        draw = NO;
153
154
        /* figure color and height of the slice of pie 
154
155
         *
166
167
                draw = NO;
167
168
            else {
168
169
                draw = YES;
169
 
                G_set_d_null_value(&dval, 1);
170
 
                arc = (double)360 *((double)dist_stats->null_stat
 
170
                Rast_set_d_null_value(&dval, 1);
 
171
                arc = 360.0 *((double)dist_stats->null_stat
171
172
                                    / (double)dist_stats->sumstat);
172
 
                draw_slice_filled(colors, dval, (int)color, (double)ORIGIN_X,
173
 
                                  (double)ORIGIN_Y, (double)RADIUS,
 
173
                draw_slice_filled(colors, dval, color, ORIGIN_X,
 
174
                                  ORIGIN_Y, RADIUS,
174
175
                                  arc_counter, arc);
175
176
                /*OUTLINE THE SLICE
176
 
                   draw_slice_unfilled(colors, (int)color,(double)ORIGIN_X,(double)ORIGIN_Y,
177
 
                   (double)RADIUS,arc_counter,arc); */
 
177
                   draw_slice_unfilled(colors, color,ORIGIN_X,ORIGIN_Y,
 
178
                   RADIUS,arc_counter,arc); */
178
179
                arc_counter += arc;
179
180
                D_d_color(dval, colors);
180
181
            }
186
187
                draw = YES;
187
188
                if (is_fp) {
188
189
                    if (cat_ranges)
189
 
                        G_get_ith_d_raster_cat(&cats, (CELL) i, &dmin, &dmax);
 
190
                        Rast_get_ith_d_cat(&cats, (CELL) i, &dmin, &dmax);
190
191
                    else {
191
 
                        dmin =
192
 
                            range_dmin + (double)i *(range_dmax -
193
 
                                                     range_dmin) /
194
 
                            (double)nsteps;
195
 
                        dmax =
196
 
                            range_dmin + (double)(i + 1) * (range_dmax -
197
 
                                                            range_dmin) /
198
 
                            (double)nsteps;
 
192
                        dmin = range_dmin + i * (range_dmax - range_dmin) / nsteps;
 
193
                        dmax = range_dmin + (i + 1) * (range_dmax - range_dmin) / nsteps;
199
194
                    }
200
 
                    arc =
201
 
                        (double)360 *((double)ptr->stat /
202
 
                                      (double)dist_stats->sumstat);
203
 
                    draw_slice(colors, 1, dmin, dmax, (int)color,
204
 
                               (double)ORIGIN_X, (double)ORIGIN_Y,
205
 
                               (double)RADIUS, arc_counter, arc);
 
195
                    arc = 360.0 * ptr->stat / dist_stats->sumstat;
 
196
                    draw_slice(colors, 1, dmin, dmax, color, ORIGIN_X, ORIGIN_Y,
 
197
                               RADIUS, arc_counter, arc);
206
198
                    arc_counter += arc;
207
199
                    D_d_color(dmin, colors);
208
200
                    /*OUTLINE THE SLICE */
209
 
                    draw_slice_unfilled(colors, (int)color, (double)ORIGIN_X,
210
 
                                        (double)ORIGIN_Y, (double)RADIUS,
 
201
                    draw_slice_unfilled(colors, color, ORIGIN_X,
 
202
                                        ORIGIN_Y, RADIUS,
211
203
                                        arc_counter, arc);
212
204
                }
213
205
                else {
214
206
                    bar_color = ptr->cat;
215
 
                    arc =
216
 
                        (double)360 *((double)ptr->stat /
217
 
                                      (double)dist_stats->sumstat);
218
 
                    draw_slice_filled(colors, (DCELL) bar_color, (int)color,
219
 
                                      (double)ORIGIN_X, (double)ORIGIN_Y,
220
 
                                      (double)RADIUS, arc_counter, arc);
 
207
                    arc = 360.0 * ptr->stat / dist_stats->sumstat;
 
208
                    draw_slice_filled(colors, (DCELL) bar_color, color,
 
209
                                      ORIGIN_X, ORIGIN_Y,
 
210
                                      RADIUS, arc_counter, arc);
221
211
                    D_color((CELL) bar_color, colors);
222
212
                    arc_counter += arc;
223
213
                }
237
227
                    draw = YES;
238
228
                    if (is_fp) {
239
229
                        if (cat_ranges)
240
 
                            G_get_ith_d_raster_cat(&cats, (CELL) i, &dmin,
241
 
                                                   &dmax);
 
230
                            Rast_get_ith_d_cat(&cats, (CELL) i, &dmin, &dmax);
242
231
                        else {
243
 
                            dmin =
244
 
                                range_dmin + (double)i *(range_dmax -
245
 
                                                         range_dmin) /
246
 
                                (double)nsteps;
247
 
                            dmax =
248
 
                                range_dmin + (double)(i + 1) * (range_dmax -
249
 
                                                                range_dmin) /
250
 
                                (double)nsteps;
 
232
                            dmin = range_dmin + i * (range_dmax - range_dmin) / nsteps;
 
233
                            dmax = range_dmin + (i + 1) * (range_dmax - range_dmin) / nsteps;
251
234
                        }
252
 
                        arc =
253
 
                            (double)360 *((double)ptr->stat /
254
 
                                          (double)dist_stats->sumstat);
255
 
                        draw_slice(colors, 1, dmin, dmax, (int)color,
256
 
                                   (double)ORIGIN_X, (double)ORIGIN_Y,
257
 
                                   (double)RADIUS, arc_counter, arc);
 
235
                        arc = 360.0 * ptr->stat / dist_stats->sumstat;
 
236
                        draw_slice(colors, 1, dmin, dmax, color,
 
237
                                   ORIGIN_X, ORIGIN_Y,
 
238
                                   RADIUS, arc_counter, arc);
258
239
                        arc_counter += arc;
259
240
                        /*OUTLINE THE SLICE */
260
 
                        draw_slice_unfilled(colors, (int)color,
261
 
                                            (double)ORIGIN_X,
262
 
                                            (double)ORIGIN_Y, (double)RADIUS,
 
241
                        draw_slice_unfilled(colors, color,
 
242
                                            ORIGIN_X,
 
243
                                            ORIGIN_Y, RADIUS,
263
244
                                            arc_counter, arc);
264
245
                        D_d_color(dmin, colors);
265
246
                    }
266
247
                    else {
267
248
                        bar_color = ptr->cat;
268
 
                        arc =
269
 
                            (double)360 *((double)ptr->stat /
270
 
                                          (double)dist_stats->sumstat);
 
249
                        arc = 360.0 * ptr->stat / dist_stats->sumstat;
271
250
                        draw_slice_filled(colors, (DCELL) bar_color,
272
 
                                          (int)color, (double)ORIGIN_X,
273
 
                                          (double)ORIGIN_Y, (double)RADIUS,
 
251
                                          color, ORIGIN_X,
 
252
                                          ORIGIN_Y, RADIUS,
274
253
                                          arc_counter, arc);
275
254
                        D_color((CELL) bar_color, colors);
276
255
                        arc_counter += arc;
285
264
                     */
286
265
                    draw = NO;
287
266
                    bar_color = D_translate_color("black");
288
 
                    R_standard_color(bar_color);
 
267
                    D_use_color(bar_color);
289
268
                }
290
269
                else
291
270
                    draw = NO;
312
291
                                       0.5 * xscale + j + 1);
313
292
                        y_box[0] = y_box[3] = y_box[4] = y_line[0];
314
293
                        y_box[1] = y_box[2] = bar_height;
315
 
                        R_polygon_abs(x_box, y_box, 4);
 
294
                        D_polygon_abs(x_box, y_box, 4);
316
295
                    }
317
296
                }
318
297
                else {          /* draw 1-color bar, color is already set */
325
304
                                   0.5 * xscale);
326
305
                    y_box[0] = y_box[3] = y_box[4] = y_line[0];
327
306
                    y_box[1] = y_box[2] = bar_height;
328
 
                    R_polygon_abs(x_box, y_box, 4);
 
307
                    D_polygon_abs(x_box, y_box, 4);
329
308
                }
330
309
            }
331
310
            else {              /* color is already set for 1-color bar */
335
314
                    xoffset + (i - dist_stats->mincat) * xscale;
336
315
                y_box[0] = yoffset;
337
316
                y_box[1] = bar_height;
338
 
                R_move_abs((int)x_box[0], (int)y_box[0]);
339
 
                R_cont_abs((int)x_box[1], (int)y_box[1]);
 
317
                D_line_abs(x_box[0], y_box[0], x_box[1], y_box[1]);
340
318
            }
341
319
        }
342
320
 
347
325
        if ((rem((long int)i, tic_every) == 0L ||
348
326
             ((i == dist_stats->mincat) && nodata))
349
327
            && !(nodata && i == dist_stats->mincat + 1)) {
 
328
 
350
329
            /* draw a numbered tic-mark */
351
 
            R_standard_color(color);
352
 
            R_move_abs((int)
353
 
                       (xoffset + (i - dist_stats->mincat) * xscale -
354
 
                        0.5 * xscale), (int)(b - BAR_Y1 * (height)));
355
 
            R_cont_rel((int)0, (int)(BIG_TIC * (height)));
 
330
            D_use_color(color);
 
331
            D_begin();
 
332
            D_move_abs(xoffset
 
333
                       + (i - dist_stats->mincat) * xscale
 
334
                       - 0.5 * xscale,
 
335
                       b - BAR_Y1 * height);
 
336
            D_cont_rel(0, BIG_TIC * height);
 
337
            D_end();
 
338
            D_stroke();
 
339
 
356
340
            if (nodata && i == dist_stats->mincat)
357
341
                sprintf(txt, "null");
358
342
            else if (is_fp)
359
343
                sprintf(txt, "%d", (int)(dmin / (double)tic_unit));
360
344
            else
361
345
                sprintf(txt, "%d", (int)(i / tic_unit));
362
 
            text_height = (height) * TEXT_HEIGHT;
363
 
            text_width = (width) * TEXT_WIDTH;
364
 
            R_text_size(text_width, text_height);
365
 
            R_get_text_box(txt, &tt, &tb, &tl, &tr);
 
346
            text_height = height * TEXT_HEIGHT;
 
347
            text_width = width * TEXT_WIDTH;
 
348
            D_text_size(text_width, text_height);
 
349
            D_get_text_box(txt, &tt, &tb, &tl, &tr);
366
350
            while ((tr - tl) > XTIC_DIST) {
367
351
                text_width *= 0.95;
368
352
                text_height *= 0.95;
369
 
                R_text_size(text_width, text_height);
370
 
                R_get_text_box(txt, &tt, &tb, &tl, &tr);
 
353
                D_text_size(text_width, text_height);
 
354
                D_get_text_box(txt, &tt, &tb, &tl, &tr);
371
355
            }
372
 
            R_move_abs((int)
373
 
                       (xoffset + (i - dist_stats->mincat) * xscale -
374
 
                        0.5 * xscale - (tr - tl) / 2),
375
 
                       (int)(b - XNUMS_Y * (height)));
376
 
            R_text(txt);
 
356
            D_pos_abs(xoffset
 
357
                      + (i - dist_stats->mincat) * xscale
 
358
                      - 0.5 * xscale
 
359
                      - (tr - tl) / 2,
 
360
                      b - XNUMS_Y * height);
 
361
            D_text(txt);
377
362
        }
378
 
        else if (rem(i, tic_unit) == (float)0) {
 
363
        else if (rem(i, tic_unit) == 0.0) {
379
364
            /* draw a tic-mark */
380
 
            R_standard_color((int)color);
381
 
            R_move_abs((int)
382
 
                       (xoffset + (i - dist_stats->mincat) * xscale -
383
 
                        0.5 * xscale), (int)(b - BAR_Y1 * (height)));
384
 
            R_cont_rel((int)0, (int)(SMALL_TIC * (height)));
 
365
            D_use_color(color);
 
366
            D_begin();
 
367
            D_move_abs(xoffset
 
368
                       + (i - dist_stats->mincat) * xscale
 
369
                       - 0.5 * xscale,
 
370
                       b - BAR_Y1 * height);
 
371
            D_cont_rel(0, SMALL_TIC * height);
 
372
            D_end();
 
373
            D_stroke();
385
374
        }
386
375
    }
387
376
 
388
377
    /* draw border around pie */
389
 
    R_standard_color((int)color);
390
 
    draw_slice_unfilled(colors, (int)color, (double)ORIGIN_X,
391
 
                        (double)ORIGIN_Y, (double)RADIUS, (double)0,
392
 
                        (double)360);
 
378
    D_use_color(color);
 
379
    draw_slice_unfilled(colors, color, ORIGIN_X, ORIGIN_Y, RADIUS, 0.0, 360.0);
393
380
 
394
381
    /* draw border around legend bar */
395
 
    R_standard_color((int)color);
396
 
    R_polyline_abs(x_line, y_line, 5);
 
382
    D_use_color(color);
 
383
    D_polyline_abs(x_line, y_line, 5);
397
384
 
398
385
    /* draw the x-axis label */
399
386
    if (tic_unit != 1)
400
387
        sprintf(xlabel, "Cell Values %s", tic_name);
401
388
    else
402
389
        sprintf(xlabel, "Cell Values");
403
 
    text_height = (height) * TEXT_HEIGHT;
404
 
    text_width = (width) * TEXT_WIDTH;
405
 
    R_text_size(text_width, text_height);
406
 
    R_get_text_box(xlabel, &tt, &tb, &tl, &tr);
407
 
    R_move_abs((int)(l + (width) / 2 - (tr - tl) / 2),
408
 
               (int)(b - LABEL * (height)));
409
 
    R_standard_color((int)color);
410
 
    R_text(xlabel);
 
390
    text_height = height * TEXT_HEIGHT;
 
391
    text_width = width * TEXT_WIDTH;
 
392
    D_text_size(text_width, text_height);
 
393
    D_get_text_box(xlabel, &tt, &tb, &tl, &tr);
 
394
    D_pos_abs(l + width / 2 - (tr - tl) / 2,
 
395
              b - LABEL * height);
 
396
    D_use_color(color);
 
397
    D_text(xlabel);
411
398
 
412
399
    return 0;
413
400
}