1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004, 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/>. */
19 #include <output/chart.h>
20 #include <output/chart-provider.h>
31 #include <libpspp/str.h>
32 #include <output/manager.h>
33 #include <output/output.h>
39 #define _(msgid) gettext (msgid)
41 extern struct som_table_class tab_table_class;
44 chart_init (struct chart *chart, const struct chart_class *class)
51 chart_geometry_init (plPlotter *lp, struct chart_geometry *geom)
53 /* Start output page. */
56 /* Set coordinate system. */
57 pl_fspace_r (lp, 0.0, 0.0, 1000.0, 1000.0);
59 /* Set line thickness. */
60 pl_flinewidth_r (lp, 0.25);
61 pl_pencolorname_r (lp, "black");
63 /* Erase graphics display. */
66 pl_filltype_r (lp, 0);
69 /* Set default chartetry. */
71 geom->data_right = 800;
72 geom->data_bottom = 120;
73 geom->data_left = 150;
74 geom->abscissa_top = 70;
75 geom->ordinate_right = 120;
76 geom->title_bottom = 920;
77 geom->legend_left = 810;
78 geom->legend_right = 1000;
80 strcpy (geom->fill_colour, "red");
82 /* Get default font size */
84 geom->font_size = pl_fontsize_r (lp, -1);
86 /* Draw the data area */
88 geom->data_left, geom->data_bottom,
89 geom->data_right, geom->data_top);
93 chart_geometry_free (plPlotter *lp)
95 if (pl_closepl_r (lp) < 0)
96 fprintf (stderr, "Couldn't close Plotter\n");
100 chart_draw (const struct chart *chart, plPlotter *lp)
102 chart->class->draw (chart, lp);
106 chart_ref (const struct chart *chart_)
108 struct chart *chart = (struct chart *) chart_;
114 chart_unref (struct chart *chart)
118 assert (chart->ref_cnt > 0);
119 if (--chart->ref_cnt == 0)
120 chart->class->destroy (chart);
125 chart_submit (struct chart *chart)
128 struct outp_driver *d;
130 for (d = outp_drivers (NULL); d; d = outp_drivers (d))
131 if (d->class->output_chart != NULL)
132 d->class->output_chart (d, chart);
139 chart_create_file (const char *type, const char *file_name_tmpl, int number,
140 plPlotterParams *params, char **file_namep, plPlotter **lpp)
142 char *file_name = NULL;
147 number_pos = strchr (file_name_tmpl, '#') - file_name_tmpl;
148 file_name = xasprintf ("%.*s%d%s", number_pos, file_name_tmpl,
149 number, file_name_tmpl + number_pos + 1);
151 fp = fopen (file_name, "wb");
154 error (0, errno, _("creating \"%s\""), file_name);
159 lp = pl_newpl_r (type, 0, fp, stderr, params);
162 params = pl_newplparams ();
163 lp = pl_newpl_r (type, 0, fp, stderr, params);
164 pl_deleteplparams (params);
169 *file_namep = file_name;
177 if (file_name != NULL)