X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_graph.c;h=323fec6dcfc1ba3d0d79c455961915e8f16e9ba0;hp=eb909522e50635ba19c2ff535afeb2d19a15b553;hb=8d46034bf5b28b3c5ec94baf7d526c6a3a95fb8b;hpb=4493487acbf098efd1aa166fc8ab05fce968dbe0 diff --git a/src/rrd_graph.c b/src/rrd_graph.c index eb90952..323fec6 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -6,15 +6,20 @@ #include -#include #ifdef WIN32 #include "strftime.h" -#include "plbasename.h" #endif #include "rrd_tool.h" +/* for basename */ +#ifdef HAVE_LIBGEN_H +# include +#else +#include "plbasename.h" +#endif + #if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) #include #include @@ -3200,14 +3205,6 @@ int graph_paint( // 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; @@ -3223,7 +3220,8 @@ int graph_paint( if (i < 0) return -1; - if ((i == 0) || lazy) + /* if we want and can be lazy ... quit now */ + if (i == 0) return 0; /************************************************************** @@ -3250,6 +3248,10 @@ int graph_paint( 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) return -1; @@ -3267,6 +3269,7 @@ int graph_paint( info.u_val = im->maxval; grinfo_push(im, sprintf_alloc("value_max"), RD_I_VAL, info); + if (!calc_horizontal_grid(im)) return -1; /* reset precalc */ @@ -3844,8 +3847,11 @@ 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)); + if ( fwrite(walker->value.u_blo.ptr, walker->value.u_blo.size, 1, + (stream ? stream : stdout)) == 0 && ferror(stream ? stream : stdout)){ + rrd_set_error("writing image"); + return 0; + } } /* skip anything else */ walker = walker->next; @@ -4861,7 +4867,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); @@ -4894,7 +4900,7 @@ int vdef_calc( } } qsort(array, nancount, sizeof(double), vdef_percent_compar); - field = (nancount - 1) * dst->vf.param / 100; + field = round( dst->vf.param * (double)(nancount - 1) / 100.0); dst->vf.val = array[field]; dst->vf.when = 0; /* no time component */ free(array);