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

« back to all changes in this revision

Viewing changes to display/d.legend/histogram.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:
 
1
/* histogram.c:
 
2
 *    Draws a histogram along the left side of a smooth gradient legend
 
3
 *    (stats fetching code adapted from d.histogram)
 
4
 *
 
5
 *    Copyright (C) 2014 by Hamish Bowman, and the GRASS Development Team* 
 
6
 *    This program is free software under the GPL (>=v2)
 
7
 *    Read the COPYING file that comes with GRASS for details.
 
8
 */
 
9
 
 
10
#include <grass/gis.h>
 
11
#include <grass/display.h>
 
12
#include "local_proto.h"
 
13
 
 
14
void draw_histogram(const char *map_name, int x0, int y0, int width,
 
15
                    int height, int color, int flip, int horiz,
 
16
                    int map_type, int is_fp)
 
17
{
 
18
    int i, nsteps;
 
19
    long cell_count = 0;
 
20
    double max_width, width_mult, dx;
 
21
    double dy, y0_adjust;       /* only needed for CELL maps */
 
22
    struct stat_list dist_stats;
 
23
    struct stat_node *ptr;
 
24
 
 
25
    if (horiz) {
 
26
        max_width = height * 1.75;
 
27
        nsteps = width - 3;
 
28
    }
 
29
    else {
 
30
        max_width = width * 1.75;
 
31
        nsteps = height - 3;
 
32
    }
 
33
 
 
34
    /* get the distribution statistics */
 
35
    get_stats(map_name, &dist_stats, nsteps, map_type);
 
36
 
 
37
    width_mult = max_width / dist_stats.maxstat;
 
38
 
 
39
    D_use_color(color);
 
40
    D_begin();
 
41
 
 
42
    ptr = dist_stats.ptr;
 
43
 
 
44
    if (!is_fp) {
 
45
        dy = (nsteps + 3.0) / (1 + dist_stats.maxcat - dist_stats.mincat);
 
46
 
 
47
        if (flip)
 
48
            dy *= -1;
 
49
 
 
50
        if (dist_stats.mincat == 0)
 
51
            y0_adjust = dy;
 
52
        else
 
53
            y0_adjust = 0;
 
54
 
 
55
        if (!flip)  /* mmph */
 
56
            y0_adjust += 0.5;
 
57
    }
 
58
 
 
59
    for (i = dist_stats.mincat; i <= dist_stats.maxcat; i++) {
 
60
        if (!ptr)
 
61
            break;
 
62
 
 
63
        if (ptr->cat == i) {    /* AH-HA!! found the stat */
 
64
            cell_count = ptr->stat;
 
65
 
 
66
            if (ptr->next != NULL)
 
67
                ptr = ptr->next;
 
68
        }
 
69
        else {                  /* we have to look for the stat */
 
70
 
 
71
            /* loop until we find it, or pass where it should be */
 
72
            while (ptr->cat < i && ptr->next != NULL)
 
73
                ptr = ptr->next;
 
74
            if (ptr->cat == i) {        /* AH-HA!! found the stat */
 
75
                cell_count = ptr->stat;
 
76
 
 
77
                if (ptr->next != NULL)
 
78
                    ptr = ptr->next;
 
79
            }
 
80
            else                /* stat cannot be found */
 
81
                G_debug(4, "No matching stat found, i=%d", i);
 
82
        }
 
83
 
 
84
        if (!cell_count)
 
85
            continue;
 
86
 
 
87
        dx = cell_count * width_mult;
 
88
 
 
89
        if (is_fp) {
 
90
            if (horiz) {
 
91
                if (flip)
 
92
                    D_move_abs(x0 + width - i - 1, y0 - 1);
 
93
                else
 
94
                    D_move_abs(x0 + i + 1, y0 - 1);
 
95
 
 
96
                D_cont_rel(0, -dx);
 
97
            }
 
98
            else {  /* vertical */
 
99
                if (flip)
 
100
                    D_move_abs(x0 - 1, y0 - 1 + height - i);
 
101
                else
 
102
                    D_move_abs(x0 - 1, y0 + 1 + i);
 
103
 
 
104
                D_cont_rel(-dx, 0);
 
105
            }
 
106
        }
 
107
        else {  /* categorical */
 
108
 
 
109
            if (horiz) {
 
110
                if (flip)
 
111
                    D_box_abs(x0 + width + y0_adjust + ((i - 1) * dy),
 
112
                              y0 - 1,
 
113
                              x0 + width + y0_adjust + 1 + (i * dy),
 
114
                              y0 - 1 - dx);
 
115
                else
 
116
                    D_box_abs(x0 + y0_adjust + ((i - 1) * dy),
 
117
                              y0 - 1,
 
118
                              x0 - 1 + y0_adjust + (i * dy),
 
119
                              y0 - 1 - dx);
 
120
            }
 
121
            else {  /* vertical */
 
122
 
 
123
                if (flip)
 
124
                    /* GRASS_EPSILON fudge around D_box_abs() weirdness + PNG driver */
 
125
                    D_box_abs(x0 - 1 - GRASS_EPSILON * 10,
 
126
                              y0 + height + y0_adjust + ((i - 1) * dy),
 
127
                              x0 - 1 - dx,
 
128
                              y0 + height + y0_adjust + 1 + (i * dy));
 
129
                else
 
130
                    D_box_abs(x0 - 1 - GRASS_EPSILON * 10,
 
131
                              y0 + y0_adjust + ((i - 1) * dy),
 
132
                              x0 - 1 - dx,
 
133
                              y0 + y0_adjust - 1 + (i * dy));
 
134
            }
 
135
        }
 
136
    }
 
137
 
 
138
    D_close();
 
139
    D_end();
 
140
    D_stroke();
 
141
}