From d4fd026f83d552e37ebe303baf60ac5dd65a6fc6 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 1 Jul 2009 15:53:55 -0700 Subject: [PATCH] output: Get rid of histogram_plot_n function. For some reason we have two functions to plot histograms, one of which is marked "deprecated" and the other of which is a trivial wrapper. It's easy, however, to get rid of one of them and make the caller in charge of doing what the wrapper does, especially since the wrapper had only a single caller. That is what this commit does. --- src/language/stats/examine.q | 5 ++- src/language/stats/frequencies.q | 2 +- src/output/charts/dummy-chart.c | 15 +++----- src/output/charts/plot-hist.c | 59 +++++++++++++++++--------------- src/output/charts/plot-hist.h | 23 ++++++------- 5 files changed, 50 insertions(+), 54 deletions(-) diff --git a/src/language/stats/examine.q b/src/language/stats/examine.q index c0facb0b..99ff5c45 100644 --- a/src/language/stats/examine.q +++ b/src/language/stats/examine.q @@ -448,15 +448,18 @@ show_histogram (const struct variable **dependent_var, struct string str; const struct factor_result *result = ll_data (ll, struct factor_result, ll); + double mean, var, n; ds_init_empty (&str); ds_put_format (&str, "%s ", var_get_name (dependent_var[v])); factor_to_string (fctr, result, &str); + moments1_calculate ((struct moments1 *) result->metrics[v].moments, + &n, &mean, &var, NULL, NULL); histogram_plot ((struct histogram *) result->metrics[v].histogram, ds_cstr (&str), - (struct moments1 *) result->metrics[v].moments); + n, mean, sqrt (var), false); ds_destroy (&str); } diff --git a/src/language/stats/frequencies.q b/src/language/stats/frequencies.q index 1fd98a30..e44e8e21 100644 --- a/src/language/stats/frequencies.q +++ b/src/language/stats/frequencies.q @@ -610,7 +610,7 @@ postcalc (const struct dataset *ds) hist = freq_tab_to_hist (ft,v); - histogram_plot_n (hist, var_to_string(v), + histogram_plot (hist, var_to_string(v), vf->tab.valid_cases, d[frq_mean], d[frq_stddev], diff --git a/src/output/charts/dummy-chart.c b/src/output/charts/dummy-chart.c index e22f958f..b859d0e0 100644 --- a/src/output/charts/dummy-chart.c +++ b/src/output/charts/dummy-chart.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2009 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 @@ -80,16 +80,9 @@ chart_datum (struct chart *ch UNUSED, int dataset UNUSED UNUSED, void histogram_plot (const struct histogram *hist UNUSED, - const char *label UNUSED, - const struct moments1 *m UNUSED) -{ -} - -void -histogram_plot_n (const struct histogram *hist UNUSED, - const char *label UNUSED, - double n UNUSED, double mean UNUSED, double stddev UNUSED, - bool show_normal UNUSED) + const char *label UNUSED, + double n UNUSED, double mean UNUSED, double stddev UNUSED, + bool show_normal UNUSED) { } diff --git a/src/output/charts/plot-hist.c b/src/output/charts/plot-hist.c index 4b11618a..abe29088 100644 --- a/src/output/charts/plot-hist.c +++ b/src/output/charts/plot-hist.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2009 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 @@ -40,24 +40,37 @@ static void histogram_write_legend (struct chart *ch, double n, double mean, double stddev) { + double y; char buf[100]; if (!ch) return ; + y = ch->data_bottom; pl_savestate_r (ch->lp); - sprintf (buf, "N = %.2f", n); - pl_move_r (ch->lp, ch->legend_left, ch->data_bottom); - pl_alabel_r (ch->lp, 0, 'b', buf); + if (n != SYSMIS) + { + sprintf (buf, "N = %.2f", n); + pl_move_r (ch->lp, ch->legend_left, y); + pl_alabel_r (ch->lp, 0, 'b', buf); + y += ch->font_size * 1.5; + } - sprintf (buf, "Mean = %.1f", mean); - pl_fmove_r (ch->lp,ch->legend_left,ch->data_bottom + ch->font_size * 1.5); - pl_alabel_r (ch->lp, 0, 'b', buf); + if (mean != SYSMIS) + { + sprintf (buf, "Mean = %.1f", mean); + pl_fmove_r (ch->lp,ch->legend_left, y); + pl_alabel_r (ch->lp, 0, 'b', buf); + y += ch->font_size * 1.5; + } - sprintf (buf, "Std. Dev = %.2f", stddev); - pl_fmove_r (ch->lp, ch->legend_left, ch->data_bottom + ch->font_size * 1.5 * 2); - pl_alabel_r (ch->lp, 0, 'b', buf); + if (stddev != SYSMIS) + { + sprintf (buf, "Std. Dev = %.2f", stddev); + pl_fmove_r (ch->lp, ch->legend_left, y); + pl_alabel_r (ch->lp, 0, 'b', buf); + } pl_restorestate_r (ch->lp); } @@ -110,25 +123,15 @@ hist_draw_bar (struct chart *ch, const struct histogram *hist, int bar) +/* Plots a histogram of the data in HIST with the given LABEL. + Labels the histogram with each of N, MEAN, and STDDEV that is + not SYSMIS. If all three are not SYSMIS and SHOW_NORMAL is + true, also draws a normal curve on the histogram. */ void histogram_plot (const struct histogram *hist, - const char *label, - const struct moments1 *m) -{ - double mean, var, n; - - moments1_calculate (m, &n, &mean, &var, NULL, NULL); - - histogram_plot_n (hist, label, n, mean, sqrt(var), m); -} - - -/* This function is deprecated. Don't use it in new code */ -void -histogram_plot_n (const struct histogram *hist, - const char *label, - double n, double mean, double stddev, - bool show_normal) + const char *label, + double n, double mean, double stddev, + bool show_normal) { int i; int bins; @@ -157,7 +160,7 @@ histogram_plot_n (const struct histogram *hist, histogram_write_legend (ch, n, mean, stddev); - if (show_normal) + if (show_normal && n != SYSMIS && mean != SYSMIS && stddev != SYSMIS) { /* Draw the normal curve */ diff --git a/src/output/charts/plot-hist.h b/src/output/charts/plot-hist.h index 606206d5..74b10bd3 100644 --- a/src/output/charts/plot-hist.h +++ b/src/output/charts/plot-hist.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2004 Free Software Foundation, Inc. + Copyright (C) 2004, 2009 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 @@ -23,17 +23,14 @@ struct chart; struct moments1; struct histogram; -/* Plot M onto histogram HIST and label it with LABEL */ -void histogram_plot (const struct histogram *hist, - const char *label, const struct moments1 *m); - - -/* A wrapper aroud histogram_plot. - Don't use this function. It's legacy only */ -void histogram_plot_n (const struct histogram *hist, - const char *label, - double n, double mean, double var, - bool show_normal); - +/* Plots a histogram of the data in HIST with the given LABEL. + Labels the histogram with each of N, MEAN, and STDDEV that is + not SYSMIS. If all three are not SYSMIS and SHOW_NORMAL is + true, also draws a normal curve on the histogram. */ +void +histogram_plot (const struct histogram *hist, + const char *label, + double n, double mean, double stddev, + bool show_normal); #endif -- 2.30.2