bd5a7a32379b3b029babb89718b53908851f13eb
[pspp-builds.git] / src / output / charts / boxplot.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2004, 2009 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef OUTPUT_CHARTS_BOXPLOT_H
18 #define OUTPUT_CHARTS_BOXPLOT_H 1
19
20 #include <stddef.h>
21 #include <output/chart-item.h>
22
23 /* Box-whiskers plot. */
24 struct boxplot
25   {
26     struct chart_item chart_item;
27
28     /* Data. */
29     struct boxplot_box *boxes;
30     size_t n_boxes, boxes_allocated;
31
32     /* Derived from data and convenient for plotting. */
33     double y_min;               /* Minimum Y coordinate of extremum. */
34     double y_max;               /* Maximum Y coordinate of extremum. */
35   };
36
37 /* One box within a box-whiskers plot. */
38 struct boxplot_box
39   {
40     struct box_whisker *bw;
41     char *label;                /* Variable name or factor label. */
42   };
43
44 struct boxplot *boxplot_create (double y_min, double y_max, const char *title);
45 void boxplot_add_box (struct boxplot *,
46                       struct box_whisker *, const char *label);
47 \f
48 /* This boilerplate for boxplot, a subclass of chart_item, was
49    autogenerated by mk-class-boilerplate. */
50
51 #include <assert.h>
52 #include <libpspp/cast.h>
53
54 extern const struct chart_item_class boxplot_class;
55
56 /* Returns true if SUPER is a boxplot, otherwise false. */
57 static inline bool
58 is_boxplot (const struct chart_item *super)
59 {
60   return super->class == &boxplot_class;
61 }
62
63 /* Returns SUPER converted to boxplot.  SUPER must be a boxplot, as
64    reported by is_boxplot. */
65 static inline struct boxplot *
66 to_boxplot (const struct chart_item *super)
67 {
68   assert (is_boxplot (super));
69   return UP_CAST (super, struct boxplot, chart_item);
70 }
71
72 /* Returns INSTANCE converted to chart_item. */
73 static inline struct chart_item *
74 boxplot_super (const struct boxplot *instance)
75 {
76   return CONST_CAST (struct chart_item *, &instance->chart_item);
77 }
78
79 /* Increments INSTANCE's reference count and returns INSTANCE. */
80 static inline struct boxplot *
81 boxplot_ref (const struct boxplot *instance)
82 {
83   return to_boxplot (chart_item_ref (&instance->chart_item));
84 }
85
86 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
87    the reference count is now zero. */
88 static inline void
89 boxplot_unref (struct boxplot *instance)
90 {
91   chart_item_unref (&instance->chart_item);
92 }
93
94 /* Returns true if INSTANCE's reference count is greater than 1,
95    false otherwise. */
96 static inline bool
97 boxplot_is_shared (const struct boxplot *instance)
98 {
99   return chart_item_is_shared (&instance->chart_item);
100 }
101
102 static inline void
103 boxplot_submit (struct boxplot *instance)
104 {
105   chart_item_submit (&instance->chart_item);
106 }
107 \f
108 #endif /* output/charts/boxplot.h */