Opened 8 years ago
Closed 8 years ago
#3013 closed enhancement (fixed)
support background and border for d.legend
| Reported by: | annakrat | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 7.2.0 |
| Component: | Display | Version: | svn-trunk |
| Keywords: | d.legend, background, gsoc2016, cartography | Cc: | |
| CPU: | Unspecified | Platform: | All |
Description
It would be nice to have background box for legend. Ideally there would be option to add border too.
Attachments (10)
Change History (35)
by , 8 years ago
| Attachment: | legend_border.png added |
|---|
by , 8 years ago
| Attachment: | d.legend_bg.diff added |
|---|
follow-up: 2 comment:1 by , 8 years ago
I added -b flag to display legend background. Then brdcolor to choose border color. So far it works only for non-categoric rasters and displays only border color but no background. I draw background at the end of the script when I know position of legend, title and all labels at the display. But when I want draw background, the background rectangular overlaps all. Is there any option how to define not to overlap other lines? Or the only solution is to draw background rectangular first?
follow-up: 3 comment:2 by , 8 years ago
Replying to lazaa:
I added
-bflag to display legend background. Thenbrdcolorto choose border color. So far it works only for non-categoric rasters and displays only border color but no background. I draw background at the end of the script when I know position of legend, title and all labels at the display. But when I want draw background, the background rectangular overlaps all. Is there any option how to define not to overlap other lines? Or the only solution is to draw background rectangular first?
Look at the other d.* modules with background - how they do it. But I am afraid you might have to draw it first, so you would need to do the computations twice.
follow-up: 4 comment:3 by , 8 years ago
Replying to annakrat:
Replying to lazaa:
I added
-bflag to display legend background. Thenbrdcolorto choose border color. So far it works only for non-categoric rasters and displays only border color but no background. I draw background at the end of the script when I know position of legend, title and all labels at the display. But when I want draw background, the background rectangular overlaps all. Is there any option how to define not to overlap other lines? Or the only solution is to draw background rectangular first?Look at the other d.* modules with background - how they do it. But I am afraid you might have to draw it first, so you would need to do the computations twice.
It seems that I have to draw background first :(. Currently all calculation is in main function. I would move all calculation into a new function and add one parameter to decide whether to draw or not. First time I would call the function to get position, second time to draw it. New function should be in separate file or it doesn't matter?
comment:4 by , 8 years ago
Replying to lazaa:
It seems that I have to draw background first :(. Currently all calculation is in main function. I would move all calculation into a new function and add one parameter to decide whether to draw or not. First time I would call the function to get position, second time to draw it. New function should be in separate file or it doesn't matter?
Separate file is probably better. BTW, do not hesitate to add comments in the code about what is which part doing.
by , 8 years ago
| Attachment: | bg_ver.png added |
|---|
For vertical legend the title is aligned to the left edge of the legend.
by , 8 years ago
| Attachment: | bg_hor.png added |
|---|
For horizontal legend the title is aligned to the center
follow-up: 6 comment:5 by , 8 years ago
What should be the behaviour of the title position for vertical/horizontal legend? For horizontal legend the title is aligned to the center so even the title is longer then legend it's not a problem. For vertical legend the title is aligned to the left edge of legend. That looks OK only if the title is not too long.
comment:6 by , 8 years ago
Replying to lazaa:
What should be the behaviour of the title position for vertical/horizontal legend? For horizontal legend the title is aligned to the center so even the title is longer then legend it's not a problem. For vertical legend the title is aligned to the left edge of legend. That looks OK only if the title is not too long.
Let's keep it that way. Could you also add an option title_fontsize? I think often the font size of the title is bigger.
by , 8 years ago
| Attachment: | landcover.png added |
|---|
d.legend raster=landcover_1m brdcolor=green bgcolor=yellow title=landcover -b at=25,75,10,15
by , 8 years ago
| Attachment: | d.leg_bg.diff added |
|---|
patch for support background option in d.legend module
follow-up: 8 comment:7 by , 8 years ago
Added flag -b and option brdcolor and bgcolor to draw background. Also added optionfont_size as requested. Code was separeted from main.c to background.c and draw.c. For background purpose in case of -d flag (histogram) added function calc_histogram in histrogram2.c
follow-up: 9 comment:8 by , 8 years ago
Replying to lazaa:
Added flag
-band optionbrdcolorandbgcolorto draw background. Also added optionfont_sizeas requested. Code was separeted from main.c to background.c and draw.c. For background purpose in case of-dflag (histogram) added function calc_histogram in histrogram2.c
Something is missing in the patch, I can't compile it.
follow-up: 10 comment:9 by , 8 years ago
Replying to annakrat:
Replying to lazaa:
Added flag
-band optionbrdcolorandbgcolorto draw background. Also added optionfont_sizeas requested. Code was separeted from main.c to background.c and draw.c. For background purpose in case of-dflag (histogram) added function calc_histogram in histrogram2.cSomething is missing in the patch, I can't compile it.
My bad, I didn't add all files. Now it should be OK.
by , 8 years ago
| Attachment: | d.legend_bg2.diff added |
|---|
patch for support background option in d.legend module
follow-up: 11 comment:10 by , 8 years ago
Replying to lazaa:
Added flag
-band optionbrdcolorandbgcolorto draw background. Also added optionfont_sizeas requested. Code was separeted from main.c to background.c and draw.c. For background purpose in case of-dflag (histogram) added function calc_histogram in histrogram2.c
Tested, it works. However, the code is not maintainable like this, you have too large overlap between draw and background functions. I suggest to merge those functions and use ifs and put some parts into separate functions. Also check during compilation for warnings, there were a couple of them, probably not serious, but better to fix them.
comment:11 by , 8 years ago
Replying to annakrat:
Replying to lazaa:
Added flag
-band optionbrdcolorandbgcolorto draw background. Also added optionfont_sizeas requested. Code was separeted from main.c to background.c and draw.c. For background purpose in case of-dflag (histogram) added function calc_histogram in histrogram2.cTested, it works. However, the code is not maintainable like this, you have too large overlap between
drawandbackgroundfunctions. I suggest to merge those functions and use ifs and put some parts into separate functions. Also check during compilation for warnings, there were a couple of them, probably not serious, but better to fix them.
That's right, I didn't realize possible problems with maintaining code. So I moved it to one function and used parameter draw and if conditions. Draw=0 is for calculation and draw=1 for calculation and drawing. I don't get any warnings now, so I hope it's OK.
by , 8 years ago
| Attachment: | d.legend_background.diff added |
|---|
follow-up: 14 comment:12 by , 8 years ago
Thank you, I committed it in r68699. I did some minor changes in guisections and fixed one warning (-Wreturn-type). I have two more suggestions:
- if you use different font than the default one, the background box is larger than it should be. You don't use
D_get_text_boxthere, I wonder if this would give you better estimate? - The ticks are currently rendered in the same color as text, but they should be black as the legend outline.
follow-ups: 15 16 comment:13 by , 8 years ago
I just tried the updated d.legend, it looks really great!
One wish: would it be possible to turn the "Font name" field into a drop down list? If yes, also these modules could benefit from that:
- d.rast.num
- d.text
- d.vect
- v.label
comment:14 by , 8 years ago
Replying to annakrat:
Thank you, I committed it in r68699. I did some minor changes in guisections and fixed one warning (-Wreturn-type). I have two more suggestions:
- if you use different font than the default one, the background box is larger than it should be. You don't use
D_get_text_boxthere, I wonder if this would give you better estimate?
Thank you! Before there was a constant for font height/width ratio, which works only for romans font. With D_get_text_box it works now for all fonts much better.
- The ticks are currently rendered in the same color as text, but they should be black as the legend outline.
I changed it to black color.
comment:15 by , 8 years ago
Replying to neteler:
I just tried the updated d.legend, it looks really great!
One wish: would it be possible to turn the "Font name" field into a drop down list? If yes, also these modules could benefit from that:
- d.rast.num
- d.text
- d.vect
- v.label
I would also add d.grid to that list... IMHO, it would be more comfortable to change font there than to change it globally, and would allow to have different font settings for different map elements displayed.
follow-up: 17 comment:16 by , 8 years ago
Replying to neteler:
I just tried the updated d.legend, it looks really great!
One wish: would it be possible to turn the "Font name" field into a drop down list? If yes, also these modules could benefit from that:
- d.rast.num
- d.text
- d.vect
- v.label
I think it's possible. Only catch I can see, is there any list of fonts which are available within GRASS on every platform? I found one in d.font documentation with approx. 20 fonts. On the other hand if I run d.font -l I get hundreds of fonts (on my Ubuntu 16.04)
follow-up: 19 comment:17 by , 8 years ago
Replying to lazaa:
Replying to neteler:
I just tried the updated d.legend, it looks really great!
One wish: would it be possible to turn the "Font name" field into a drop down list? If yes, also these modules could benefit from that:
- d.rast.num
- d.text
- d.vect
- v.label
I think it's possible. Only catch I can see, is there any list of fonts which are available within GRASS on every platform? I found one in d.font documentation with approx. 20 fonts. On the other hand if I run
d.font -lI get hundreds of fonts (on my Ubuntu 16.04)
I would add a button to the font option field which opens the same font dialog which is in settings. So any d.* module with font would have that automatically.
comment:18 by , 8 years ago
There is still a bug - when you use categorical legend (eg landuse96_28m@PERMANENT) the background doesn't take into account the labels.
comment:19 by , 8 years ago
by , 8 years ago
| Attachment: | legend_histogram_left_border.png added |
|---|
Legend missing left background border when histogram is active
comment:20 by , 8 years ago
The -d flag (histogram) causes d.legend not to draw left border of the background (-b flag).
comment:21 by , 8 years ago
follow-up: 23 comment:22 by , 8 years ago
The problem is that the part of background is not rendered at all because of its position. The at option specifies the position and size of the legend bar, so if it's placed too close to the edge, the problem appears. Not sure what to do about it.
follow-up: 24 comment:23 by , 8 years ago
Replying to annakrat:
The problem is that the part of background is not rendered at all because of its position. The at option specifies the position and size of the legend bar, so if it's placed too close to the edge, the problem appears. Not sure what to do about it.
For GUI we can change the default position and move the legend closer to the center so the legend will be drawn with complete border and user can later move it interactively to wherever needs. For d.mon user can use the at option to move the legend further from the edge.
comment:24 by , 8 years ago
Replying to lazaa:
Replying to annakrat:
The problem is that the part of background is not rendered at all because of its position. The at option specifies the position and size of the legend bar, so if it's placed too close to the edge, the problem appears. Not sure what to do about it.
For GUI we can change the default position and move the legend closer to the center so the legend will be drawn with complete border and user can later move it interactively to wherever needs. For d.mon user can use the
atoption to move the legend further from the edge.
I hopefully fixed that in r68958.
comment:25 by , 8 years ago
| Milestone: | 7.3.0 → 7.2.0 |
|---|---|
| Resolution: | → fixed |
| Status: | new → closed |


patch with border option