From: Tobias Oetiker Date: Wed, 15 Apr 2015 20:34:41 +0000 (+0200) Subject: integrate gradient functionality into AREA X-Git-Tag: v1.5.0~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c8cb208a8a2501ecd0ad3b7966d5f78828a91ecd;p=thirdparty%2Frrdtool-1.x.git integrate gradient functionality into AREA --- diff --git a/doc/rrdgraph_graph.pod b/doc/rrdgraph_graph.pod index eb0863d3..f1f40539 100644 --- a/doc/rrdgraph_graph.pod +++ b/doc/rrdgraph_graph.pod @@ -320,18 +320,20 @@ When you do not specify a color, you cannot specify a legend. Should you want to use B, use the "LINEx:::STACK" form. -=head3 BB<:>I[B<#>I][B<:>[I][B<:STACK>][B<:skipscale>]] +=head3 BB<:>I[B<#>I[B<#>I]][B<:>[I][B<:STACK>][B<:skipscale>][B<:gradheight=>I] See B, however the area between the x-axis and the line will be filled. -=head3 BB<:>I[B<#>I[B<#>IB<:>I][B<:>[I][B<:STACK>]] +If color2 is specified, the area will be filled with a gradient. -Similar to B, except the area between the line and the x-axis will contain a gradient from color1 to color2. +The I parameter can create three different behaviors. If +I > 0, then the gradient is a fixed height, starting at the line +going down. If I < 0, then the gradient starts at a fixed height +above the x-axis, going down to the x-axis. If I == 0, then the +gradient goes from the line to x-axis. -The I parameter can create three different behaviors. If I > 0, then the gradient is a fixed height, starting at the line going down. If I < 0, then the gradient starts at fixed height above the x-axis, going down to the x-axis. If I == 0, then the gradient goes from the line to x-axis. - -If not present, I defaults to #00000000 and I defaults to 50. +The default value for I is 50. =head3 BB<:>IB<#>I[I][B<:>I[B<:>I]] diff --git a/src/rrd_graph.c b/src/rrd_graph.c index 7b48ad0b..5787597f 100644 --- a/src/rrd_graph.c +++ b/src/rrd_graph.c @@ -302,7 +302,6 @@ 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); @@ -1346,7 +1345,6 @@ int data_proc( 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) { @@ -1368,7 +1366,6 @@ 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; @@ -2000,7 +1997,6 @@ int print_calc( break; case GF_LINE: case GF_AREA: - case GF_GRAD: case GF_TICK: graphelement = 1; break; @@ -3898,8 +3894,7 @@ int graph_paint_timestring( } break; case GF_LINE: - case GF_AREA: - case GF_GRAD: { + case GF_AREA: { rrd_value_t diffval = im->maxval - im->minval; rrd_value_t maxlimit = im->maxval + 9 * diffval; rrd_value_t minlimit = im->minval - 9 * diffval; @@ -4010,6 +4005,7 @@ int graph_paint_timestring( } else { double lastx=0; double lasty=0; + int isArea = isnan(im->gdes[i].col2.red); int idxI = -1; double *foreY = (double *) malloc(sizeof(double) * im->xsize * 2); @@ -4040,7 +4036,7 @@ int graph_paint_timestring( [cntI + 1], 4)) { cntI++; } - if (im->gdes[i].gf != GF_GRAD) { + if (isArea) { gfx_new_area(im, backX[0], backY[0], foreX[0], foreY[0], @@ -4066,7 +4062,7 @@ int graph_paint_timestring( + 1], 4)) { cntI++; } - if (im->gdes[i].gf != GF_GRAD) { + if (isArea) { gfx_add_point(im, foreX[cntI], foreY[cntI]); } else { gfx_add_rect_fadey(im, @@ -4080,7 +4076,7 @@ int graph_paint_timestring( lasty = foreY[cntI]; } } - if (im->gdes[i].gf != GF_GRAD) { + if (isArea) { gfx_add_point(im, backX[idxI], backY[idxI]); } else { gfx_add_rect_fadey(im, @@ -4108,7 +4104,7 @@ int graph_paint_timestring( - 1], 4)) { idxI--; } - if (im->gdes[i].gf != GF_GRAD) { + if (isArea) { gfx_add_point(im, backX[idxI], backY[idxI]); } else { gfx_add_rect_fadey(im, @@ -4123,7 +4119,7 @@ int graph_paint_timestring( } idxI = -1; drawem = 0; - if (im->gdes[i].gf != GF_GRAD) + if (isArea) gfx_close_path(im); } if (drawem != 0) { @@ -4187,7 +4183,7 @@ int graph_paint_timestring( } lastgdes = &(im->gdes[i]); break; - } /* GF_AREA, GF_LINE, GF_GRAD */ + } /* GF_AREA, GF_LINE*/ case GF_STACK: rrd_set_error ("STACK should already be turned into LINE or AREA here"); @@ -4422,9 +4418,9 @@ 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.red = DNAN; + im->gdes[im->gdes_c - 1].col2.green = DNAN; + im->gdes[im->gdes_c - 1].col2.blue = DNAN; 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'; diff --git a/src/rrd_graph.h b/src/rrd_graph.h index 4e2019bd..8c62ef73 100644 --- a/src/rrd_graph.h +++ b/src/rrd_graph.h @@ -65,7 +65,7 @@ enum grc_en { GRC_CANVAS = 0, GRC_BACK, GRC_SHADEA, GRC_SHADEB, #define GRIDWIDTH 0.4 enum gf_en { GF_PRINT = 0, GF_GPRINT, GF_COMMENT, GF_HRULE, GF_VRULE, GF_LINE, - GF_AREA,GF_GRAD, GF_STACK, GF_TICK, GF_TEXTALIGN, + GF_AREA,GF_STACK, GF_TICK, GF_TEXTALIGN, GF_DEF, GF_CDEF, GF_VDEF, GF_SHIFT, GF_XPORT, GF_XAXIS, GF_YAXIS }; diff --git a/src/rrd_graph_helper.c b/src/rrd_graph_helper.c index 47219c42..fa3be141 100644 --- a/src/rrd_graph_helper.c +++ b/src/rrd_graph_helper.c @@ -366,7 +366,7 @@ int parse_color( const char *const string, struct gfx_color_t *c) #define PARSE_SKIPSCALE (PARSE_FIELD1|(1ULL<<16)) #define PARSE_DASHES (PARSE_FIELD1|(1ULL<<20)) -#define PARSE_HEIGHT (PARSE_FIELD1|(1ULL<<21)) +#define PARSE_GRADHEIGHT (PARSE_FIELD1|(1ULL<<21)) #define PARSE_FORMAT (PARSE_FIELD1|(1ULL<<22)) #define PARSE_STRFTIMEVFMT (PARSE_FIELD1|(1ULL<<23)) #define PARSE_FRACTION (PARSE_FIELD1|(1ULL<<24)) @@ -538,15 +538,15 @@ static graph_desc_t* newGraphDescription(image_desc_t *const im,enum gf_en gf,pa dprintfparsed("got linewidth: %s (%g)\n",t,linewidth); gdp->linewidth=linewidth; } - if (bitscmp(PARSE_HEIGHT)) { - double height=0; + if (bitscmp(PARSE_GRADHEIGHT)) { + double gradheight=0; char *t,*x; - if ((t=getKeyValueArgument("height",1,pa))&&(*t!=0)) { - if (getDouble(t,&height,&x)) { - rrd_set_error("Bad height: %s",t); return NULL; + if ((t=getKeyValueArgument("gradheight",1,pa))&&(*t!=0)) { + if (getDouble(t,&gradheight,&x)) { + rrd_set_error("Bad gradheight: %s",t); return NULL; } - dprintfparsed("got height: %s (%g)\n",t,height); - gdp->gradheight=height; + dprintfparsed("got gradheight: %s (%g)\n",t,gradheight); + gdp->gradheight=gradheight; } } if (bitscmp(PARSE_STEP)) { @@ -721,7 +721,7 @@ static graph_desc_t* newGraphDescription(image_desc_t *const im,enum gf_en gf,pa } } - /* and set some of those late assignments to accomodate the legacy parser*/ + /* and set some of those late assignments to accommodate the legacy parser*/ /* first split vname into color */ if (vname) { /* check for color */ @@ -1080,7 +1080,7 @@ int parse_area(enum gf_en gf,parsedargs_t*pa,image_desc_t *const im){ |PARSE_SKIPSCALE |PARSE_XAXIS |PARSE_YAXIS - |PARSE_HEIGHT + |PARSE_GRADHEIGHT ); if (!gdp) { return 1;} @@ -1537,10 +1537,7 @@ void rrd_graph_script( case GF_SHIFT: r=parse_shift(gf,&pa,im); break; case GF_XPORT: r=parse_xport(gf,&pa,im); break; /* unsupported types right now */ - case GF_GRAD: - rrd_set_error("GRAD unsupported - use AREA instead"); - break; - } + } /* handle the return error case */ if (r) { freeParsedArguments(&pa); return;} /* check for unprocessed keyvalue args */