[GRASS-SVN] r60383 - grass/branches/releasebranch_7_0/display/d.legend
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue May 20 19:38:22 PDT 2014
Author: hamish
Date: 2014-05-20 19:38:22 -0700 (Tue, 20 May 2014)
New Revision: 60383
Modified:
grass/branches/releasebranch_7_0/display/d.legend/histogram.c
grass/branches/releasebranch_7_0/display/d.legend/local_proto.h
grass/branches/releasebranch_7_0/display/d.legend/main.c
Log:
histogram support for categorical maps, run grass_indent.sh on histogram.c (merge from trunk)
Modified: grass/branches/releasebranch_7_0/display/d.legend/histogram.c
===================================================================
--- grass/branches/releasebranch_7_0/display/d.legend/histogram.c 2014-05-21 02:38:04 UTC (rev 60382)
+++ grass/branches/releasebranch_7_0/display/d.legend/histogram.c 2014-05-21 02:38:22 UTC (rev 60383)
@@ -13,11 +13,12 @@
void draw_histogram(const char *map_name, int x0, int y0, int width,
int height, int color, int flip, int horiz,
- int map_type)
+ int map_type, int is_fp)
{
int i, nsteps;
long cell_count;
double max_width, width_mult, dx;
+ double dy, y0_adjust; /* only needed for CELL maps */
struct stat_list dist_stats;
struct stat_node *ptr;
@@ -40,51 +41,97 @@
ptr = dist_stats.ptr;
+ if (!is_fp) {
+ dy = (nsteps + 3.0) / (1 + dist_stats.maxcat - dist_stats.mincat);
+
+ if (flip)
+ dy *= -1;
+
+ if (dist_stats.mincat == 0)
+ y0_adjust = dy;
+ else
+ y0_adjust = 0;
+
+ if (!flip) /* mmph */
+ y0_adjust += 0.5;
+ }
+
for (i = dist_stats.mincat; i <= dist_stats.maxcat; i++) {
if (!ptr)
break;
- if (ptr->cat == i) { /* AH-HA!! found the stat */
- cell_count = ptr->stat;
+ if (ptr->cat == i) { /* AH-HA!! found the stat */
+ cell_count = ptr->stat;
- if (ptr->next != NULL)
- ptr = ptr->next;
- }
- else { /* we have to look for the stat */
+ if (ptr->next != NULL)
+ ptr = ptr->next;
+ }
+ else { /* we have to look for the stat */
- /* loop until we find it, or pass where it should be */
- while (ptr->cat < i && ptr->next != NULL)
- ptr = ptr->next;
- if (ptr->cat == i) { /* AH-HA!! found the stat */
- cell_count = ptr->stat;
+ /* loop until we find it, or pass where it should be */
+ while (ptr->cat < i && ptr->next != NULL)
+ ptr = ptr->next;
+ if (ptr->cat == i) { /* AH-HA!! found the stat */
+ cell_count = ptr->stat;
- if (ptr->next != NULL)
- ptr = ptr->next;
- }
- else /* stat cannot be found */
+ if (ptr->next != NULL)
+ ptr = ptr->next;
+ }
+ else /* stat cannot be found */
G_debug(4, "No matching stat found, i=%d", i);
- }
+ }
if (!cell_count)
continue;
dx = cell_count * width_mult;
- if (horiz) {
- if (flip)
- D_move_abs(x0 + width - i - 1, y0 - 1);
- else
- D_move_abs(x0 + i + 1, y0 - 1);
+ if (is_fp) {
+ if (horiz) {
+ if (flip)
+ D_move_abs(x0 + width - i - 1, y0 - 1);
+ else
+ D_move_abs(x0 + i + 1, y0 - 1);
- D_cont_rel(0, -dx);
+ D_cont_rel(0, -dx);
+ }
+ else { /* vertical */
+ if (flip)
+ D_move_abs(x0 - 1, y0 - 1 + height - i);
+ else
+ D_move_abs(x0 - 1, y0 + 1 + i);
+
+ D_cont_rel(-dx, 0);
+ }
}
- else { /* vertical */
- if (flip)
- D_move_abs(x0 - 1, y0 - 1 + height - i);
- else
- D_move_abs(x0 - 1, y0 + 1 + i);
+ else { /* categorical */
- D_cont_rel(-dx, 0);
+ if (horiz) {
+ if (flip)
+ D_box_abs(x0 + width + y0_adjust + ((i - 1) * dy),
+ y0 - 1,
+ x0 + width + y0_adjust + 1 + (i * dy),
+ y0 - 1 - dx);
+ else
+ D_box_abs(x0 + y0_adjust + ((i - 1) * dy),
+ y0 - 1,
+ x0 - 1 + y0_adjust + (i * dy),
+ y0 - 1 - dx);
+ }
+ else { /* vertical */
+
+ if (flip)
+ /* GRASS_EPSILON fudge around D_box_abs() weirdness + PNG driver */
+ D_box_abs(x0 - 1 - GRASS_EPSILON * 10,
+ y0 + height + y0_adjust + ((i - 1) * dy),
+ x0 - 1 - dx,
+ y0 + height + y0_adjust + 1 + (i * dy));
+ else
+ D_box_abs(x0 - 1 - GRASS_EPSILON * 10,
+ y0 + y0_adjust + ((i - 1) * dy),
+ x0 - 1 - dx,
+ y0 + y0_adjust - 1 + (i * dy));
+ }
}
}
Modified: grass/branches/releasebranch_7_0/display/d.legend/local_proto.h
===================================================================
--- grass/branches/releasebranch_7_0/display/d.legend/local_proto.h 2014-05-21 02:38:04 UTC (rev 60382)
+++ grass/branches/releasebranch_7_0/display/d.legend/local_proto.h 2014-05-21 02:38:22 UTC (rev 60383)
@@ -27,7 +27,7 @@
/* histogram.c */
-void draw_histogram(const char *, int, int, int, int, int, int, int, int);
+void draw_histogram(const char *, int, int, int, int, int, int, int, int, int);
/* get_stats.c */
void get_stats(const char *, struct stat_list *, int, int);
Modified: grass/branches/releasebranch_7_0/display/d.legend/main.c
===================================================================
--- grass/branches/releasebranch_7_0/display/d.legend/main.c 2014-05-21 02:38:04 UTC (rev 60382)
+++ grass/branches/releasebranch_7_0/display/d.legend/main.c 2014-05-21 02:38:22 UTC (rev 60383)
@@ -467,7 +467,7 @@
if (!hide_catnum)
if (i > maxCat)
maxCat = (double)i;
- k++; /* count of actual boxes drawn (hide_nodata option invaidates using j-1) */
+ k++; /* count of actual boxes drawn (hide_nodata option invaidates using j-1) */
}
lines = k;
@@ -526,10 +526,10 @@
/* switch to a smooth legend for CELL maps with too many cats */
/* an alternate solution is to set dots_per_line=1 */
- if ((dots_per_line == 0) && (do_smooth == 0)) {
+ if ((dots_per_line == 0) && (do_smooth == FALSE)) {
if (!use_catlist) {
G_message(_("Forcing a smooth legend: too many categories for current window height"));
- do_smooth = 1;
+ do_smooth = TRUE;
}
}
@@ -540,7 +540,7 @@
y0 = ((b - t) - (dots_per_line * lines)) / 2;
}
- /* D_text_size(dots_per_line*4/5., dots_per_line*4/5.); redundant */
+ /* D_text_size(dots_per_line*4/5., dots_per_line*4/5.); redundant */
/* if(Rast_is_c_null_value(&min_ind) && Rast_is_c_null_value(&max_ind))
{
min_ind = 1;
@@ -616,9 +616,10 @@
cats_num = catlistCount;
do_cats = catlistCount;
lines = catlistCount;
- do_smooth = 0;
+ do_smooth = FALSE;
}
+
if (do_smooth) {
int wleg, lleg, dx, dy;
double txsiz;
@@ -813,14 +814,25 @@
units = "";
if(strlen(units)) {
+ double x_pos, y_pos;
+ int default_pos = TRUE;
+
D_use_color(color);
/* D_text_size() should be already set */
- if (horiz)
- D_pos_abs((x0 + x1)/2. - (strlen(units) * txsiz * 0.81)/2,
- y1 + (txsiz * 3));
- else
- D_pos_abs(x1 - 4, y0 - (txsiz * 1.75));
+ if (horiz) {
+ x_pos = (x0 + x1)/2. - (strlen(units) * txsiz * 0.81)/2;
+ y_pos = y1 + (txsiz * 3);
+ }
+ else {
+ x_pos = x1 - 4;
+ if (default_pos)
+ y_pos = y0 - (txsiz * 1.75);
+ else
+ y_pos = y1 + (txsiz * 2.75);
+ }
+
+ D_pos_abs(x_pos, y_pos);
D_text(units);
}
@@ -831,7 +843,7 @@
G_warning(_("Histogram constrained by range not yet implemented"));
else
draw_histogram(map_name, x0, y0, wleg, lleg, color, flip,
- horiz, maptype);
+ horiz, maptype, fp);
}
}
@@ -843,7 +855,7 @@
/* set legend box bounds */
true_l = l;
- true_r = r; /* preserve window width */
+ true_r = r; /* preserve window width */
l = x0;
t = y0;
r = x1;
@@ -858,7 +870,7 @@
dots_per_line = (b - t) / (lines + 2); /* + another line for 'x of y categories' text */
/* adjust text size */
- /* txsiz = (int)((y1-y0)/(1.5*(lines+5))); */
+ /* txsiz = (int)((y1-y0)/(1.5*(lines+5))); */
txsiz = (y1 - y0) / (2.0 * lines);
/* scale text to fit in window if position not manually set */
More information about the grass-commit
mailing list