1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004, 2008, 2009 Free Software Foundation, Inc.
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.
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.
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/>. */
20 #include <output/charts/boxplot.h>
22 #include <math/box-whisker.h>
23 #include <output/chart-item-provider.h>
26 boxplot_create (double y_min, double y_max, const char *title)
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;
38 boxplot_add_box (struct boxplot *boxplot,
39 struct box_whisker *bw, const char *label)
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++];
47 box->label = xstrdup (label);
51 boxplot_chart_destroy (struct chart_item *chart_item)
53 struct boxplot *boxplot = to_boxplot (chart_item);
56 for (i = 0; i < boxplot->n_boxes; i++)
58 struct boxplot_box *box = &boxplot->boxes[i];
59 struct statistic *statistic = &box->bw->parent.parent;
60 statistic->destroy (statistic);
63 free (boxplot->boxes);
67 const struct chart_item_class boxplot_class =