From: oetiker Date: Mon, 17 Apr 2006 20:25:33 +0000 (+0000) Subject: Add a second label to the Y axis if there is only going to be one -- Jason A. Smith... X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=commitdiff_plain;h=9b62097825d9a0311bef2e733919de037ac0a593 Add a second label to the Y axis if there is only going to be one -- Jason A. Smith smithj4 X bnl.gov git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@795 a5681a0c-68f1-0310-ab6d-d61299d08faa --- diff --git a/src/rrd_graph.c b/src/rrd_graph.c index a71a174..f8a52e0 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -1612,6 +1612,7 @@ int draw_horizontal_grid(image_desc_t *im) int i; double scaledstep; char graph_label[100]; + int nlabels=0; double X0=im->xorigin; double X1=im->xorigin+im->xsize; @@ -1622,9 +1623,13 @@ int draw_horizontal_grid(image_desc_t *im) MaxY = scaledstep*(double)egrid; for (i = sgrid; i <= egrid; i++){ double Y0=ytr(im,im->ygrid_scale.gridstep*i); + double YN=ytr(im,im->ygrid_scale.gridstep*(i+1)); if ( Y0 >= im->yorigin-im->ysize && Y0 <= im->yorigin){ - if(i % im->ygrid_scale.labfact == 0){ + /* Make sure at least 2 grid labels are shown, even if it doesn't agree + with the chosen settings. Add a label if required by settings, or if + there is only one label so far and the next grid line is out of bounds. */ + if(i % im->ygrid_scale.labfact == 0 || ( nlabels==1 && (YN < im->yorigin-im->ysize || YN > im->yorigin) )){ if (im->symbol == ' ') { if(im->extra_flags & ALTYGRID) { sprintf(graph_label,im->ygrid_scale.labfmt,scaledstep*(double)i); @@ -1647,6 +1652,7 @@ int draw_horizontal_grid(image_desc_t *im) } } } + nlabels++; gfx_new_text ( im->canvas, X0-im->text_prop[TEXT_PROP_AXIS].size, Y0,