1 #ifndef _RRD_GRAPH_H 2 #define _RRD_GRAPH_H 3 4 #include "rrd_tool.h" 5 #include "rrd_rpncalc.h" 6 #include "rrd_gfx.h" 7 #include <libgen.h> 8 9 #define MAX_VNAME_LEN 255 10 #define DEF_NAM_FMT "%255[-_A-Za-z0-9]" 11 12 #define ALTYGRID 0x01 /* use alternative y grid algorithm */ 13 #define ALTAUTOSCALE 0x02 /* use alternative algorithm to find lower and upper bounds */ 14 #define ALTAUTOSCALE_MIN 0x04 /* use alternative algorithm to find lower bounds */ 15 #define ALTAUTOSCALE_MAX 0x08 /* use alternative algorithm to find upper bounds */ 16 #define NOLEGEND 0x10 /* use no legend */ 17 #define NOMINOR 0x20 /* Turn off minor gridlines */ 18 #define ONLY_GRAPH 0x40 /* use only graph */ 19 #define FORCE_RULES_LEGEND 0x80 /* force printing of HRULE and VRULE legend */ 20 21 #define FORCE_UNITS 0x100 /* mask for all FORCE_UNITS_* flags */ 22 #define FORCE_UNITS_SI 0x100 /* force use of SI units in Y axis (no effect in linear graph, SI instead of E in log graph) */ 23 #define NO_RRDTOOL_TAG 0x200 /* disable the rrdtool tag */ 24 25 enum tmt_en {TMT_SECOND=0,TMT_MINUTE,TMT_HOUR,TMT_DAY, 26 TMT_WEEK,TMT_MONTH,TMT_YEAR}; 27 28 enum grc_en {GRC_CANVAS=0,GRC_BACK,GRC_SHADEA,GRC_SHADEB, 29 GRC_GRID,GRC_MGRID,GRC_FONT,GRC_ARROW,GRC_AXIS,GRC_FRAME,__GRC_END__}; 30 31 #define MGRIDWIDTH 0.6 32 #define GRIDWIDTH 0.4 33 34 enum gf_en {GF_PRINT=0,GF_GPRINT,GF_COMMENT,GF_HRULE,GF_VRULE,GF_LINE, 35 GF_AREA,GF_STACK,GF_TICK, 36 GF_DEF, GF_CDEF, GF_VDEF, GF_SHIFT, 37 #ifdef WITH_PIECHART 38 GF_PART, 39 #endif 40 GF_XPORT}; 41 42 enum vdef_op_en { 43 VDEF_MAXIMUM=0 /* like the MAX in (G)PRINT */ 44 ,VDEF_MINIMUM /* like the MIN in (G)PRINT */ 45 ,VDEF_AVERAGE /* like the AVERAGE in (G)PRINT */ 46 ,VDEF_PERCENT /* Nth percentile */ 47 ,VDEF_TOTAL /* average multiplied by time */ 48 ,VDEF_FIRST /* first non-unknown value and time */ 49 ,VDEF_LAST /* last non-unknown value and time */ 50 ,VDEF_LSLSLOPE /* least squares line slope */ 51 ,VDEF_LSLINT /* least squares line y_intercept */ 52 ,VDEF_LSLCORREL /* least squares line correlation coefficient */ 53 }; 54 enum text_prop_en { TEXT_PROP_DEFAULT=0, /* default settings */ 55 TEXT_PROP_TITLE, /* properties for the title */ 56 TEXT_PROP_AXIS, /* for the numbers next to the axis */ 57 TEXT_PROP_UNIT, /* for the vertical unit description */ 58 TEXT_PROP_LEGEND, /* fot the legend below the graph */ 59 TEXT_PROP_LAST }; 60 61 typedef struct text_prop_t { 62 double size; 63 char font[1024]; 64 } text_prop_t; 65 66 67 typedef struct vdef_t { 68 enum vdef_op_en op; 69 double param; /* parameter for function, if applicable */ 70 double val; /* resulting value */ 71 time_t when; /* timestamp, if applicable */ 72 } vdef_t; 73 74 typedef struct xlab_t { 75 long minsec; /* minimum sec per pix */ 76 long length; /* number of secs on the image */ 77 enum tmt_en gridtm; /* grid interval in what ?*/ 78 long gridst; /* how many whats per grid*/ 79 enum tmt_en mgridtm; /* label interval in what ?*/ 80 long mgridst; /* how many whats per label*/ 81 enum tmt_en labtm; /* label interval in what ?*/ 82 long labst; /* how many whats per label*/ 83 long precis; /* label precision -> label placement*/ 84 char *stst; /* strftime string*/ 85 } xlab_t; 86 87 typedef struct ygrid_scale_t { /* y axis grid scaling info */ 88 double gridstep; 89 int labfact; 90 char labfmt[64]; 91 } ygrid_scale_t; 92 93 /* sensible y label intervals ...*/ 94 95 typedef struct ylab_t { 96 double grid; /* grid spacing */ 97 int lfac[4]; /* associated label spacing*/ 98 } ylab_t; 99 100 101 /* this structure describes the elements which can make up a graph. 102 because they are quite diverse, not all elements will use all the 103 possible parts of the structure. */ 104 #ifdef HAVE_SNPRINTF 105 #define FMT_LEG_LEN 200 106 #else 107 #define FMT_LEG_LEN 2000 108 #endif 109 110 typedef struct graph_desc_t { 111 enum gf_en gf; /* graphing function */ 112 int stack; /* boolean */ 113 int debug; /* boolean */ 114 char vname[MAX_VNAME_LEN+1]; /* name of the variable */ 115 long vidx; /* gdes reference */ 116 char rrd[1024]; /* name of the rrd_file containing data */ 117 char ds_nam[DS_NAM_SIZE]; /* data source name */ 118 long ds; /* data source number */ 119 enum cf_en cf; /* consolidation function */ 120 enum cf_en cf_reduce; /* consolidation function for reduce_data() */ 121 gfx_color_t col; /* graph color */ 122 char format[FMT_LEG_LEN+5]; /* format for PRINT AND GPRINT */ 123 char legend[FMT_LEG_LEN+5]; /* legend*/ 124 int strftm; /* should the VDEF legend be formated with strftime */ 125 double leg_x,leg_y; /* location of legend */ 126 double yrule; /* value for y rule line and for VDEF */ 127 time_t xrule; /* time for x rule line and for VDEF */ 128 vdef_t vf; /* instruction for VDEF function */ 129 rpnp_t *rpnp; /* instructions for CDEF function */ 130 131 /* SHIFT implementation */ 132 int shidx; /* gdes reference for offset (-1 --> constant) */ 133 time_t shval; /* offset if shidx is -1 */ 134 time_t shift; /* current shift applied */ 135 136 /* description of data fetched for the graph element */ 137 time_t start,end; /* timestaps for first and last data element */ 138 time_t start_orig,end_orig; /* timestaps for first and last data element */ 139 unsigned long step; /* time between samples */ 140 unsigned long step_orig; /* time between samples */ 141 unsigned long ds_cnt; /* how many data sources are there in the fetch */ 142 long data_first; /* first pointer to this data */ 143 char **ds_namv; /* name of datasources in the fetch. */ 144 rrd_value_t *data; /* the raw data drawn from the rrd */ 145 rrd_value_t *p_data; /* processed data, xsize elments */ 146 double linewidth; /* linewideth */ 147 } graph_desc_t; 148 149 typedef struct image_desc_t { 150 151 /* configuration of graph */ 152 153 char graphfile[MAXPATH]; /* filename for graphic */ 154 FILE *graphhandle; /* FILE to use if filename is "-" */ 155 long xsize,ysize; /* graph area size in pixels */ 156 #ifdef WITH_PIECHART 157 long piesize; /* size of the piechart */ 158 #endif 159 gfx_color_t graph_col[__GRC_END__]; /* real colors for the graph */ 160 text_prop_t text_prop[TEXT_PROP_LAST]; /* text properties */ 161 char ylegend[210]; /* legend along the yaxis */ 162 char title[210]; /* title for graph */ 163 char watermark[110]; /* watermark for graph */ 164 int draw_x_grid; /* no x-grid at all */ 165 int draw_y_grid; /* no x-grid at all */ 166 double grid_dash_on, grid_dash_off; 167 xlab_t xlab_user; /* user defined labeling for xaxis */ 168 char xlab_form[210]; /* format for the label on the xaxis */ 169 170 double second_axis_scale; /* relative to the first axis (0 to disable) */ 171 double second_axis_shift; /* how much is it shifted vs the first axis */ 172 char second_axis_legend[210]; /* label to put on the seond axis */ 173 char second_axis_format[210]; /* format for the numbers on the scond axis */ 174 175 double ygridstep; /* user defined step for y grid */ 176 int ylabfact; /* every how many y grid shall a label be written ? */ 177 double tabwidth; /* tabwdith */ 178 time_t start,end; /* what time does the graph cover */ 179 unsigned long step; /* any preference for the default step ? */ 180 rrd_value_t minval,maxval; /* extreme values in the data */ 181 int rigid; /* do not expand range even with 182 values outside */ 183 ygrid_scale_t ygrid_scale; /* calculated y axis grid info */ 184 int gridfit; /* adjust y-axis range etc so all 185 grindlines falls in integer pixel values */ 186 char* imginfo; /* construct an <IMG ... tag and return 187 as first retval */ 188 int lazy; /* only update the image if there is 189 reasonable probablility that the 190 existing one is out of date */ 191 int slopemode; /* connect the dots of the curve directly, not using a stair */ 192 int logarithmic; /* scale the yaxis logarithmic */ 193 194 /* status information */ 195 196 long xorigin,yorigin;/* where is (0,0) of the graph */ 197 #ifdef WITH_PIECHART 198 long pie_x,pie_y; /* where is the centerpoint */ 199 #endif 200 long ximg,yimg; /* total size of the image */ 201 double magfact; /* numerical magnitude*/ 202 long base; /* 1000 or 1024 depending on what we graph */ 203 char symbol; /* magnitude symbol for y-axis */ 204 float viewfactor; /* how should the numbers on the y-axis be scaled for viewing ? */ 205 int unitsexponent; /* 10*exponent for units on y-asis */ 206 int unitslength; /* width of the yaxis labels */ 207 int forceleftspace; /* do not kill the space to the left of the y-axis if there is no grid */ 208 209 int extra_flags; /* flags for boolean options */ 210 /* data elements */ 211 212 long prt_c; /* number of print elements */ 213 long gdes_c; /* number of graphics elements */ 214 graph_desc_t *gdes; /* points to an array of graph elements */ 215 gfx_canvas_t *canvas; /* graphics library */ 216 } image_desc_t; 217 218 /* Prototypes */ 219 int xtr(image_desc_t *,time_t); 220 double ytr(image_desc_t *, double); 221 enum gf_en gf_conv(char *); 222 enum gfx_if_en if_conv(char *); 223 enum tmt_en tmt_conv(char *); 224 enum grc_en grc_conv(char *); 225 enum text_prop_en text_prop_conv(char *); 226 int im_free(image_desc_t *); 227 void auto_scale( image_desc_t *, double *, char **, double *); 228 void si_unit( image_desc_t *); 229 void expand_range(image_desc_t *); 230 void apply_gridfit(image_desc_t *); 231 void reduce_data( enum cf_en, unsigned long, time_t *, time_t *, unsigned long *, unsigned long *, rrd_value_t **); 232 int data_fetch( image_desc_t *); 233 long find_var(image_desc_t *, char *); 234 long find_var_wrapper(void *arg1, char *key); 235 long lcd(long *); 236 int data_calc( image_desc_t *); 237 int data_proc( image_desc_t *); 238 time_t find_first_time( time_t, enum tmt_en, long); 239 time_t find_next_time( time_t, enum tmt_en, long); 240 int print_calc(image_desc_t *, char ***); 241 int leg_place(image_desc_t *); 242 int calc_horizontal_grid(image_desc_t *); 243 int draw_horizontal_grid(image_desc_t *); 244 int horizontal_log_grid(image_desc_t *); 245 void vertical_grid(image_desc_t *); 246 void axis_paint(image_desc_t *); 247 void grid_paint(image_desc_t *); 248 int lazy_check(image_desc_t *); 249 int graph_paint(image_desc_t *, char ***); 250 #ifdef WITH_PIECHART 251 void pie_part(image_desc_t *, gfx_color_t, double, double, double, double, double); 252 #endif 253 int gdes_alloc(image_desc_t *); 254 int scan_for_col(const char *const , int, char *const); 255 int rrd_graph(int, char **, char ***, int *, int *, FILE *, double *, double *); 256 void rrd_graph_init(image_desc_t *); 257 void rrd_graph_options(int, char **, image_desc_t *); 258 void rrd_graph_script(int, char **, image_desc_t *, int); 259 int rrd_graph_color(image_desc_t *, char *, char *, int); 260 int bad_format(char *); 261 int vdef_parse(struct graph_desc_t *,const char *const); 262 int vdef_calc(image_desc_t *, int); 263 int vdef_percent_compar(const void *,const void *); 264 int graph_size_location(image_desc_t *, int 265 #ifdef WITH_PIECHART 266 ,int 267 #endif 268 ); 269 270 #endif 271