Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#3017 closed enhancement (fixed)

support for background option for grid labels in d.grid

Reported by: veroandreo Owned by: grass-dev@…
Priority: normal Milestone: 7.4.0
Component: Display Version: unspecified
Keywords: d.grid, gsoc2016, cartography Cc:
CPU: Unspecified Platform: Unspecified

Description

It would be nice to also have background color option (along with grid color, text color and border color) when adding grid labels with d.grid.

Attachments (7)

d.grid.diff (42.6 KB ) - added by lazaa 8 years ago.
Added option bg_color to choose background color of grid labels
dgrid.png (94.9 KB ) - added by annakrat 8 years ago.
d.grid with the new bgcolor option
d.grid2.diff (9.8 KB ) - added by lazaa 8 years ago.
Updated patch with original whitespaces/tabs. Text box margin is calculated as a percentage of text width/height.
map.png (234.5 KB ) - added by lazaa 8 years ago.
geographical grid and non-rotated labels
d_grid_examples.png (80.1 KB ) - added by veroandreo 8 years ago.
d.grid testing transparency vs no-transparency and labels positioning
d.grid3.diff (18.1 KB ) - added by lazaa 8 years ago.
Labels are displayed in front of grid lines.
d.grid4.diff (2.1 KB ) - added by lazaa 8 years ago.
Bg rectangular size fixed

Download all attachments as: .zip

Change History (23)

comment:1 by annakrat, 8 years ago

Keywords: gsoc2016 cartography added

by lazaa, 8 years ago

Attachment: d.grid.diff added

Added option bg_color to choose background color of grid labels

comment:2 by annakrat, 8 years ago

Thanks for the patch, but I am getting weird results (see attachment). It's possible I might have done something wrong when applying the patch, because I needed to get rid of the whitespace changes. Could you please check this?

Also bg_color should be probably changed to bgcolor to be compatible with all other modules having this option.

Ideally please upload a new patch without the whitespace changes.

by annakrat, 8 years ago

Attachment: dgrid.png added

d.grid with the new bgcolor option

in reply to:  2 ; comment:3 by lazaa, 8 years ago

Replying to annakrat:

Thanks for the patch, but I am getting weird results (see attachment). It's possible I might have done something wrong when applying the patch, because I needed to get rid of the whitespace changes. Could you please check this?

Also bg_color should be probably changed to bgcolor to be compatible with all other modules having this option.

Ideally please upload a new patch without the whitespace changes.

OK, I will change it to bgcolor. I think the problem is not in whitespaces. The size of label background depends on the font size. I tested it on several font sizes and I got good results but obviously it doesn't work in general.

in reply to:  3 ; comment:4 by annakrat, 8 years ago

Replying to lazaa:

Replying to annakrat:

Thanks for the patch, but I am getting weird results (see attachment). It's possible I might have done something wrong when applying the patch, because I needed to get rid of the whitespace changes. Could you please check this?

Also bg_color should be probably changed to bgcolor to be compatible with all other modules having this option.

Ideally please upload a new patch without the whitespace changes.

OK, I will change it to bgcolor. I think the problem is not in whitespaces. The size of label background depends on the font size. I tested it on several font sizes and I got good results but obviously it doesn't work in general.

It seems to change with zoom level, so I think you have to somehow convert between the pixel and geographic coordinates.

by lazaa, 8 years ago

Attachment: d.grid2.diff added

Updated patch with original whitespaces/tabs. Text box margin is calculated as a percentage of text width/height.

by lazaa, 8 years ago

Attachment: map.png added

geographical grid and non-rotated labels

in reply to:  4 ; comment:5 by lazaa, 8 years ago

Replying to annakrat:

Replying to lazaa:

Replying to annakrat:

Thanks for the patch, but I am getting weird results (see attachment). It's possible I might have done something wrong when applying the patch, because I needed to get rid of the whitespace changes. Could you please check this?

Also bg_color should be probably changed to bgcolor to be compatible with all other modules having this option.

Ideally please upload a new patch without the whitespace changes.

OK, I will change it to bgcolor. I think the problem is not in whitespaces. The size of label background depends on the font size. I tested it on several font sizes and I got good results but obviously it doesn't work in general.

It seems to change with zoom level, so I think you have to somehow convert between the pixel and geographic coordinates.

I uploaded new patch with original whitespaces/tabs.

I looked how it is done in d.text module. Now is the margin of the text box calculated from width and height of the text inside text box.

Another problem is that if user uses flag -g or -w. The geographical grid isn't horizontal/vertical so the labels are a bit rotated. But I couldn't find any way how to rotate the text box for filling background. I attached an image.

comment:6 by annakrat, 8 years ago

In 68542:

d.grid: add bgcolor, see #3017, author Adam Laza

in reply to:  5 comment:7 by annakrat, 8 years ago

Replying to lazaa:

I uploaded new patch with original whitespaces/tabs.

