Add GRAPH command initially with just scatterplots and histograms.
[pspp] / src / output / charts / scatterplot.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2014 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_SCATTERPLOT_H
18 #define OUTPUT_CHARTS_SCATTERPLOT_H 1
19
20 #include "output/chart-item.h"
21
22 /* A  scatterplot. */
23 struct scatterplot_chart
24   {
25     struct chart_item chart_item;
26     struct casereader *data;
27     const struct variable *xvar, *yvar, *byvar;
28
29     double y_min, y_max;
30     double x_min, x_max;
31     /* If the number of distinct values of byvar */
32     /* exceeds a certain limit, the warning flag */
33     /* is activated after the chart is drawn     */
34     bool *byvar_overflow;
35   };
36
37 struct scatterplot_chart *
38 scatterplot_create (const struct casereader *, 
39                     const struct variable *, 
40                     const struct variable *,
41                     const struct variable *,
42                     bool *,
43                     const char *label,
44                     double xmin, double xmax, double ymin, double ymax);
45 \f
46 /* This boilerplate for scatterplot_chart, a subclass of chart_item, was
47    autogenerated by mk-class-boilerplate. */
48
49 #include <assert.h>
50 #include "libpspp/cast.h"
51
52 extern const struct chart_item_class scatterplot_chart_class;
53
54 /* Returns true if SUPER is a scatterplot_chart, otherwise false. */
55 static inline bool
56 is_scatterplot_chart (const struct chart_item *super)
57 {
58   return super->class == &scatterplot_chart_class;
59 }
60
61 /* Returns SUPER converted to scatterplot_chart.  SUPER must be a scatterplot_chart, as
62    reported by is_scatterplot_chart. */
63 static inline struct scatterplot_chart *
64 to_scatterplot_chart (const struct chart_item *super)
65 {
66   assert (is_scatterplot_chart (super));
67   return UP_CAST (super, struct scatterplot_chart, chart_item);
68 }
69
70 /* Returns INSTANCE converted to chart_item. */
71 static inline struct chart_item *
72 scatterplot_chart_super (const struct scatterplot_chart *instance)
73 {
74   return CONST_CAST (struct chart_item *, &instance->chart_item);
75 }
76
77 /* Increments INSTANCE's reference count and returns INSTANCE. */
78 static inline struct scatterplot_chart *
79 scatterplot_chart_ref (const struct scatterplot_chart *instance)
80 {
81   return to_scatterplot_chart (chart_item_ref (&instance->chart_item));
82 }
83
84 /* Decrements INSTANCE's reference count, then destroys INSTANCE if
85    the reference count is now zero. */
86 static inline void
87 scatterplot_chart_unref (struct scatterplot_chart *instance)
88 {
89   chart_item_unref (&instance->chart_item);
90 }
91
92 /* Returns true if INSTANCE's reference count is greater than 1,
93    false otherwise. */
94 static inline bool
95 scatterplot_chart_is_shared (const struct scatterplot_chart *instance)
96 {
97   return chart_item_is_shared (&instance->chart_item);
98 }
99
100 static inline void
101 scatterplot_chart_submit (struct scatterplot_chart *instance)
102 {
103   chart_item_submit (&instance->chart_item);
104 }
105 \f
106 #endif /* output/charts/scatterplot.h */