X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_graph.c;h=5dd332861bfe5074f394f22481ea10ee0c6765b0;hp=217710da23194bbf7b1f8d9ede49785dc888ad0e;hb=49593a6456b8dd4e82f82d8c76aaf21ce876ea92;hpb=56d67cdd0c5b2c27c9242a3d5810c7184917f663 diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 217710d..5dd3328 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -1,5 +1,5 @@ /**************************************************************************** - * RRDtool 1.4.0 Copyright by Tobi Oetiker, 1997-2009 + * RRDtool 1.4.3 Copyright by Tobi Oetiker, 1997-2010 **************************************************************************** * rrd__graph.c produce graphs from data in rrdfiles ****************************************************************************/ @@ -29,6 +29,10 @@ #include +#ifdef HAVE_LANGINFO_H +#include +#endif + #include "rrd_graph.h" #include "rrd_client.h" @@ -230,6 +234,7 @@ enum gf_en gf_conv( conv_if(VRULE, GF_VRULE); conv_if(LINE, GF_LINE); conv_if(AREA, GF_AREA); + conv_if(GRAD, GF_GRAD); conv_if(STACK, GF_STACK); conv_if(TICK, GF_TICK); conv_if(TEXTALIGN, GF_TEXTALIGN); @@ -1212,8 +1217,11 @@ int data_proc( /* memory for the processed data */ for (i = 0; i < im->gdes_c; i++) { - if ((im->gdes[i].gf == GF_LINE) || - (im->gdes[i].gf == GF_AREA) || (im->gdes[i].gf == GF_TICK)) { + if ((im->gdes[i].gf == GF_LINE) + || (im->gdes[i].gf == GF_AREA) + || (im->gdes[i].gf == GF_TICK) + || (im->gdes[i].gf == GF_GRAD) + ) { if ((im->gdes[i].p_data = (rrd_value_t*)malloc((im->xsize + 1) * sizeof(rrd_value_t))) == NULL) { rrd_set_error("malloc data_proc"); @@ -1234,6 +1242,7 @@ int data_proc( switch (im->gdes[ii].gf) { case GF_LINE: case GF_AREA: + case GF_GRAD: case GF_TICK: if (!im->gdes[ii].stack) paintval = 0.0; @@ -1248,7 +1257,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) @@ -1355,7 +1364,21 @@ int data_proc( return 0; } - +static int find_first_weekday(void){ + static int first_weekday = -1; + if (first_weekday == -1){ +#ifdef HAVE__NL_TIME_WEEK_1STDAY + /* according to http://sourceware.org/ml/libc-locales/2009-q1/msg00011.html */ + long week_1stday_l = (long) nl_langinfo (_NL_TIME_WEEK_1STDAY); + if (week_1stday_l == 19971130) first_weekday = 0; /* Sun */ + else if (week_1stday_l == 19971201) first_weekday = 1; /* Mon */ + else first_weekday = 1; /* we go for a monday default */ +#else + first_weekday = 1; +#endif + } + return first_weekday; +} /* identify the point where the first gridline, label ... gets placed */ @@ -1397,10 +1420,10 @@ time_t find_first_time( tm. tm_sec = 0; tm. tm_min = 0; tm. tm_hour = 0; - tm. tm_mday -= tm.tm_wday - 1; /* -1 because we want the monday */ + tm. tm_mday -= tm.tm_wday - find_first_weekday(); - if (tm.tm_wday == 0) - tm. tm_mday -= 7; /* we want the *previous* monday */ + if (tm.tm_wday == 0 && find_first_weekday() > 0) + tm. tm_mday -= 7; /* we want the *previous* week */ break; case TMT_MONTH: @@ -1613,6 +1636,7 @@ int print_calc( break; case GF_LINE: case GF_AREA: + case GF_GRAD: case GF_TICK: graphelement = 1; break; @@ -1730,6 +1754,7 @@ int leg_place( prt_fctn != 'r' && prt_fctn != 'j' && prt_fctn != 'c' && + prt_fctn != 'u' && prt_fctn != 's' && prt_fctn != '\0' && prt_fctn != 'g') { free(legspace); rrd_set_error @@ -1818,7 +1843,7 @@ int leg_place( if (prt_fctn == 'c') leg_x = (double)(legendwidth - fill) / 2.0; if (prt_fctn == 'r') - leg_x = legendwidth - fill - border; + leg_x = legendwidth - fill + border; for (ii = mark; ii <= i; ii++) { if (im->gdes[ii].legend[0] == '\0') continue; /* skip empty legends */ @@ -1839,6 +1864,8 @@ int leg_place( leg_y += im->text_prop[TEXT_PROP_LEGEND].size * 1.8; if (prt_fctn == 's') leg_y -= im->text_prop[TEXT_PROP_LEGEND].size; + if (prt_fctn == 'u') + leg_y -= im->text_prop[TEXT_PROP_LEGEND].size *1.8; if(calc_width && (fill > legendwidth)){ legendwidth = fill; @@ -2733,7 +2760,8 @@ void grid_paint( boxV = boxH; /* shift the box up a bit */ Y0 -= boxV * 0.4; - if (im->gdes[i].gf == GF_HRULE) { /* [-] */ + + if (im->dynamic_labels && im->gdes[i].gf == GF_HRULE) { /* [-] */ cairo_save(im->cr); cairo_new_path(im->cr); cairo_set_line_width(im->cr, 1.0); @@ -2742,7 +2770,7 @@ void grid_paint( X0 + boxH, Y0 - boxV / 2, 1.0, im->gdes[i].col); gfx_close_path(im); - } else if (im->gdes[i].gf == GF_VRULE) { /* [|] */ + } else if (im->dynamic_labels && im->gdes[i].gf == GF_VRULE) { /* [|] */ cairo_save(im->cr); cairo_new_path(im->cr); cairo_set_line_width(im->cr, 1.0); @@ -2751,7 +2779,7 @@ void grid_paint( X0 + boxH / 2, Y0 - boxV, 1.0, im->gdes[i].col); gfx_close_path(im); - } else if (im->gdes[i].gf == GF_LINE) { /* [/] */ + } else if (im->dynamic_labels && im->gdes[i].gf == GF_LINE) { /* [/] */ cairo_save(im->cr); cairo_new_path(im->cr); cairo_set_line_width(im->cr, im->gdes[i].linewidth); @@ -3402,6 +3430,7 @@ int graph_paint( break; case GF_LINE: case GF_AREA: + case GF_GRAD: /* fix data points at oo and -oo */ for (ii = 0; ii < im->xsize; ii++) { if (isinf(im->gdes[i].p_data[ii])) { @@ -3500,6 +3529,8 @@ int graph_paint( cairo_stroke(im->cr); cairo_restore(im->cr); } else { + double lastx=0; + double lasty=0; int idxI = -1; double *foreY = (double *) malloc(sizeof(double) * im->xsize * 2); @@ -3530,12 +3561,17 @@ int graph_paint( [cntI + 1], 4)) { cntI++; } - gfx_new_area(im, - backX[0], backY[0], - foreX[0], foreY[0], - foreX[cntI], - foreY[cntI], im->gdes[i].col); - while (cntI < idxI) { + if (im->gdes[i].gf != GF_GRAD) { + gfx_new_area(im, + backX[0], backY[0], + foreX[0], foreY[0], + foreX[cntI], + foreY[cntI], im->gdes[i].col); + } else { + lastx = foreX[cntI]; + lasty = foreY[cntI]; + } + while (cntI < idxI) { lastI = cntI; cntI++; while (cntI < idxI @@ -3551,9 +3587,32 @@ int graph_paint( + 1], 4)) { cntI++; } - gfx_add_point(im, foreX[cntI], foreY[cntI]); + if (im->gdes[i].gf != GF_GRAD) { + gfx_add_point(im, foreX[cntI], foreY[cntI]); + } else { + gfx_add_rect_fadey(im, + lastx, foreY[0], + foreX[cntI], foreY[cntI], lasty, + im->gdes[i].col, + im->gdes[i].col2, + im->gdes[i].gradheight + ); + lastx = foreX[cntI]; + lasty = foreY[cntI]; + } } - gfx_add_point(im, backX[idxI], backY[idxI]); + if (im->gdes[i].gf != GF_GRAD) { + gfx_add_point(im, backX[idxI], backY[idxI]); + } else { + gfx_add_rect_fadey(im, + lastx, foreY[0], + backX[idxI], backY[idxI], lasty, + im->gdes[i].col, + im->gdes[i].col2, + im->gdes[i].gradheight); + lastx = backX[idxI]; + lasty = backY[idxI]; + } while (idxI > 1) { lastI = idxI; idxI--; @@ -3570,11 +3629,23 @@ int graph_paint( - 1], 4)) { idxI--; } - gfx_add_point(im, backX[idxI], backY[idxI]); + if (im->gdes[i].gf != GF_GRAD) { + gfx_add_point(im, backX[idxI], backY[idxI]); + } else { + gfx_add_rect_fadey(im, + lastx, foreY[0], + backX[idxI], backY[idxI], lasty, + im->gdes[i].col, + im->gdes[i].col2, + im->gdes[i].gradheight); + lastx = backX[idxI]; + lasty = backY[idxI]; + } } idxI = -1; drawem = 0; - gfx_close_path(im); + if (im->gdes[i].gf != GF_GRAD) + gfx_close_path(im); } if (drawem != 0) { drawem = 0; @@ -3768,6 +3839,11 @@ int gdes_alloc( im->gdes[im->gdes_c - 1].col.green = 0.0; im->gdes[im->gdes_c - 1].col.blue = 0.0; im->gdes[im->gdes_c - 1].col.alpha = 0.0; + im->gdes[im->gdes_c - 1].col2.red = 0.0; + im->gdes[im->gdes_c - 1].col2.green = 0.0; + im->gdes[im->gdes_c - 1].col2.blue = 0.0; + im->gdes[im->gdes_c - 1].col2.alpha = 0.0; + im->gdes[im->gdes_c - 1].gradheight = 50.0; im->gdes[im->gdes_c - 1].legend[0] = '\0'; im->gdes[im->gdes_c - 1].format[0] = '\0'; im->gdes[im->gdes_c - 1].strftm = 0; @@ -4009,6 +4085,7 @@ void rrd_graph_init( im->draw_x_grid = 1; im->draw_y_grid = 1; im->draw_3d_border = 2; + im->dynamic_labels = 0; im->extra_flags = 0; im->font_options = cairo_font_options_create(); im->forceleftspace = 0; @@ -4177,6 +4254,7 @@ void rrd_graph_options( { "legend-direction", required_argument, 0, 1006}, { "border", required_argument, 0, 1007}, { "grid-dash", required_argument, 0, 1008}, + { "dynamic-labels", no_argument, 0, 1009}, { 0, 0, 0, 0} }; /* *INDENT-ON* */ @@ -4191,7 +4269,7 @@ void rrd_graph_options( int col_start, col_end; opt = getopt_long(argc, argv, - "Aa:B:b:c:Dd:Ee:Ff:G:gh:IiJjL:l:Nn:Bb:oPR:rS:s:T:t:u:v:W:w:X:x:Yy:z", + "Aa:B:b:c:Dd:Ee:Ff:G:gh:IiJjL:l:Mm:Nn:oPR:rS:s:T:t:u:v:W:w:X:x:Yy:z", long_options, &option_index); if (opt == EOF) break; @@ -4358,7 +4436,10 @@ void rrd_graph_options( rrd_set_error("expected grid-dash format float:float"); return; } - break; + break; + case 1009: /* enable dynamic labels */ + im->dynamic_labels = 1; + break; case 1002: /* right y axis */ if(sscanf(optarg,