فهرست منبع

better units label placement + adjustable (code) (merge from devbr6)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33446 15284696-431f-4ddb-bdfa-cd5b030d7da7
Hamish Bowman 17 سال پیش
والد
کامیت
ccc90788ef
2فایلهای تغییر یافته به همراه70 افزوده شده و 16 حذف شده
  1. 15 10
      ps/ps.map/ps.map.html
  2. 55 6
      ps/ps.map/ps_fclrtbl.c

+ 15 - 10
ps/ps.map/ps.map.html

@@ -239,38 +239,42 @@ USAGE:	<B>colortable</B> [y|n]
 </PRE>
 </PRE>
 The color table will display the colors for each raster map layer
 The color table will display the colors for each raster map layer
 category value and the category label.
 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 
 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 
 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.
 rules with <em>r.colors</em> which cover this range.
 The default location for the colortable is immediately below any other
 The default location for the colortable is immediately below any other
 map legend information, starting at the left margin.
 map legend information, starting at the left margin.
 The default text color is black.
 The default text color is black.
+
 Omitting the <B>colortable</B> instruction would result in
 Omitting the <B>colortable</B> instruction would result in
 no color table. For floating point legends <B>width</B> is width of color
 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.
 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 
 Adding the <B>nodata n</B> instruction will prevent the "no data" box 
 from being drawn (category based legends only).
 from being drawn (category based legends only).
+
 Adding the <B>tickbar y</B> instruction will change the tick mark style
 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 
 so that ticks are drawn across the color table instead of protruding out 
 to the right (floating point legends only).
 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> 
 <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.
 raster map layers which have many categories, such as elevation.
 This could result in the printing of an extremely long color table!
 This could result in the printing of an extremely long color table!
 <P>
 <P>
 Another issue is that the color table only includes categories which
 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>
-(&lt;gisdbase&gt;/&lt;location&gt;/&lt;mapset&gt;/cats/&lt;mapname&gt;).
+have a label. You can use the r.category module to add labels.
 <P>
 <P>
 If the colortable is turned off with a &quot;<tt>colortable&nbsp;n</tt>&quot;
 If the colortable is turned off with a &quot;<tt>colortable&nbsp;n</tt>&quot;
 instruction the <B>end</B> command should not be given as the  
 instruction the <B>end</B> command should not be given as the  
 main command will be treated as a single line instruction.
 main command will be treated as a single line instruction.
 
 
 <P>
 <P>
-
 This example would print a color table immediately below any other map legend
 This example would print a color table immediately below any other map legend
 information, starting at the left margin, with 4 columns:
 information, starting at the left margin, with 4 columns:
 <PRE>
 <PRE>
@@ -1157,7 +1161,8 @@ the text box <B>border</B> color;
 This reference point specifies the text handle - what
 This reference point specifies the text handle - what
 part of the text should be placed on the location specified by the map
 part of the text should be placed on the location specified by the map
 coordinates.  Reference points can refer to:
 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>
 <P>
 <B>rotate</B>
 <B>rotate</B>
 sets the text rotation angle, measured in degrees counter-clockwise.
 sets the text rotation angle, measured in degrees counter-clockwise.
@@ -1256,8 +1261,8 @@ first vector is used.
 simple PostScript commands. It is similar to EPS but more limited, meaning that
 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
 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
 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
 Pattern may be scaled with the <b>scale</b> command. Several standard hatching
 patterns are provided in <tt>$GISBASE/etc/paint/patterns/</tt>.
 patterns are provided in <tt>$GISBASE/etc/paint/patterns/</tt>.
 Demonstrative images can be found on the
 Demonstrative images can be found on the

+ 55 - 6
ps/ps.map/ps_fclrtbl.c

@@ -26,7 +26,7 @@ int PS_fcolortable(void)
     int R, G, B;
     int R, G, B;
     DCELL dmin, dmax, val;
     DCELL dmin, dmax, val;
     double t, l, r;		/* legend top, left, right */
     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 col_width;
     double width;		/* width of legend in map units */
     double width;		/* width of legend in map units */
     double height;		/* width of legend in map units */
     double height;		/* width of legend in map units */
@@ -40,7 +40,7 @@ int PS_fcolortable(void)
     double ex, cur_d, cur_ex;
     double ex, cur_d, cur_ex;
     int do_color;
     int do_color;
     double grey_color_val, margin;
     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 */
     /* let user know what's happenning */
     G_message(_("Creating color table for <%s in %s>..."),
     G_message(_("Creating color table for <%s in %s>..."),
@@ -251,17 +251,66 @@ int PS_fcolortable(void)
     if (G_read_raster_units(ct.name, ct.mapset, units) != 0)
     if (G_read_raster_units(ct.name, ct.mapset, units) != 0)
         units[0] = '\0';
         units[0] = '\0';
 
 
-    /* TODO: nicer placement as label length changes; realign for tickbar mode */
     if(strlen(units)) {
     if(strlen(units)) {
 	margin = 0.2 * fontsize;
 	margin = 0.2 * fontsize;
 	if (margin < 2)
 	if (margin < 2)
 	    margin = 2;
 	    margin = 2;
 	fprintf(PS.fp, "/mg %.1f def\n", margin);
 	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); 
 	set_rgb_color(BLACK); 
 	fprintf(PS.fp, "TIB\n");
 	fprintf(PS.fp, "TIB\n");
     }
     }