1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2012 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/>. */
19 #include "output/charts/spreadlevel-plot.h"
21 #include "libpspp/cast.h"
22 #include "output/chart-item-provider.h"
24 #include "gl/xalloc.h"
25 #include "gl/minmax.h"
31 spreadlevel_plot_create (const char *label, double tx_pwr)
33 struct spreadlevel_plot_chart *sl = xzalloc (sizeof *sl);
34 chart_item_init (&sl->chart_item, &spreadlevel_plot_chart_class, label);
36 sl->x_lower = DBL_MAX;
37 sl->x_upper = -DBL_MAX;
39 sl->y_lower = DBL_MAX;
40 sl->y_upper = -DBL_MAX;
47 return &sl->chart_item;
51 spreadlevel_plot_add (struct chart_item *ci, double spread, double level)
53 struct spreadlevel_plot_chart *sl = to_spreadlevel_plot_chart (ci);
57 spread = log (spread);
62 spread = pow (spread, sl->tx_pwr);
63 level = pow (level, sl->tx_pwr);
66 sl->x_lower = MIN (sl->x_lower, level);
67 sl->x_upper = MAX (sl->x_upper, level);
69 sl->y_lower = MIN (sl->y_lower, spread);
70 sl->y_upper = MAX (sl->y_upper, spread);
73 sl->data = xrealloc (sl->data, sizeof (*sl->data) * sl->n_data);
74 sl->data[sl->n_data - 1].x = level;
75 sl->data[sl->n_data - 1].y = spread;
80 spreadlevel_plot_chart_destroy (struct chart_item *chart_item)
82 struct spreadlevel_plot_chart *sl = to_spreadlevel_plot_chart (chart_item);
88 const struct chart_item_class spreadlevel_plot_chart_class =
90 spreadlevel_plot_chart_destroy