+static void
+_choose_colors (acre_t *acre)
+{
+ cmsHPROFILE lab_profile, srgb_profile;
+ cmsHTRANSFORM lab_to_srgb;
+ int i;
+ double theta, radius, srgb[3];
+ cmsCIELab lab;
+
+ lab_profile = cmsCreateLabProfile (NULL); /* D50 */
+ srgb_profile = cmsCreate_sRGBProfile ();
+
+ lab_to_srgb = cmsCreateTransform (lab_profile, TYPE_Lab_DBL,
+ srgb_profile, TYPE_RGB_DBL,
+ INTENT_PERCEPTUAL, 0);
+
+ acre->num_colors = acre->num_data;
+
+ if (acre->num_colors > acre->colors_size) {
+ acre->colors_size = acre->num_colors;
+ acre->colors = xrealloc (acre->colors,
+ acre->colors_size * sizeof (acre_color_t));
+ }
+
+ lab.L = 36;
+ radius = 130;
+ for (i = 0; i < acre->num_colors; i++) {
+ theta = 0.713 + 2 * M_PI * (double) i / acre->num_colors;
+ lab.a = radius * cos (theta);
+ lab.b = radius * sin (theta);
+
+ cmsDoTransform (lab_to_srgb, &lab, srgb, 1);
+
+ acre->colors[i].red = srgb[0];
+ acre->colors[i].green = srgb[1];
+ acre->colors[i].blue = srgb[2];
+ }
+
+ cmsDeleteTransform (lab_to_srgb);
+ cmsCloseProfile (lab_profile);
+ 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);
+}
+
+#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. */