X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fcharts%2Fpiechart.c;h=ad3b2eafd7926e88dfa56f3ba16362f92ea0d60d;hb=c0b02c779f26fe801dbc83f1650294df03e0522a;hp=aac8bfbf8d03429517987e4c52e4d03f7f4d85cf;hpb=81579d9e9f994fb2908f50af41c3eb033d216e58;p=pspp diff --git a/src/output/charts/piechart.c b/src/output/charts/piechart.c index aac8bfbf8d..ad3b2eafd7 100644 --- a/src/output/charts/piechart.c +++ b/src/output/charts/piechart.c @@ -22,37 +22,54 @@ #include "libpspp/cast.h" #include "libpspp/str.h" -#include "output/chart-item-provider.h" +#include "data/variable.h" +#include "output/chart-provider.h" #include "gl/xalloc.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) +#define N_(msgid) msgid + + /* Creates and returns a chart that will render a piechart with - the given TITLE and the N_SLICES described in SLICES. */ -struct chart_item * -piechart_create (const char *title, const struct slice *slices, int n_slices) + the of VAR and the N_SLICES described in SLICES. */ +struct chart * +piechart_create (const struct variable *var, const struct freq *slices, int n_slices) { struct piechart *pie; int i; pie = xmalloc (sizeof *pie); - chart_item_init (&pie->chart_item, &piechart_class, title); + chart_init (&pie->chart, &piechart_class, var_to_string (var)); pie->slices = xnmalloc (n_slices, sizeof *pie->slices); for (i = 0; i < n_slices; i++) { - const struct slice *src = &slices[i]; + const struct freq *src = &slices[i]; struct slice *dst = &pie->slices[i]; - ds_init_string (&dst->label, &src->label); - dst->magnitude = src->magnitude; + ds_init_empty (&dst->label); + + if (var_is_value_missing (var, &src->values[0])) + ds_assign_cstr (&dst->label, _("*MISSING*")); + else + var_append_value_name (var, &src->values[0], &dst->label); + + /* Chomp any whitespace from the RHS of the label. + Doing this ensures that those labels to the right + of the pie, appear right justified. */ + ds_rtrim (&dst->label, ss_cstr (" \t")); + ds_ltrim (&dst->label, ss_cstr (" \t")); + dst->magnitude = src->count; } pie->n_slices = n_slices; - return &pie->chart_item; + return &pie->chart; } static void -piechart_destroy (struct chart_item *chart_item) +piechart_destroy (struct chart *chart) { - struct piechart *pie = to_piechart (chart_item); + struct piechart *pie = to_piechart (chart); int i; for (i = 0; i < pie->n_slices; i++) @@ -64,7 +81,7 @@ piechart_destroy (struct chart_item *chart_item) free (pie); } -const struct chart_item_class piechart_class = +const struct chart_class piechart_class = { piechart_destroy };