~ubuntu-branches/ubuntu/trusty/picviz/trusty

« back to all changes in this revision

Viewing changes to src/libpicviz/axis.c

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Chifflier
  • Date: 2009-03-30 10:42:08 UTC
  • Revision ID: james.westby@ubuntu.com-20090330104208-j095obwkp574t1lm
Tags: upstream-0.5
ImportĀ upstreamĀ versionĀ 0.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Picviz - Parallel coordinates ploter
 
3
 * Copyright (C) 2008 Sebastien Tricaud <toady@gscore.org>
 
4
 *
 
5
 * This program is free software: you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation version 3.
 
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
 * $Id: axis.c 374 2009-01-20 18:08:24Z toady $
 
18
 */
 
19
 
 
20
#include <stdio.h>
 
21
#include <stdlib.h>
 
22
#include <string.h>
 
23
 
 
24
#include <pcimage.h>
 
25
#include <linuxlist.h>
 
26
 
 
27
#include "axis.h"
 
28
#include "line.h"
 
29
 
 
30
/**
 
31
 * \ingroup PicvizMain
 
32
 * @{
 
33
 */
 
34
 
 
35
/** \file axis.c
 
36
 * \brief Create and manipulate axes
 
37
 */
 
38
 
 
39
static unsigned int id = 0;
 
40
 
 
41
 
 
42
PicvizAxis *picviz_axis_new(void)
 
43
{
 
44
        PicvizAxis *axis = NULL;
 
45
 
 
46
        axis = malloc(sizeof(*axis));
 
47
        if ( ! axis ) {
 
48
                fprintf(stderr, "Cannot initialize axis: memory exhausted.\n");
 
49
                return NULL;
 
50
        }
 
51
        INIT_LLIST_HEAD(&axis->list);
 
52
        axis->id = id++;
 
53
        axis->type = DATATYPE_EMPTY;
 
54
        axis->xpos = 0;
 
55
        axis->ymin = ~0; /* FIXME: that must be auto-adaptative */
 
56
        axis->ymax = 0;
 
57
 
 
58
        picviz_properties_new(&axis->props);
 
59
        picviz_properties_set(axis->props, "label", "");
 
60
        picviz_properties_set(axis->props, "color", "#000000");
 
61
 
 
62
        return axis;
 
63
}
 
64
 
 
65
void picviz_axis_destroy(PicvizAxis *axis)
 
66
{
 
67
                picviz_properties_destroy(axis->props);
 
68
                free(axis);
 
69
}
 
70
 
 
71
PicvizAxis *picviz_axis_get(PicvizImage *i, unsigned int id)
 
72
{
 
73
        PicvizAxis *a;
 
74
 
 
75
        llist_for_each_entry(a, &i->axes, list) {
 
76
                if (a->id == id)
 
77
                        return a;
 
78
        }
 
79
 
 
80
        return NULL;
 
81
}
 
82
 
 
83
void picviz_axis_set_type(PicvizAxis *axis, PicvizDataType type)
 
84
{
 
85
        axis->type = type;
 
86
}
 
87
 
 
88
void picviz_axis_set_type_from_string(PicvizAxis *axis, char *string)
 
89
{
 
90
        if (!strcmp(string, "timeline")) {
 
91
                axis->type = DATATYPE_TIMELINE;
 
92
                return;
 
93
        }
 
94
        if (!strcmp(string, "integer")) {
 
95
                axis->type = DATATYPE_INTEGER;
 
96
                return;
 
97
        }
 
98
        if (!strcmp(string, "string")) {
 
99
                axis->type = DATATYPE_STRING;
 
100
                return;
 
101
        }
 
102
        if (!strcmp(string, "float")) {
 
103
                axis->type = DATATYPE_FLOAT;
 
104
                return;
 
105
        }
 
106
        if (!strcmp(string, "short")) {
 
107
                axis->type = DATATYPE_SHORT;
 
108
                return;
 
109
        }
 
110
        if (!strcmp(string, "ipv4")) {
 
111
                axis->type = DATATYPE_IPV4;
 
112
                return;
 
113
        }
 
114
        if (!strcmp(string, "char")) {
 
115
                axis->type = DATATYPE_CHAR;
 
116
                return;
 
117
        }
 
118
        if (!strcmp(string, "gold")) {
 
119
                axis->type = DATATYPE_GOLD;
 
120
                return;
 
121
        }
 
122
        if (!strcmp(string, "years")) {
 
123
                axis->type = DATATYPE_YEARS;
 
124
                return;
 
125
        }
 
126
        if (!strcmp(string, "enum")) {
 
127
                axis->type = DATATYPE_ENUM;
 
128
                return;
 
129
        }
 
130
        if (!strcmp(string, "ln")) {
 
131
                axis->type = DATATYPE_LN;
 
132
                return;
 
133
        }
 
134
        if (!strcmp(string, "port")) {
 
135
                axis->type = DATATYPE_PORT;
 
136
                return;
 
137
        }
 
138
 
 
139
        axis->type = DATATYPE_EMPTY;
 
140
}
 
141
 
 
142
char *picviz_axis_get_string_from_type(PicvizAxis *axis)
 
143
{
 
144
        switch(axis->type) {
 
145
                case DATATYPE_TIMELINE:
 
146
                        return "timeline";
 
147
                        break;
 
148
                case DATATYPE_INTEGER:
 
149
                        return "integer";
 
150
                        break;
 
151
                case DATATYPE_STRING:
 
152
                        return "string";
 
153
                        break;
 
154
                case DATATYPE_FLOAT:
 
155
                        return "float";
 
156
                        break;
 
157
                case DATATYPE_SHORT:
 
158
                        return "short";
 
159
                        break;
 
160
                case DATATYPE_IPV4:
 
161
                        return "ipv4";
 
162
                        break;
 
163
                case DATATYPE_CHAR:
 
164
                        return "char";
 
165
                        break;
 
166
                case DATATYPE_GOLD:
 
167
                        return "gold";
 
168
                        break;
 
169
                case DATATYPE_YEARS:
 
170
                        return "years";
 
171
                        break;
 
172
                case DATATYPE_ENUM:
 
173
                        return "enum";
 
174
                        break;
 
175
                case DATATYPE_LN:
 
176
                        return "ln";
 
177
                        break;
 
178
                default:
 
179
                        return "*** error ***";
 
180
                        break;
 
181
        }
 
182
}
 
183
 
 
184
 
 
185
PicvizAxisPlot *picviz_axisplot_new(void)
 
186
{
 
187
        PicvizAxisPlot *axisplot;
 
188
 
 
189
        axisplot = malloc(sizeof(*axisplot));
 
190
        if ( ! axisplot ) {
 
191
                fprintf(stderr, "Cannot initalize axisplot: memory exhaustred.\n");
 
192
                return NULL;
 
193
        }
 
194
 
 
195
        axisplot->strval  = NULL;
 
196
        axisplot->y       = 0;
 
197
        axisplot->axis_id = 0;
 
198
        picviz_properties_new(&axisplot->props);
 
199
 
 
200
        return axisplot;
 
201
}
 
202
 
 
203
void picviz_axisplot_destroy(PicvizAxisPlot *axisplot)
 
204
{
 
205
        picviz_properties_destroy(axisplot->props);
 
206
        free(axisplot);
 
207
}