Code

* adjusted element spacing within the graph
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Mon, 11 Apr 2005 23:22:57 +0000 (23:22 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Mon, 11 Apr 2005 23:22:57 +0000 (23:22 +0000)
* re-intruduced --units-length option
* stabilized --units-exponent option by jumping to alt-y-grid mode
  once the default autogrid can not cope with the data anymore.

git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@397 a5681a0c-68f1-0310-ab6d-d61299d08faa

doc/rrdgraph.src
src/rrd_graph.c
src/rrd_graph.h
src/rrd_tool.c

index 7f912bed5c5cb7f36eea08aac3cabdbf55fd2837..faee46e21406562bd13d9f12ef511f3160cc1243 100644 (file)
@@ -226,6 +226,16 @@ display the y-axis values in k (Kilo, 10e3, thousands), use -6 to
 display the y-axis values in u (Micro, 10e-6, millionths).  Use a value
 of 0 to prevent any scaling of the y-axis values.
 
+This option is very effective at confusing the heck out of the default
+rrdtool autoscaler and grid painter. If rrdtool detects that it is not
+successful in labeling the graph under the given circumstances, it will switch
+to the more robust B<--alt-y-grid> mode.
+
+B<[-L|--units-length E<lt>valueE<gt>]>
+
+How many digits should rrdtool assume the y-axis labels to be ? You may have to use this option
+to make enough space once you start fideling with the y-axis labeling.
+
 Z<>
 
 =back
index a0748ad800059c892fa133c079991ded45a2f767..0daa551c5707d4401006fa9763585b82dc186d85 100644 (file)
@@ -338,7 +338,7 @@ si_unit(
         digits = floor( log( max( fabs(im->minval),fabs(im->maxval)))/log((double)im->base)); 
     }
     im->magfact = pow((double)im->base , digits);
-
+    
 #ifdef DEBUG
     printf("digits %6.3f  im->magfact %6.3f\n",digits,im->magfact);
 #endif
@@ -347,7 +347,7 @@ si_unit(
                    ((digits+symbcenter) >= 0) )
         im->symbol = symbol[(int)digits+symbcenter];
     else
-       im->symbol = ' ';
+       im->symbol = '?';
  }
 
 /*  move min and max values around to become sensible */
@@ -423,6 +423,10 @@ expand_range(image_desc_t *im)
                    -sensiblevalues[i] >=scaled_max)
                    im->maxval = -sensiblevalues[i]*(im->magfact);
            }
