X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_graph.c;h=a71a174a5001cc931a0013fed39a93e6d8302bc4;hb=87bfb3981c5c5bbf5843144a1d94c4011043592d;hp=a4f250c9b6ddffb773d5149c0a8c628d42552cae;hpb=3895c7d3d1089bcf68d89390189d96497392df23;p=rrdtool.git diff --git a/src/rrd_graph.c b/src/rrd_graph.c index a4f250c..a71a174 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -1,5 +1,5 @@ /**************************************************************************** - * RRDtool 1.2.11 Copyright by Tobi Oetiker, 1997-2005 + * RRDtool 1.2.12 Copyright by Tobi Oetiker, 1997-2005 **************************************************************************** * rrd__graph.c produce graphs from data in rrdfiles ****************************************************************************/ @@ -179,7 +179,7 @@ enum gf_en gf_conv(char *string){ conv_if(VRULE,GF_VRULE) conv_if(LINE,GF_LINE) conv_if(AREA,GF_AREA) - conv_if(STACK,GF_STACK) + conv_if(STACK,GF_STACK) conv_if(TICK,GF_TICK) conv_if(DEF,GF_DEF) conv_if(CDEF,GF_CDEF) @@ -1020,8 +1020,7 @@ data_proc( image_desc_t *im ){ for(i=0;igdes_c;i++) { if((im->gdes[i].gf==GF_LINE) || (im->gdes[i].gf==GF_AREA) || - (im->gdes[i].gf==GF_TICK) || - (im->gdes[i].gf==GF_STACK)) { + (im->gdes[i].gf==GF_TICK)) { if((im->gdes[i].p_data = malloc((im->xsize +1) * sizeof(rrd_value_t)))==NULL){ rrd_set_error("malloc data_proc"); @@ -1043,7 +1042,6 @@ data_proc( image_desc_t *im ){ case GF_TICK: if (!im->gdes[ii].stack) paintval = 0.0; - case GF_STACK: value = im->gdes[ii].yrule; if (isnan(value) || (im->gdes[ii].gf == GF_TICK)) { /* The time of the data doesn't necessarily match @@ -1082,6 +1080,10 @@ data_proc( image_desc_t *im ){ im->gdes[ii].p_data[i] = DNAN; } break; + case GF_STACK: + rrd_set_error("STACK should already be turned into LINE or AREA here"); + return -1; + break; default: break; } @@ -1361,7 +1363,6 @@ print_calc(image_desc_t *im, char ***prdata) case GF_LINE: case GF_AREA: case GF_TICK: - case GF_STACK: case GF_HRULE: case GF_VRULE: graphelement = 1; @@ -1376,6 +1377,10 @@ print_calc(image_desc_t *im, char ***prdata) case GF_SHIFT: case GF_XPORT: break; + case GF_STACK: + rrd_set_error("STACK should already be turned into LINE or AREA here"); + return -1; + break; } } return graphelement; @@ -1527,11 +1532,10 @@ calc_horizontal_grid(image_desc_t *im) double range; double scaledrange; int pixel,i; - int gridind; + int gridind=0; int decimals, fractionals; im->ygrid_scale.labfact=2; - gridind=-1; range = im->maxval - im->minval; scaledrange = range / im->magfact; @@ -1582,17 +1586,16 @@ calc_horizontal_grid(image_desc_t *im) else { for(i=0;ylab[i].grid > 0;i++){ pixel = im->ysize / (scaledrange / ylab[i].grid); - if (pixel > 7) { - gridind = i; - break; - } + gridind = i; + if (pixel > 7) + break; } for(i=0; i<4;i++) { if (pixel * ylab[gridind].lfac[i] >= 2.5 * im->text_prop[TEXT_PROP_AXIS].size) { - im->ygrid_scale.labfact = ylab[gridind].lfac[i]; + im->ygrid_scale.labfact = ylab[gridind].lfac[i]; break; - } + } } im->ygrid_scale.gridstep = ylab[gridind].grid * im->magfact; @@ -1974,6 +1977,17 @@ grid_paint(image_desc_t *im) 5.5, im->tabwidth, 270, GFX_H_RIGHT, GFX_V_TOP, "RRDTOOL / TOBI OETIKER"); + + /* graph watermark */ + if(im->watermark[0] != '\0') { + gfx_new_text( im->canvas, + im->ximg/2, im->yimg-6, + ( im->graph_col[GRC_FONT] & 0xffffff00 ) | 0x00000044, + im->text_prop[TEXT_PROP_AXIS].font, + 5.5, im->tabwidth, 0, + GFX_H_CENTER, GFX_V_BOTTOM, + im->watermark); + } /* graph labels */ if( !(im->extra_flags & NOLEGEND) & !(im->extra_flags & ONLY_GRAPH) ) { @@ -2137,6 +2151,8 @@ graph_size_location(image_desc_t *im, int elements ** |v+--+-------------------------------+--------+ ** | |..............legends......................| ** +-+-------------------------------------------+ + ** | watermark | + ** +---------------------------------------------+ */ int Xvertical=0, Ytitle =0, @@ -2149,7 +2165,9 @@ graph_size_location(image_desc_t *im, int elements #if 0 Xlegend =0, Ylegend =0, #endif - Xspacing =15, Yspacing =15; + Xspacing =15, Yspacing =15, + + Ywatermark =4; if (im->extra_flags & ONLY_GRAPH) { im->xorigin =0; @@ -2236,12 +2254,13 @@ graph_size_location(image_desc_t *im, int elements xtr(im,0); /* The vertical size is interesting... we need to compare - ** the sum of {Ytitle, Ymain, Yxlabel, Ylegend} with Yvertical - ** however we need to know {Ytitle+Ymain+Yxlabel} in order to - ** start even thinking about Ylegend. + ** the sum of {Ytitle, Ymain, Yxlabel, Ylegend, Ywatermark} with + ** Yvertical however we need to know {Ytitle+Ymain+Yxlabel} + ** in order to start even thinking about Ylegend or Ywatermark. ** ** Do it in three portions: First calculate the inner part, - ** then do the legend, then adjust the total height of the img. + ** then do the legend, then adjust the total height of the img, + ** adding space for a watermark if one exists; */ /* reserve space for main and/or pie */ @@ -2270,7 +2289,10 @@ graph_size_location(image_desc_t *im, int elements */ if(leg_place(im)==-1) return -1; - + + if (im->watermark[0] != '\0') { + im->yimg += Ywatermark; + } #if 0 if (Xlegend > im->ximg) { @@ -2344,7 +2366,6 @@ graph_paint(image_desc_t *im, char ***calcpr) gfx_node_t *node; double areazero = 0.0; - enum gf_en stack_gf = GF_PRINT; graph_desc_t *lastgdes = NULL; /* if we are lazy and there is nothing to PRINT ... quit now */ @@ -2468,22 +2489,27 @@ graph_paint(image_desc_t *im, char ***calcpr) for (ii = 0; ii < im->xsize; ii++) { if (!isnan(im->gdes[i].p_data[ii]) && - im->gdes[i].p_data[ii] > 0.0) - { - /* generate a tick */ - gfx_new_line(im->canvas, im -> xorigin + ii, - im -> yorigin - (im -> gdes[i].yrule * im -> ysize), - im -> xorigin + ii, - im -> yorigin, - 1.0, - im -> gdes[i].col ); - } + im->gdes[i].p_data[ii] != 0.0) + { + if (im -> gdes[i].yrule > 0 ) { + gfx_new_line(im->canvas, + im -> xorigin + ii, im->yorigin, + im -> xorigin + ii, im->yorigin - im -> gdes[i].yrule * im -> ysize, + 1.0, + im -> gdes[i].col ); + } else if ( im -> gdes[i].yrule < 0 ) { + gfx_new_line(im->canvas, + im -> xorigin + ii, im->yorigin - im -> ysize, + im -> xorigin + ii, im->yorigin - ( 1 - im -> gdes[i].yrule ) * im -> ysize, + 1.0, + im -> gdes[i].col ); + + } + } } break; case GF_LINE: case GF_AREA: - stack_gf = im->gdes[i].gf; - case GF_STACK: /* fix data points at oo and -oo */ for(ii=0;iixsize;ii++){ if (isinf(im->gdes[i].p_data[ii])){ @@ -2509,7 +2535,7 @@ graph_paint(image_desc_t *im, char ***calcpr) ********************************************************* */ if (im->gdes[i].col != 0x0){ /* GF_LINE and friend */ - if(stack_gf == GF_LINE ){ + if(im->gdes[i].gf == GF_LINE ){ double last_y=0.0; node = NULL; for(ii=1;iixsize;ii++){ @@ -2653,6 +2679,10 @@ graph_paint(image_desc_t *im, char ***calcpr) } break; #endif + case GF_STACK: + rrd_set_error("STACK should already be turned into LINE or AREA here"); + return -1; + break; } /* switch */ } @@ -2742,6 +2772,7 @@ gdes_alloc(image_desc_t *im){ im->gdes[im->gdes_c-1].step=im->step; im->gdes[im->gdes_c-1].step_orig=im->step; im->gdes[im->gdes_c-1].stack=0; + im->gdes[im->gdes_c-1].linewidth=0; im->gdes[im->gdes_c-1].debug=0; im->gdes[im->gdes_c-1].start=im->start; im->gdes[im->gdes_c-1].end=im->end; @@ -2766,7 +2797,7 @@ gdes_alloc(image_desc_t *im){ /* copies input untill the first unescaped colon is found or until input ends. backslashes have to be escaped as well */ int -scan_for_col(char *input, int len, char *output) +scan_for_col(const char *const input, int len, char *const output) { int inp,outp=0; for (inp=0; @@ -2872,6 +2903,9 @@ rrd_graph_init(image_desc_t *im) #endif #ifdef HAVE_SETLOCALE setlocale(LC_TIME,""); +#ifdef HAVE_MBSTOWCS + setlocale(LC_CTYPE,""); +#endif #endif im->yorigin=0; im->xorigin=0; @@ -2884,6 +2918,7 @@ rrd_graph_init(image_desc_t *im) im->step = 0; im->ylegend[0] = '\0'; im->title[0] = '\0'; + im->watermark[0] = '\0'; im->minval = DNAN; im->maxval = DNAN; im->unitsexponent= 9999; @@ -2919,8 +2954,8 @@ rrd_graph_init(image_desc_t *im) windir = getenv("windir"); /* %windir% is something like D:\windows or C:\winnt */ if (windir != NULL) { - strncpy(rrd_win_default_font,windir,999); - rrd_win_default_font[999] = '\0'; + strncpy(rrd_win_default_font,windir,500); + rrd_win_default_font[500] = '\0'; strcat(rrd_win_default_font,"\\fonts\\"); strcat(rrd_win_default_font,RRD_DEFAULT_FONT); for(i=0;icanvas->font_aa_threshold = atof(optarg); break; + case 'W': + strncpy(im->watermark,optarg,100); + im->watermark[99]='\0'; + break; + case '?': if (optopt != 0) rrd_set_error("unknown option '%c'", optopt); @@ -3386,12 +3427,17 @@ int bad_format(char *fmt) { /* '%s', '%S' and '%%' are allowed */ if (*ptr == 's' || *ptr == 'S' || *ptr == '%') ptr++; + /* %c is allowed (but use only with vdef!) */ + else if (*ptr == 'c') { + ptr++; + n=1; + } + /* or else '% 6.2lf' and such are allowed */ else { - /* optional padding character */ if (*ptr == ' ' || *ptr == '+' || *ptr == '-') ptr++; - + /* This should take care of 'm.n' with all three optional */ while (*ptr >= '0' && *ptr <= '9') ptr++; if (*ptr == '.') ptr++; @@ -3412,7 +3458,7 @@ int bad_format(char *fmt) { int vdef_parse(gdes,str) struct graph_desc_t *gdes; -char *str; +const char *const str; { /* A VDEF currently is either "func" or "param,func" * so the parsing is rather simple. Change if needed.