Add GRAPH command initially with just scatterplots and histograms.
[pspp] / src / output / charts / scatterplot.c
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 #include <config.h>
18
19 #include "output/charts/scatterplot.h"
20
21 #include <gsl/gsl_cdf.h>
22
23 #include "data/casereader.h"
24 #include "libpspp/cast.h"
25 #include "output/chart-item-provider.h"
26
27 #include "gl/minmax.h"
28
29
30 /* Creates a scatterplot 
31
32    The caller retains ownership of READER. */
33 struct scatterplot_chart *
34 scatterplot_create (const struct casereader *reader, 
35                     const struct variable *xvar, 
36                     const struct variable *yvar,
37                     const struct variable *byvar,
38                     bool *byvar_overflow,
39                     const char *label,
40                     double xmin, double xmax, double ymin, double ymax)
41 {
42   struct scatterplot_chart *spc;
43
44   spc = xzalloc (sizeof *spc);
45   chart_item_init (&spc->chart_item, &scatterplot_chart_class, label);
46   spc->data = casereader_clone (reader);
47
48   spc->y_min = ymin;
49   spc->y_max = ymax;
50
51   spc->x_min = xmin;
52   spc->x_max = xmax;
53
54   spc->xvar = xvar;
55   spc->yvar = yvar;
56   spc->byvar = byvar;
57   spc->byvar_overflow = byvar_overflow;
58
59   return spc;
60 }
61
62 static void
63 scatterplot_chart_destroy (struct chart_item *chart_item)
64 {
65   struct scatterplot_chart *spc = to_scatterplot_chart (chart_item);
66   casereader_destroy (spc->data);
67   free (spc);
68 }
69
70 const struct chart_item_class scatterplot_chart_class =
71   {
72     scatterplot_chart_destroy
73   };