* Initial checkin.
[scdataviz] / graph.c
1 /*
2 ** Graph.c
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 Lesser 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 Lesser General Public License for more details.
19
20 You should have received a copy of the GNU Lesser General Public License
21 along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
23 **Many thanks to Davyd Madeley for the excellent Cairo  Tutorial
24 **  at http://gnomejournal.org/article/34/writing-a--using-cairo-and-gtk28
25
26 ** Started on  Thu Jul 17 10:51:32 2008 Johnny Q. Hacker
27 ** Last update Sun May 12 01:17:25 2002 Speed Blue
28 */
29
30 #include "graph.h"
31
32 G_DEFINE_TYPE(Graph, graph, G_TYPE_OBJECT);
33
34 static void graph_class_init(GraphClass *klass) {
35   GObjectClass *gobject_klass;
36   gobject_klass = G_OBJECT_CLASS(klass);
37 }
38
39 static void graph_init(Graph *graph) {
40   graph->symbol = CIRCLE;
41   GPtrArray = g_ptr_array_new();
42 }
43
44 Graph *graph_new(void) {
45   return g_object_new(G_GRAPH_TYPE);
46 }
47
48 int graph_add_point(Graph* graph, double x, double y) {
49   double *point = (double*)malloc(2*sizeof(double));
50   if(point == NULL) return 1;
51   point[0] = x;
52   point[1] = y;
53   g_ptr_array_add(graph->points, (gpointer)point);
54   if(points->len == 1) {
55     maxx = minx = x;
56     maxy = miny = x;
57   }else{
58     if(x > maxx) maxx = x;
59     if(x < minx) minx = x;
60     if(y > mayy) maxy = y;
61     if(y < miny) miny = y;
62   }
63   return 0;
64 }