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"
32 spreadlevel_plot_create (const char *label, double tx_pwr)
34 struct spreadlevel_plot_chart *sl = xzalloc (sizeof *sl);
35 chart_item_init (&sl->chart_item, &spreadlevel_plot_chart_class, label);
37 sl->x_lower = DBL_MAX;
38 sl->x_upper = -DBL_MAX;
40 sl->y_lower = DBL_MAX;
41 sl->y_upper = -DBL_MAX;
48 return &sl->chart_item;
52 spreadlevel_plot_add (struct chart_item *ci, double spread, double level)
54 struct spreadlevel_plot_chart *sl = to_spreadlevel_plot_chart (ci);
58 spread = log (spread);
63 spread = pow (spread, sl->tx_pwr);
64 level = pow (level, sl->tx_pwr);
67 sl->x_lower = MIN (sl->x_lower, level);
68 sl->x_upper = MAX (sl->x_upper, level);
70 sl->y_lower = MIN (sl->y_lower, spread);
71 sl->y_upper = MAX (sl->y_upper, spread);
74 sl->data = xrealloc (sl->data, sizeof (*sl->data) * sl->n_data);
75 sl->data[sl->n_data - 1].x = level;
76 sl->data[sl->n_data - 1].y = spread;
81 spreadlevel_plot_chart_destroy (struct chart_item *chart_item)
83 struct spreadlevel_plot_chart *sl = to_spreadlevel_plot_chart (chart_item);
89 const struct chart_item_class spreadlevel_plot_chart_class =
91 spreadlevel_plot_chart_destroy