From 3f0ffe22c166d1c8a89822d96f61131180d177d5 Mon Sep 17 00:00:00 2001 From: John Darrington Date: Sun, 18 Jan 2015 15:19:10 +0100 Subject: [PATCH] Piecharts: Avoid the segment fill obscuring the labels --- src/output/charts/piechart-cairo.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/output/charts/piechart-cairo.c b/src/output/charts/piechart-cairo.c index 7b847f123e..bd0452ca3b 100644 --- a/src/output/charts/piechart-cairo.c +++ b/src/output/charts/piechart-cairo.c @@ -75,25 +75,41 @@ xrchart_draw_piechart (const struct chart_item *chart_item, cairo_t *cr, for (i = 0; i < pie->n_slices; i++) total_magnitude += pie->slices[i].magnitude; + + /* Draw the segments */ angle = 0.0; for (i = 0; i < pie->n_slices ; ++i ) { const double segment_angle = pie->slices[i].magnitude / total_magnitude * 2 * M_PI ; - const double label_x = centre_x + - radius * cos (angle + segment_angle/2.0); - - const double label_y = centre_y + - radius * sin (angle + segment_angle/2.0); - /* Fill the segment */ draw_segment (cr, centre_x, centre_y, radius, angle, segment_angle, &data_colour[i % XRCHART_N_COLOURS]); - /* Now add the labels */ + angle += segment_angle; + } + + + /* Now add the labels. + Don't put this in the loop above; the labels must + be put in last, otherwise the segment fill could + obscure them. + */ + angle = 0.0; + for (i = 0; i < pie->n_slices ; ++i ) + { + const double segment_angle = + pie->slices[i].magnitude / total_magnitude * 2 * M_PI ; + + const double label_x = centre_x + + radius * cos (angle + segment_angle/2.0); + + const double label_y = centre_y + + radius * sin (angle + segment_angle/2.0); + if ( label_x < centre_x ) { cairo_move_to (cr, label_x, label_y); -- 2.30.2