9c9c42a71ebf0fd06b22e3a451e4befc9e78ddaa
[pspp] / src / output / charts / scatterplot.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2014, 2015 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 "data/variable.h"
25 #include "libpspp/cast.h"
26 #include "output/chart-provider.h"
27
28 #include "gl/minmax.h"
29
30 /* Creates a scatterplot */
31 struct scatterplot_chart *
32 scatterplot_create (struct casereader *reader,
33                     const char *xlabel,
34                     const char *ylabel,
35                     const struct variable *byvar,
36                     bool *byvar_overflow,
37                     const char *label,
38                     double xmin, double xmax, double ymin, double ymax)
39 {
40   struct scatterplot_chart *spc;
41
42   spc = xzalloc (sizeof *spc);
43   chart_init (&spc->chart, &scatterplot_chart_class, label);
44   spc->data = reader;
45
46   spc->y_min = ymin;
47   spc->y_max = ymax;
48
49   spc->x_min = xmin;
50   spc->x_max = xmax;
51
52   spc->xlabel = xstrdup (xlabel);
53   spc->ylabel = xstrdup (ylabel);
54   spc->byvar = byvar != NULL ? var_clone (byvar) : NULL;
55
56   spc->byvar_overflow = byvar_overflow;
57
58   return spc;
59 }
60
61 static void
62 scatterplot_chart_destroy (struct chart *chart)
63 {
64   struct scatterplot_chart *spc = to_scatterplot_chart (chart);
65   casereader_destroy (spc->data);
66   free (spc->xlabel);
67   free (spc->ylabel);
68   if (spc->byvar)
69     var_unref (spc->byvar);
70   free (spc);
71 }
72
73 const struct chart_class scatterplot_chart_class =
74   {
75     scatterplot_chart_destroy
76   };