atomes 1.1.16
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
yaxis.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'yaxis.c'
24*
25* Contains:
26*
27
28 - The functions to draw the y axis
29
30*
31* List of functions:
32
33 void autoscale_axis (project * this_proj, int rid, int cid, int aid);
34 void setup_yaxis_linear (cairo_t * cr, project * this_proj, int rid, int cid);
35 void setup_yaxis_log (cairo_t * cr, project * this_proj, int rid, int cid, gboolean draw_it);
36
37*/
38
39#include <math.h>
40#include <cairo.h>
41
42#include "global.h"
43#include "curve.h"
44
55void autoscale_axis (project * this_proj, int rid, int cid, int aid)
56{
57 int i, j, k, l, m, n;
58 if (! aid && (rid == RI ||rid == CH))
59 {
60 i = cid / ((this_proj -> nspec+1) * 4);
61 this_proj -> curves[rid][cid] -> axmax[aid] = (rid == RI) ? this_proj -> rsparam[i][1]: this_proj -> csparam[5];
62 this_proj -> curves[rid][cid] -> axmax[aid] += 1.0;
63 this_proj -> curves[rid][cid] -> axmin[aid] = (rid == RI) ? 2 : 1;
64 }
65 else
66 {
67 n = (activer == SP && aid == 1) ? 1 : 0;
68 this_proj -> curves[rid][cid] -> axmax[aid] = this_proj -> curves[rid][cid] -> data[aid][n];
69 this_proj -> curves[rid][cid] -> axmin[aid] = this_proj -> curves[rid][cid] -> data[aid][n];
70 for ( i=n ; i < this_proj -> curves[rid][cid] -> ndata ; i++ )
71 {
72 this_proj -> curves[rid][cid] -> axmax[aid] = max(this_proj -> curves[rid][cid] -> axmax[aid],
73 this_proj -> curves[rid][cid] -> data[aid][i]);
74 this_proj -> curves[rid][cid] -> axmin[aid] = min(this_proj -> curves[rid][cid] -> axmin[aid],
75 this_proj -> curves[rid][cid] -> data[aid][i]);
76 }
77 CurveExtra * ctmp = this_proj -> curves[rid][cid] -> extrac -> first;
78 project * that_proj;
79 for ( j=0 ; j < this_proj -> curves[rid][cid] -> extrac -> extras ; j++ )
80 {
81 m = ctmp -> id.a;
82 k = ctmp -> id.b;
83 l = ctmp -> id.c;
84 that_proj = get_project_by_id(m);
85 for ( i=n ; i < that_proj -> curves[k][l] -> ndata ; i++ )
86 {
87 this_proj -> curves[rid][cid] -> axmax[aid] = max(this_proj -> curves[rid][cid] -> axmax[aid],
88 that_proj -> curves[k][l] -> data[aid][i]);
89 this_proj -> curves[rid][cid] -> axmin[aid] = min(this_proj -> curves[rid][cid] -> axmin[aid],
90 that_proj -> curves[k][l] -> data[aid][i]);
91 }
92 if (ctmp -> next != NULL) ctmp = ctmp -> next;
93 }
94 }
95
96 if (aid == 1)
97 {
98 this_proj -> curves[rid][cid] -> cmin[aid] = this_proj -> curves[rid][cid] -> axmin[aid];
99 this_proj -> curves[rid][cid] -> cmax[aid] = this_proj -> curves[rid][cid] -> axmax[aid];
100 this_proj -> curves[rid][cid] -> axmin[aid] = this_proj -> curves[rid][cid] -> cmin[aid]
101 - fabs(this_proj -> curves[rid][cid] -> cmin[aid]) / 10.0;
102 this_proj -> curves[rid][cid] -> axmax[aid] = this_proj -> curves[rid][cid] -> cmax[aid]
103 + fabs(this_proj -> curves[rid][cid] -> cmax[aid]) / 10.0;
104 if (activer > GK && activer < MS)
105 {
106 this_proj -> curves[rid][cid] -> axmin[aid] = 0.0;
107 }
108 }
109}
110
121void setup_yaxis_linear (cairo_t * cr, project * this_proj, int rid, int cid)
122{
123 int k;
124 double u, v;
125
126 k = cxy[1] / mticks;
127 v = cxy[1] - k * mticks;
128 if (k * mticks < cxy[1]) v = mticks - v;
129 v = fabs(v);
130 if (k * mticks > fabs(cxy[1])) v = mticks - v;
131 for ( u = 0.0 ; u < ymax ; u = u + mticks )
132 {
133 if (y_min + (u + v) * YDRAW / ymax >= y_max)
134 {
135 switch (labpos)
136 {
137 case 0:
138 ax = x_min - x_shift;
139 ay = y_min - y_shift + (u + v) * YDRAW / ymax;
140 label (cr, cxy[1] + v + u, 1, 0, this_proj);
141 break;
142 case 1:
143 ax = x_max + x_shift;
144 ay = y_min - y_shift + (u + v) * YDRAW / ymax;
145 label (cr, cxy[1] + v + u, 1, 1, this_proj);
146 break;
147 case 2:
148 ax = x_min - x_shift;
149 ay = y_min - y_shift + (u + v) * YDRAW / ymax;
150 label (cr, cxy[1] + v + u, 1, 0, this_proj);
151 ax = x_max + x_shift;
152 ay = y_min - y_shift + (u + v) * YDRAW / ymax;
153 label (cr, cxy[1] + v + u, 1, 1, this_proj);
154 break;
155 }
156 switch (tickpos)
157 {
158 case 0:
159 cairo_move_to(cr, x_min, y_min + (u + v) * YDRAW / ymax);
160 cairo_line_to(cr, x_min - amajt, y_min + (u + v) * YDRAW / ymax);
161 break;
162 case 1:
163 cairo_move_to(cr, x_max, y_min + (u + v) * YDRAW / ymax);
164 cairo_line_to(cr, x_max + amajt, y_min + (u + v) * YDRAW / ymax);
165 break;
166 case 2:
167 cairo_move_to(cr, x_min, y_min + (u + v) * YDRAW / ymax);
168 cairo_line_to(cr, x_min - amajt, y_min + (u + v) * YDRAW / ymax);
169 cairo_move_to(cr, x_max, y_min + (u + v) * YDRAW / ymax);
170 cairo_line_to(cr, x_max + amajt, y_min + (u + v) * YDRAW / ymax);
171 break;
172 }
173 }
174 }
175 cairo_stroke (cr);
176
177 for (u = v ; u > mticks / nticks ; u -= mticks / nticks);
178 v = u;
179 for (u = 0.0 ; u < ymax ; u = u + mticks / nticks)
180 {
181 if (y_min + (u + v) * YDRAW / ymax >= y_max)
182 {
183 if (dogrid)
184 {
185 cairo_stroke(cr);
186 cairo_set_line_width (cr, GRIDSIZE);
187 cairo_set_dash (cr, pdashed, lenp, 0.0);
188 cairo_move_to(cr, x_min, y_min + (u + v) * YDRAW / ymax);
189 cairo_line_to(cr, x_max, y_min + (u + v) * YDRAW / ymax);
190 cairo_stroke(cr);
191 prep_frame (cr, this_proj -> curves[rid][cid] -> frame_dash,
192 this_proj -> curves[rid][cid] -> frame_thickness,
193 this_proj -> curves[rid][cid] -> frame_color);
194 }
195 if (fmod(u+v, mticks) != 0.0)
196 {
197 switch (tickpos)
198 {
199 case 0:
200 cairo_move_to(cr, x_min, y_min + (u + v) * YDRAW / ymax);
201 cairo_line_to(cr, x_min - amint, y_min + (u + v) * YDRAW / ymax);
202 break;
203 case 1:
204 cairo_move_to(cr, x_max, y_min + (u + v) * YDRAW / ymax);
205 cairo_line_to(cr, x_max + amint, y_min + (u + v) * YDRAW / ymax);
206 break;
207 case 2:
208 cairo_move_to(cr, x_min, y_min + (u + v) * YDRAW / ymax);
209 cairo_line_to(cr, x_min - amint, y_min + (u + v) * YDRAW / ymax);
210 cairo_move_to(cr, x_max, y_min + (u + v) * YDRAW / ymax);
211 cairo_line_to(cr, x_max + amint, y_min + (u + v) * YDRAW / ymax);
212 break;
213 }
214 }
215 }
216 cairo_stroke (cr);
217 }
218}
219
231void setup_yaxis_log (cairo_t * cr, project * this_proj, int rid, int cid, gboolean draw_it)
232{
233 int i, k, l;
234 gboolean istrue;
235 double v;
236
237 istrue = TRUE;
238 ylog = 1;
239 if (cxy[1] != 0.0)
240 {
241 k = (ymax+cxy[1])/cxy[1];
242 }
243 while (istrue)
244 {
245 k = k/10;
246 if (k > 0)
247 {
248 ylog ++;
249 }
250 else
251 {
252 ylog ++;
253 istrue = FALSE;
254 }
255 }
256 istrue = TRUE;
257 dylog = 0;
258 i = 100;
259 while (istrue)
260 {
261 if (cxy[1] >= pow(10, i))
262 {
263 istrue = FALSE;
264 }
265 else
266 {
267 dylog ++;
268 i=i-1;
269 }
270 }
271 dylog = dylog - 100;
272 if (draw_it)
273 {
274 for ( l = 0 ; l < ylog ; l ++ )
275 {
276 v = pow (10, l-dylog);
277 if (dogrid)
278 {
279 cairo_stroke(cr);
280 cairo_set_line_width (cr, GRIDSIZE);
281 cairo_set_dash (cr, pdashed, lenp, 0.0);
282 cairo_move_to(cr, x_min, y_min + YDRAW * l / ylog);
283 cairo_line_to(cr, x_max, y_min + YDRAW * l / ylog);
284 cairo_stroke(cr);
285 prep_frame (cr, this_proj -> curves[rid][cid] -> frame_dash,
286 this_proj -> curves[rid][cid] -> frame_thickness,
287 this_proj -> curves[rid][cid] -> frame_color);
288 }
289 switch (labpos)
290 {
291 case 0:
292 ax = x_min - x_shift;
293 ay = y_min - y_shift + YDRAW *l / ylog;
294 label (cr, v, 1, 0, this_proj);
295 break;
296 case 1:
297 ax = x_max + x_shift;
298 ay = y_min - y_shift + YDRAW *l / ylog;
299 label (cr, v, 1, 1, this_proj);
300 break;
301 case 2:
302 ax = x_min - x_shift;
303 ay = y_min - y_shift + YDRAW *l / ylog;
304 label (cr, v, 1, 0, this_proj);
305 ax = x_max + x_shift;
306 ay = y_min - y_shift + YDRAW *l / ylog;
307 label (cr, v, 1, 1, this_proj);
308 break;
309 }
310 switch (tickpos)
311 {
312 case 0:
313 cairo_move_to(cr, x_min, y_min + YDRAW * l / ylog);
314 cairo_line_to(cr, x_min - amajt, y_min + YDRAW * l / ylog);
315 break;
316 case 1:
317 cairo_move_to(cr, x_max, y_min + YDRAW * l / ylog);
318 cairo_line_to(cr, x_max - amajt, y_min + YDRAW * l / ylog);
319 break;
320 case 2:
321 cairo_move_to(cr, x_min, y_min + YDRAW * l / ylog);
322 cairo_line_to(cr, x_min - amajt, y_min + YDRAW * l / ylog);
323 cairo_move_to(cr, x_max, y_min + YDRAW * l / ylog);
324 cairo_line_to(cr, x_max - amajt, y_min + YDRAW * l / ylog);
325 break;
326 }
327 for ( k = 2 ; k < 10 ; k ++ )
328 {
329 if (dogrid)
330 {
331 cairo_stroke(cr);
332 cairo_set_line_width (cr, GRIDSIZE);
333 cairo_set_dash (cr, pdashed, lenp, 0.0);
334 cairo_move_to(cr, x_min, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
335 cairo_line_to(cr, x_max, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
336 cairo_stroke(cr);
337 prep_frame (cr, this_proj -> curves[rid][cid] -> frame_dash,
338 this_proj -> curves[rid][cid] -> frame_thickness,
339 this_proj -> curves[rid][cid] -> frame_color);
340 }
341 switch (tickpos)
342 {
343 case 0:
344 cairo_move_to(cr, x_min, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
345 cairo_line_to(cr, x_min - amint, y_min + YDRAW *(l + log(k) / log(10.0)) / ylog);
346 break;
347 case 1:
348 cairo_move_to(cr, x_max, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
349 cairo_line_to(cr, x_max + amint, y_min + YDRAW *(l + log(k) / log(10.0)) / ylog);
350 break;
351 case 2:
352 cairo_move_to(cr, x_min, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
353 cairo_line_to(cr, x_min - amint, y_min + YDRAW *(l + log(k) / log(10.0)) / ylog);
354 cairo_move_to(cr, x_max, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
355 cairo_line_to(cr, x_max + amint, y_min + YDRAW *(l + log(k) / log(10.0)) / ylog);
356 break;
357 }
358 }
359 }
360 cairo_stroke (cr);
361 }
362}
int tickpos
Definition curve.c:83
int labpos
Definition curve.c:83
double ay
Definition curve.c:70
double cxy[2]
Definition curve.c:71
int ylog
Definition curve.c:74
int dylog
Definition curve.c:75
double YDRAW
Definition curve.c:65
double mticks
Definition curve.c:72
const double pdashed[]
Definition curve.c:124
int amajt
Definition curve.c:82
double y_max
Definition curve.c:69
double x_max
Definition curve.c:68
gboolean dogrid
Definition curve.c:80
double ax
Definition curve.c:70
int lenp
Definition curve.c:125
double y_min
Definition curve.c:69
int nticks
Definition curve.c:73
int x_shift
Definition curve.c:81
int amint
Definition curve.c:82
double x_min
Definition curve.c:68
double ymax
Definition curve.c:67
int y_shift
Definition curve.c:81
Variable declarations for the curve widget Functions for interactions with the curve widget.
void label(cairo_t *cr, double val, int axe, int p, project *this_proj)
draw axis label
Definition labels.c:56
int activer
Definition w_curve.c:74
void prep_frame(cairo_t *fr, int da, double ti, ColRGBA dcol)
draw frame line
Definition frame.c:56
#define GRIDSIZE
Definition curve.h:39
Global variable declarations Global convenience function declarations Global data structure defin...
#define RI
Definition global.h:328
#define MS
Definition global.h:331
#define min(a, b)
Definition global.h:81
#define GK
Definition global.h:325
#define SP
Definition global.h:330
#define CH
Definition global.h:329
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
#define max(a, b)
Definition global.h:80
void setup_yaxis_log(cairo_t *cr, project *this_proj, int rid, int cid, gboolean draw_it)
setup y axis using a log scale
Definition yaxis.c:231
void setup_yaxis_linear(cairo_t *cr, project *this_proj, int rid, int cid)
setup y axis using a linear scale
Definition yaxis.c:121
void autoscale_axis(project *this_proj, int rid, int cid, int aid)
autoscale axis
Definition yaxis.c:55