Code

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