[GRASS-dev] Re: updated d.histogram
Paul Kelly
paul-grass at stjohnspoint.co.uk
Fri May 18 05:01:15 EDT 2007
Hello Michael
On Thu, 17 May 2007, Michael Barton wrote:
> I¹ve attached a small screenshot of d.histogram displaying in wxgrass with a
> blue background and white foreground. It looks nice. I¹m using the slope
> example that was problematic before. It is also better formatted. But I
> thought that we¹d get some decimal places on the x axis?
Strange, it almost looks like the patch hasn't applied properly and only
some of the bugs are fixed, i.e. like the big tick spacing isn't
calculated correctly and the numbers are still being truncated to integers
before printing. See attached for how it looks for me and an updated copy
of the patch against the latest source, in case anybody else would like to
try and verify their results (Note: PNG attachment hopefully results in
much smaller file size than JPEG...).
The commandline I used was:
GRASS 6.3.cvs (spearfish):C:\ >set GRASS_PNGFILE=c:\temp\histogram.png
GRASS 6.3.cvs (spearfish):C:\ >set GRASS_RENDER_IMMEDIATE=TRUE
GRASS 6.3.cvs (spearfish):C:\ >d.histogram slope color=white bgcolor=black
100%
PNG: GRASS_TRUECOLOR status: FALSE
PNG: collecting to file: c:\temp\histogram.png,
GRASS_WIDTH=640, GRASS_HEIGHT=480
GRASS 6.3.cvs (spearfish):C:\ >
Paul
-------------- next part --------------
A non-text attachment was scrubbed...
Name: histogram.png
Type: image/png
Size: 5711 bytes
Desc:
Url : http://lists.osgeo.org/pipermail/grass-dev/attachments/20070518/b229a201/histogram.png
-------------- next part --------------
Index: bar.c
===================================================================
RCS file: /home/grass/grassrepository/grass6/display/d.histogram/bar.c,v
retrieving revision 2.3
diff -u -r2.3 bar.c
--- bar.c 17 May 2007 08:13:14 -0000 2.3
+++ bar.c 18 May 2007 08:50:35 -0000
@@ -112,14 +112,11 @@
if(G_is_d_null_value(&range_dmin) || G_is_d_null_value(&range_dmax))
G_fatal_error("Floating point data range is empty");
- while((range_dmax - range_dmin)/tics[i].every > max_tics)
- i++;
- }
- else
- {
- while ((num_cats/tics[i].every) > max_tics)
- i++;
}
+
+ while ((num_cats/tics[i].every) > max_tics)
+ i++;
+
tic_every = tics[i].every;
tic_unit = tics[i].unit;
strcpy(tic_name,tics[i].name);
@@ -234,9 +231,9 @@
&dmin, &dmax);
else
{
- dmin=range_dmin+(double)i*
+ dmin=range_dmin+(double)(i-1)*
(range_dmax-range_dmin)/(double)nsteps;
- dmax=range_dmin+(double)(i+1)*
+ dmax=range_dmin+(double)(i)*
(range_dmax-range_dmin)/(double)nsteps;
}
if(dmin != dmax)
@@ -282,9 +279,9 @@
&dmin, &dmax);
else
{
- dmin=range_dmin+(double)i*
+ dmin=range_dmin+(double)(i-1)*
(range_dmax-range_dmin)/(double)nsteps;
- dmax=range_dmin+(double)(i+1)*
+ dmax=range_dmin+(double)(i)*
(range_dmax-range_dmin)/(double)nsteps;
}
D_d_color(dmin, colors);
@@ -307,17 +304,27 @@
i==dist_stats->mincat && nodata)
&& !(nodata && i==dist_stats->mincat+1))
{
+ int text_middle = 0; /* Print text labels in middle
+ * of intervals */
+ double text_offset;
+
/* draw a numbered tic-mark */
D_raster_use_color(color);
R_move_abs( (int)(xoffset+(i-dist_stats->mincat)*xscale - 0.5 * xscale),
(int)(b-ORIGIN_Y*(b-t)) );
R_cont_rel( (int)0 , (int)(BIG_TIC*(b-t)) );
if(nodata && i==dist_stats->mincat)
+ {
sprintf(txt, "null");
+ text_middle = 1;
+ }
else if(is_fp)
- sprintf(txt,"%d",(int) (dmin/(double) tic_unit));
- else
+ sprintf(txt,"%.3g", dmin / tic_unit);
+ else
+ {
sprintf(txt,"%d",(int) (i/tic_unit));
+ text_middle = 1;
+ }
text_height = (b-t)*TEXT_HEIGHT;
text_width = (r-l)*TEXT_WIDTH;
R_text_size(text_width,text_height);
@@ -329,7 +336,11 @@
R_text_size(text_width,text_height);
R_get_text_box(txt,&tt,&tb,&tl,&tr);
}
- R_move_abs((int)(xoffset+(i-dist_stats->mincat)*xscale - 0.5 * xscale -(tr-tl)/2),
+ if (text_middle)
+ text_offset = 0;
+ else
+ text_offset = - (0.5 * xscale);
+ R_move_abs((int)(xoffset+(i-dist_stats->mincat)*xscale + text_offset -(tr-tl)/2),
(int)(b-XNUMS_Y*(b-t)));
R_text(txt);
}
More information about the grass-dev
mailing list