blob: e7d879d683533ebfea5527ce21b9f2b2dfbfb12f [file] [log] [blame]
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +01001#ifndef GRAPH_H
2#define GRAPH_H
3
4struct graph;
Jens Axboe8dfd6072012-03-22 22:10:37 +01005struct graph_label;
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +01006
Jens Axboe8dfd6072012-03-22 22:10:37 +01007typedef struct graph_label * graph_label_t;
Stephen M. Cameroncae08722012-03-07 14:47:38 +01008
Jens Axboef3e84402012-03-07 13:14:32 +01009struct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010010/* graph_new() Returns a new graph structure of the given dimensions and font */
Stephen M. Cameron3ea48b82012-03-07 19:40:58 +010011void graph_set_size(struct graph *g, unsigned int xdim, unsigned int ydim);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010012/* graph_set_size() Changes the size of a graph to the given dimensions. */
Stephen M. Cameron57f9d282012-03-11 11:36:51 +010013void graph_set_position(struct graph *g, double xoffset, double yoffset);
14/* graph_set_position() sets the x- and y-offset to translate the graph */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010015void bar_graph_draw(struct graph *g, cairo_t *cr);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010016/* bar_graph_draw() draws the given graph as a bar graph */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010017void line_graph_draw(struct graph *g, cairo_t *cr);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010018/* line_graph_draw draws the given graph as a line graph */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010019void line_graph_set_data_count_limit(struct graph *g, int per_label_limit);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010020/* line_graph_set_data_count_limit() limits the amount of data which can
21 * be added to a line graph. Once the limit is reached, the oldest data
22 * is discarded as new data is added
23 */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010024void graph_title(struct graph *g, const char *title);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010025/* graph_title() sets the main title of the graph to the given string */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010026void graph_x_title(struct graph *g, const char *title);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010027/* graph_x_title() sets the title of the x axis to the given string */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010028void graph_y_title(struct graph *g, const char *title);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010029/* graph_y_title() sets the title of the y axis to the given string */
Jens Axboe8dfd6072012-03-22 22:10:37 +010030graph_label_t graph_add_label(struct graph *g, const char *label);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010031/* graph_add_label() adds a new "stream" of data to be graphed.
32 * For line charts, each label is a separate line on the graph.
33 * For bar charts, each label is a grouping of columns on the x-axis
34 * For example:
35 *
36 * | * | **
37 * | * xxxxxxxx | **
38 * | *** x | ** **
39 * | *x **** | ** ** **
40 * | xxxx* ***** | ** xx ** xx **
41 * | x ** | ** xx ** xx ** xx
42 * | x | ** xx ** xx ** xx
43 * ----------------------- -------------------------
44 * A B C
45 *
46 * For a line graph, the 'x's For a bar graph,
47 * would be on one "label", and 'A', 'B', and 'C'
48 * the '*'s would be on another are the labels.
49 * label.
50 */
51
Jens Axboe8dfd6072012-03-22 22:10:37 +010052int graph_add_data(struct graph *g, graph_label_t label, const double value);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010053/* graph_add_data() is used to add data to the labels of a bar graph */
Jens Axboe8dfd6072012-03-22 22:10:37 +010054int graph_add_xy_data(struct graph *g, graph_label_t label,
Jens Axboe93e2db22012-03-13 09:45:22 +010055 const double x, const double y, const char *tooltip);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010056/* graph_add_xy_data is used to add data to the labels of a line graph */
57
Jens Axboe8dfd6072012-03-22 22:10:37 +010058void graph_set_color(struct graph *g, graph_label_t label,
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010059 double red, double green, double blue);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010060#define INVISIBLE_COLOR (-1.0)
61/* graph_set_color is used to set the color used to plot the data in
62 * a line graph. INVISIBLE_COLOR can be used to plot the data invisibly.
63 * Invisible data will have the same effect on the scaling of the axes
64 * as visible data.
65 */
66
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010067void graph_free(struct graph *bg);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010068/* free a graph allocated by graph_new() */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010069
Stephen M. Cameron7175d912012-03-11 11:35:10 +010070typedef void (*graph_axis_unit_change_callback)(struct graph *g, int power_of_ten);
71void graph_x_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f);
72void graph_y_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f);
Stephen M. Cameronba35aa82012-03-11 11:36:14 +010073/* The labels used on the x and y axes may be shortened. You can register for callbacks
74 * so that you can know how the labels are shorted, typically used to adjust the axis
75 * titles to display the proper units. The power_of_ten parameter indicates what power
76 * of ten the labels have been divided by (9, 6, 3, or 0, corresponding to billions,
77 * millions, thousands and ones.
78 */
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010079
Stephen M. Camerondef0ac22012-03-12 07:32:57 +010080void graph_add_extra_space(struct graph *g, double left_percent, double right_percent,
81 double top_percent, double bottom_percent);
82/* graph_add_extra_space() adds extra space to edges of the the graph
83 * so that the data doesn't go to the very edges.
84 */
85
Jens Axboe93e2db22012-03-13 09:45:22 +010086extern int graph_has_tooltips(struct graph *g);
87extern const char *graph_find_tooltip(struct graph *g, int x, int y);
88extern int graph_contains_xy(struct graph *p, int x, int y);
89
Jens Axboed8fbeef2012-03-14 10:25:44 +010090extern void graph_set_base_offset(struct graph *g, unsigned int base_offset);
Jens Axboe01a947f2012-03-22 21:21:00 +010091extern void graph_set_graph_all_zeroes(struct graph *g, unsigned int set);
Jens Axboed8fbeef2012-03-14 10:25:44 +010092
Stephen M. Cameronaf58ef32012-03-07 07:56:16 +010093#endif
94