X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Frrd_graph.c;h=7908ad4564e18f3138abb7d596915732c0e21aab;hb=3c8cee9e032f175c987c538a49e6dc0440789e02;hp=8900872a42e47c37170d8ede74bd72768febc781;hpb=a1fe8fd19bb4f558150e52c0624869667b739877;p=rrdtool.git diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 8900872..7908ad4 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -1,5 +1,5 @@ /**************************************************************************** - * RRDtool 1.0.33 Copyright Tobias Oetiker, 1997 - 2000 + * RRDtool 1.1.x Copyright Tobias Oetiker, 1997 - 2002 **************************************************************************** * rrd__graph.c make creates ne rrds ****************************************************************************/ @@ -21,7 +21,7 @@ #ifndef RRD_DEFAULT_FONT -#define RRD_DEFAULT_FONT "/usr/openwin/lib/X11/fonts/TrueType/Arial.ttf" +#define RRD_DEFAULT_FONT "/usr/share/fonts/truetype/openoffice/ariosor.ttf" /* #define RRD_DEFAULT_FONT "/usr/share/fonts/truetype/Arial.ttf" */ #endif @@ -45,8 +45,8 @@ xlab_t xlab[] = { /*{300, TMT_HOUR,3, TMT_HOUR,12, TMT_HOUR,12, 12*3600,"%a %p"}, this looks silly*/ {600, TMT_HOUR,6, TMT_DAY,1, TMT_DAY,1, 24*3600,"%a"}, {1800, TMT_HOUR,12, TMT_DAY,1, TMT_DAY,2, 24*3600,"%a"}, - {3600, TMT_DAY,1, TMT_WEEK,1, TMT_WEEK,1, 7*24*3600,"Week %W"}, - {3*3600, TMT_WEEK,1, TMT_MONTH,1, TMT_WEEK,2, 7*24*3600,"Week %W"}, + {3600, TMT_DAY,1, TMT_WEEK,1, TMT_WEEK,1, 7*24*3600,"Week %V"}, + {3*3600, TMT_WEEK,1, TMT_MONTH,1, TMT_WEEK,2, 7*24*3600,"Week %V"}, {6*3600, TMT_MONTH,1, TMT_MONTH,1, TMT_MONTH,1, 30*24*3600,"%b"}, {48*3600, TMT_MONTH,1, TMT_MONTH,3, TMT_MONTH,3, 30*24*3600,"%b"}, {10*24*3600, TMT_YEAR,1, TMT_YEAR,1, TMT_YEAR,1, 365*24*3600,"%y"}, @@ -174,13 +174,13 @@ enum gf_en gf_conv(char *string){ conv_if(DEF,GF_DEF) conv_if(CDEF,GF_CDEF) conv_if(VDEF,GF_VDEF) + conv_if(PART,GF_PART) return (-1); } enum if_en if_conv(char *string){ - conv_if(GIF,IF_GIF) conv_if(PNG,IF_PNG) return (-1); @@ -803,7 +803,7 @@ printf("DEBUG: value from vdef is %f\n",im->gdes[ptr].vf.val); * further save step size and data source * count of this rra */ - im->gdes[gdi].rpnp[rpi].data = im->gdes[ptr].data; + im->gdes[gdi].rpnp[rpi].data = im->gdes[ptr].data + im->gdes[ptr].ds; im->gdes[gdi].rpnp[rpi].step = im->gdes[ptr].step; im->gdes[gdi].rpnp[rpi].ds_cnt = im->gdes[ptr].ds_cnt; @@ -815,6 +815,17 @@ printf("DEBUG: value from vdef is %f\n",im->gdes[ptr].vf.val); } /* if OP_VARIABLE */ } /* loop through all rpi */ + /* move the data pointers to the correct period */ + for(rpi=0;im->gdes[gdi].rpnp[rpi].op != OP_END;rpi++){ + if(im->gdes[gdi].rpnp[rpi].op == OP_VARIABLE){ + long ptr = im->gdes[gdi].rpnp[rpi].ptr; + if(im->gdes[gdi].start > im->gdes[ptr].start) { + im->gdes[gdi].rpnp[rpi].data += im->gdes[gdi].rpnp[rpi].ds_cnt; + } + } + } + + if(steparray == NULL){ rrd_set_error("rpn expressions without DEF" " or CDEF variables are not supported"); @@ -937,6 +948,7 @@ data_proc( image_desc_t *im ){ case GF_DEF: case GF_CDEF: case GF_VDEF: + case GF_PART: break; } } @@ -1217,6 +1229,7 @@ print_calc(image_desc_t *im, char ***prdata) case GF_DEF: case GF_CDEF: case GF_VDEF: + case GF_PART: break; } } @@ -1267,7 +1280,7 @@ leg_place(image_desc_t *im) leg_cc--; im->gdes[i].legend[leg_cc]='\0'; } - if (leg_cc != 0 ){ + if (leg_cc != 0 ){ legspace[i]=(prt_fctn=='g' ? 0 : interleg); if (fill > 0){ @@ -1328,7 +1341,7 @@ leg_place(image_desc_t *im) gfx_get_text_width(leg_x,im->text_prop[TEXT_PROP_LEGEND].font, im->text_prop[TEXT_PROP_LEGEND].size, im->tabwidth, - im->gdes[i].legend) + im->gdes[ii].legend) + legspace[ii] + glue; if (im->gdes[ii].gf != GF_GPRINT && @@ -1342,7 +1355,7 @@ leg_place(image_desc_t *im) mark = ii; } } - im->ygif = leg_y+6; + im->ygif = leg_y; free(legspace); } return 0; @@ -1641,6 +1654,8 @@ vertical_grid( ti = find_next_time(ti,im->xlab_user.labtm,im->xlab_user.labst) ){ tilab= ti + im->xlab_user.precis/2; /* correct time for the label */ + /* are we inside the graph ? */ + if (ti < im->start || ti > im->end) continue; #if HAVE_STRFTIME strftime(graph_label,99,im->xlab_user.stst,localtime(&tilab)); @@ -1703,24 +1718,27 @@ grid_paint( ) { long i; - int boxH=8, boxV=8; int res=0; double x0,x1,x2,x3,y0,y1,y2,y3; /* points for filled graph and more*/ gfx_node_t *node; - /* draw 3d border */ - node = gfx_new_area (canvas, 0,im->ygif, 0,0, im->xgif, 0,im->graph_col[GRC_SHADEA]); + node = gfx_new_area (canvas, 0,im->ygif, + 2,im->ygif-2, + 2,2,im->graph_col[GRC_SHADEA]); gfx_add_point( node , im->xgif - 2, 2 ); - gfx_add_point( node , 2,2 ); - gfx_add_point( node , 2,im->ygif-2 ); - gfx_add_point( node , 0,im->ygif ); + gfx_add_point( node , im->xgif, 0 ); + gfx_add_point( node , 0,0 ); +/* gfx_add_point( node , 0,im->ygif ); */ - node = gfx_new_area (canvas, 0,im->ygif, im->xgif,im->ygif, im->xgif,0,im->graph_col[GRC_SHADEB]); - gfx_add_point( node , im->xgif - 2, 2 ); - gfx_add_point( node , im->xgif-2,im->ygif-2 ); - gfx_add_point( node , 2,im->ygif-2 ); - gfx_add_point( node , 0,im->ygif ); + node = gfx_new_area (canvas, 2,im->ygif-2, + im->xgif-2,im->ygif-2, + im->xgif - 2, 2, + im->graph_col[GRC_SHADEB]); + gfx_add_point( node , im->xgif,0); + gfx_add_point( node , im->xgif,im->ygif); + gfx_add_point( node , 0,im->ygif); +/* gfx_add_point( node , 0,im->ygif ); */ if (im->draw_x_grid == 1 ) @@ -1746,68 +1764,85 @@ grid_paint( } /* yaxis description */ - gfx_new_text( canvas, - 7, (im->yorigin - im->ysize/2), - im->graph_col[GRC_FONT], - im->text_prop[TEXT_PROP_AXIS].font, - im->text_prop[TEXT_PROP_AXIS].size, im->tabwidth, 270.0, - GFX_H_CENTER, GFX_V_CENTER, - im->ylegend); + #if 0 + gfx_new_text( canvas, + 7, (im->yorigin - im->ysize/2), + im->graph_col[GRC_FONT], + im->text_prop[TEXT_PROP_AXIS].font, + im->text_prop[TEXT_PROP_AXIS].size, im->tabwidth, 270.0, + GFX_H_CENTER, GFX_V_CENTER, + im->ylegend); + #else + /* horrible hack until we can actually print vertically */ + { + int n; + int l=strlen(im->ylegend); + char s[2]; + for (n=0;nylegend);n++) { + s[0]=im->ylegend[n]; + s[1]='\0'; + gfx_new_text(canvas,7,im->text_prop[TEXT_PROP_AXIS].size*(l-n), + im->graph_col[GRC_FONT], + im->text_prop[TEXT_PROP_AXIS].font, + im->text_prop[TEXT_PROP_AXIS].size, im->tabwidth, 270.0, + GFX_H_CENTER, GFX_V_CENTER, + s); + } + } + #endif /* graph title */ gfx_new_text( canvas, - im->xgif/2, im->text_prop[TEXT_PROP_TITLE].size*1.5, + im->xgif/2, im->text_prop[TEXT_PROP_TITLE].size, im->graph_col[GRC_FONT], im->text_prop[TEXT_PROP_TITLE].font, im->text_prop[TEXT_PROP_TITLE].size, im->tabwidth, 0.0, GFX_H_CENTER, GFX_V_CENTER, im->title); - /* graph labels */ - if( !(im->extra_flags & NOLEGEND) ) { + /* graph labels */ + if( !(im->extra_flags & NOLEGEND) ) { for(i=0;igdes_c;i++){ - if(im->gdes[i].legend[0] =='\0') - continue; + if(im->gdes[i].legend[0] =='\0') + continue; - if(im->gdes[i].gf != GF_GPRINT && im->gdes[i].gf != GF_COMMENT){ - x0 = im->gdes[i].leg_x; - y0 = im->gdes[i].leg_y+1.0; - x1 = x0+boxH; - x2 = x0+boxH; - x3 = x0; - y1 = y0; - y2 = y0+boxV; - y3 = y0+boxV; - node = gfx_new_area(canvas, x0,y0,x1,y1,x2,y2 ,im->gdes[i].col); - gfx_add_point ( node, x3, y3 ); - gfx_add_point ( node, x0, y0 ); - node = gfx_new_line(canvas, x0,y0,x1,y1 ,GRIDWIDTH, im->graph_col[GRC_FRAME]); - gfx_add_point ( node, x2, y2 ); - gfx_add_point ( node, x3, y3 ); - gfx_add_point ( node, x0, y0 ); - - gfx_new_text ( canvas, x0+boxH+6, (y0+y2) / 2.0, - im->graph_col[GRC_FONT], - im->text_prop[TEXT_PROP_AXIS].font, - im->text_prop[TEXT_PROP_AXIS].size, - im->tabwidth,0.0, GFX_H_LEFT, GFX_V_CENTER, - im->gdes[i].legend ); - - } else { - x0 = im->gdes[i].leg_x; - y0 = im->gdes[i].leg_y; - - gfx_new_text ( canvas, x0, (y0+y2) / 2.0, - im->graph_col[GRC_FONT], - im->text_prop[TEXT_PROP_AXIS].font, - im->text_prop[TEXT_PROP_AXIS].size, - im->tabwidth,0.0, GFX_H_LEFT, GFX_V_BOTTOM, - im->gdes[i].legend ); - - } - } - } -} + /* im->gdes[i].leg_y is the bottom of the legend */ + x0 = im->gdes[i].leg_x; + y0 = im->gdes[i].leg_y; + /* Box needed? */ + if ( im->gdes[i].gf != GF_GPRINT + && im->gdes[i].gf != GF_COMMENT) { + int boxH, boxV; + + boxH = gfx_get_text_width(0, + im->text_prop[TEXT_PROP_AXIS].font, + im->text_prop[TEXT_PROP_AXIS].size, + im->tabwidth,"M") * 1.25; + boxV = boxH; + + node = gfx_new_area(canvas, + x0,y0-boxV, + x0,y0, + x0+boxH,y0, + im->gdes[i].col); + gfx_add_point ( node, x0+boxH, y0-boxV ); + node = gfx_new_line(canvas, + x0,y0-boxV, x0,y0, + 1,0x000000FF); + gfx_add_point(node,x0+boxH,y0); + gfx_add_point(node,x0+boxH,y0-boxV); + gfx_add_point(node,x0,y0-boxV); + x0 += boxH / 1.25 * 2; + } + gfx_new_text ( canvas, x0, y0, + im->graph_col[GRC_FONT], + im->text_prop[TEXT_PROP_AXIS].font, + im->text_prop[TEXT_PROP_AXIS].size, + im->tabwidth,0.0, GFX_H_LEFT, GFX_V_BOTTOM, + im->gdes[i].legend ); + } + } + } /***************************************************** @@ -1830,9 +1865,6 @@ int lazy_check(image_desc_t *im){ if ((fd = fopen(im->graphfile,"rb")) == NULL) return 0; /* the file does not exist */ switch (im->imgformat) { - case IF_GIF: - size = GifSize(fd,&(im->xgif),&(im->ygif)); - break; case IF_PNG: size = PngSize(fd,&(im->xgif),&(im->ygif)); break; @@ -1841,6 +1873,192 @@ int lazy_check(image_desc_t *im){ return size; } +void +pie_part(gfx_canvas_t *canvas, gfx_color_t color, + double PieCenterX, double PieCenterY, double Radius, + double startangle, double endangle) +{ + gfx_node_t *node; + double angle; + double step=M_PI/50; /* Number of iterations for the circle; + ** 10 is definitely too low, more than + ** 50 seems to be overkill + */ + + /* Strange but true: we have to work clockwise or else + ** anti aliasing nor transparency don't work. + ** + ** This test is here to make sure we do it right, also + ** this makes the for...next loop more easy to implement. + ** The return will occur if the user enters a negative number + ** (which shouldn't be done according to the specs) or if the + ** programmers do something wrong (which, as we all know, never + ** happens anyway :) + */ + if (endangle