summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2010-06-23 15:37:46 +0200
committerBenjamin Otte <otte@redhat.com>2010-06-23 15:37:46 +0200
commite43f0b4c1ae0985f6c8616a21327859383ad157c (patch)
tree8a14c106dacaaa63b0c954a92b3b400a848185d5
parentbfe2cc5ec45e1d557ca752884825d577ba1780eb (diff)
perf-chart: Factor out static colors into a common getter
-rw-r--r--perf/cairo-perf-chart.c47
1 files changed, 36 insertions, 11 deletions
diff --git a/perf/cairo-perf-chart.c b/perf/cairo-perf-chart.c
index 69f76f67..c098bfc9 100644
--- a/perf/cairo-perf-chart.c
+++ b/perf/cairo-perf-chart.c
@@ -271,21 +271,45 @@ hsv_to_rgb (double h, double s, double v, struct color *color)
}
#define ARRAY_LENGTH(x) (sizeof (x) / sizeof ((x)[0]))
+static struct color predefined_colors[] = {
+ { 204./255, 0, 0 },
+ { 237./255, 212./255, 0 },
+ { 115./255, 210./255, 22./255 },
+ { 114./255, 159./255, 207./255 }
+};
+
+static cairo_bool_t
+using_predefined_colors (struct chart *chart)
+{
+ return (unsigned) chart->num_reports <= ARRAY_LENGTH (predefined_colors);
+}
static void
get_report_color (struct chart *chart, int report, struct color * color_out)
{
- static struct color predefined_colors[] = {
- { 204./255, 0, 0 },
- { 237./255, 212./255, 0 },
- { 115./255, 210./255, 22./255 },
- { 114./255, 159./255, 207./255 }
- };
-
- if ((unsigned) chart->num_reports > ARRAY_LENGTH (predefined_colors)) {
- hsv_to_rgb (6. / chart->num_reports * report, .7, .7, color_out);
- } else {
+ if (using_predefined_colors (chart)) {
*color_out = predefined_colors[report];
+ } else {
+ hsv_to_rgb (6. / chart->num_reports * report, .7, .7, color_out);
+ }
+}
+
+typedef enum {
+ SPECIAL_COLOR_BAR_LABEL
+} special_color_t;
+
+static void
+get_special_color (struct chart *chart, special_color_t special, struct color * color_out)
+{
+ switch (special) {
+ case SPECIAL_COLOR_BAR_LABEL:
+ if (using_predefined_colors (chart))
+ SET_COLOR (color_out, 0.15, 0.15, 0.15);
+ else
+ SET_COLOR (color_out, 0.95, 0.95, 0.95);
+ break;
+ default:
+ SET_COLOR (color_out, 1, 0, 1);
}
}
@@ -385,7 +409,8 @@ add_chart (struct chart *c, int test, int report, double value)
show_label = y > extents.width + 6;
}
- cairo_set_source_rgb (c->cr, .95, .95, .95);
+ get_special_color (c, SPECIAL_COLOR_BAR_LABEL, &color);
+ cairo_set_source_rgb (c->cr, color.red, color.green, color.blue);
if (show_label)
cairo_show_text (c->cr, buf);
cairo_restore (c->cr);