43f5b822482c066bbf7b7364ce301f4fdd3e02a2
[pspp-builds.git] / src / output / charts / scree.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 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_SCREE_H
18 #define OUTPUT_CHARTS_SCREE_H 1
19
20 #include <gsl/gsl_vector.h>
21 #include <output/chart-item.h>
22
23 /* A scree plot. */
24 struct scree
25   {
26     struct chart_item chart_item;
27     gsl_vector *eval;
28     char *xlabel;
29   };
30
31 /* Create a "Scree Plot" of EIGENVALUES with LABEL on the X Axis */
32 struct scree *scree_create (const gsl_vector *eigenvalues, const char *label);
33
34 /* Return the chart underlying SCREE */
35 struct chart *scree_get_chart (struct scree *scree);
36 \f
37 /* This boilerplate for scree, a subclass of chart_item, was
38    autogenerated by mk-class-boilerplate. */
39
40 #include <assert.h>
41 #include <libpspp/cast.h>
42
43 extern const struct chart_item_class scree_class;
44
45 /* Returns true if SUPER is a scree, otherwise false. */
46 static inline bool
47 is_scree (const struct chart_item *super)
48 {
49   return super->class == &scree_class;
50 }
51
52 /* Returns SUPER converted to scree.  SUPER must be a scree, as
53    reported by is_scree. */
54 static inline struct scree *
55 to_scree (const struct chart_item *super)
56 {
57   assert (is_scree (super));
58   return UP_CAST (super, struct scree, chart_item);
59 }
60
61 /* Returns INSTANCE converted to chart_item. */
62 static inline struct chart_item *
63 scree_super (const struct scree *instance)
64 {
65   return CONST_CAST (struct chart_item *, &instance->chart_item);
66 }
67
68 /* Increments INSTANCE's reference count and returns INSTANCE. */
69 static inline struct scree *
70 scree_ref (const struct scree *instance)
71 {
72   return to_scree (chart_item_ref (&instance->chart_item));
73 }
74
75 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
76    the reference count is now zero. */
77 static inline void
78 scree_unref (struct scree *instance)
79 {
80   chart_item_unref (&instance->chart_item);
81 }
82
83 /* Returns true if INSTANCE's reference count is greater than 1,
84    false otherwise. */
85 static inline bool
86 scree_is_shared (const struct scree *instance)
87 {
88   return chart_item_is_shared (&instance->chart_item);
89 }
90
91 static inline void
92 scree_submit (struct scree *instance)
93 {
94   chart_item_submit (&instance->chart_item);
95 }
96 \f
97 #endif /* output/charts/scree.h */