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