X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fcharts%2Fscatterplot-cairo.c;h=a6a499b868c2144dce9145ca46958970858b1b32;hb=b531990f665ed1ad4c0c46d7de174f9aaff5a697;hp=2c01429c4e9d74529c3243f45179290a9ab756f9;hpb=a24846d816e431b579bd5dfc3a80e234da24199c;p=pspp diff --git a/src/output/charts/scatterplot-cairo.c b/src/output/charts/scatterplot-cairo.c index 2c01429c4e..a6a499b868 100644 --- a/src/output/charts/scatterplot-cairo.c +++ b/src/output/charts/scatterplot-cairo.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2014 Free Software Foundation, Inc. + Copyright (C) 2014, 2015 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,12 +28,13 @@ #include "gettext.h" #define _(msgid) gettext (msgid) +static const struct xrchart_colour black = {0,0,0}; void -xrchart_draw_scatterplot (const struct chart_item *chart_item, cairo_t *cr, +xrchart_draw_scatterplot (const struct chart *chart, cairo_t *cr, struct xrchart_geometry *geom) { - const struct scatterplot_chart *spc = to_scatterplot_chart (chart_item); + const struct scatterplot_chart *spc = to_scatterplot_chart (chart); struct casereader *data; struct ccase *c; /* While reading the cases, a list with categories of the byvar is build */ @@ -45,15 +46,17 @@ xrchart_draw_scatterplot (const struct chart_item *chart_item, cairo_t *cr, int byvar_width = 0; int i = 0; const struct xrchart_colour *colour; - + if (spc->byvar) byvar_width = var_get_width (spc->byvar); - xrchart_write_xscale (cr, geom, spc->x_min, spc->x_max); - xrchart_write_yscale (cr, geom, spc->y_min, spc->y_max); - xrchart_write_title (cr, geom, _("Scatterplot %s"), chart_item->title); - xrchart_write_xlabel (cr, geom, var_to_string(spc->xvar)); - xrchart_write_ylabel (cr, geom, var_to_string(spc->yvar)); + if (! xrchart_write_xscale (cr, geom, spc->x_min, spc->x_max)) + return; + if (! xrchart_write_yscale (cr, geom, spc->y_min, spc->y_max)) + return; + xrchart_write_title (cr, geom, _("Scatterplot %s"), chart->title); + xrchart_write_xlabel (cr, geom, spc->xlabel); + xrchart_write_ylabel (cr, geom, spc->ylabel); cairo_save (cr); data = casereader_clone (spc->data); @@ -61,7 +64,7 @@ xrchart_draw_scatterplot (const struct chart_item *chart_item, cairo_t *cr, { if (spc->byvar) { - const union value *val = case_data (c,spc->byvar); + const union value *val = case_data_idx (c,SP_IDX_BY); for(i=0;ibyvar,val,MV_ANY)) + if (var_is_value_missing (spc->byvar,val)) ds_put_cstr (&label,"missing"); else var_append_value_name (spc->byvar,val,&label); @@ -87,16 +90,19 @@ xrchart_draw_scatterplot (const struct chart_item *chart_item, cairo_t *cr, i--; } } + colour = &data_colour[i % XRCHART_N_COLOURS]; } - colour = &data_colour[i % XRCHART_N_COLOURS]; + else + colour = &black; + cairo_set_source_rgb (cr, colour->red / 255.0, colour->green / 255.0, colour->blue / 255.0); - + xrchart_datum (cr, geom, 0, - case_data (c, spc->xvar)->f, - case_data (c, spc->yvar)->f); + case_num_idx (c, SP_IDX_X), + case_num_idx (c, SP_IDX_Y)); } casereader_destroy (data); cairo_restore (cr);