9eb33d7fe121b7e0062cb8e16e5794e728f931f1
[fio.git] / graph.h
1 #ifndef GRAPH_H
2 #define GRAPH_H
3
4 struct graph;
5
6
7 struct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font);
8 /* graph_new() Returns a new graph structure of the given dimensions and font */
9 void graph_set_size(struct graph *g, unsigned int xdim, unsigned int ydim);
10 /* graph_set_size() Changes the size of a graph to the given dimensions. */ 
11 void bar_graph_draw(struct graph *g, cairo_t *cr);
12 /* bar_graph_draw() draws the given graph as a bar graph */
13 void line_graph_draw(struct graph *g, cairo_t *cr);
14 /* line_graph_draw draws the given graph as a line graph */
15 void line_graph_set_data_count_limit(struct graph *g, int per_label_limit);
16 /* line_graph_set_data_count_limit() limits the amount of data which can
17  * be added to a line graph.  Once the limit is reached, the oldest data 
18  * is discarded as new data is added
19  */
20 void graph_title(struct graph *g, const char *title);
21 /* graph_title() sets the main title of the graph to the given string */
22 void graph_x_title(struct graph *g, const char *title);
23 /* graph_x_title() sets the title of the x axis to the given string */
24 void graph_y_title(struct graph *g, const char *title);
25 /* graph_y_title() sets the title of the y axis to the given string */
26 void graph_add_label(struct graph *g, const char *label);
27 /* graph_add_label() adds a new "stream" of data to be graphed.
28  * For line charts, each label is a separate line on the graph.
29  * For bar charts, each label is a grouping of columns on the x-axis
30  * For example:
31  *
32  *  |  *                          | **
33  *  |   *      xxxxxxxx           | **
34  *  |    ***  x                   | **              **
35  *  |       *x       ****         | **      **      **
36  *  |    xxxx*  *****             | ** xx   ** xx   **
37  *  |   x     **                  | ** xx   ** xx   ** xx
38  *  |  x                          | ** xx   ** xx   ** xx
39  *  -----------------------       -------------------------
40  *                                    A       B       C
41  *
42  * For a line graph, the 'x's     For a bar graph, 
43  * would be on one "label", and   'A', 'B', and 'C'
44  * the '*'s would be on another   are the labels.
45  * label.
46  */
47
48 int graph_add_data(struct graph *g, const char *label, const double value);
49 /* graph_add_data() is used to add data to the labels of a bar graph */
50 int graph_add_xy_data(struct graph *g, const char *label,
51                 const double x, const double y);
52 /* graph_add_xy_data is used to add data to the labels of a line graph */
53
54 void graph_set_color(struct graph *g, const char *label,
55                 double red, double green, double blue);
56 #define INVISIBLE_COLOR (-1.0)
57 /* graph_set_color is used to set the color used to plot the data in
58  * a line graph.  INVISIBLE_COLOR can be used to plot the data invisibly.
59  * Invisible data will have the same effect on the scaling of the axes
60  * as visible data.
61  */
62
63 void graph_free(struct graph *bg);
64 /* free a graph allocated by graph_new() */
65
66 typedef void (*graph_axis_unit_change_callback)(struct graph *g, int power_of_ten);
67 void graph_x_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f);
68 void graph_y_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f);
69 /* The labels used on the x and y axes may be shortened.  You can register for callbacks
70  * so that you can know how the labels are shorted, typically used to adjust the axis
71  * titles to display the proper units.  The power_of_ten parameter indicates what power
72  * of ten the labels have been divided by (9, 6, 3, or 0, corresponding to billions,
73  * millions, thousands and ones. 
74  */ 
75
76 #endif
77