1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004, 2008, 2009, 2011 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)
30 struct boxplot *boxplot = xmalloc (sizeof *boxplot);
31 chart_item_init (&boxplot->chart_item, &boxplot_class, title);
32 boxplot->y_min = y_min;
33 boxplot->y_max = y_max;
34 boxplot->boxes = NULL;
35 boxplot->n_boxes = boxplot->boxes_allocated = 0;
40 boxplot_add_box (struct boxplot *boxplot,
41 struct box_whisker *bw, const char *label)
45 struct statistic *statistic = &bw->parent.parent;
46 statistic->destroy (statistic);
50 struct boxplot_box *box;
51 if (boxplot->n_boxes >= boxplot->boxes_allocated)
52 boxplot->boxes = x2nrealloc (boxplot->boxes, &boxplot->boxes_allocated,
53 sizeof *boxplot->boxes);
54 box = &boxplot->boxes[boxplot->n_boxes++];
56 box->label = xstrdup (label);
60 boxplot_chart_destroy (struct chart_item *chart_item)
62 struct boxplot *boxplot = to_boxplot (chart_item);
68 for (i = 0; i < boxplot->n_boxes; i++)
70 struct boxplot_box *box = &boxplot->boxes[i];
71 struct statistic *statistic = &box->bw->parent.parent;
72 statistic->destroy (statistic);
75 free (boxplot->boxes);
79 const struct chart_item_class boxplot_class =