[GRASS-dev] [GRASS GIS] #3013: support background and border for d.legend

#3013: support background and border for d.legend
-------------------------------------------------+-------------------------
Reporter: annakrat | Owner: grass-dev@…
     Type: enhancement | Status: new
Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Keywords: d.legend, background, gsoc2016, | CPU: Unspecified
  cartography |
Platform: All |
-------------------------------------------------+-------------------------
It would be nice to have background box for legend. Ideally there would be
option to add border too.

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------
Changes (by lazaa):

* Attachment "legend_border.png" added.

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------
Changes (by lazaa):

* Attachment "d.legend_bg.diff" added.

patch with border option

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by lazaa):

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?

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by annakrat):

Replying to [comment:1 lazaa]:
> 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?

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.

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by lazaa):

Replying to [comment:2 annakrat]:
> Replying to [comment:1 lazaa]:
> > 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?
>
> 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?

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by annakrat):

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

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------
Changes (by lazaa):

* Attachment "bg_ver.png" added.

For vertical legend the title is aligned to the left edge of the legend.

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------
Changes (by lazaa):

* Attachment "bg_hor.png" added.

For horizontal legend the title is aligned to the center

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

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

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by annakrat):

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

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------
Changes (by lazaa):

* Attachment "landcover.png" added.

{{{d.legend raster=landcover_1m brdcolor=green bgcolor=yellow
title=landcover -b at=25,75,10,15}}}

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------
Changes (by lazaa):

* Attachment "d.leg_bg.diff" added.

patch for support background option in d.legend module

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by lazaa):

Added flag {{{-b}}} and option {{{brdcolor}}} and {{{bgcolor}}} to draw
background. Also added option{{{font_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

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by annakrat):

Replying to [comment:7 lazaa]:
> Added flag {{{-b}}} and option {{{brdcolor}}} and {{{bgcolor}}} to draw
background. Also added option{{{font_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

Something is missing in the patch, I can't compile it.

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by lazaa):

Replying to [comment:8 annakrat]:
> Replying to [comment:7 lazaa]:
> > Added flag {{{-b}}} and option {{{brdcolor}}} and {{{bgcolor}}} to
draw background. Also added option{{{font_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
>
> Something is missing in the patch, I can't compile it.
My bad, I didn't add all files. Now it should be OK.

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------
Changes (by lazaa):

* Attachment "d.legend_bg2.diff" added.

patch for support background option in d.legend module

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by annakrat):

> > Replying to [comment:7 lazaa]:
> > > Added flag {{{-b}}} and option {{{brdcolor}}} and {{{bgcolor}}} to
draw background. Also added option{{{font_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

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.

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------

Comment (by lazaa):

Replying to [comment:10 annakrat]:
> > > Replying to [comment:7 lazaa]:
> > > > Added flag {{{-b}}} and option {{{brdcolor}}} and {{{bgcolor}}} to
draw background. Also added option{{{font_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
>
> 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.

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.

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

#3013: support background and border for d.legend
-------------------------+-------------------------------------------------
  Reporter: annakrat | Owner: grass-dev@…
      Type: | Status: new
  enhancement |
  Priority: normal | Milestone: 7.3.0
Component: Display | Version: svn-trunk
Resolution: | Keywords: d.legend, background, gsoc2016,
       CPU: | cartography
  Unspecified | Platform: All
-------------------------+-------------------------------------------------
Changes (by lazaa):

* Attachment "d.legend_background.diff" added.

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