Opened 9 years ago

Closed 8 years ago

#3014 closed enhancement (fixed)

Add ticks to continuous raster legend

Reported by: annakrat Owned by: grass-dev@…
Priority: normal Milestone: 7.2.0
Component: Display Version: svn-trunk
Keywords: d.legend, gsoc2016, cartography Cc:
CPU: Unspecified Platform: All

Description

Continuous legend should have option to add ticks, so that it is easier to read. It would be good to have the option to add the tick numbers.

Attachments (3)

d.legend.diff (10.7 KB ) - added by lazaa 8 years ago.
added several options for d.legend
d.legend2.diff (16.1 KB ) - added by lazaa 8 years ago.
updated patch
legends.png (39.4 KB ) - added by lazaa 8 years ago.
legend examples

Download all attachments as: .zip

Change History (10)

comment:1 by lazaa, 8 years ago

Currently legend has ticks in regular intervals depend on labelnum. The aim is to add option e.g. steps=100 for display label every hundred or labels_at=[list of values] to add one or more labels at specific values? (value would have to be min < label_at < max)

in reply to:  1 comment:2 by annakrat, 8 years ago

Replying to lazaa:

Currently legend has ticks in regular intervals depend on labelnum. The aim is to add option e.g. steps=100 for display label every hundred or labels_at=[list of values] to add one or more labels at specific values? (value would have to be min < label_at < max)

Start with drawing the tick marks based on labelnum. You should probably center the label at the tick.

If we want to further complicate it, there is couple of options. For example, we could have a parameter tick_value (or something similar) where user would specify values where to plot the ticks and labels.

Another option is to add tick_step which would create ticks based on the step. But the tick_start may be needed to know where to draw the first one.

comment:3 by lazaa, 8 years ago

I uploaded new patch and I added several new options. Option title to define custom title to display on the top of the legend.

d.legend raster=srtm title="Map legend"

An option tick_value to specify values where the ticks and labels will be displayed. Option labelnum is used to show only min and max.

d.legend raster=srtm labelnum=2 tick_value=1000,1848,2700,3500

Then option step to draw ticks and display labels at rounded values-values divisible by step value with rest 0. (Flag -c is used to hide labels generated from labelnum and to display only labels with defined interval.)

d.legend raster=srtm -c step=500

I've tested it for vertical/horizontal and normal/flipped legend it works fine. There's a problem with horizontal legend if user define more ticks then longer labels can overlap.

More testing welcome.

by lazaa, 8 years ago

Attachment: d.legend.diff added

added several options for d.legend

comment:4 by annakrat, 8 years ago

Thanks, I tested it and it works very well. I have couple of suggestions:

  • if you compare the default before and after this change, the white border is now transparent, so that should be changed back. Also if you test categorical data, the black/white border is switched (inner is black, should be white). The current default legend size is wider than the previous one, that should be fixed as well.
  • drawing ticks should be optional, implement for example '-t' flag. Question is if it should draw the ticks by default or not. Let's switch them off by default for now.
  • the vertical centering of the labels and ticks is not quite perfect, I wonder if it could be improved
  • I thought more about the names of the new parameters and decided label_values and label_step would fit more to labelnum
  • the -c flag should always hide all the numbers, it is actually useful mostly with categorical data
  • I think when option label_value or label_step is used, labelnum should be ignored. So the min max values won't be displayed. I hope we could get some feedback from other users what kind of behavior would be more natural.

by lazaa, 8 years ago

Attachment: d.legend2.diff added

updated patch

by lazaa, 8 years ago

Attachment: legends.png added

legend examples

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

Replying to annakrat:

Thanks, I tested it and it works very well. I have couple of suggestions:

  • if you compare the default before and after this change, the white border is now transparent, so that should be changed back. Also if you test categorical data, the black/white border is switched (inner is black, should be white). The current default legend size is wider than the previous one, that should be fixed as well.

It's fixed, it should be the same like before.

  • drawing ticks should be optional, implement for example '-t' flag. Question is if it should draw the ticks by default or not. Let's switch them off by default for now.

-t option added. By default ticks are switched off.

  • the vertical centering of the labels and ticks is not quite perfect, I wonder if it could be improved

It's the same problem with fonts like in d.grid. Centering works fine for default GRASS_FONT. The problem is there's a constant which define the width/height ratio of a letter.

  • I thought more about the names of the new parameters and decided label_values and label_step would fit more to labelnum

I changed both option names.

  • the -c flag should always hide all the numbers, it is actually useful mostly with categorical data

-c flag now hide all labels. G_option_exclusive is used so user can't use c flag with label_value or label_step option.

  • I think when option label_value or label_step is used, labelnum should be ignored. So the min max values won't be displayed. I hope we could get some feedback from other users what kind of behavior would be more natural.

I add G_option_exclusive but please test it if everything is OK.

comment:6 by annakrat, 8 years ago

In 68671:

d.legend: improvements by Adam Laza: ticks, new options for labels, title, see #3014, #3015

comment:7 by annakrat, 8 years ago

Milestone: 7.3.07.2.0
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.