[GRASS-SVN] r69000 - grass/trunk/display/d.legend
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Jul 18 07:01:45 PDT 2016
Author: annakrat
Date: 2016-07-18 07:01:45 -0700 (Mon, 18 Jul 2016)
New Revision: 69000
Modified:
grass/trunk/display/d.legend/draw.c
grass/trunk/display/d.legend/histogram.c
grass/trunk/display/d.legend/local_proto.h
grass/trunk/display/d.legend/main.c
Log:
d.legend: fix histograms for continuous gradient where categories are missing, add text after each label #3081 (by Adam Laza)
Modified: grass/trunk/display/d.legend/draw.c
===================================================================
--- grass/trunk/display/d.legend/draw.c 2016-07-18 13:54:01 UTC (rev 68999)
+++ grass/trunk/display/d.legend/draw.c 2016-07-18 14:01:45 UTC (rev 69000)
@@ -29,7 +29,7 @@
double t_step, int colorb, int colorbg, struct Option *opt_use,
struct Option *opt_at, struct Option *opt_fontsize,
struct Option *opt_tstep, struct Option *opt_range, struct Flag *histo,
- struct Flag *hidestr, int log_sc, int draw, int digits)
+ struct Flag *hidestr, int log_sc, int draw, int digits, char *units)
{
char buff[512];
int black, white;
@@ -53,7 +53,7 @@
char DispFormat[5]; /* %.Xf\0 */
double maxCat;
int horiz;
- char *units;
+ char *units_bottom;
double t_start;
double max_hist;
double txsiz, titsiz;
@@ -482,10 +482,27 @@
sprintf(buff, DispFormat, tcell);
if (!hide_catstr) /* both */
strcat(buff, ")");
+ D_text_size(txsiz, txsiz);
+ D_get_text_box(buff,&bb,&bt, &bl, &br);
+ LabelW = br - bl;
+ if (LabelW > MaxLabelW) {
+ MaxLabelW = LabelW;
+ sprintf(MaxLabel, "%s", buff);
}
- if (!hide_catstr) /* str */
+ }
+ if (!hide_catstr) { /* str */
sprintf(buff + strlen(buff), " %s", cstr);
+ if (strlen(units)>0)
+ strcat(buff, units);
+ D_text_size(txsiz, txsiz);
+ D_get_text_box(buff,&bb,&bt, &bl, &br);
+ LabelW = br - bl;
+ if (LabelW > MaxLabelW) {
+ MaxLabelW = LabelW;
+ sprintf(MaxLabel, "%s", buff);
}
+ }
+ }
else { /* ie FP map */
if (hide_catnum)
buff[0] = 0; /* no text */
@@ -501,8 +518,17 @@
val = dmax - k * (dmax - dmin) / (steps - 1);
}
sprintf(buff, DispFormat, val);
+ if (strlen(units)>0)
+ strcat(buff, units);
+ D_text_size(txsiz, txsiz);
+ D_get_text_box(buff,&bb,&bt, &bl, &br);
+ LabelW = br - bl;
+ if (LabelW > MaxLabelW) {
+ MaxLabelW = LabelW;
+ sprintf(MaxLabel, "%s", buff);
}
}
+ }
if (draw) {
if (!hide_catnum) {
@@ -571,13 +597,6 @@
D_text(buff);
}
}
- D_text_size(txsiz, txsiz);
- D_get_text_box(buff,&bb,&bt, &bl, &br);
- LabelW = br - bl;
- if (LabelW > MaxLabelW) {
- MaxLabelW = LabelW;
- sprintf(MaxLabel, DispFormat, val);
- }
} /* for */
}
@@ -595,6 +614,15 @@
tick_values[i], dmin, dmax);
}
sprintf(buff, DispFormat, tick_values[i]);
+ if (strlen(units)>0)
+ strcat(buff, units);
+ D_text_size(txsiz, txsiz);
+ D_get_text_box(buff,&bb,&bt, &bl, &br);
+ LabelW = br - bl;
+ if (LabelW > MaxLabelW) {
+ MaxLabelW = LabelW;
+ sprintf(MaxLabel, "%s", buff);
+ }
if (log_sc) {
coef = (log10(tick_values[i]) - log10(dmin)) / (log10(dmax) - log10(dmin));
@@ -648,15 +676,8 @@
D_use_color(color);
D_text(buff);
}
- D_text_size(txsiz, txsiz);
- D_get_text_box(buff,&bb,&bt, &bl, &br);
- LabelW = br - bl;
- if (LabelW > MaxLabelW) {
- MaxLabelW = LabelW;
- sprintf(MaxLabel, DispFormat, tick_values[i]);
}
}
- }
/* LABEL_STEP OPTION */
if (opt_tstep->answer) {
@@ -666,6 +687,15 @@
num = ceil(log10(dmin)) + t_start;
val = pow(10,num);
sprintf(buff, DispFormat, val);
+ if (strlen(units)>0)
+ strcat(buff, units);
+ D_text_size(txsiz, txsiz);
+ D_get_text_box(buff,&bb,&bt, &bl, &br);
+ LabelW = br - bl;
+ if (LabelW > MaxLabelW) {
+ MaxLabelW = LabelW;
+ sprintf(MaxLabel, "%s", buff);
+ }
coef = (log10(val) - log10(dmin)) / (log10(dmax) - log10(dmin));
if (draw){
if (!flip){
@@ -712,6 +742,7 @@
}
D_use_color(color);
D_text(buff);
+
}
t_start += t_step;
}
@@ -725,12 +756,14 @@
if (!horiz)
while (t_start <= dmax) {
sprintf(buff, DispFormat, t_start);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
if (LabelW > MaxLabelW) {
MaxLabelW = LabelW;
- sprintf(MaxLabel, DispFormat, t_start);
+ sprintf(MaxLabel, "%s", buff);
}
if (draw) {
coef = (t_start - dmin) / ((dmax - dmin) * 1.0);
@@ -749,12 +782,14 @@
else
while (t_start <= dmax) {
sprintf(buff, DispFormat, t_start);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
if (LabelW > MaxLabelW) {
MaxLabelW = LabelW;
- sprintf(MaxLabel, DispFormat, t_start);
+ sprintf(MaxLabel, "%s", buff);
}
if (draw) {
@@ -777,12 +812,14 @@
if (!horiz)
while (t_start <= dmax) {
sprintf(buff, DispFormat, t_start);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
if (LabelW > MaxLabelW) {
MaxLabelW = LabelW;
- sprintf(MaxLabel, DispFormat, t_start);
+ sprintf(MaxLabel, "%s", buff);
}
if (draw) {
@@ -802,12 +839,14 @@
else
while (t_start <= dmax) {
sprintf(buff, DispFormat, t_start);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
if (LabelW > MaxLabelW) {
MaxLabelW = LabelW;
- sprintf(MaxLabel, DispFormat, t_start);
+ sprintf(MaxLabel, "%s", buff);
}
if (draw) {
@@ -906,16 +945,16 @@
/* units */
/* print units label, if present */
if (maptype == MAP_TYPE_RASTER2D)
- units = Rast_read_units(map_name, "");
+ units_bottom = Rast_read_units(map_name, "");
else
units = "";
/* FIXME: does the raster3d really need to be opened to read the units?
- units = Rast3d_get_unit(map_fid); */
+ units_bottom = Rast3d_get_unit(map_fid); */
- if (!units)
- units = "";
+ if (!units_bottom)
+ units_bottom = "";
- if (strlen(units)) {
+ if (strlen(units_bottom)) {
D_text_size(titsiz, titsiz);
D_get_text_box(title, &bb, &bt, &bl, &br);
if (horiz) {
@@ -931,7 +970,7 @@
if (draw) {
D_use_color(color);
D_pos_abs(x_tit, y_tit);
- D_text(units);
+ D_text(units_bottom);
}
}
} /* end of display units) */
@@ -1128,33 +1167,38 @@
buff[0] = 0;
if (!hide_catnum) { /* num */
sprintf(buff, DispFormat, (int)catlist[i]);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
if (LabelW > MaxLabelW) {
MaxLabelW = LabelW;
- sprintf(MaxLabel, DispFormat, (int)catlist[i]);
+ sprintf(MaxLabel, "%s", buff);
}
if (!flip) {
sprintf(buff, DispFormat, (int)catlist[i]);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
if (LabelW > MaxLabelW) {
MaxLabelW = LabelW;
- sprintf(MaxLabel, DispFormat, (int)catlist[i]);
+ sprintf(MaxLabel, "%s", buff);
}
}
else {
sprintf(buff, DispFormat,
(int)catlist[catlistCount - i - 1]);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
if (LabelW > MaxLabelW) {
MaxLabelW = LabelW;
- sprintf(MaxLabel, DispFormat,
- (int)catlist[catlistCount - i - 1]);
+ sprintf(MaxLabel, "%s", buff);
}
}
if (!hide_catstr) /* both */
@@ -1162,6 +1206,8 @@
}
if (!hide_catstr) { /* str */
sprintf(buff + strlen(buff), " %s", cstr);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
@@ -1177,45 +1223,53 @@
/* pass through format exactly as given by the user in
the use= command line parameter (helps with log scale) */
sprintf(buff, "%s", opt_use->answers[i]);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
if (LabelW > MaxLabelW) {
MaxLabelW = LabelW;
- sprintf(MaxLabel, " %s", opt_use->answers[i]);
+ sprintf(MaxLabel, " %s", buff);
}
}
else {
/* automatically generated/tuned decimal precision format */
sprintf(buff, DispFormat, catlist[i]);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
if (LabelW > MaxLabelW) {
MaxLabelW = LabelW;
- sprintf(MaxLabel, DispFormat, catlist[i]);
+ sprintf(MaxLabel, "%s", buff);
}
}
}
else {
if (use_catlist){
sprintf(buff, "%s", opt_use->answers[catlistCount - i - 1]);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
if (LabelW > MaxLabelW) {
MaxLabelW = LabelW;
- sprintf(MaxLabel, " %s", opt_use->answers[catlistCount - i - 1]);
+ sprintf(MaxLabel, " %s", buff);
}
}
else {
sprintf(buff, DispFormat, catlist[catlistCount - i - 1]);
+ if (strlen(units)>0)
+ strcat(buff, units);
D_text_size(txsiz, txsiz);
D_get_text_box(buff,&bb,&bt, &bl, &br);
LabelW = br - bl;
if (LabelW > MaxLabelW) {
MaxLabelW = LabelW;
- sprintf(MaxLabel, " %s", opt_use->answers[catlistCount - i - 1]);
+ sprintf(MaxLabel, " %s", buff);
}
}
}
Modified: grass/trunk/display/d.legend/histogram.c
===================================================================
--- grass/trunk/display/d.legend/histogram.c 2016-07-18 13:54:01 UTC (rev 68999)
+++ grass/trunk/display/d.legend/histogram.c 2016-07-18 14:01:45 UTC (rev 69000)
@@ -149,6 +149,7 @@
dist_stats.maxcat);
for (i = dist_stats.mincat, ystep = 0; i <= dist_stats.maxcat; i++) {
+ cell_count = 0;
if (!ptr)
break;
Modified: grass/trunk/display/d.legend/local_proto.h
===================================================================
--- grass/trunk/display/d.legend/local_proto.h 2016-07-18 13:54:01 UTC (rev 68999)
+++ grass/trunk/display/d.legend/local_proto.h 2016-07-18 14:01:45 UTC (rev 69000)
@@ -42,4 +42,4 @@
double, int, int, double, double, double *, int, int, int, double,
double, const char *, double *, double, int, int, struct Option *,
struct Option *, struct Option *, struct Option *, struct Option *,
- struct Flag *, struct Flag *, int, int, int);
+ struct Flag *, struct Flag *, int, int, int, char *);
Modified: grass/trunk/display/d.legend/main.c
===================================================================
--- grass/trunk/display/d.legend/main.c 2016-07-18 13:54:01 UTC (rev 68999)
+++ grass/trunk/display/d.legend/main.c 2016-07-18 14:01:45 UTC (rev 69000)
@@ -54,7 +54,7 @@
*opt_thin, *opt_labelnum, *opt_at, *opt_use, *opt_range,
*opt_font, *opt_path, *opt_charset, *opt_fontsize, *opt_title,
*opt_ticks, *opt_tstep, *opt_brdcolor, *opt_bgcolor,
- *opt_tit_fontsize, *opt_digits;
+ *opt_tit_fontsize, *opt_digits, *opt_units;
struct Flag *hidestr, *hidenum, *hidenodata, *smooth, *flipit, *histo,
*showtick, *showbg, *log_sc;
double X0, X1, Y0, Y1;
@@ -64,6 +64,7 @@
int catlistCount, use_catlist, ticksCount;
double fontsize;
char *title;
+ char *units;
double *tick_values;
double t_step;
int colorb, colorbg;
@@ -126,6 +127,14 @@
_("Thinning factor (thin=10 gives cats 0,10,20...)");
opt_thin->guisection = _("Advanced");
+ opt_units = G_define_option();
+ opt_units->key = "units";
+ opt_units->type = TYPE_STRING;
+ opt_units->required = NO;
+ opt_units->description =
+ _("Units to display after labels (e.g. meters)");
+ opt_units->guisection = _("Advanced");
+
opt_labelnum = G_define_option();
opt_labelnum->key = "labelnum";
opt_labelnum->type = TYPE_INTEGER;
@@ -306,6 +315,12 @@
else
title = "";
+ if (opt_units->answer) {
+ units = opt_units->answer;
+ }
+ else
+ units = "";
+
hide_catstr = hidestr->answer; /* note hide_catstr gets changed and re-read below */
hide_catnum = hidenum->answer;
show_ticks = showtick->answer;
@@ -461,7 +476,7 @@
UserRangeMax, catlist, catlistCount, use_catlist, ticksCount,
fontsize, tit_fontsize, title, tick_values, t_step, colorb,
colorbg, opt_use, opt_at, opt_fontsize, opt_tstep,
- opt_range, histo, hidestr, log_scale, 0, digits);
+ opt_range, histo, hidestr, log_scale, 0, digits, units);
draw(map_name, maptype, color, thin, lines, steps, fp, label_indent,
hide_catnum, hide_catstr, show_ticks, hide_nodata, do_smooth, cats,
@@ -469,7 +484,7 @@
catlist, catlistCount, use_catlist, ticksCount, fontsize,
tit_fontsize, title, tick_values, t_step, colorb, colorbg, opt_use,
opt_at, opt_fontsize, opt_tstep, opt_range, histo,
- hidestr, log_scale, 1, digits);
+ hidestr, log_scale, 1, digits, units);
D_close_driver();
More information about the grass-commit
mailing list