]> git.ipfire.org Git - thirdparty/rrdtool-1.x.git/commitdiff
integrate gradient functionality into AREA
authorTobias Oetiker <tobi@oetiker.ch>
Wed, 15 Apr 2015 20:34:41 +0000 (22:34 +0200)
committerTobias Oetiker <tobi@oetiker.ch>
Wed, 15 Apr 2015 20:34:41 +0000 (22:34 +0200)
doc/rrdgraph_graph.pod
src/rrd_graph.c
src/rrd_graph.h
src/rrd_graph_helper.c

index eb0863d3062a61b45e97402e17ff0ebf8b32b4d3..f1f40539c1cfe80792ce06b910f04e9374ea64da 100644 (file)
@@ -320,18 +320,20 @@ When you do not specify a color, you cannot specify a legend.  Should
 you want to use B<STACK>, use the "LINEx:<value>::STACK" form.
 
 
-=head3 B<AREA>B<:>I<value>[B<#>I<color>][B<:>[I<legend>][B<:STACK>][B<:skipscale>]]
+=head3 B<AREA>B<:>I<value>[B<#>I<color>[B<#>I<color2>]][B<:>[I<legend>][B<:STACK>][B<:skipscale>][B<:gradheight=>I<y>]
 
 See B<LINE>, however the area between the x-axis and the line will
 be filled.
 
-=head3 B<GRAD>B<:>I<value>[B<#>I<color1>[B<#>I<color2>B<:>I<height>][B<:>[I<legend>][B<:STACK>]]
+If color2 is specified, the area will be filled with a gradient.
 
-Similar to B<AREA>, except the area between the line and the x-axis will contain a gradient from color1 to color2.
+The I<gradheight> parameter can create three different behaviors. If
+I<gradheight> > 0, then the gradient is a fixed height, starting at the line
+going down.  If I<gradheight> < 0, then the gradient starts at a fixed height
+above the x-axis, going down to the x-axis.  If I<height> == 0, then the
+gradient goes from the line to x-axis.
 
-The I<height> parameter can create three different behaviors. If I<height> > 0, then the gradient is a fixed height, starting at the line going down. If I<height> < 0, then the gradient starts at fixed height above the x-axis, going down to the x-axis. If I<height> == 0, then the gradient goes from the line to x-axis. 
-
-If not present, I<color2> defaults to #00000000 and I<height> defaults to 50.
+The default value for I<gradheight> is 50.
 
 =head3 B<TICK>B<:>I<vname>B<#>I<rrggbb>[I<aa>][B<:>I<fraction>[B<:>I<legend>]]
 
index 7b48ad0b2139bf07b67a14fbb3b4264cf750b3ed..5787597f62f14b033c808dccdbd69bdaee4b9588 100644 (file)
@@ -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';
index 4e2019bd6b80385c73cd0d181993d15f638584d2..8c62ef737569ae3d3c76c8f049db1923708ea0a1 100644 (file)
@@ -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
 };
index 47219c4273822638566207432343b16e79a4cc94..fa3be141e61ddbd33af9fb8f4d0357651fd1a1e2 100644 (file)
@@ -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 */