e140057ad583768824fc6027dcb164e9f09a3e7f
[scdataviz] / graph.h
1 /*
2 ** Graph.h
3 ** 
4 ** Made by Johnny Q. Hacker
5 ** Login   <solarion@johnathan>
6 ** 
7
8     Copyright (C) 2008 Joseph Pingenot
9
10     This program is free software: you can redistribute it and/or modify
11     it under the terms of the GNU Affero General Public License as published by
12     the Free Software Foundation, either version 3 of the License, or
13     (at your option) any later version.
14
15     This program is distributed in the hope that it will be useful,
16     but WITHOUT ANY WARRANTY; without even the implied warranty of
17     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18     GNU Affero General Public License for more details.
19
20     You should have received a copy of the GNU Affero General Public License
21     along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 ** Started on  Thu Jul 17 10:51:32 2008 Johnny Q. Hacker
24 ** Last update Thu Jul 17 10:51:32 2008 Johnny Q. Hacker
25 */
26
27 #ifndef         GRAPHCLASS_H_
28 #define         GRAPHCLASS_H_
29
30 #include <glib-2.0/glib-object.h>
31
32 typedef enum {SQUARE, CIRCLE, STAR, PLUS, MINUS, CROSS} graph_symbol;
33
34 struct graph_point {
35   double x;
36   double y;
37   GString *label;
38 };
39
40 /*Bezier line*/
41 struct graph_line {
42   /*First point*/
43   double p0_x;
44   double p0_y;
45   double p1_x;
46   double p1_y;
47   double p2_x;
48   double p2_y;
49   /*End point*/
50   double p3_x;
51   double p3_y;
52 };
53
54 typedef struct _Graph {
55   GObject parent_instance;
56   /*Array of n_points sets of x,y coords*/
57   GPtrArray *points;
58   /*This draws all of the lines (generally between points)*/
59   GPtrArray *lines;
60   double maxx;
61   double minx;
62   double maxy;
63   double miny;
64   graph_symbol symbol;
65 } Graph;
66
67 typedef struct _GraphClass {
68   GObjectClass parent_class;
69 } GraphClass;
70
71 #define GRAPH_TYPE (graph_get_type())
72 #define GRAPH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GRAPH_TYPE, Graph))
73 #define GRAPH_CLASS(obj) (G_TYPE_CHECK_CLASS_CAST ((obj), GRAPH, GraphClass))
74 #define IS_GRAPH(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GRAPH_TYPE))
75 #define IS_GRAPH_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE ((obj), GRAPH_CLASS_TYPE))
76 #define GRAPH_GET_CLASS (G_TYPE_INSTANCE_GET_CLASS ((obj), GRAPH, GraphClass))
77
78 Graph *graph_new(void);
79 int graph_add_point(Graph* graph, double x, double y, const GString *label);
80 int graph_add_graph_point(Graph* graph, struct graph_point *pt);
81 int graph_add_line(Graph* graph, double p0_x, double p0_y, double p1_x, double p1_y, double p2_x, double p2_y, double p3_x, double p3_y);
82 void graph_add_linear_connectors(Graph* graph);
83
84 #endif      /* !GRAPHCLASS_H_ */