PATCH: Fix looping in rrdgraph

"Peter Stamfest" <[email protected]>
Newsgroups gmane.comp.db.rrdtool.devel
Message-ID <OFCF4A81EA.2EFD4365-ONC12577D5.007F6A0C-C12577D5.00806F09@domino.stamfest.net>
Find attached a small patch that fixes a problem when using --rigid with 
the graph command.

The problem this patch fixes is reproducible using the following command:

rrdtool  graph a.png --rigid --start 1287948770 --end 1289406370 
--upper-limit 100 --lower-limit -100 DEF:out=/tmp/a.rrd:out:AVERAGE 
CDEF:negout=out,-1,*   AREA:negout#0000ff:out

Unfortunately, I do not have a simple way to create a RRD file exhibiting 
the problem easily, so I have to use a real-life RRD file. The gzipped 
rrddump output has a size of over 300kB, unfortunately, so I am not 
attaching this file here.

The fix also fixes some incorrect graphing of data - the graphics output 
with and without the patch is often different - with the patchless version 
being wrong... That said, I'm not 100% sure that this is the correct fix 
for the problem. It definitly improves the situation, though.

peter

_______________________________________________
rrd-developers mailing list
[email protected]
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers
fix-large-y-values-make-rrdtool-loop.patch (application/octet-stream, 1.2 KB)
diff -ur rrdtool-1.4.4/src/rrd_graph.c rrdtool-1.4.4-fixed/src/rrd_graph.c
--- rrdtool-1.4.4/src/rrd_graph.c	2010-07-05 17:38:22.000000000 +0200
+++ rrdtool-1.4.4-old/src/rrd_graph.c	2010-11-08 21:14:35.000000000 +0100
@@ -3423,7 +3423,10 @@
             }
             break;
         case GF_LINE:
-        case GF_AREA:
+        case GF_AREA: {
+	    rrd_value_t diffval = im->maxval - im->minval;
+	    rrd_value_t maxlimit = im->maxval + 9 * diffval;
+	    rrd_value_t minlimit = im->minval - 9 * diffval;
             /* fix data points at oo and -oo */
             for (ii = 0; ii < im->xsize; ii++) {
                 if (isinf(im->gdes[i].p_data[ii])) {
@@ -3434,6 +3437,12 @@
                     }
 
                 }
+		if (im->gdes[i].p_data[ii] > maxlimit) {
+		    im->gdes[i].p_data[ii] = maxlimit;
+		}
+		if (im->gdes[i].p_data[ii] < minlimit) {
+		    im->gdes[i].p_data[ii] = minlimit;
+		}
             }           /* for */
 
             /* *******************************************************
@@ -3659,6 +3668,7 @@
             }
             lastgdes = &(im->gdes[i]);
             break;
+	}
         case GF_STACK:
             rrd_set_error
                 ("STACK should already be turned into LINE or AREA here");
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.