+#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
+ * with a name) specifies the (start,stop) of a single timeline bar.
+ *
+ * Each independent timeline dataset in the chart is given its own
+ * vertical position, as specified by 'y_position'.
+ */
+static void
+_draw_data_timeline (acre_t *acre, acre_data_t *data, int y_position)
+{
+ unsigned i;
+ cairo_t *cr = acre->cr;
+ PangoLayout *timeline_label_layout;
+ double ignored, label_offset;
+ int labels_within_bar;
+
+ cairo_save (cr);
+
+ timeline_label_layout = _create_layout (acre, "Timeline");
+ pango_layout_set_font_description (timeline_label_layout, acre->font);
+
+ ignored = 0.0;
+ label_offset = ACRE_FONT_SIZE;
+ cairo_device_to_user_distance (cr, &ignored, &label_offset);
+
+ labels_within_bar = TIMELINE_BAR_HEIGHT / fabs (label_offset);
+
+ for (i = 0; i < data->num_points; i++) {
+ cairo_rectangle (cr,
+ data->points[i].x,
+ y_position - TIMELINE_BAR_HEIGHT / 2.0,
+ data->points[i].y - data->points[i].x,
+ TIMELINE_BAR_HEIGHT);
+
+ cairo_save (cr);
+ cairo_identity_matrix (cr);
+ cairo_set_line_width (cr, 1.0);
+ cairo_stroke_preserve (cr);
+ cairo_restore (cr);
+
+ cairo_new_path (cr);
+
+ if (i <= data->num_names && data->names[i]) {
+ cairo_save (cr);
+
+ cairo_move_to (cr, data->points[i].x,
+ y_position + TIMELINE_BAR_HEIGHT / 2.0 +
+ (i % labels_within_bar) * label_offset);
+ pango_layout_set_text (timeline_label_layout, data->names[i], -1);
+ cairo_identity_matrix (cr);
+ pango_cairo_show_layout (cr, timeline_label_layout);
+
+ cairo_restore (cr);
+ } else {
+ cairo_new_path (cr);
+ }
+
+ }
+
+ _destroy_layout (timeline_label_layout);
+
+ cairo_restore (cr);
+}
+
+/* Draw all the datasets of the chart. */