I looked how it is done in d.text module. Now is the margin of the text box calculated from width and height of the text inside text box.

Another problem is that if user uses flag -g or -w. The geographical grid isn't horizontal/vertical so the labels are a bit rotated. But I couldn't find any way how to rotate the text box for filling background. I attached an image.

Thank you, I committed it. I don't think the rotation is a huge problem here for most cases. You could look at d.labels, it can do the rotation of the background. But I don't think you should focus on this now.

More testing welcome.

comment:8 by veroandreo, 8 years ago

Hi, I'm happy to have background option in d.grid :)

I did a quick test and I attach an example below. I noted that when choosing white background for grid labels, I loose part of the map in the east (See no-transparency in fig 1 vs transparency in fig 2). So, background of labels seems to be a continuous white strip for Y coordinate, while it's fine for X coordinate.

On the other hand, grid lines overlap the white background of labels, while IMHO, label should always be in front.

I personally don't like the border tickmarks of d.grid but when disabling them, labels remain aligned as if there were border tickmarks (last fig). Maybe they could be aligned more close to the border (if not against it) as in ps.map.

And, would that be possible to also change font of labels?? :)

by veroandreo, 8 years ago

Attachment: d_grid_examples.png added

d.grid testing transparency vs no-transparency and labels positioning

in reply to:  8 ; comment:9 by annakrat, 8 years ago

Replying to veroandreo:

Hi, I'm happy to have background option in d.grid :)

I did a quick test and I attach an example below. I noted that when choosing white background for grid labels, I loose part of the map in the east (See no-transparency in fig 1 vs transparency in fig 2). So, background of labels seems to be a continuous white strip for Y coordinate, while it's fine for X coordinate.

I can confirm this, the size of the background rectangle still needs fixing, the problem showed up only in latlon for me.

On the other hand, grid lines overlap the white background of labels, while IMHO, label should always be in front.

Yes, the horizontal labels are fine, just the vertical ones are below the grid lines.

I personally don't like the border tickmarks of d.grid but when disabling them, labels remain aligned as if there were border tickmarks (last fig). Maybe they could be aligned more close to the border (if not against it) as in ps.map.

And, would that be possible to also change font of labels?? :)

You can do that from GUI settings - you set display font for all d.* commands.

in reply to:  9 comment:10 by lazaa, 8 years ago

Replying to annakrat:

Replying to veroandreo:

Hi, I'm happy to have background option in d.grid :)

I did a quick test and I attach an example below. I noted that when choosing white background for grid labels, I loose part of the map in the east (See no-transparency in fig 1 vs transparency in fig 2). So, background of labels seems to be a continuous white strip for Y coordinate, while it's fine for X coordinate.

I can confirm this, the size of the background rectangle still needs fixing, the problem showed up only in latlon for me.

I tried to find the problem, but I didn't succeed :(

On the other hand, grid lines overlap the white background of labels, while IMHO, label should always be in front.

Yes, the horizontal labels are fine, just the vertical ones are below the grid lines.

I fixed this problem. Now the grid lines are drawn first (both vertical and horizontal) and after that are drawn labels so at final they are shown in front.

I personally don't like the border tickmarks of d.grid but when disabling them, labels remain aligned as if there were border tickmarks (last fig). Maybe they could be aligned more close to the border (if not against it) as in ps.map.

And, would that be possible to also change font of labels?? :)

You can do that from GUI settings - you set display font for all d.* commands.

by lazaa, 8 years ago

Attachment: d.grid3.diff added

Labels are displayed in front of grid lines.

by lazaa, 8 years ago

Attachment: d.grid4.diff added

Bg rectangular size fixed

comment:11 by annakrat, 8 years ago

In 68556:

d.grid: fix labels in latlon, see #3017

comment:12 by veroandreo, 8 years ago

I confirm that the rectangular size in Y coordinate now appears as expected, but I noticed that disabling grid drawing (-n) also makes text disappear (both in latlong and projected locations).

in reply to:  12 ; comment:13 by annakrat, 8 years ago

Replying to veroandreo:

I confirm that the rectangular size in Y coordinate now appears as expected, but I noticed that disabling grid drawing (-n) also makes text disappear (both in latlong and projected locations).

The behavior didn't change, it was there before. Please create a separate ticket for that.

in reply to:  13 comment:14 by veroandreo, 8 years ago

Replying to annakrat:

Replying to veroandreo:

I confirm that the rectangular size in Y coordinate now appears as expected, but I noticed that disabling grid drawing (-n) also makes text disappear (both in latlong and projected locations).

The behavior didn't change, it was there before. Please create a separate ticket for that.

Done in #3053

comment:15 by annakrat, 8 years ago

Resolution: fixed
Status: newclosed

Backported in r68964.

comment:16 by martinl, 8 years ago

Milestone: 7.3.07.4.0

Milestone renamed

Note: See TracTickets for help on using tickets.