+           /* no sensiblevalues found. we switch to ALTYGRID mode */
+           if (sensiblevalues[i] == 0){
+               im->extra_flags |= ALTYGRID;
+           }           
        }
     } else {
        /* adjust min and max to the grid definition if there is one */
@@ -1535,10 +1539,15 @@ calc_horizontal_grid(image_desc_t   *im)
                decimals = 1;
            
            fractionals = floor(log10(range));
-           if(fractionals < 0) /* small amplitude. */
-               sprintf(im->ygrid_scale.labfmt, "%%%d.%df", decimals - fractionals + 1, -fractionals + 1);
-           else
-               sprintf(im->ygrid_scale.labfmt, "%%%d.1f", decimals + 1);
+           if(fractionals < 0) { /* small amplitude. */
+               int len = decimals - fractionals + 1;
+               if (im->unitslength < len) im->unitslength = len;
+               sprintf(im->ygrid_scale.labfmt, "%%%d.%df", len, -fractionals + 1);
+           } else {
+               int len = decimals + 1;
+               if (im->unitslength < len) im->unitslength = len;
+               sprintf(im->ygrid_scale.labfmt, "%%%d.1f", len);
+           }
            im->ygrid_scale.gridstep = pow((double)10, (double)fractionals);
            if(im->ygrid_scale.gridstep == 0) /* range is one -> 0.1 is reasonable scale */
                im->ygrid_scale.gridstep = 0.1;
@@ -1560,7 +1569,7 @@ calc_horizontal_grid(image_desc_t   *im)
        else {
            for(i=0;ylab[i].grid > 0;i++){
                pixel = im->ysize / (scaledrange / ylab[i].grid);
-               if (gridind == -1 && pixel > 5) {
+               if (pixel > 5) {
                    gridind = i;
                    break;
                }
@@ -1618,7 +1627,7 @@ int draw_horizontal_grid(image_desc_t *im)
                }
 
               gfx_new_text ( im->canvas,
-                             X0-im->text_prop[TEXT_PROP_AXIS].size/1.5, Y0,
+                             X0-im->text_prop[TEXT_PROP_AXIS].size, Y0,
                              im->graph_col[GRC_FONT],
                              im->text_prop[TEXT_PROP_AXIS].font,
                              im->text_prop[TEXT_PROP_AXIS].size,
@@ -1712,7 +1721,7 @@ horizontal_log_grid(image_desc_t   *im)
           
           sprintf(graph_label,"%3.0e",value * yloglab[majoridx][i]);
           gfx_new_text ( im->canvas,
-                         X0-im->text_prop[TEXT_PROP_AXIS].size/1.5, Y0,
+                         X0-im->text_prop[TEXT_PROP_AXIS].size, Y0,
                          im->graph_col[GRC_FONT],
                          im->text_prop[TEXT_PROP_AXIS].font,
                          im->text_prop[TEXT_PROP_AXIS].size,
@@ -1819,7 +1828,7 @@ vertical_grid(
 # error "your libc has no strftime I guess we'll abort the exercise here."
 #endif
        gfx_new_text ( im->canvas,
-                     xtr(im,tilab), Y0+im->text_prop[TEXT_PROP_AXIS].size/1.5,
+                     xtr(im,tilab), Y0+im->text_prop[TEXT_PROP_AXIS].size,
                      im->graph_col[GRC_FONT],
                      im->text_prop[TEXT_PROP_AXIS].font,
                      im->text_prop[TEXT_PROP_AXIS].size,
@@ -2101,16 +2110,16 @@ graph_size_location(image_desc_t *im, int elements
     */
     int Xvertical=0,   Yvertical=0,
        Xtitle   =0,    Ytitle   =0,
-       Xylabel  =0,    Yylabel  =0,
+       Xylabel  =0,    
        Xmain    =0,    Ymain    =0,
 #ifdef WITH_PIECHART
        Xpie     =0,    Ypie     =0,
 #endif
-       Xxlabel  =0,    Yxlabel  =0,
+                       Yxlabel  =0,
 #if 0
        Xlegend  =0,    Ylegend  =0,
 #endif
-        Xspacing =10,  Yspacing =10;
+        Xspacing =15,  Yspacing =15;
 
     if (im->extra_flags & ONLY_GRAPH) {
        im->xorigin =0;
@@ -2146,12 +2155,14 @@ graph_size_location(image_desc_t *im, int elements
        Xmain=im->xsize;
        Ymain=im->ysize;
        if (im->draw_x_grid) {
-           Xxlabel=Xmain;
            Yxlabel=im->text_prop[TEXT_PROP_AXIS].size *2.5;
        }
        if (im->draw_y_grid) {
-           Xylabel=im->text_prop[TEXT_PROP_AXIS].size *6;
-           Yylabel=Ymain;
+           Xylabel=gfx_get_text_width(im->canvas, 0,
+                       im->text_prop[TEXT_PROP_AXIS].font,
+                       im->text_prop[TEXT_PROP_AXIS].size,
+                       im->tabwidth,
+                       "0", 0) * im->unitslength + im->text_prop[TEXT_PROP_AXIS].size * 2;
        }
     }
 
@@ -2742,6 +2753,7 @@ rrd_graph_init(image_desc_t *im)
     im->minval = DNAN;
     im->maxval = DNAN;    
     im->unitsexponent= 9999;
+    im->unitslength= 5; 
     im->extra_flags= 0;
     im->rigid = 0;
     im->gridfit = 1;
@@ -2839,17 +2851,18 @@ rrd_graph_options(int argc, char *argv[],image_desc_t *im)
             {"no-minor",   no_argument,       0,  'I'},
            {"alt-autoscale", no_argument,    0,  'A'},
            {"alt-autoscale-max", no_argument, 0, 'M'},
+            {"no-gridfit", no_argument,       0,   'N'},
            {"units-exponent",required_argument, 0, 'X'},
+           {"units-length",required_argument, 0, 'L'},
            {"step",       required_argument, 0,    'S'},
             {"tabwidth",   required_argument, 0,    'T'},            
-           {"no-gridfit", no_argument,       0,   'N'},
            {0,0,0,0}};
        int option_index = 0;
        int opt;
         int col_start,col_end;
 
        opt = getopt_long(argc, argv, 
-                        "s:e:x:y:v:w:h:iu:l:rb:oc:n:m:t:f:a:I:zgjFYAMX:S:NT:",
+                        "s:e:x:y:v:w:h:iu:l:rb:oc:n:m:t:f:a:I:zgjFYAMX:L:S:T:N",
                          long_options, &option_index);
 
        if (opt == EOF)
@@ -2880,13 +2893,16 @@ rrd_graph_options(int argc, char *argv[],image_desc_t *im)
        case 'X':
            im->unitsexponent = atoi(optarg);
            break;
+       case 'L':
+           im->unitslength = atoi(optarg);
+           break;
        case 'T':
            im->tabwidth = atof(optarg);
            break;
        case 'S':
            im->step =  atoi(optarg);
            break;
-       case 262:
+       case 'N':
            im->gridfit = 0;
            break;
        case 's':
index 1e02c624ad5269788c97c7d9a66a70aac1f7e4a3..cf9964562a4e1c7e4fe7fc437b76efd735278d3f 100644 (file)
@@ -183,6 +183,7 @@ typedef struct image_desc_t {
     long         base;            /* 1000 or 1024 depending on what we graph */
     char           symbol;         /* magnitude symbol for y-axis */
     int            unitsexponent;    /* 10*exponent for units on y-asis */
+    int            unitslength;    /* width of the yaxis labels */
     int            extra_flags;    /* flags for boolean options */
     /* data elements */
 
index fb0fafead8c3c1f19f62d6592567df2a00c64be6..784f6dc4a3918ee39f9286044551c6e7244bc057 100644 (file)
@@ -108,7 +108,9 @@ void PrintUsage(char *cmd)
            "\t\t[--zoom factor]\n"       
           "\t\t[--alt-autoscale]\n"
           "\t\t[--alt-autoscale-max]\n"
-          "\t\t[--units-exponent value]\n"        
+          "\t\t[--no-gridfit]\n"
+          "\t\t[--units-exponent value]\n"
+          "\t\t[--units-length value]\n"
           "\t\t[--step seconds]\n"        
           "\t\t[-f|--imginfo printfstr]\n"
           "\t\t[-a|--imgformat PNG]\n"