]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
Added support for --allow-shrink with --rigid flag (#843)
authorMatej Dujava <mdujava@gmail.com>
Mon, 27 Nov 2017 14:31:38 +0000 (15:31 +0100)
committerTobias Oetiker <tobi@oetiker.ch>
Mon, 27 Nov 2017 14:31:38 +0000 (15:31 +0100)
* Added support for --allow-shrink with --rigid flag

Signed-off-by: Matej Dujava <mdujava@gmail.com>
* Fixed typo in doc/rrdgraph.pod.

Signed-off-by: Matej Dujava <mdujava@gmail.com>
doc/rrdgraph.pod
src/rrd_graph.c
src/rrd_graph.h

index 8a425bd29f49913c241feea8e4adb9a91f0d8d56..ec426c0fffc12e6474bc69edc23c27179fdf9d50 100644 (file)
@@ -115,13 +115,15 @@ the graph.
 [B<-u>|B<--upper-limit> I<value>]
 [B<-l>|B<--lower-limit> I<value>]
 [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<lower-limit> to B<upper-limit>. Autoscaling will still
 permit those boundaries to be stretched unless the B<rigid> option is
-set.
+set. B<allow-shrink> alters behaivor of B<rigid> by allowing auto down scale,
+graph will not overrun user specified limits.
 
 [B<-A>|B<--alt-autoscale>]
 
index d903b99fe8dd0cf63b4af2aa6f7f378bb3eb7e10..2e7d7fc1e425579bc7e70362ff74e4c17c73e292 100644 (file)
@@ -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;
index f2aa6c1f195b22f4fff8d6a26aa6ba90dd5d1942..180e08f10aacccd3b303b0a2ee3987aa2b74930c 100644 (file)
@@ -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 */