2
* Draws a histogram along the left side of a smooth gradient legend
3
* (stats fetching code adapted from d.histogram)
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.
10
#include <grass/gis.h>
11
#include <grass/display.h>
12
#include "local_proto.h"
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)
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;
26
max_width = height * 1.75;
30
max_width = width * 1.75;
34
/* get the distribution statistics */
35
get_stats(map_name, &dist_stats, nsteps, map_type);
37
width_mult = max_width / dist_stats.maxstat;
45
dy = (nsteps + 3.0) / (1 + dist_stats.maxcat - dist_stats.mincat);
50
if (dist_stats.mincat == 0)
59
for (i = dist_stats.mincat; i <= dist_stats.maxcat; i++) {
63
if (ptr->cat == i) { /* AH-HA!! found the stat */
64
cell_count = ptr->stat;
66
if (ptr->next != NULL)
69
else { /* we have to look for the stat */
71
/* loop until we find it, or pass where it should be */
72
while (ptr->cat < i && ptr->next != NULL)
74
if (ptr->cat == i) { /* AH-HA!! found the stat */
75
cell_count = ptr->stat;
77
if (ptr->next != NULL)
80
else /* stat cannot be found */
81
G_debug(4, "No matching stat found, i=%d", i);
87
dx = cell_count * width_mult;
92
D_move_abs(x0 + width - i - 1, y0 - 1);
94
D_move_abs(x0 + i + 1, y0 - 1);
100
D_move_abs(x0 - 1, y0 - 1 + height - i);
102
D_move_abs(x0 - 1, y0 + 1 + i);
107
else { /* categorical */
111
D_box_abs(x0 + width + y0_adjust + ((i - 1) * dy),
113
x0 + width + y0_adjust + 1 + (i * dy),
116
D_box_abs(x0 + y0_adjust + ((i - 1) * dy),
118
x0 - 1 + y0_adjust + (i * dy),
121
else { /* vertical */
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),
128
y0 + height + y0_adjust + 1 + (i * dy));
130
D_box_abs(x0 - 1 - GRASS_EPSILON * 10,
131
y0 + y0_adjust + ((i - 1) * dy),
133
y0 + y0_adjust - 1 + (i * dy));