1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2004 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>
32 #include <libpspp/str.h>
33 #include <output/manager.h>
34 #include <output/output.h>
40 #define _(msgid) gettext (msgid)
42 extern struct som_table_class tab_table_class;
48 struct outp_driver *d;
50 d = outp_drivers (NULL);
54 chart = xmalloc (sizeof *chart);
56 d->class->initialise_chart(d, chart);
63 if (pl_openpl_r (chart->lp) < 0) /* open Plotter */
66 pl_fspace_r (chart->lp, 0.0, 0.0, 1000.0, 1000.0); /* set coordinate system */
67 pl_flinewidth_r (chart->lp, 0.25); /* set line thickness */
68 pl_pencolorname_r (chart->lp, "black");
70 pl_erase_r (chart->lp); /* erase graphics display */
71 pl_filltype_r(chart->lp,0);
73 pl_savestate_r(chart->lp);
75 /* Set default chartetry */
76 chart->data_top = 900;
77 chart->data_right = 800;
78 chart->data_bottom = 120;
79 chart->data_left = 150;
80 chart->abscissa_top = 70;
81 chart->ordinate_right = 120;
82 chart->title_bottom = 920;
83 chart->legend_left = 810;
84 chart->legend_right = 1000;
86 strcpy(chart->fill_colour,"red");
88 /* Get default font size */
89 if ( !chart->font_size)
90 chart->font_size = pl_fontsize_r(chart->lp, -1);
92 /* Draw the data area */
94 chart->data_left, chart->data_bottom,
95 chart->data_right, chart->data_top);
101 chart_submit(struct chart *chart)
104 struct outp_driver *d;
109 pl_restorestate_r(chart->lp);
111 s.class = &tab_table_class;
116 if (pl_closepl_r (chart->lp) < 0) /* close Plotter */
118 fprintf (stderr, "Couldn't close Plotter\n");
121 pl_deletepl_r(chart->lp);
123 pl_deleteplparams(chart->pl_params);
125 d = outp_drivers (NULL);
126 d->class->finalise_chart(d, chart);
131 chart_init_separate (struct chart *ch, const char *type,
132 const char *file_name_tmpl, int number)
137 number_pos = strchr (file_name_tmpl, '#') - file_name_tmpl;
138 ch->file_name = xasprintf ("%.*s%d%s",
139 number_pos, file_name_tmpl,
141 file_name_tmpl + number_pos + 1);
142 fp = fopen (ch->file_name, "wb");
145 error (0, errno, _("creating \"%s\""), ch->file_name);
146 free (ch->file_name);
147 ch->file_name = NULL;
151 ch->pl_params = pl_newplparams ();
152 ch->lp = pl_newpl_r (type, 0, fp, stderr, ch->pl_params);
156 chart_finalise_separate (struct chart *ch)
158 free (ch->file_name);