Update all #include directives to the currently preferred style.
[pspp-builds.git] / src / output / charts / boxplot.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2004, 2008, 2009, 2011 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
18 #include <config.h>
19
20 #include "output/charts/boxplot.h"
21
22 #include "math/box-whisker.h"
23 #include "output/chart-item-provider.h"
24
25 struct boxplot *
26 boxplot_create (double y_min, double y_max, const char *title)
27 {
28   struct boxplot *boxplot = xmalloc (sizeof *boxplot);
29   chart_item_init (&boxplot->chart_item, &boxplot_class, title);
30   boxplot->y_min = y_min;
31   boxplot->y_max = y_max;
32   boxplot->boxes = NULL;
33   boxplot->n_boxes = boxplot->boxes_allocated = 0;
34   return boxplot;
35 }
36
37 void
38 boxplot_add_box (struct boxplot *boxplot,
39                  struct box_whisker *bw, const char *label)
40 {
41   struct boxplot_box *box;
42   if (boxplot->n_boxes >= boxplot->boxes_allocated)
43     boxplot->boxes = x2nrealloc (boxplot->boxes, &boxplot->boxes_allocated,
44                                  sizeof *boxplot->boxes);
45   box = &boxplot->boxes[boxplot->n_boxes++];
46   box->bw = bw;
47   box->label = xstrdup (label);
48 }
49
50 static void
51 boxplot_chart_destroy (struct chart_item *chart_item)
52 {
53   struct boxplot *boxplot = to_boxplot (chart_item);
54   size_t i;
55
56   for (i = 0; i < boxplot->n_boxes; i++)
57     {
58       struct boxplot_box *box = &boxplot->boxes[i];
59       struct statistic *statistic = &box->bw->parent.parent;
60       statistic->destroy (statistic);
61       free (box->label);
62     }
63   free (boxplot->boxes);
64   free (boxplot);
65 }
66
67 const struct chart_item_class boxplot_class =
68   {
69     boxplot_chart_destroy
70   };