[GRASS-user] Horizontal legend font size
hamish_b at yahoo.com
Wed Aug 13 03:42:00 EDT 2008
Paul Moen wrote:
> I want to create a horizontal legend for a raster.
> The docs say,
> > When using the mouse or at to size & place the
> legend, a user may create a horizontal legend by making
> the box wider than it is tall.
> I read the previous line to mean the only way to create a
> legend is to use at and make the box wider than it is tall.
> Is that correct?
> Can I make a legend horizontal without using at=bottom,top,left,right
>From the command line and xmons you can use 'd.legend -m' to place the
legend with the mouse. I am not sure if you get the same chance from
the GUIs or if the only option there is filling in at=.
> The docs also say,
> > Vertical legends produced with d.legend will place text
> labels to the right of the legend box, horizontal legends
> will place text below. This text will be auto-scaled to fit
> within the frame, reducing the size of the legend if
> necessary. Legends positioned with the mouse or with
> the at option will not auto-scale text, in order to provide
> more control to the user.
> The last line that says that the text will not auto-scale
> when using at,
correct. Only d.legend without at= or -m will autoscale. If manually
placed it will assume you know what you are doing and give you exactly
what you requested.
WRT horizontal scales, I think it only autoscales from the right side of the window, not the bottom. But anyway, full labels are useless in a
horiz legend, they just fall on top of each other.
but see below- what is being autoscaled is the category label.
e.g. "d.legend -n landcover.30m" in the spearfish dataset then adjust
the window so it is narrower and watch it autoscale.
> which means that a horizontal legend¹s text will never auto-scale
> since the horizontal legend can only be made by using at to create
> a box that is wider than it is tall. Am I misinterpreting anything?
a couple of things:
you can make a box wider than it is tall on an xmon using the -m "place
with mouse" command line flag. The GUIs don't use xmons, which forces the
use of at=.
But what I meant by "text labels" is for categorical legends not tick numbers. e.g.:
[red] pine forest
[blue] deciduous forest
[grey] urban area
in this case the "pine forest" text would automatically shrink if it would
fall off the right side of the window.
For horizontal legends font size is purely a function of legend width.
(for vertical legends it is the legend height)
I guess for horiz legends I could look at rotating the font 90deg for
categorical legends with text labels (set with r.cats/r.category). But
I'd wait for strong user demand before spending any time on that.
> My problem is that I get a horizontal legend that looks great except
> the text is huge and looks awful.
you mean numbers (category or value) or text labels of categories?
could you provide a screenshot?
is this a floating point (FCELL or DCELL) or categorical (CELL) map?
> How can I change the size of the text in the legend?
you need to recompile d.legend with the following patch:
--- display/d.legend/main.c (revision 32734)
+++ display/d.legend/main.c (working copy)
@@ -672,7 +672,7 @@
txsiz = (int)((y1 - y0) / 20);
- txsiz = (int)((x1 - x0) / 20);
+ txsiz = (int)((x1 - x0) / 25);
/* scale text to fit in window if position not manually set */
/* usually not needed, except when frame is really narrow */
adjust the divisor to suit. The above patch makes the font super tiny
for legends which are around 2-3 inches wide, so I am loathe to apply
it in SVN. Maybe it would be better to make textsize it a fn of width^2
so the rate of change was not so dramatic.
> The following are my commands.
> d.rast raster at Temp
> d.frame -c frame=leg at=1,10,5,95
> d.legend -s range=0,13.5 labelnum=5 at=80,100,5,95 map=raster at Temp
after changing the scaling with the above patch, this looks nice for me:
d.legend -s range=0,13.5 labelnum=4 at=50,90,5,95 map=
More information about the grass-user