Opened 5 years ago

Closed 4 years ago

Last modified 4 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 5 years ago.
Added option bg_color to choose background color of grid labels
dgrid.png (94.9 KB) - added by annakrat 5 years ago.
d.grid with the new bgcolor option
d.grid2.diff (9.8 KB) - added by lazaa 5 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 5 years ago.
geographical grid and non-rotated labels
d_grid_examples.png (80.1 KB) - added by veroandreo 5 years ago.
d.grid testing transparency vs no-transparency and labels positioning
d.grid3.diff (18.1 KB) - added by lazaa 5 years ago.
Labels are displayed in front of grid lines.
d.grid4.diff (2.1 KB) - added by lazaa 5 years ago.
Bg rectangular size fixed

Download all attachments as: .zip

Change History (23)

comment:1 Changed 5 years ago by annakrat

Keywords: gsoc2016 cartography added

Changed 5 years ago by lazaa

Attachment: d.grid.diff added

Added option bg_color to choose background color of grid labels

comment:2 Changed 5 years ago by 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.

Changed 5 years ago by annakrat

Attachment: dgrid.png added

d.grid with the new bgcolor option

comment:3 in reply to:  2 ; Changed 5 years ago by 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.

comment:4 in reply to:  3 ; Changed 5 years ago by 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.

Changed 5 years ago by lazaa

Attachment: d.grid2.diff added

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

Changed 5 years ago by lazaa

Attachment: map.png added

geographical grid and non-rotated labels

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

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 Changed 5 years ago by annakrat

In 68542:

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

comment:7 in reply to:  5 Changed 5 years ago by annakrat

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 Changed 5 years ago by 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.

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?? :)

Changed 5 years ago by veroandreo

Attachment: d_grid_examples.png added

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

comment:9 in reply to:  8 ; Changed 5 years ago by 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.

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.

comment:10 in reply to:  9 Changed 5 years ago by lazaa

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.

Changed 5 years ago by lazaa

Attachment: d.grid3.diff added

Labels are displayed in front of grid lines.

Changed 5 years ago by lazaa

Attachment: d.grid4.diff added

Bg rectangular size fixed

comment:11 Changed 5 years ago by annakrat

In 68556:

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

comment:12 Changed 5 years ago by 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).

comment:13 in reply to:  12 ; Changed 5 years ago by 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.

comment:14 in reply to:  13 Changed 5 years ago by veroandreo

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 Changed 4 years ago by annakrat

Resolution: fixed
Status: newclosed

Backported in r68964.

comment:16 Changed 4 years ago by martinl

Milestone: 7.3.07.4.0

Milestone renamed

Note: See TracTickets for help on using tickets.