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