[GRASS-dev] [GRASS GIS] #3017: support for background option for grid labels in d.grid

#3017: support for background option for grid labels in d.grid
-------------------------+-------------------------
Reporter: veroandreo | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Keywords: d.grid | CPU: Unspecified
Platform: Unspecified |
-------------------------+-------------------------
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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------
Changes (by annakrat):

* keywords: d.grid => d.grid, gsoc2016, cartography

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/3017#comment:1&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------
Changes (by lazaa):

* Attachment "d.grid.diff" added.

Added option bg_color to choose background color of grid labels

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------

Comment (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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017#comment:2&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------
Changes (by annakrat):

* Attachment "dgrid.png" added.

d.grid with the new bgcolor option

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------

Comment (by lazaa):

Replying to [comment:2 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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017#comment:3&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------

Comment (by annakrat):

Replying to [comment:3 lazaa]:
> Replying to [comment:2 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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017#comment:4&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------
Changes (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.

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/3017&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------
Changes (by lazaa):

* Attachment "map.png" added.

geographical grid and non-rotated labels

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------

Comment (by lazaa):

Replying to [comment:4 annakrat]:
> Replying to [comment:3 lazaa]:
> > Replying to [comment:2 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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017#comment:5&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------

Comment (by annakrat):

In [changeset:"68542" 68542]:
{{{
#!CommitTicketReference repository="" revision="68542"
d.grid: add bgcolor, see #3017, author Adam Laza
}}}

--
Ticket URL: </ticket/3017#comment:6>
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------

Comment (by annakrat):

Replying to [comment:5 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.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017#comment:7&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------

Comment (by veroandreo):

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

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

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017#comment:8&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------
Changes (by veroandreo):

* Attachment "d_grid_examples.png" added.

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

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------

Comment (by annakrat):

Replying to [comment:8 veroandreo]:
> Hi, I'm happy to have background option in d.grid :slight_smile:
>
> 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?? :slight_smile:
>
You can do that from GUI settings - you set display font for all d.*
commands.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017#comment:9&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------

Comment (by lazaa):

Replying to [comment:9 annakrat]:
> Replying to [comment:8 veroandreo]:
> > Hi, I'm happy to have background option in d.grid :slight_smile:
> >
> > 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 :frowning:

> >
> > 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?? :slight_smile:
> >
> You can do that from GUI settings - you set display font for all d.*
commands.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017#comment:10&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------
Changes (by lazaa):

* Attachment "d.grid3.diff" added.

Labels are displayed in front of grid lines.

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------
Changes (by lazaa):

* Attachment "d.grid4.diff" added.

Bg rectangular size fixed

--
Ticket URL: <http://trac.osgeo.org/grass/ticket/3017&gt;
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------

Comment (by annakrat):

In [changeset:"68556" 68556]:
{{{
#!CommitTicketReference repository="" revision="68556"
d.grid: fix labels in latlon, see #3017
}}}

--
Ticket URL: </ticket/3017#comment:11>
GRASS GIS <https://grass.osgeo.org>

#3017: support for background option for grid labels in d.grid
--------------------------+-------------------------------------------
  Reporter: veroandreo | Owner: grass-dev@…
      Type: enhancement | Status: new
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: unspecified
Resolution: | Keywords: d.grid, gsoc2016, cartography
       CPU: Unspecified | Platform: Unspecified
--------------------------+-------------------------------------------

Comment (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).

--
Ticket URL: <https://trac.osgeo.org/grass/ticket/3017#comment:12&gt;
GRASS GIS <https://grass.osgeo.org>