]> git.cworth.org Git - acre/blobdiff - acre.c
Add the notion of a style for each data set.
[acre] / acre.c
diff --git a/acre.c b/acre.c
index 8945292b3578ad530c0d653ee407da73d429a718..f46aebf6441271523aba89dda74d5e8d17e9e5f0 100644 (file)
--- 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;