]> git.cworth.org Git - acre/commitdiff
Add another dataset style: ACRE_STYLE_BARS master
authorCarl Worth <cworth@cworth.org>
Sat, 9 Nov 2013 20:40:31 +0000 (12:40 -0800)
committerCarl Worth <cworth@cworth.org>
Sat, 9 Nov 2013 20:40:31 +0000 (12:40 -0800)
This is a mode to draw a dataset unconditionally as a bar chart,
(unlike BARS_OR_LINE which will use BARS when zoomed in sufficiently
or LINE when zoomed out).

acre.c
acre.h

diff --git a/acre.c b/acre.c
index 9a9851c568a684d3623e6b29b8d9a0b77c32301c..9f6f26ebaab1f854cd8cd392c92d19fa64a92e6c 100644 (file)
--- a/acre.c
+++ b/acre.c
@@ -848,28 +848,12 @@ _draw_data_line (acre_t *acre, acre_data_t *data)
 
 #define BARS_WIDTH 0.8
 
-/* Draw the given dataset as bars if there is room for that.
- *
- * Or, if the bars would run into each other, use a line instead.
- */
+/* Draw the given dataset as bars. */
 static void
-_draw_data_bars_or_line (acre_t *acre, acre_data_t *data)
+_draw_data_bars (acre_t *acre, acre_data_t *data)
 {
     unsigned i;
     cairo_t *cr = acre->cr;
-    double ignored, width;
-
-    /* Check device-space width available for inter-bad padding. */
-    width = 1.0 - BARS_WIDTH;
-    ignored = 0.0;
-    cairo_user_to_device_distance (cr, &width, &ignored);
-
-    /* If padding is less than two pixels, draw with a line instead. */
-    if (width < 2.0) {
-       _draw_data_line (acre, data);
-
-       return;
-    }
 
     cairo_save (cr);
 
@@ -888,6 +872,28 @@ _draw_data_bars_or_line (acre_t *acre, acre_data_t *data)
     cairo_restore (cr);
 }
 
+/* Draw the given dataset as bars if there is room for that.
+ *
+ * Or, if the bars would run into each other, use a line instead.
+ */
+static void
+_draw_data_bars_or_line (acre_t *acre, acre_data_t *data)
+{
+    cairo_t *cr = acre->cr;
+    double ignored, width;
+
+    /* Check device-space width available for inter-bar padding. */
+    width = 1.0 - BARS_WIDTH;
+    ignored = 0.0;
+    cairo_user_to_device_distance (cr, &width, &ignored);
+
+    /* If padding is less than two pixels, draw with a line instead. */
+    if (width < 2.0)
+       _draw_data_line (acre, data);
+    else
+       _draw_data_bars (acre, data);
+}
+
 #define TIMELINE_BAR_HEIGHT 0.6
 
 /* Draw the given dataset as a timeline. Each (X,Y) point (potentially
@@ -984,6 +990,9 @@ _draw_data (acre_t *acre)
        case ACRE_STYLE_LINE:
            _draw_data_line (acre, data);
            break;
+       case ACRE_STYLE_BARS:
+           _draw_data_bars (acre, data);
+           break;
        case ACRE_STYLE_BARS_OR_LINE:
            _draw_data_bars_or_line (acre, data);
            break;
diff --git a/acre.h b/acre.h
index 4cd58d4f4c4b179bd94e675d27de27d1ccc76d09..7924cba2d26d38603b0318ac1d319a3f72ed6198 100644 (file)
--- a/acre.h
+++ b/acre.h
@@ -118,6 +118,9 @@ typedef enum
        /* A simple line graph connection each (X,Y) pair in order. */
        ACRE_STYLE_LINE,
 
+       /* A bar chart. */
+       ACRE_STYLE_BARS,
+
        /* Bars if there is room for them, a line otherwise. */
        ACRE_STYLE_BARS_OR_LINE,