Skip to content

Commit

Permalink
d.legend: Fix position of units and background (#1075)
Browse files Browse the repository at this point in the history
Do the same for units from metadata (r.info, r.support units=, aka units_bottom)
as for the title, i.e., use the same computation. Use of the right variables
(not title or (the other) units). Use the same check already used for title
for the units too when drawing the background.
(This is applicable only to the do_smooth if statement branch,
not the non FP, no smoothing branch in the code.)
  • Loading branch information
wenzeslaus authored and neteler committed Nov 18, 2020
1 parent 1e4183d commit 1d2e13b
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions display/d.legend/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ void draw(const char *map_name, int maptype, int color, int thin, int lines,
if (maptype == MAP_TYPE_RASTER2D)
units_bottom = Rast_read_units(map_name, "");
else
units = "";
units_bottom = "";
/* FIXME: does the raster3d really need to be opened to read the units?
units_bottom = Rast3d_get_unit(map_fid); */

Expand All @@ -956,15 +956,16 @@ void draw(const char *map_name, int maptype, int color, int thin, int lines,

if (strlen(units_bottom)) {
D_text_size(titsiz, titsiz);
D_get_text_box(title, &bb, &bt, &bl, &br);
D_get_text_box(units_bottom, &bb, &bt, &bl, &br);
if (horiz) {
x_tit =
(x0 + x1) / 2. - (br - bl) / 2;
y_tit = y1 + (txsiz * 2.75);
x_tit = (x0 + x1) / 2. - (br - bl) / 2;
y_tit = y0 - (titsiz) - max_hist;
}
else {
x_tit = x0;
y_tit = y0 - txsiz;
}

x1_tit = x_tit + (br - bl);

if (draw) {
Expand All @@ -985,7 +986,7 @@ void draw(const char *map_name, int maptype, int color, int thin, int lines,
if (x1bg < x1_tit)
x1bg = x1_tit + txsiz;
y1bg = y0 + lleg + txsiz;
if (strlen(title) > 0)
if (strlen(title) > 0 || strlen(units_bottom) > 0)
y0bg = y0 - titsiz -2 * txsiz;
else
y0bg = y0 - txsiz;
Expand All @@ -998,7 +999,7 @@ void draw(const char *map_name, int maptype, int color, int thin, int lines,
x1bg = x1_tit + txsiz;
}
y1bg = y0 + lleg + label_indent + 1.5 * txsiz;
if (strlen(title) > 0)
if (strlen(title) > 0 || strlen(units_bottom) > 0)
y0bg = y0 - (2.5 * titsiz) - max_hist;
else
y0bg = y0 - titsiz - max_hist;
Expand Down

0 comments on commit 1d2e13b

Please sign in to comment.