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/alloc.h>
33 #include <libpspp/str.h>
34 #include <output/manager.h>
35 #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);
55 d->class->initialise_chart(d, chart);
62 if (pl_openpl_r (chart->lp) < 0) /* open Plotter */
65 pl_fspace_r (chart->lp, 0.0, 0.0, 1000.0, 1000.0); /* set coordinate system */
66 pl_flinewidth_r (chart->lp, 0.25); /* set line thickness */
67 pl_pencolorname_r (chart->lp, "black");
69 pl_erase_r (chart->lp); /* erase graphics display */
70 pl_filltype_r(chart->lp,0);
72 pl_savestate_r(chart->lp);
74 /* Set default chartetry */
75 chart->data_top = 900;
76 chart->data_right = 800;
77 chart->data_bottom = 120;
78 chart->data_left = 150;
79 chart->abscissa_top = 70;
80 chart->ordinate_right = 120;
81 chart->title_bottom = 920;
82 chart->legend_left = 810;
83 chart->legend_right = 1000;
85 strcpy(chart->fill_colour,"red");
87 /* Get default font size */
88 if ( !chart->font_size)
89 chart->font_size = pl_fontsize_r(chart->lp, -1);
91 /* Draw the data area */
93 chart->data_left, chart->data_bottom,
94 chart->data_right, chart->data_top);
100 chart_submit(struct chart *chart)
103 struct outp_driver *d;
108 pl_restorestate_r(chart->lp);
110 s.class = &tab_table_class;
115 if (pl_closepl_r (chart->lp) < 0) /* close Plotter */
117 fprintf (stderr, "Couldn't close Plotter\n");
120 pl_deletepl_r(chart->lp);
122 pl_deleteplparams(chart->pl_params);
124 d = outp_drivers (NULL);
125 d->class->finalise_chart(d, chart);
130 chart_init_separate (struct chart *ch, const char *type,
131 const char *file_name_tmpl, int number)
136 number_pos = strchr (file_name_tmpl, '#') - file_name_tmpl;
137 ch->file_name = xasprintf ("%.*s%d%s",
138 number_pos, file_name_tmpl,
140 file_name_tmpl + number_pos + 1);
141 fp = fopen (ch->file_name, "wb");
144 error (0, errno, _("creating \"%s\""), ch->file_name);
145 free (ch->file_name);
146 ch->file_name = NULL;
150 ch->pl_params = pl_newplparams ();
151 ch->lp = pl_newpl_r (type, 0, fp, stderr, ch->pl_params);
155 chart_finalise_separate (struct chart *ch)
157 free (ch->file_name);