Code

the end time itself is not part of a time range ... this fixes the segfault reported...
[rrdtool-all.git] / program / src / rrd_graph.c
index 63a4b2e1dad9639a9901f71f3283c2abd132c0e1..a65bca64378904a84e7c24ebf7c77b9d6ae4250a 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * RRDtool 1.3.5  Copyright by Tobi Oetiker, 1997-2008
+ * RRDtool 1.3.9  Copyright by Tobi Oetiker, 1997-2009
  ****************************************************************************
  * rrd__graph.c  produce graphs from data in rrdfiles
  ****************************************************************************/
@@ -1211,7 +1211,7 @@ int data_proc(
                     } else
                         if (((long int) gr_time >=
                              (long int) im->gdes[vidx].start)
-                            && ((long int) gr_time <=
+                            && ((long int) gr_time <
                                 (long int) im->gdes[vidx].end)) {
                         value = im->gdes[vidx].data[(unsigned long)
                                                     floor((double)
@@ -1633,7 +1633,7 @@ int leg_place(
     int      *legspace;
     char     *tab;
 
-    if (!(im->extra_flags & NOLEGEND) & !(im->extra_flags & ONLY_GRAPH)) {
+    if (!(im->extra_flags & NOLEGEND) && !(im->extra_flags & ONLY_GRAPH)) {
         if ((legspace = (int*)(malloc(im->gdes_c * sizeof(int)))) == NULL) {
             rrd_set_error("malloc for legspace");
             return -1;
@@ -2647,7 +2647,7 @@ void grid_paint(
     }
 
     /* graph labels */
-    if (!(im->extra_flags & NOLEGEND) & !(im->extra_flags & ONLY_GRAPH)) {
+    if (!(im->extra_flags & NOLEGEND) && !(im->extra_flags & ONLY_GRAPH)) {
         for (i = 0; i < im->gdes_c; i++) {
             if (im->gdes[i].legend[0] == '\0')
                 continue;
@@ -3032,16 +3032,7 @@ int graph_paint(
     graph_desc_t *lastgdes = NULL;
     rrd_infoval_t info;
 
-//    PangoFontMap *font_map = pango_cairo_font_map_get_default();
 
-    /* if we want and can be lazy ... quit now */
-    if (lazy) {
-        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;
-    }
     /* pull the data from the rrd files ... */
     if (data_fetch(im) == -1)
         return -1;
@@ -3057,7 +3048,7 @@ int graph_paint(
     if (i < 0)
         return -1;
 
-    if ((i == 0) || lazy)
+    if (i == 0)
         return 0;
 
 /**************************************************************
@@ -3079,6 +3070,14 @@ int graph_paint(
     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);
+    info.u_cnt = im->start;
+    grinfo_push(im, sprintf_alloc("graph_start"), RD_I_CNT, info);
+    info.u_cnt = im->end;
+    grinfo_push(im, sprintf_alloc("graph_end"), RD_I_CNT, info);
+
+    /* if we want and can be lazy ... quit now */
+    if (lazy)
+        return 0;
 
     /* get actual drawing data and find min and max values */
     if (data_proc(im) == -1)
@@ -3654,9 +3653,9 @@ int rrd_graph(
     *ymax = 0;
     while (walker) {
         if (strcmp(walker->key, "image_width") == 0) {
-            *xsize = walker->value.u_int;
+            *xsize = walker->value.u_cnt;
         } else if (strcmp(walker->key, "image_height") == 0) {
-            *ysize = walker->value.u_int;
+            *ysize = walker->value.u_cnt;
         } else if (strcmp(walker->key, "value_min") == 0) {
             *ymin = walker->value.u_val;
         } else if (strcmp(walker->key, "value_max") == 0) {
@@ -3979,7 +3978,7 @@ void rrd_graph_options(
         int       col_start, col_end;
 
         opt = getopt_long(argc, argv,
-                          "s:e:x:y:v:w:h:D:iu:l:rb:oc:n:m:t:f:a:I:zgjFYAMEX:L:S:T:NR:B:W:kP",
+                          "s:e:x:y:v:w:h:Diu:l:rb:oc:n:m:t:f:a:I:zgG:jFYAMEX:L:S:T:NR:B:W:kP",
                           long_options, &option_index);
         if (opt == EOF)
             break;
@@ -4625,7 +4624,7 @@ int vdef_calc(
             array[step] = data[step * src->ds_cnt];
         }
         qsort(array, step, sizeof(double), vdef_percent_compar);
-        field = (steps - 1) * dst->vf.param / 100;
+        field = round((dst->vf.param * (double)(steps - 1)) / 100.0);
         dst->vf.val = array[field];
         dst->vf.when = 0;   /* no time component */
         free(array);
@@ -4634,7 +4633,7 @@ int vdef_calc(
             printf("DEBUG: %3li:%10.2f %c\n",
                    step, array[step], step == field ? '*' : ' ');
 #endif
-    }
+        }
         break;
     case VDEF_MAXIMUM:
         step = 0;