pdf, svg and ps formats were not being created
[rrdtool.git] / src / rrd_graph.c
index a1a0da5..09e0cb1 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * RRDtool 1.2.99907080300  Copyright by Tobi Oetiker, 1997-2007
+ * RRDtool 1.3rc4  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
                     };
@@ -3028,31 +3033,29 @@ int graph_paint(
     case IF_PDF:
         im->gridfit = 0;
         im->surface = strlen(im->graphfile)
-            ?
-            cairo_pdf_surface_create_for_stream
-            (&cairo_output, im, im->ximg * im->zoom, im->yimg * im->zoom)
-            : cairo_pdf_surface_create(im->graphfile, im->ximg * im->zoom,
-                                       im->yimg * im->zoom);
+            ? cairo_pdf_surface_create(im->graphfile, im->ximg * im->zoom,
+                                       im->yimg * im->zoom)
+            : cairo_pdf_surface_create_for_stream
+            (&cairo_output, im, im->ximg * im->zoom, im->yimg * im->zoom);
         break;
     case IF_EPS:
         im->gridfit = 0;
         im->surface = strlen(im->graphfile)
             ?
-            cairo_ps_surface_create_for_stream
-            (&cairo_output, im, im->ximg * im->zoom, im->yimg * im->zoom)
-            : cairo_ps_surface_create(im->graphfile, im->ximg * im->zoom,
-                                      im->yimg * im->zoom);
+            cairo_ps_surface_create(im->graphfile, im->ximg * im->zoom,
+                                    im->yimg * im->zoom)
+            : cairo_ps_surface_create_for_stream
+            (&cairo_output, im, im->ximg * im->zoom, im->yimg * im->zoom);
         break;
     case IF_SVG:
         im->gridfit = 0;
         im->surface = strlen(im->graphfile)
             ?
-            cairo_svg_surface_create_for_stream
-            (&cairo_output, im, im->ximg * im->zoom, im->yimg * im->zoom)
-            : cairo_svg_surface_create(im->
-                                       graphfile,
-                                       im->
-                                       ximg * im->zoom, im->yimg * im->zoom);
+            cairo_svg_surface_create(im->
+                                     graphfile,
+                                     im->ximg * im->zoom, im->yimg * im->zoom)
+            : cairo_svg_surface_create_for_stream
+            (&cairo_output, im, im->ximg * im->zoom, im->yimg * im->zoom);
         cairo_svg_surface_restrict_to_version
             (im->surface, CAIRO_SVG_VERSION_1_1);
         break;
@@ -3428,8 +3431,8 @@ int graph_paint(
             rrd_set_error("Could not save png to '%s'", im->graphfile);
             return 1;
         }
-    }
         break;
+    }
     default:
         if (strlen(im->graphfile)) {
             cairo_show_page(im->cr);
@@ -3566,7 +3569,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),
@@ -4277,7 +4280,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;