From f8d14d07de8db5ba5aa1377650a69532ff744552 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Tue, 28 Jul 2009 06:41:06 -0700 Subject: [PATCH] charts: Use numeric colors instead of color names. Cairo doesn't support color names, so this will ease the transition. --- src/output/chart-provider.h | 10 +++++++++- src/output/chart.c | 7 +++++-- src/output/charts/box-whisker.c | 5 ++++- src/output/charts/piechart.c | 8 ++++---- src/output/charts/plot-chart.c | 20 ++++++++++---------- src/output/charts/plot-chart.h | 11 +++++------ src/output/charts/plot-hist.c | 5 ++++- 7 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/output/chart-provider.h b/src/output/chart-provider.h index 4b36c55a..2ff4aafa 100644 --- a/src/output/chart-provider.h +++ b/src/output/chart-provider.h @@ -18,8 +18,16 @@ #define OUTPUT_CHART_PROVIDER_H 1 #include +#include #include +struct chart_colour + { + uint8_t red; + uint8_t green; + uint8_t blue; + }; + struct chart_class { void (*draw) (const struct chart *, plPlotter *); @@ -57,7 +65,7 @@ struct chart_geometry /* Default font size for the plot (if zero, then use plotter default) */ int font_size; - char fill_colour[10]; + struct chart_colour fill_colour; /* Stuff Particular to Cartesians (and Boxplots ) */ double ordinate_scale; diff --git a/src/output/chart.c b/src/output/chart.c index 2a2bc124..8d99f41f 100644 --- a/src/output/chart.c +++ b/src/output/chart.c @@ -58,7 +58,7 @@ chart_geometry_init (plPlotter *lp, struct chart_geometry *geom) /* Set line thickness. */ pl_flinewidth_r (lp, 0.25); - pl_pencolorname_r (lp, "black"); + pl_pencolor_r (lp, 0, 0, 0); /* Erase graphics display. */ pl_erase_r (lp); @@ -77,7 +77,10 @@ chart_geometry_init (plPlotter *lp, struct chart_geometry *geom) geom->legend_left = 810; geom->legend_right = 1000; geom->font_size = 0; - strcpy (geom->fill_colour, "red"); + + geom->fill_colour.red = 255; + geom->fill_colour.green = 0; + geom->fill_colour.blue = 0; /* Get default font size */ if (!geom->font_size) diff --git a/src/output/charts/box-whisker.c b/src/output/charts/box-whisker.c index 301d762b..24b29145 100644 --- a/src/output/charts/box-whisker.c +++ b/src/output/charts/box-whisker.c @@ -142,7 +142,10 @@ boxplot_draw_box (plPlotter *lp, const struct chart_geometry *geom, /* Draw the box */ pl_savestate_r (lp); - pl_fillcolorname_r (lp, geom->fill_colour); + pl_fillcolor_r (lp, + geom->fill_colour.red * 257, + geom->fill_colour.green * 257, + geom->fill_colour.blue * 257); pl_filltype_r (lp,1); pl_fbox_r (lp, box_left, diff --git a/src/output/charts/piechart.c b/src/output/charts/piechart.c index 4b7b1400..94881b41 100644 --- a/src/output/charts/piechart.c +++ b/src/output/charts/piechart.c @@ -48,7 +48,7 @@ draw_segment(plPlotter *, double centre_x, double centre_y, double radius, double start_angle, double segment_angle, - const char *colour) ; + const struct chart_colour *) ; @@ -121,7 +121,7 @@ piechart_draw (const struct chart *chart, plPlotter *lp) draw_segment (lp, centre_x, centre_y, radius, angle, segment_angle, - data_colour[i % N_CHART_COLOURS]); + &data_colour[i % N_CHART_COLOURS]); /* Now add the labels */ if ( label_x < centre_x ) @@ -197,7 +197,7 @@ draw_segment(plPlotter *lp, double x0, double y0, double radius, double start_angle, double segment_angle, - const char *colour) + const struct chart_colour *colour) { const double start_x = x0 - radius * sin(start_angle); const double start_y = y0 + radius * cos(start_angle); @@ -205,7 +205,7 @@ draw_segment(plPlotter *lp, pl_savestate_r(lp); pl_savestate_r(lp); - pl_colorname_r(lp, colour); + pl_color_r(lp, colour->red * 257, colour->green * 257, colour->blue * 257); pl_pentype_r(lp,1); pl_filltype_r(lp,1); diff --git a/src/output/charts/plot-chart.c b/src/output/charts/plot-chart.c index 86e1c80f..9d298cd2 100644 --- a/src/output/charts/plot-chart.c +++ b/src/output/charts/plot-chart.c @@ -35,17 +35,17 @@ #include "xalloc.h" -const char *const data_colour[N_CHART_COLOURS] = +const struct chart_colour data_colour[N_CHART_COLOURS] = { - "brown", - "red", - "orange", - "yellow", - "green", - "blue", - "violet", - "grey", - "pink" + { 165, 42, 42 }, /* brown */ + { 255, 0, 0 }, /* red */ + { 255, 165, 0 }, /* orange */ + { 255, 255, 0 }, /* yellow */ + { 0, 255, 0 }, /* green */ + { 0, 0, 255 }, /* blue */ + { 238, 130, 238 }, /* violet */ + { 190, 190, 190 }, /* grey */ + { 255, 192, 203 }, /* pink */ }; diff --git a/src/output/charts/plot-chart.h b/src/output/charts/plot-chart.h index 59d385bb..e425987b 100644 --- a/src/output/charts/plot-chart.h +++ b/src/output/charts/plot-chart.h @@ -14,6 +14,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ +#ifndef PLOT_CHART_H +#define PLOT_CHART_H + #include #include #include @@ -25,19 +28,15 @@ #include #include +#include #include #include #include #include -#include "xalloc.h" - -#ifndef PLOT_CHART_H -#define PLOT_CHART_H - #define N_CHART_COLOURS 9 -extern const char *const data_colour[]; +extern const struct chart_colour data_colour[]; enum tick_orientation { diff --git a/src/output/charts/plot-hist.c b/src/output/charts/plot-hist.c index d647dd71..0e52889f 100644 --- a/src/output/charts/plot-hist.c +++ b/src/output/charts/plot-hist.c @@ -96,7 +96,10 @@ hist_draw_bar (plPlotter *lp, const struct chart_geometry *geom, pl_savestate_r (lp); pl_move_r (lp,geom->data_left, geom->data_bottom); - pl_fillcolorname_r (lp, geom->fill_colour); + pl_fillcolor_r (lp, + geom->fill_colour.red * 257, + geom->fill_colour.green * 257, + geom->fill_colour.blue * 257); pl_filltype_r (lp,1); -- 2.30.2