Change license from GPLv2+ to GPLv3+.
[pspp-builds.git] / src / output / chart.c
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2004 Free Software Foundation, Inc.
3
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.
8
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.
13
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/>. */
16
17 #include <config.h>
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <plot.h>
21 #include <stdarg.h>
22 #include <string.h>
23 #include <float.h>
24 #include <assert.h>
25 #include <math.h>
26
27 #include "chart.h"
28 #include <libpspp/str.h>
29 #include <libpspp/alloc.h>
30 #include "manager.h"
31 #include "output.h"
32
33 extern struct som_table_class tab_table_class;
34
35 struct chart *
36 chart_create(void)
37 {
38   struct chart *chart;
39   struct outp_driver *d;
40
41   d = outp_drivers (NULL);
42   if (d == NULL)
43     return NULL;
44
45   chart = xmalloc (sizeof *chart);
46   d->class->initialise_chart(d, chart);
47   if (!chart->lp)
48     {
49       free (chart);
50       return NULL;
51     }
52
53   if (pl_openpl_r (chart->lp) < 0)      /* open Plotter */
54     return NULL;
55
56   pl_fspace_r (chart->lp, 0.0, 0.0, 1000.0, 1000.0); /* set coordinate system */
57   pl_flinewidth_r (chart->lp, 0.25);    /* set line thickness */
58   pl_pencolorname_r (chart->lp, "black");
59
60   pl_erase_r (chart->lp);               /* erase graphics display */
61   pl_filltype_r(chart->lp,0);
62
63   pl_savestate_r(chart->lp);
64
65   /* Set default chartetry */
66   chart->data_top =   900;
67   chart->data_right = 800;
68   chart->data_bottom = 120;
69   chart->data_left = 150;
70   chart->abscissa_top = 70;
71   chart->ordinate_right = 120;
72   chart->title_bottom = 920;
73   chart->legend_left = 810;
74   chart->legend_right = 1000;
75   chart->font_size = 0;
76   strcpy(chart->fill_colour,"red");
77
78   /* Get default font size */
79   if ( !chart->font_size)
80     chart->font_size = pl_fontsize_r(chart->lp, -1);
81
82   /* Draw the data area */
83   pl_box_r(chart->lp,
84            chart->data_left, chart->data_bottom,
85            chart->data_right, chart->data_top);
86
87   return chart;
88 }
89
90 void
91 chart_submit(struct chart *chart)
92 {
93   struct som_entity s;
94   struct outp_driver *d;
95
96   if ( ! chart )
97      return ;
98
99   pl_restorestate_r(chart->lp);
100
101   s.class = &tab_table_class;
102   s.ext = chart;
103   s.type = SOM_CHART;
104   som_submit (&s);
105
106   if (pl_closepl_r (chart->lp) < 0)     /* close Plotter */
107     {
108       fprintf (stderr, "Couldn't close Plotter\n");
109     }
110
111   pl_deletepl_r(chart->lp);
112
113   pl_deleteplparams(chart->pl_params);
114
115   d = outp_drivers (NULL);
116   d->class->finalise_chart(d, chart);
117   free(chart);
118 }
119