summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2010-06-23 15:11:02 +0200
committerBenjamin Otte <otte@redhat.com>2010-06-23 15:11:02 +0200
commitb67f31dff8459aec2d468dbf4b314c419b1b89d8 (patch)
tree986f0e0585610caa508a693dda02af64f0be0610
parentf38960e75afbdd1e1e72528a7fd35dbae68dc65f (diff)
perf-chart: Report chart color instead of just setting it
-rw-r--r--perf/cairo-perf-chart.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/perf/cairo-perf-chart.c b/perf/cairo-perf-chart.c
index 433491e9..ae2c07f0 100644
--- a/perf/cairo-perf-chart.c
+++ b/perf/cairo-perf-chart.c
@@ -270,12 +270,23 @@ hsv_to_rgb (double h, double s, double v, struct color *color)
}
}
-static void set_report_color (struct chart *chart, int report)
-{
- struct color color;
+#define ARRAY_LENGTH(x) (sizeof (x) / sizeof ((x)[0]))
- hsv_to_rgb (6. / chart->num_reports * report, .7, .7, &color);
- cairo_set_source_rgb (chart->cr, color.red, color.green, color.blue);
+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 {
+ *color_out = predefined_colors[report];
+ }
}
static void
@@ -300,11 +311,13 @@ static void
add_chart (struct chart *c, int test, int report, double value)
{
double dx, dy, x;
+ struct color color;
if (fabs (value) < 0.1)
return;
- set_report_color (c, report);
+ get_report_color (c, report, &color);
+ cairo_set_source_rgb (c->cr, color.red, color.green, color.blue);
if (c->relative) {
cairo_text_extents_t extents;
@@ -755,6 +768,7 @@ static void
add_legend (struct chart *chart)
{
cairo_text_extents_t extents;
+ struct color color;
const char *str;
int i, x, y;
@@ -766,7 +780,8 @@ add_legend (struct chart *chart)
str = chart->names[i] ?
chart->names[i] : chart->reports[i].configuration;
- set_report_color (chart, i);
+ get_report_color (chart, i, &color);
+ cairo_set_source_rgb (chart->cr, color.red, color.green, color.blue);
cairo_rectangle (chart->cr, x, y + 6, 8, 8);
cairo_fill (chart->cr);