From: Matej Dujava Date: Mon, 27 Nov 2017 14:31:38 +0000 (+0100) Subject: Added support for --allow-shrink with --rigid flag (#843) X-Git-Tag: v1.7.1~87 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b7636a941cf3379c07a0e23765826bed5166750;p=thirdparty%2Frrdtool-1.x.git Added support for --allow-shrink with --rigid flag (#843) * Added support for --allow-shrink with --rigid flag Signed-off-by: Matej Dujava * Fixed typo in doc/rrdgraph.pod. Signed-off-by: Matej Dujava --- diff --git a/doc/rrdgraph.pod b/doc/rrdgraph.pod index 8a425bd2..ec426c0f 100644 --- a/doc/rrdgraph.pod +++ b/doc/rrdgraph.pod @@ -115,13 +115,15 @@ the graph. [B<-u>|B<--upper-limit> I] [B<-l>|B<--lower-limit> I] [B<-r>|B<--rigid>] +[B<--allow-shrink>] By default the graph will be autoscaling so that it will adjust the y-axis to the range of the data. You can change this behavior by explicitly setting the limits. The displayed y-axis will then range at least from B to B. Autoscaling will still permit those boundaries to be stretched unless the B option is -set. +set. B alters behaivor of B by allowing auto down scale, +graph will not overrun user specified limits. [B<-A>|B<--alt-autoscale>] diff --git a/src/rrd_graph.c b/src/rrd_graph.c index d903b99f..2e7d7fc1 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -1462,7 +1462,24 @@ int data_proc( im->minval = minval; } if (isnan(im->maxval) - || (!im->rigid && im->maxval < maxval) + || ((!im->rigid) && im->maxval < maxval) + ) { + if (im->logarithmic) + im->maxval = maxval * 2.0; + else + im->maxval = maxval; + } + + if (!isnan(im->minval) + && (im->rigid && im->allow_shrink && im->minval < minval) + ) { + if (im->logarithmic) + im->minval = minval / 2.0; + else + im->minval = minval; + } + if (!isnan(im->maxval) + && (im->rigid && im->allow_shrink && im->maxval > maxval) ) { if (im->logarithmic) im->maxval = maxval * 2.0; @@ -1490,6 +1507,7 @@ int data_proc( im->maxval = 1.0; } } + return 0; } @@ -3864,14 +3882,16 @@ int graph_paint_timestring( /* get actual drawing data and find min and max values */ if (data_proc(im) == -1) return -1; + + /* identify si magnitude Kilo, Mega Giga ? */ if (!im->logarithmic) { si_unit(im); } - /* identify si magnitude Kilo, Mega Giga ? */ - if (!im->rigid && !im->logarithmic) - expand_range(im); /* make sure the upper and lower limit are - sensible values */ + /* make sure the upper and lower limit are sensible values + if rigid is without alow_shrink skip expanding limits */ + if ((!im->rigid || im->allow_shrink) && !im->logarithmic) + expand_range(im); info.u_val = im->minval; grinfo_push(im, sprintf_alloc("value_min"), RD_I_VAL, info); @@ -4742,6 +4762,7 @@ void rrd_graph_init( im->magfact = 1; im->prt_c = 0; im->rigid = 0; + im->allow_shrink = 0; im->rendered_image_size = 0; im->rendered_image = NULL; im->slopemode = 0; @@ -4910,6 +4931,7 @@ void rrd_graph_options( {"left-axis-format", 1012, OPTPARSE_REQUIRED}, {"left-axis-formatter",1013, OPTPARSE_REQUIRED}, {"right-axis-formatter",1014, OPTPARSE_REQUIRED}, + {"allow-shrink", 1015, OPTPARSE_NONE}, {0} }; /* *INDENT-ON* */ @@ -5220,6 +5242,9 @@ void rrd_graph_options( case 'r': im->rigid = 1; break; + case 1015: + im->allow_shrink = 1; + break; case 'f': im->imginfo = (char *)poptions->optarg; break; diff --git a/src/rrd_graph.h b/src/rrd_graph.h index f2aa6c1f..180e08f1 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -297,6 +297,7 @@ typedef struct image_desc_t { rrd_value_t minval, maxval; /* extreme values in the data */ int rigid; /* do not expand range even with values outside */ + int allow_shrink; /* less "rigid" --rigid */ ygrid_scale_t ygrid_scale; /* calculated y axis grid info */ int gridfit; /* adjust y-axis range etc so all grindlines falls in integer pixel values */