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