PRINT returns from rrd_graph did not work due to an off by one error
[rrdtool.git] / src / rrd_graph.c
index 0f84b80..22b6ad3 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * RRDtool 1.2.99907080300  Copyright by Tobi Oetiker, 1997-2007
+ * RRDtool 1.3rc3  Copyright by Tobi Oetiker, 1997-2008
  ****************************************************************************
  * rrd__graph.c  produce graphs from data in rrdfiles
  ****************************************************************************/
@@ -1255,24 +1255,29 @@ int data_proc(
        lets set these to dummy values then ... */
 
     if (im->logarithmic) {
-        if (isnan(minval))
-            minval = 0.2;
-        if (isnan(maxval))
+        if (isnan(minval) || isnan(maxval) || maxval <= 0) {
+            minval = 0.0; /* catching this right away below */
             maxval = 5.1;
+        }
+        /* in logarithm mode, where minval is smaller or equal 
+           to 0 make the beast just way smaller than maxval */
+        if (minval <= 0) {
+            minval = maxval / 10e8;
+        }
     } else {
-        if (isnan(minval))
+        if (isnan(minval) || isnan(maxval)) {
             minval = 0.0;
-        if (isnan(maxval))
             maxval = 1.0;
+        }
     }
 
-    /* adjust min and max values */
+    /* adjust min and max values given by the user*/
     /* for logscale we add something on top */
     if (isnan(im->minval)
         || ((!im->rigid) && im->minval > minval)
         ) {
         if (im->logarithmic)
-            im->minval = minval * 0.5;
+            im->minval = minval / 2.0;
         else
             im->minval = minval;
     }
@@ -2650,7 +2655,7 @@ void grid_paint(
                                       [GRC_FRAME].
                                       blue, im->graph_col[GRC_FRAME].alpha);
                 if (im->gdes[i].dash) {
-                    // make box borders in legend dashed if the graph is dashed
+                    /* make box borders in legend dashed if the graph is dashed */
                     double    dashes[] = {
                         3.0
                     };
@@ -2713,7 +2718,6 @@ int graph_size_location(
     int       Xvertical = 0, Ytitle =
         0, Xylabel = 0, Xmain = 0, Ymain =
         0, Yxlabel = 0, Xspacing = 15, Yspacing = 15, Ywatermark = 4;
-    infoval   info;
 
     if (im->extra_flags & ONLY_GRAPH) {
         im->xorigin = 0;
@@ -2923,18 +2927,6 @@ int graph_size_location(
     }
 
     ytr(im, DNAN);
-    info.u_cnt = im->xorigin;
-    grinfo_push(im, sprintf_alloc("graph_left"), RD_I_CNT, info);
-    info.u_cnt = im->yorigin - Ymain;
-    grinfo_push(im, sprintf_alloc("graph_top"), RD_I_CNT, info);
-    info.u_cnt = im->xsize;
-    grinfo_push(im, sprintf_alloc("graph_width"), RD_I_CNT, info);
-    info.u_cnt = im->ysize;
-    grinfo_push(im, sprintf_alloc("graph_height"), RD_I_CNT, info);
-    info.u_cnt = im->ximg;
-    grinfo_push(im, sprintf_alloc("image_width"), RD_I_CNT, info);
-    info.u_cnt = im->yimg;
-    grinfo_push(im, sprintf_alloc("image_height"), RD_I_CNT, info);
     return 0;
 }
 
@@ -2991,6 +2983,20 @@ int graph_paint(
  **************************************************************/
     if (graph_size_location(im, i) == -1)
         return -1;
+
+    info.u_cnt = im->xorigin;
+    grinfo_push(im, sprintf_alloc("graph_left"), RD_I_CNT, info);
+    info.u_cnt = im->yorigin - im->ysize;
+    grinfo_push(im, sprintf_alloc("graph_top"), RD_I_CNT, info);
+    info.u_cnt = im->xsize;
+    grinfo_push(im, sprintf_alloc("graph_width"), RD_I_CNT, info);
+    info.u_cnt = im->ysize;
+    grinfo_push(im, sprintf_alloc("graph_height"), RD_I_CNT, info);
+    info.u_cnt = im->ximg;
+    grinfo_push(im, sprintf_alloc("image_width"), RD_I_CNT, info);
+    info.u_cnt = im->yimg;
+    grinfo_push(im, sprintf_alloc("image_height"), RD_I_CNT, info);
+
     /* get actual drawing data and find min and max values */
     if (data_proc(im) == -1)
         return -1;
@@ -3565,7 +3571,7 @@ int rrd_graph(
             *ymin = walker->value.u_val;
         } else if (strcmp(walker->key, "value_max") == 0) {
             *ymax = walker->value.u_val;
-        } else if (strncmp(walker->key, "print", 6) == 0) {    /* keys are prdate[0..] */
+        } else if (strncmp(walker->key, "print", 5) == 0) { /* keys are prdate[0..] */
             prlines++;
             if (((*prdata) =
                  rrd_realloc((*prdata),
@@ -3578,7 +3584,8 @@ int rrd_graph(
             (*prdata)[prlines] = NULL;
             strcpy((*prdata)[prlines - 1], walker->value.u_str);
         } else if (strcmp(walker->key, "image") == 0) {
-            fwrite(walker->value.u_blo.ptr, walker->value.u_blo.size, 1, (stream ? stream : stdout));
+            fwrite(walker->value.u_blo.ptr, walker->value.u_blo.size, 1,
+                   (stream ? stream : stdout));
         }
         /* skip anything else */
         walker = walker->next;
@@ -3594,12 +3601,13 @@ int rrd_graph(
 ** - options parsing  now in rrd_graph_options()
 ** - script parsing   now in rrd_graph_script()
 */
-info_t rrd_graph_v(
+info_t   *rrd_graph_v(
     int argc,
     char **argv)
 {
     image_desc_t im;
-    info_t *grinfo;
+    info_t   *grinfo;
+
     rrd_graph_init(&im);
     /* a dummy surface so that we can measure text sizes for placements */
     im.surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 10, 10);
@@ -3665,6 +3673,7 @@ info_t * rrd_graph_v(
     }
     if (im.rendered_image) {
         infoval   img;
+
         img.u_blo.size = im.rendered_image_size;
         img.u_blo.ptr = im.rendered_image;
         grinfo_push(&im, sprintf_alloc("image"), RD_I_BLO, img);
@@ -4273,7 +4282,7 @@ void rrd_graph_options(
         }
     }
 
-    if (im->logarithmic == 1 && im->minval <= 0) {
+    if (im->logarithmic && im->minval <= 0) {
         rrd_set_error
             ("for a logarithmic yaxis you must specify a lower-limit > 0");
         return;