cairo_restore (cr);
}
+#define BARS_WIDTH 0.8
+
+/* Draw the given dataset as bars. */
+static void
+_draw_data_bars (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_rectangle (cr,
+ data->points[i].x - BARS_WIDTH / 2.0, 0.0,
+ BARS_WIDTH, data->points[i].y);
+ }
+
+ cairo_identity_matrix (cr);
+ cairo_set_line_width (cr, 1.0);
+ cairo_stroke (cr);
+
+ 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
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;
case ACRE_STYLE_TIMELINE:
/* Position the timeline bars top-down */
_draw_data_timeline (acre, data, acre->num_data - 1 - i);