Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 1 | #ifndef GRAPH_H |
| 2 | #define GRAPH_H |
| 3 | |
| 4 | struct graph; |
Jens Axboe | 8dfd607 | 2012-03-22 22:10:37 +0100 | [diff] [blame] | 5 | struct graph_label; |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 6 | |
Jens Axboe | 8dfd607 | 2012-03-22 22:10:37 +0100 | [diff] [blame] | 7 | typedef struct graph_label * graph_label_t; |
Stephen M. Cameron | cae0872 | 2012-03-07 14:47:38 +0100 | [diff] [blame] | 8 | |
Jens Axboe | a1e7972 | 2012-03-23 10:52:25 +0100 | [diff] [blame] | 9 | #define GRAPH_DEFAULT_FONT "Sans 12" |
| 10 | |
Jens Axboe | f3e8440 | 2012-03-07 13:14:32 +0100 | [diff] [blame] | 11 | struct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 12 | /* graph_new() Returns a new graph structure of the given dimensions and font */ |
Stephen M. Cameron | 3ea48b8 | 2012-03-07 19:40:58 +0100 | [diff] [blame] | 13 | void graph_set_size(struct graph *g, unsigned int xdim, unsigned int ydim); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 14 | /* graph_set_size() Changes the size of a graph to the given dimensions. */ |
Stephen M. Cameron | 57f9d28 | 2012-03-11 11:36:51 +0100 | [diff] [blame] | 15 | void graph_set_position(struct graph *g, double xoffset, double yoffset); |
| 16 | /* graph_set_position() sets the x- and y-offset to translate the graph */ |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 17 | void bar_graph_draw(struct graph *g, cairo_t *cr); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 18 | /* bar_graph_draw() draws the given graph as a bar graph */ |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 19 | void line_graph_draw(struct graph *g, cairo_t *cr); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 20 | /* line_graph_draw draws the given graph as a line graph */ |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 21 | void line_graph_set_data_count_limit(struct graph *g, int per_label_limit); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 22 | /* line_graph_set_data_count_limit() limits the amount of data which can |
| 23 | * be added to a line graph. Once the limit is reached, the oldest data |
| 24 | * is discarded as new data is added |
| 25 | */ |
Jens Axboe | a1e7972 | 2012-03-23 10:52:25 +0100 | [diff] [blame] | 26 | void graph_set_font(struct graph *g, const char *font); |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 27 | void graph_title(struct graph *g, const char *title); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 28 | /* graph_title() sets the main title of the graph to the given string */ |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 29 | void graph_x_title(struct graph *g, const char *title); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 30 | /* graph_x_title() sets the title of the x axis to the given string */ |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 31 | void graph_y_title(struct graph *g, const char *title); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 32 | /* graph_y_title() sets the title of the y axis to the given string */ |
Jens Axboe | 8dfd607 | 2012-03-22 22:10:37 +0100 | [diff] [blame] | 33 | graph_label_t graph_add_label(struct graph *g, const char *label); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 34 | /* graph_add_label() adds a new "stream" of data to be graphed. |
| 35 | * For line charts, each label is a separate line on the graph. |
| 36 | * For bar charts, each label is a grouping of columns on the x-axis |
| 37 | * For example: |
| 38 | * |
| 39 | * | * | ** |
| 40 | * | * xxxxxxxx | ** |
| 41 | * | *** x | ** ** |
| 42 | * | *x **** | ** ** ** |
| 43 | * | xxxx* ***** | ** xx ** xx ** |
| 44 | * | x ** | ** xx ** xx ** xx |
| 45 | * | x | ** xx ** xx ** xx |
| 46 | * ----------------------- ------------------------- |
| 47 | * A B C |
| 48 | * |
| 49 | * For a line graph, the 'x's For a bar graph, |
| 50 | * would be on one "label", and 'A', 'B', and 'C' |
| 51 | * the '*'s would be on another are the labels. |
| 52 | * label. |
| 53 | */ |
| 54 | |
Jens Axboe | 8dfd607 | 2012-03-22 22:10:37 +0100 | [diff] [blame] | 55 | int graph_add_data(struct graph *g, graph_label_t label, const double value); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 56 | /* graph_add_data() is used to add data to the labels of a bar graph */ |
Jens Axboe | 8dfd607 | 2012-03-22 22:10:37 +0100 | [diff] [blame] | 57 | int graph_add_xy_data(struct graph *g, graph_label_t label, |
Jens Axboe | 93e2db2 | 2012-03-13 09:45:22 +0100 | [diff] [blame] | 58 | const double x, const double y, const char *tooltip); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 59 | /* graph_add_xy_data is used to add data to the labels of a line graph */ |
| 60 | |
Jens Axboe | 8dfd607 | 2012-03-22 22:10:37 +0100 | [diff] [blame] | 61 | void graph_set_color(struct graph *g, graph_label_t label, |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 62 | double red, double green, double blue); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 63 | #define INVISIBLE_COLOR (-1.0) |
| 64 | /* graph_set_color is used to set the color used to plot the data in |
| 65 | * a line graph. INVISIBLE_COLOR can be used to plot the data invisibly. |
| 66 | * Invisible data will have the same effect on the scaling of the axes |
| 67 | * as visible data. |
| 68 | */ |
| 69 | |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 70 | void graph_free(struct graph *bg); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 71 | /* free a graph allocated by graph_new() */ |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 72 | |
Stephen M. Cameron | 7175d91 | 2012-03-11 11:35:10 +0100 | [diff] [blame] | 73 | typedef void (*graph_axis_unit_change_callback)(struct graph *g, int power_of_ten); |
| 74 | void graph_x_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f); |
| 75 | void graph_y_axis_unit_change_notify(struct graph *g, graph_axis_unit_change_callback f); |
Stephen M. Cameron | ba35aa8 | 2012-03-11 11:36:14 +0100 | [diff] [blame] | 76 | /* The labels used on the x and y axes may be shortened. You can register for callbacks |
| 77 | * so that you can know how the labels are shorted, typically used to adjust the axis |
| 78 | * titles to display the proper units. The power_of_ten parameter indicates what power |
| 79 | * of ten the labels have been divided by (9, 6, 3, or 0, corresponding to billions, |
| 80 | * millions, thousands and ones. |
| 81 | */ |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 82 | |
Stephen M. Cameron | def0ac2 | 2012-03-12 07:32:57 +0100 | [diff] [blame] | 83 | void graph_add_extra_space(struct graph *g, double left_percent, double right_percent, |
| 84 | double top_percent, double bottom_percent); |
| 85 | /* graph_add_extra_space() adds extra space to edges of the the graph |
| 86 | * so that the data doesn't go to the very edges. |
| 87 | */ |
| 88 | |
Jens Axboe | 93e2db2 | 2012-03-13 09:45:22 +0100 | [diff] [blame] | 89 | extern int graph_has_tooltips(struct graph *g); |
| 90 | extern const char *graph_find_tooltip(struct graph *g, int x, int y); |
| 91 | extern int graph_contains_xy(struct graph *p, int x, int y); |
| 92 | |
Jens Axboe | d8fbeef | 2012-03-14 10:25:44 +0100 | [diff] [blame] | 93 | extern void graph_set_base_offset(struct graph *g, unsigned int base_offset); |
Jens Axboe | 01a947f | 2012-03-22 21:21:00 +0100 | [diff] [blame] | 94 | extern void graph_set_graph_all_zeroes(struct graph *g, unsigned int set); |
Jens Axboe | d8fbeef | 2012-03-14 10:25:44 +0100 | [diff] [blame] | 95 | |
Jens Axboe | 5721d27 | 2012-09-26 14:11:49 +0200 | [diff] [blame] | 96 | extern void graph_clear_values(struct graph *g); |
| 97 | |
Stephen M. Cameron | af58ef3 | 2012-03-07 07:56:16 +0100 | [diff] [blame] | 98 | #endif |
| 99 | |