X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Foutput%2Fcharts%2Fbarchart.h;h=df27304c568149930637eb2cfa80b62c97c73688;hb=9aae6dac247693f23282f52c0968444e8f5f363c;hp=4a6e3b725c62334a6a06d314d91271ff94a63fcf;hpb=a19b858e0ac3c69e4a28c0ca6d8674427268a863;p=pspp diff --git a/src/output/charts/barchart.h b/src/output/charts/barchart.h index 4a6e3b725c..df27304c56 100644 --- a/src/output/charts/barchart.h +++ b/src/output/charts/barchart.h @@ -1,34 +1,146 @@ -/* PSPP - computes sample statistics. - Copyright (C) 2004 Free Software Foundation, Inc. - Written by John Darrington +/* PSPP - a program for statistical analysis. + Copyright (C) 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 the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. + 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 + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. - This program is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. */ + along with this program. If not, see . */ #ifndef BARCHART_H #define BARCHART_H -#include +#include "libpspp/str.h" +#include "libpspp/hmap.h" +#include "data/value.h" +#include "output/chart.h" -enum bar_opts { - BAR_GROUPED = 0, - BAR_STACKED, - BAR_RANGE + +struct category +{ + struct hmap_node node; + int idx; /* Unique zero based index */ + struct string label; /* The label to be displayed for this category */ + union value val; /* The value of this category */ + int width; /* The width of VAL */ }; -void draw_barchart(struct chart *ch, const char *title, - const char *xlabel, const char *ylabel, enum bar_opts opt); -#endif +struct barchart + { + struct chart chart; + + /* Should the chart be displayed as percentages */ + bool percent; + + /* The categories */ + struct freq **cats; + + /* The total number of categories (regardless of level) */ + int n_nzcats; + + /* The number of primary categories */ + int n_pcats; + + /* The largest count of all the categories */ + double largest; + + /* The sum of all the counts */ + double total_count; + + /* The label for the ordinate (vertical axis) */ + char *ylabel; + + /* The variables holding the categorical values */ + const struct variable **var; + int n_vars; + + int widths[2]; + + /* A hash table of struct category indexed by VAL */ + struct hmap primaries; + + /* A hash table of struct category indexed by VAL */ + struct hmap secondaries; + + /* A array of pointers to the members of the above hmap, + (the secondaries) sorted by VAL */ + struct category **ss; + }; + + +struct variable; +struct freq; + +struct chart *barchart_create (const struct variable **, int n_vars, + const char *ylabel, bool percent, + struct freq *const *, int n_cats); + +/* This boilerplate for barchart, a subclass of chart, was + autogenerated by mk-class-boilerplate. */ + +#include +#include "libpspp/cast.h" + +extern const struct chart_class barchart_class; + +/* Returns true if SUPER is a barchart, otherwise false. */ +static inline bool +is_barchart (const struct chart *super) +{ + return super->class == &barchart_class; +} + +/* Returns SUPER converted to barchart. SUPER must be a barchart, as + reported by is_barchart. */ +static inline struct barchart * +to_barchart (const struct chart *super) +{ + assert (is_barchart (super)); + return UP_CAST (super, struct barchart, chart); +} + +/* Returns INSTANCE converted to chart. */ +static inline struct chart * +barchart_super (const struct barchart *instance) +{ + return CONST_CAST (struct chart *, &instance->chart); +} + +/* Increments INSTANCE's reference count and returns INSTANCE. */ +static inline struct barchart * +barchart_ref (const struct barchart *instance) +{ + return to_barchart (chart_ref (&instance->chart)); +} + +/* Decrements INSTANCE's reference count, then destroys INSTANCE if + the reference count is now zero. */ +static inline void +barchart_unref (struct barchart *instance) +{ + chart_unref (&instance->chart); +} + +/* Returns true if INSTANCE's reference count is greater than 1, + false otherwise. */ +static inline bool +barchart_is_shared (const struct barchart *instance) +{ + return chart_is_shared (&instance->chart); +} + +static inline void +barchart_submit (struct barchart *instance) +{ + chart_submit (&instance->chart); +} + +#endif /* output/charts/barchart.h */