[GRASS-SVN] r33445 - grass/branches/develbranch_6/ps/ps.map
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Sep 15 03:31:34 EDT 2008
Author: hamish
Date: 2008-09-15 03:31:34 -0400 (Mon, 15 Sep 2008)
New Revision: 33445
Modified:
grass/branches/develbranch_6/ps/ps.map/description.html
grass/branches/develbranch_6/ps/ps.map/ps_fclrtbl.c
Log:
better units label placement + adjustable (code)
Modified: grass/branches/develbranch_6/ps/ps.map/description.html
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/description.html 2008-09-15 00:04:32 UTC (rev 33444)
+++ grass/branches/develbranch_6/ps/ps.map/description.html 2008-09-15 07:31:34 UTC (rev 33445)
@@ -239,38 +239,45 @@
</PRE>
The color table will display the colors for each raster map layer
category value and the category label.
-If <B>raster</B> is omitted, the colortable defaults to a previously registered raster layer.
+If <B>raster</B> is omitted, the colortable defaults to a previously
+registered raster layer.
The legend's <B>range</B> can be adjusted for floating point rasters, but if
set beyond the extent of the map's range be sure that you have set up color
rules with <em>r.colors</em> which cover this range.
The default location for the colortable is immediately below any other
map legend information, starting at the left margin.
The default text color is black.
+
Omitting the <B>colortable</B> instruction would result in
no color table. For floating point legends <B>width</B> is width of color
band only. <B>height</B> is used only for floating point legend.
Adding the <B>nodata n</B> instruction will prevent the "no data" box
from being drawn (category based legends only).
+
Adding the <B>tickbar y</B> instruction will change the tick mark style
so that ticks are drawn across the color table instead of protruding out
to the right (floating point legends only).
+
+If the map has been given a data units label with r.support then this
+label will be displayed.
+<!-- bonus prize for code explorers: you can switch the label placement by
+ editing the label_posn variable in ps.map/ps_fclrtbl.c -->
<P>
-<B>Note</B>: Be careful about asking for color tables for
+<B>Note</B>: Be careful about asking for color tables for integer
raster map layers which have many categories, such as elevation.
This could result in the printing of an extremely long color table!
<P>
Another issue is that the color table only includes categories which
have a label. If there are only a few categories, you can use
r.support to manually add labels. If there are too many categories to
-do this, you could write a script to add dummy labels to the cats file<br>
-(<gisdbase>/<location>/<mapset>/cats/<mapname>).
+do this by hand, you can supply a label rules file to the r.category
+module.
<P>
If the colortable is turned off with a "<tt>colortable n</tt>"
instruction the <B>end</B> command should not be given as the
main command will be treated as a single line instruction.
<P>
-
This example would print a color table immediately below any other map legend
information, starting at the left margin, with 4 columns:
<PRE>
@@ -1157,7 +1164,8 @@
This reference point specifies the text handle - what
part of the text should be placed on the location specified by the map
coordinates. Reference points can refer to:
-[lower|upper|center] [left|right|center] of the text to be printed; The default is center center, i.e the text is centered on the reference point.
+[lower|upper|center] [left|right|center] of the text to be printed;
+The default is center center, i.e the text is centered on the reference point.
<P>
<B>rotate</B>
sets the text rotation angle, measured in degrees counter-clockwise.
@@ -1256,8 +1264,8 @@
simple PostScript commands. It is similar to EPS but more limited, meaning that
while each pattern file is a true EPS file, most EPS files are not useful as pattern
files because they contain restricted commands. Color and width of patterns are set
-by <B>fcolor</B> (red, green, ..., none, R:G:B) and <B>width</B> until overwritten
-in the pattern file.
+by <B>fcolor</B> (red, green, ..., none, R:G:B) and <B>width</B> until
+overwritten in the pattern file.
Pattern may be scaled with the <b>scale</b> command. Several standard hatching
patterns are provided in <tt>$GISBASE/etc/paint/patterns/</tt>.
Demonstrative images can be found on the
Modified: grass/branches/develbranch_6/ps/ps.map/ps_fclrtbl.c
===================================================================
--- grass/branches/develbranch_6/ps/ps.map/ps_fclrtbl.c 2008-09-15 00:04:32 UTC (rev 33444)
+++ grass/branches/develbranch_6/ps/ps.map/ps_fclrtbl.c 2008-09-15 07:31:34 UTC (rev 33445)
@@ -26,7 +26,7 @@
int R, G, B;
DCELL dmin, dmax, val;
double t, l, r; /* legend top, left, right */
- double x1, x2, y, dy, fontsize;
+ double x1, x2, y, dy, fontsize, xu, yu;
double col_width;
double width; /* width of legend in map units */
double height; /* width of legend in map units */
@@ -40,7 +40,7 @@
double ex, cur_d, cur_ex;
int do_color;
double grey_color_val, margin;
- int max_label_length = 0;
+ int max_label_length = 0, label_posn, label_xref, label_yref;
/* let user know what's happenning */
G_message(_("Creating color table for <%s in %s>..."),
@@ -251,17 +251,66 @@
if (G_read_raster_units(ct.name, ct.mapset, units) != 0)
units[0] = '\0';
- /* TODO: nicer placement as label length changes; realign for tickbar mode */
if(strlen(units)) {
margin = 0.2 * fontsize;
if (margin < 2)
margin = 2;
fprintf(PS.fp, "/mg %.1f def\n", margin);
- text_box_path( x2 + max_label_length*(fontsize*.7),
- t - height/2,
- LEFT, CENTER, units, fontsize, 0);
+ /* select label position */
+ label_posn = 3;
+ /* 1 2
+ 3
+ 5 4 */
+ switch (label_posn) {
+ case 1:
+ /* above the tick numbers */
+ xu = x1;
+ yu = t + 0.05*72;
+ label_xref = LEFT;
+ label_yref = LOWER;
+ break;
+ case 2:
+ /* directly above the tick numbers */
+ if (ct.tickbar)
+ xu += x1 + 0.2 * fontsize;
+ else
+ xu += x2 + 0.2 * fontsize;
+ yu = t + 0.05*72;
+ label_xref = LEFT;
+ label_yref = LOWER;
+ break;
+ case 3:
+ /* to the right of the tick numbers */
+ xu = 0.15*72 + max_label_length*fontsize*0.5;
+ if (ct.tickbar)
+ xu += x1;
+ else
+ xu += x2;
+ yu = t - height/2;
+ label_xref = LEFT;
+ label_yref = CENTER;
+ break;
+ case 4:
+ /* directly below the tick numbers */
+ if (ct.tickbar)
+ xu += x1 + 0.2 * fontsize;
+ else
+ xu += x2 + 0.2 * fontsize;
+ yu = t - height - 0.05*72;
+ label_xref = LEFT;
+ label_yref = UPPER;
+ break;
+ case 5:
+ /* below the tick numbers */
+ xu = x1;
+ yu = t - height - 0.05*72;
+ label_xref = LEFT;
+ label_yref = UPPER;
+ break;
+ }
+ text_box_path( xu, yu, label_xref, label_yref, units, fontsize, 0);
set_rgb_color(BLACK);
fprintf(PS.fp, "TIB\n");
}
More information about the grass-commit
mailing list