don't panic if the user forgets to specify the name of the rrd file
[rrdtool.git] / src / rrd_graph.c
index 77a401a..201ee4c 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * RRDtool 1.2.12  Copyright by Tobi Oetiker, 1997-2005
+ * RRDtool 1.2.13  Copyright by Tobi Oetiker, 1997-2006
  ****************************************************************************
  * rrd__graph.c  produce graphs from data in rrdfiles
  ****************************************************************************/
@@ -327,7 +327,7 @@ static char si_symbol[] = {
                     'P', /* 10e15  Peta */
                     'E', /* 10e18  Exa */
 };
-const static int si_symbcenter = 6;
+static const int si_symbcenter = 6;
 
 /* find SI magnitude symbol for the numbers on the y-axis*/
 void 
@@ -1399,6 +1399,7 @@ leg_place(image_desc_t *im)
     int   fill=0, fill_last;
     int   leg_c = 0;
     int   leg_x = border, leg_y = im->yimg;
+    int   leg_y_prev = im->yimg;
     int   leg_cc;
     int   glue = 0;
     int   i,ii, mark = 0;
@@ -1507,14 +1508,22 @@ leg_place(image_desc_t *im)
                   + legspace[ii]
                   + glue;
            }                   
-           leg_y += im->text_prop[TEXT_PROP_LEGEND].size*1.8;
-           if (prt_fctn == 's') leg_y -=  im->text_prop[TEXT_PROP_LEGEND].size;           
+            leg_y_prev = leg_y;
+            /* only add y space if there was text on the line */
+            if (leg_x > border || prt_fctn == 's')            
+              leg_y += im->text_prop[TEXT_PROP_LEGEND].size*1.8;
+           if (prt_fctn == 's')
+               leg_y -=  im->text_prop[TEXT_PROP_LEGEND].size;    
            fill = 0;
            leg_c = 0;
            mark = ii;
        }          
     }
-    im->yimg = leg_y;
+    im->yimg = leg_y_prev;
+    /* if we did place some legends we have to add vertical space */
+    if (leg_y != im->yimg){
+       im->yimg += im->text_prop[TEXT_PROP_LEGEND].size*1.8;
+    }
     free(legspace);
   }
   return 0;
@@ -1752,9 +1761,10 @@ horizontal_log_grid(image_desc_t   *im)
           if (im->extra_flags & FORCE_UNITS_SI) {
              double pvalue = value * yloglab[majoridx][i];
              double scale = floor( log10( fabs(pvalue)) / 3);
+             char symbol;
+
              pvalue /= pow(10, 3*scale);
 
-             char symbol;
              if ( ((scale+si_symbcenter) < sizeof(si_symbol)) &&
                   ((scale+si_symbcenter) >= 0) )
                 symbol = si_symbol[(int)scale+si_symbcenter];