From ac32a03148355f54e5d00a6defeea0cd177328a8 Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 7 Nov 2013 09:48:53 -0800 Subject: [PATCH] Add the notion of a style for each data set. There's no real change here yet, since the only style offered so far is the default ACRE_STYLE_LINE, (which is the same as how acre has always drawn things). But things will get more interesting as new styles are added in the future. --- acre.c | 55 ++++++++++++++++++++++++++++++++++++++----------------- acre.h | 13 ++++++++++++- 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/acre.c b/acre.c index 8945292..f46aebf 100644 --- a/acre.c +++ b/acre.c @@ -40,6 +40,9 @@ struct _acre_data { /* The name of this data set. */ char *name; + /* The style for rendering (line, bar, etc.) */ + acre_style_t style; + /* Minimum and mximum extents of data. */ acre_data_point_2d_t min; acre_data_point_2d_t max; @@ -795,11 +798,36 @@ _choose_colors (acre_t *acre) cmsCloseProfile (srgb_profile); } +/* Draw the given dataset as a line. */ +static void +_draw_data_line (acre_t *acre, acre_data_t *data) +{ + unsigned i; + cairo_t *cr = acre->cr; + + cairo_save (cr); + + cairo_new_path (cr); + + for (i = 0; i < data->num_points; i++) { + cairo_line_to (cr, + data->points[i].x, + data->points[i].y); + } + + cairo_identity_matrix (cr); + cairo_set_line_width (cr, 1.0); + cairo_stroke (cr); + + cairo_restore (cr); +} + +/* Draw all the datasets of the chart. */ static void _draw_data (acre_t *acre) { cairo_t *cr = acre->cr; - unsigned int d, i; + unsigned int i; acre_data_t *data; cairo_save (cr); @@ -813,28 +841,19 @@ _draw_data (acre_t *acre) _set_transform_to_data_space (acre); - for (d = 0; d < acre->num_data; d++) { - int color = d % acre->num_colors; + for (i = 0; i < acre->num_data; i++) { + int color = i % acre->num_colors; cairo_set_source_rgb (cr, acre->colors[color].red, acre->colors[color].green, acre->colors[color].blue); - data = acre->data[d]; - - cairo_new_path (cr); + data = acre->data[i]; - for (i = 0; i < data->num_points; i++) { - cairo_line_to (cr, - data->points[i].x, - data->points[i].y); - } - cairo_save (cr); - { - cairo_identity_matrix (cr); - cairo_set_line_width (cr, 1.0); - cairo_stroke (cr); + switch (data->style) { + case ACRE_STYLE_LINE: + _draw_data_line (acre, data); + break; } - cairo_restore (cr); } cairo_restore (cr); @@ -1056,6 +1075,8 @@ acre_data_create (void) data->name = NULL; + data->style = ACRE_STYLE_LINE; + data->points = NULL; data->points_size = 0; data->num_points = 0; diff --git a/acre.h b/acre.h index 663835c..6bad89a 100644 --- a/acre.h +++ b/acre.h @@ -89,7 +89,8 @@ void acre_set_y_axis_range_auto (acre_t *acre); /* Add a dataset to the plot. The plot assumes ownership of the - * dataset so it is not necessary to call acre_data_destroy on it. */ + * dataset so it is not necessary to call acre_data_destroy on it. + */ void acre_add_data (acre_t *acre, acre_data_t *data); @@ -111,6 +112,16 @@ acre_data_create (void); void acre_data_destroy (acre_data_t *data); +/* The style to be used for rendering data sets. */ +typedef enum +{ + ACRE_STYLE_LINE +} acre_style_t; + +/* Set the rendering style for this dataset. */ +void +acre_data_set_style (acre_data_t *data, acre_style_t style); + /* Set the label for this dataset (to appear in the plot's key). */ void acre_data_set_name (acre_data_t *data, const char *name); -- 2.43.0