1 /*
2  * Grace - GRaphing, Advanced Computation and Exploration of data
3  *
4  * Home page: http://plasma-gate.weizmann.ac.il/Grace/
5  *
6  * Copyright (c) 1991-1995 Paul J Turner, Portland, OR
7  * Copyright (c) 1996-2001 Grace Development Team
8  *
9  * Maintained by Evgeny Stambulchik
10  *
11  *
12  *                           All Rights Reserved
13  *
14  *    This program is free software; you can redistribute it and/or modify
15  *    it under the terms of the GNU General Public License as published by
16  *    the Free Software Foundation; either version 2 of the License, or
17  *    (at your option) any later version.
18  *
19  *    This program is distributed in the hope that it will be useful,
20  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *    GNU General Public License for more details.
23  *
24  *    You should have received a copy of the GNU General Public License
25  *    along with this program; if not, write to the Free Software
26  *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27  */
28 
29 #ifndef __GRAPHS_H_
30 #define __GRAPHS_H_
31 
32 #include "defines.h"
33 
34 /* Graph type */
35 typedef enum {
36     GRAPH_XY   ,
37     GRAPH_CHART,
38     GRAPH_POLAR,
39     GRAPH_SMITH,
40     GRAPH_FIXED,
41     GRAPH_PIE
42 } GraphType;
43 
44 /* Set types */
45 typedef enum {
46     SET_XY        ,
47     SET_XYDX      ,
48     SET_XYDY      ,
49     SET_XYDXDX    ,
50     SET_XYDYDY    ,
51     SET_XYDXDY    ,
52     SET_XYDXDXDYDY,
53     SET_BAR       ,
54     SET_BARDY     ,
55     SET_BARDYDY   ,
56     SET_XYHILO    ,
57     SET_XYZ       ,
58     SET_XYR       ,
59     SET_XYSIZE    ,
60     SET_XYCOLOR   ,
61     SET_XYCOLPAT  ,
62     SET_XYVMAP    ,
63     SET_BOXPLOT   ,
64     SET_BAD
65 } SetType;
66 #define NUMBER_OF_SETTYPES  SET_BAD
67 
68 /* Data column names; */
69 typedef enum {
70     DATA_X ,
71     DATA_Y ,
72     DATA_Y1,
73     DATA_Y2,
74     DATA_Y3,
75     DATA_Y4,
76     DATA_BAD
77 } DataColumn;
78 #define MAX_SET_COLS    DATA_BAD
79 
80 
81 /* target graph & set*/
82 typedef struct {
83     int gno;    /* graph # */
84     int setno;  /* set # */
85 } target;
86 
87 typedef struct {
88     int len;                    /* dataset length */
89     double *ex[MAX_SET_COLS];   /* arrays of x, y, z, ... depending on type */
90     char **s;                   /* pointer to strings */
91 } Dataset;
92 
93 typedef struct {
94     double ex[MAX_SET_COLS];   /* x, y, dx, z, ... depending on dataset type */
95     char *s;                   /* string */
96 } Datapoint;
97 
98 typedef struct {
99     Dataset data;               /* dataset */
100 
101     int hidden;                 /* hidden set */
102 
103     int type;                   /* dataset type */
104 
105     char comments[MAX_STRING_LENGTH];   /* how did this set originate */
106 
107     int hotlink;                /* hot linked set */
108     int hotsrc;                 /* source for hot linked file (DISK|PIPE) */
109     char hotfile[GR_MAXPATHLEN];   /* hot linked filename */
110 
111     int sym;                    /* set plot symbol type */
112     double symsize;             /* size of symbols */
113     Pen sympen;                 /* pen props of symbol line */
114     Pen symfillpen;             /* pen props of symbol filling */
115     int symlines;               /* symbol linestyle */
116     double symlinew;            /* symbol linewidth */
117     int symskip;                /* number of symbols to skip */
118     unsigned char symchar;      /* char used if sym == SYM_CHAR */
119     int charfont;               /* font for symchar if sym == SYM_CHAR */
120 
121     int linet;                  /* set line type */
122     int lines;                  /* set line style */
123     double linew;               /* line width */
124     Pen linepen;                /* pen for connecting line */
125 
126     int baseline_type;          /* type of baseline */
127     int baseline;               /* should the baseline be drawn */
128     int dropline;               /* should the drop lines (from data points to
129                                                       the baseline) be drawn */
130 
131     int filltype;               /* fill type */
132     int fillrule;               /* fill rule (winding/even-odd) */
133     Pen setfillpen;             /* pen props for set fill */
134 
135     char lstr[MAX_STRING_LENGTH];       /* legend for this set */
136 
137     AValue avalue;              /* Parameters for annotative string */
138     Errbar errbar;              /* error bar properties */
139 } plotarr;
140 
141 /* Locator props */
142 typedef struct {
143     int pointset;               /* if (dsx, dsy) have been set */
144     int pt_type;                /* type of locator display */
145     double dsx, dsy;            /* locator fixed point */
146     int fx, fy;                 /* locator format type */
147     int px, py;                 /* locator precision */
148 } GLocator;
149 
150 /*
151  * a graph
152  */
153 typedef struct {
154     int hidden;                 /* display or not */
155 
156     int type;                   /* type of graph */
157 
158     int maxplot;                /* number of sets allocated for this graph */
159 
160     int xscale;                 /* scale mapping of X axes*/
161     int yscale;                 /* scale mapping of Y axes*/
162     int xinvert;                /* X axes inverted, TRUE or FALSE */
163     int yinvert;                /* Y axes inverted, TRUE or FALSE */
164     int xyflip;                 /* whether x and y axes should be flipped */
165 
166     int stacked;                /* TRUE if graph is stacked */
167     double bargap;              /* Distance between bars (in bar charts) */
168     double znorm;               /* Normalization of pseudo-3D graphs */
169 
170     plotarr *p;                 /* sets go here */
171 
172     legend l;                   /* legends */
173 
174     world w;                    /* world */
175     view v;                     /* viewport */
176 
177     labels labs;                /* title and subtitle */
178 
179     tickmarks *t[MAXAXES];      /* flags etc. for tickmarks for all axes */
180 
181     framep f;                   /* type of box around plot */
182 
183     GLocator locator;           /* locator props */
184 
185     world_stack ws[MAX_ZOOM_STACK]; /* zoom stack */
186     int ws_top;                 /* stack pointer */
187     int curw;                   /* for cycling through the stack */
188 } graph;
189 
190 
191 int get_cg(void);
192 
193 char *graph_types(int it);
194 char *set_types(int it);
195 int get_settype_by_name(char *s);
196 
197 int kill_graph(int gno);
198 void kill_all_graphs(void);
199 int copy_graph(int from, int to);
200 int move_graph(int from, int to);
201 int swap_graph(int from, int to);
202 int duplicate_graph(int gno);
203 
204 tickmarks *new_graph_tickmarks(void);
205 tickmarks *copy_graph_tickmarks(tickmarks *);
206 tickmarks *get_graph_tickmarks(int gno, int a);
207 void free_graph_tickmarks(tickmarks *t);
208 int set_graph_tickmarks(int gno, int a, tickmarks *t);
209 
210 int get_graph_framep(int gno, framep *f);
211 int get_graph_world(int gno, world *w);
212 int get_graph_viewport(int gno, view *v);
213 int get_graph_labels(int gno, labels *labs);
214 int get_graph_plotarr(int gno, int i, plotarr *p);
215 int get_graph_legend(int gno, legend *leg);
216 
217 int graph_allocate(int gno);
218 int set_graph_active(int gno);
219 
220 void set_graph_framep(int gno, framep *f);
221 void set_graph_world(int gno, world w);
222 void set_graph_viewport(int gno, view v);
223 void set_graph_labels(int gno, labels *labs);
224 void set_graph_plotarr(int gno, int i, plotarr *p);
225 void set_graph_legend(int gno, legend *leg);
226 void set_graph_legend_active(int gno, int flag);
227 
228 
229 int nactive(int gno);
230 
231 #define is_graph_active(gno) is_valid_gno(gno)
232 
233 int is_graph_hidden(int gno);
234 int set_graph_hidden(int gno, int flag);
235 
236 int get_graph_type(int gno);
237 
238 int is_graph_stacked(int gno);
239 int set_graph_stacked(int gno, int flag);
240 
241 double get_graph_bargap(int gno);
242 int set_graph_bargap(int gno, double bargap);
243 
244 int islogx(int gno);
245 int islogy(int gno);
246 
247 int islogitx(int gno);
248 int islogity(int gno);
249 
250 int number_of_graphs(void);
251 int select_graph(int gno);
252 
253 int realloc_graphs(int n);
254 int realloc_graph_plots(int gno, int n);
255 
256 int set_graph_xscale(int gno, int scale);
257 int set_graph_yscale(int gno, int scale);
258 
259 int get_graph_xscale(int gno);
260 int get_graph_yscale(int gno);
261 
262 int set_graph_znorm(int gno, double norm);
263 double get_graph_znorm(int gno);
264 
265 int is_valid_gno(int gno);
266 
267 int set_graph_type(int gno, int gtype);
268 
269 int allocate_set(int gno, int setno);
270 int activateset(int gno, int setno);
271 
272 int is_valid_setno(int gno, int setno);
273 int is_set_active(int gno, int setno);
274 int is_set_hidden(int gno, int setno);
275 int set_set_hidden(int gno, int setno, int flag);
276 
277 #define is_set_drawable(gno, setno) (is_set_active(gno, setno) && !is_set_hidden(gno, setno))
278 
279 int number_of_sets(int gno);
280 
281 int load_comments_to_legend(int gno, int setno);
282 
283 int settype_cols(int type);
284 int dataset_type(int gno, int setno);
285 int dataset_cols(int gno, int setno);
286 char *dataset_colname(int col);
287 
288 int is_refpoint_active(int gno);
289 
290 int set_refpoint(int gno, WPoint wp);
291 
292 WPoint get_refpoint(int gno);
293 
294 double *getcol(int gno, int setno, int col);
295 #define getx(gno, setno) getcol(gno, setno, 0)
296 #define gety(gno, setno) getcol(gno, setno, 1)
297 
298 char *get_legend_string(int gno, int setno);
299 int set_legend_string(int gno, int setno, char *s);
300 
301 int set_dataset_type(int gno, int set, int stype);
302 
303 char *getcomment(int gno, int setno);
304 int setcomment(int gno, int setno, char *s);
305 
306 int set_set_strings(int gno, int setno, int len, char **s);
307 char **get_set_strings(int gno, int setno);
308 
309 int setlength(int gno, int setno, int length);
310 int getsetlength(int gno, int setno);
311 
312 double setybase(int gno, int setno);
313 
314 int is_graph_xinvert(int gno);
315 int is_graph_yinvert(int gno);
316 
317 int set_graph_xinvert(int gno, int flag);
318 int set_graph_yinvert(int gno, int flag);
319 
320 int is_valid_axis(int gno, int axis);
321 int is_axis_active(int gno, int axis);
322 int is_zero_axis(int gno, int axis);
323 
324 void cycle_world_stack(void);
325 void clear_world_stack(void);
326 void show_world_stack(int n);
327 void add_world(int gno, double x1, double x2, double y1, double y2);
328 void push_world(void);
329 
330 int activate_tick_labels(int gno, int axis, int flag);
331 
332 int get_graph_locator(int gno, GLocator *locator);
333 void set_graph_locator(int gno, GLocator *locator);
334 
335 int graph_world_stack_size(int gno);
336 int get_world_stack_current(int gno);
337 int get_world_stack_entry(int gno, int n, world_stack *ws);
338 
339 int set_set_colors(int gno, int setno, int color);
340 
341 int moveset(int gnofrom, int setfrom, int gnoto, int setto);
342 int copyset(int gnofrom, int setfrom, int gnoto, int setto);
343 int copysetdata(int gnofrom, int setfrom, int gnoto, int setto);
344 
345 int get_recent_setno(void);
346 int get_recent_gno(void);
347 
348 int get_project_version(void);
349 int set_project_version(int version);
350 void reset_project_version(void);
351 
352 void set_project_description(char *descr);
353 char *get_project_description(void);
354 
355 void postprocess_project(int version);
356 
357 #endif /* __GRAPHS_H_ */
358