X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fplot-hist.c;h=fd1a88d8a69cfbb325723522707eaf8471ff565c;hb=92fb12eb06716d14c05b781f5d9dcde956d77c30;hp=ad86769325a3fbfbf63a5dc87c847a1bbe966d3e;hpb=4fdeb2145d081ff1b84e3f6c99f9d1c048c0d64a;p=pspp diff --git a/src/plot-hist.c b/src/plot-hist.c index ad86769325..fd1a88d8a6 100644 --- a/src/plot-hist.c +++ b/src/plot-hist.c @@ -28,19 +28,20 @@ #include #include #include - #include "hash.h" - #include "var.h" #include "chart.h" +#include "gettext.h" +#define _(msgid) gettext (msgid) + /* Write the legend of the chart */ void histogram_write_legend(struct chart *ch, const struct normal_curve *norm) { char buf[100]; if ( !ch ) - return ; + return ; pl_savestate_r(ch->lp); @@ -65,43 +66,46 @@ static void hist_draw_bar(struct chart *ch, const gsl_histogram *hist, int bar); static void hist_draw_bar(struct chart *ch, const gsl_histogram *hist, int bar) { - double upper; - double lower; - double height; - if ( !ch ) - return ; - const size_t bins = gsl_histogram_bins(hist); - const double x_pos = (ch->data_right - ch->data_left) * bar / (double) bins ; - const double width = (ch->data_right - ch->data_left) / (double) bins ; + return ; - assert ( 0 == gsl_histogram_get_range(hist, bar, &lower, &upper)); + { + double upper; + double lower; + double height; - assert( upper >= lower); + const size_t bins = gsl_histogram_bins(hist); + const double x_pos = (ch->data_right - ch->data_left) * bar / (double) bins ; + const double width = (ch->data_right - ch->data_left) / (double) bins ; - height = gsl_histogram_get(hist, bar) * - (ch->data_top - ch->data_bottom) / gsl_histogram_max_val(hist); - pl_savestate_r(ch->lp); - pl_move_r(ch->lp,ch->data_left, ch->data_bottom); - pl_fillcolorname_r(ch->lp, ch->fill_colour); - pl_filltype_r(ch->lp,1); + assert ( 0 == gsl_histogram_get_range(hist, bar, &lower, &upper)); + assert( upper >= lower); - pl_fboxrel_r(ch->lp, - x_pos, 0, - x_pos + width, height); + height = gsl_histogram_get(hist, bar) * + (ch->data_top - ch->data_bottom) / gsl_histogram_max_val(hist); - pl_restorestate_r(ch->lp); + pl_savestate_r(ch->lp); + pl_move_r(ch->lp,ch->data_left, ch->data_bottom); + pl_fillcolorname_r(ch->lp, ch->fill_colour); + pl_filltype_r(ch->lp,1); - { - char buf[5]; - snprintf(buf,5,"%g",(upper + lower) / 2.0); - draw_tick(ch, TICK_ABSCISSA, - x_pos + width / 2.0, buf); - } + pl_fboxrel_r(ch->lp, + x_pos, 0, + x_pos + width, height); + + pl_restorestate_r(ch->lp); + + { + char buf[5]; + snprintf(buf,5,"%g",(upper + lower) / 2.0); + draw_tick(ch, TICK_ABSCISSA, + x_pos + width / 2.0, buf); + } + } } @@ -117,14 +121,22 @@ histogram_plot(const gsl_histogram *hist, struct chart *ch; - bins = gsl_histogram_bins(hist); - ch = chart_create(); chart_write_title(ch, _("HISTOGRAM")); chart_write_ylabel(ch, _("Frequency")); chart_write_xlabel(ch, factorname); + if ( ! hist ) /* If this happens, probably all values are SYSMIS */ + { + chart_submit(ch); + return ; + } + else + { + bins = gsl_histogram_bins(hist); + } + chart_write_yscale(ch, 0, gsl_histogram_max_val(hist), 5); for ( i = 0 ; i < bins ; ++i )