atomes 1.3.1
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-2026 by CNRS and University of Strasbourg */
15
21
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, Curve * this_curve);
35 void setup_yaxis_log (cairo_t * cr, Curve * this_curve, gboolean draw_it);
36
37*/
38
39#include <math.h>
40#include <cairo.h>
41
42#include "global.h"
43#include "curve.h"
44
56void autoscale_axis (project * this_proj, Curve * this_curve, int rid, int cid, int aid)
57{
58 int i, j, k, l, m, n;
59 if (! aid && (rid == RIN ||rid == CHA))
60 {
61 i = cid / ((this_proj -> nspec+1) * 4);
62 this_curve -> axmax[aid] = (rid == RIN) ? this_proj -> rsparam[i][1]: this_proj -> csparam[5];
63 this_curve -> axmax[aid] += 1.0;
64 this_curve -> axmin[aid] = (rid == RIN) ? 2 : 1;
65 }
66 else
67 {
68 n = (rid == SPH && aid == 1) ? 1 : 0;
69 this_curve -> axmax[aid] = this_curve -> data[aid][n];
70 this_curve -> axmin[aid] = this_curve -> data[aid][n];
71 for ( i=n ; i < this_curve -> ndata ; i++ )
72 {
73 this_curve -> axmax[aid] = max(this_curve -> axmax[aid], this_curve -> data[aid][i]);
74 this_curve -> axmin[aid] = min(this_curve -> axmin[aid], this_curve -> data[aid][i]);
75 }
76 if (this_curve -> extrac)
77 {
78 CurveExtra * ctmp = this_curve -> extrac -> first;
79 project * that_proj;
80 for ( j=0 ; j < this_curve -> extrac -> extras ; j++ )
81 {
82 m = ctmp -> id.a;
83 k = ctmp -> id.b;
84 l = ctmp -> id.c;
85 that_proj = get_project_by_id(m);
86 for ( i=n ; i < that_proj -> analysis[k] -> curves[l] -> ndata ; i++ )
87 {
88 this_curve -> axmax[aid] = max(this_curve -> axmax[aid], that_proj -> analysis[k] -> curves[l] -> data[aid][i]);
89 this_curve -> axmin[aid] = min(this_curve -> axmin[aid], that_proj -> analysis[k] -> curves[l] -> data[aid][i]);
90 }
91 if (ctmp -> next != NULL) ctmp = ctmp -> next;
92 }
93 }
94 }
95
96 if (aid == 1)
97 {
98 this_curve -> cmin[aid] = this_curve -> axmin[aid];
99 this_curve -> cmax[aid] = this_curve -> axmax[aid];
100 this_curve -> axmin[aid] = this_curve -> cmin[aid] - fabs(this_curve -> cmin[aid]) / 10.0;
101 this_curve -> axmax[aid] = this_curve -> cmax[aid] + fabs(this_curve -> cmax[aid]) / 10.0;
102// Adjust autoscale information if required
103 if (rid > GDK && rid < MSD)
104 {
105 this_curve -> axmin[aid] = 0.0;
106 }
107 }
108}
109
118void setup_yaxis_linear (cairo_t * cr, Curve * this_curve)
119{
120 int k;
121 double u, v;
122
123 k = cxy[1] / mticks;
124 v = cxy[1] - k * mticks;
125 if (k * mticks < cxy[1]) v = mticks - v;
126 v = fabs(v);
127 if (k * mticks > fabs(cxy[1])) v = mticks - v;
128 for ( u = 0.0 ; u < ymax ; u = u + mticks )
129 {
130 if (y_min + (u + v) * YDRAW / ymax >= y_max)
131 {
132 switch (labpos)
133 {
134 case 0:
135 ax = x_min - x_shift;
136 ay = y_min - y_shift + (u + v) * YDRAW / ymax;
137 label_curve (cr, cxy[1] + v + u, 1, 0, this_curve);
138 break;
139 case 1:
140 ax = x_max + x_shift;
141 ay = y_min - y_shift + (u + v) * YDRAW / ymax;
142 label_curve (cr, cxy[1] + v + u, 1, 1, this_curve);
143 break;
144 case 2:
145 ax = x_min - x_shift;
146 ay = y_min - y_shift + (u + v) * YDRAW / ymax;
147 label_curve (cr, cxy[1] + v + u, 1, 0, this_curve);
148 ax = x_max + x_shift;
149 ay = y_min - y_shift + (u + v) * YDRAW / ymax;
150 label_curve (cr, cxy[1] + v + u, 1, 1, this_curve);
151 break;
152 }
153 switch (tickpos)
154 {
155 case 0:
156 cairo_move_to(cr, x_min, y_min + (u + v) * YDRAW / ymax);
157 cairo_line_to(cr, x_min - amajt, y_min + (u + v) * YDRAW / ymax);
158 break;
159 case 1:
160 cairo_move_to(cr, x_max, y_min + (u + v) * YDRAW / ymax);
161 cairo_line_to(cr, x_max + amajt, y_min + (u + v) * YDRAW / ymax);
162 break;
163 case 2:
164 cairo_move_to(cr, x_min, y_min + (u + v) * YDRAW / ymax);
165 cairo_line_to(cr, x_min - amajt, y_min + (u + v) * YDRAW / ymax);
166 cairo_move_to(cr, x_max, y_min + (u + v) * YDRAW / ymax);
167 cairo_line_to(cr, x_max + amajt, y_min + (u + v) * YDRAW / ymax);
168 break;
169 }
170 }
171 }
172 cairo_stroke (cr);
173
174 for (u = v ; u > mticks / nticks ; u -= mticks / nticks);
175 v = u;
176 for (u = 0.0 ; u < ymax ; u = u + mticks / nticks)
177 {
178 if (y_min + (u + v) * YDRAW / ymax >= y_max)
179 {
180 if (dogrid)
181 {
182 cairo_stroke(cr);
183 cairo_set_line_width (cr, GRIDSIZE);
184 cairo_set_dash (cr, pdashed, lenp, 0.0);
185 cairo_move_to(cr, x_min, y_min + (u + v) * YDRAW / ymax);
186 cairo_line_to(cr, x_max, y_min + (u + v) * YDRAW / ymax);
187 cairo_stroke(cr);
188 prep_frame (cr, this_curve -> frame_dash, this_curve -> frame_thickness, this_curve -> frame_color);
189 }
190 if (fmod(u+v, mticks) != 0.0)
191 {
192 switch (tickpos)
193 {
194 case 0:
195 cairo_move_to(cr, x_min, y_min + (u + v) * YDRAW / ymax);
196 cairo_line_to(cr, x_min - amint, y_min + (u + v) * YDRAW / ymax);
197 break;
198 case 1:
199 cairo_move_to(cr, x_max, y_min + (u + v) * YDRAW / ymax);
200 cairo_line_to(cr, x_max + amint, y_min + (u + v) * YDRAW / ymax);
201 break;
202 case 2:
203 cairo_move_to(cr, x_min, y_min + (u + v) * YDRAW / ymax);
204 cairo_line_to(cr, x_min - amint, y_min + (u + v) * YDRAW / ymax);
205 cairo_move_to(cr, x_max, y_min + (u + v) * YDRAW / ymax);
206 cairo_line_to(cr, x_max + amint, y_min + (u + v) * YDRAW / ymax);
207 break;
208 }
209 }
210 }
211 cairo_stroke (cr);
212 }
213}
214
224void setup_yaxis_log (cairo_t * cr, Curve * this_curve, gboolean draw_it)
225{
226 int i, k, l;
227 gboolean istrue;
228 double v;
229
230 istrue = TRUE;
231 ylog = 1;
232 if (cxy[1] != 0.0)
233 {
234 k = (ymax+cxy[1])/cxy[1];
235 }
236 while (istrue)
237 {
238 k = k/10;
239 if (k > 0)
240 {
241 ylog ++;
242 }
243 else
244 {
245 ylog ++;
246 istrue = FALSE;
247 }
248 }
249 istrue = TRUE;
250 dylog = 0;
251 i = 100;
252 while (istrue)
253 {
254 if (cxy[1] >= pow(10, i))
255 {
256 istrue = FALSE;
257 }
258 else
259 {
260 dylog ++;
261 i=i-1;
262 }
263 }
264 dylog = dylog - 100;
265 if (draw_it)
266 {
267 for ( l = 0 ; l < ylog ; l ++ )
268 {
269 v = pow (10, l-dylog);
270 if (dogrid)
271 {
272 cairo_stroke(cr);
273 cairo_set_line_width (cr, GRIDSIZE);
274 cairo_set_dash (cr, pdashed, lenp, 0.0);
275 cairo_move_to(cr, x_min, y_min + YDRAW * l / ylog);
276 cairo_line_to(cr, x_max, y_min + YDRAW * l / ylog);
277 cairo_stroke(cr);
278 prep_frame (cr, this_curve -> frame_dash, this_curve -> frame_thickness, this_curve -> frame_color);
279 }
280 switch (labpos)
281 {
282 case 0:
283 ax = x_min - x_shift;
284 ay = y_min - y_shift + YDRAW *l / ylog;
285 label_curve (cr, v, 1, 0, this_curve);
286 break;
287 case 1:
288 ax = x_max + x_shift;
289 ay = y_min - y_shift + YDRAW *l / ylog;
290 label_curve (cr, v, 1, 1, this_curve);
291 break;
292 case 2:
293 ax = x_min - x_shift;
294 ay = y_min - y_shift + YDRAW *l / ylog;
295 label_curve (cr, v, 1, 0, this_curve);
296 ax = x_max + x_shift;
297 ay = y_min - y_shift + YDRAW *l / ylog;
298 label_curve (cr, v, 1, 1, this_curve);
299 break;
300 }
301 switch (tickpos)
302 {
303 case 0:
304 cairo_move_to(cr, x_min, y_min + YDRAW * l / ylog);
305 cairo_line_to(cr, x_min - amajt, y_min + YDRAW * l / ylog);
306 break;
307 case 1:
308 cairo_move_to(cr, x_max, y_min + YDRAW * l / ylog);
309 cairo_line_to(cr, x_max - amajt, y_min + YDRAW * l / ylog);
310 break;
311 case 2:
312 cairo_move_to(cr, x_min, y_min + YDRAW * l / ylog);
313 cairo_line_to(cr, x_min - amajt, y_min + YDRAW * l / ylog);
314 cairo_move_to(cr, x_max, y_min + YDRAW * l / ylog);
315 cairo_line_to(cr, x_max - amajt, y_min + YDRAW * l / ylog);
316 break;
317 }
318 for ( k = 2 ; k < 10 ; k ++ )
319 {
320 if (dogrid)
321 {
322 cairo_stroke(cr);
323 cairo_set_line_width (cr, GRIDSIZE);
324 cairo_set_dash (cr, pdashed, lenp, 0.0);
325 cairo_move_to(cr, x_min, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
326 cairo_line_to(cr, x_max, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
327 cairo_stroke(cr);
328 prep_frame (cr, this_curve -> frame_dash, this_curve -> frame_thickness, this_curve -> frame_color);
329 }
330 switch (tickpos)
331 {
332 case 0:
333 cairo_move_to(cr, x_min, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
334 cairo_line_to(cr, x_min - amint, y_min + YDRAW *(l + log(k) / log(10.0)) / ylog);
335 break;
336 case 1:
337 cairo_move_to(cr, x_max, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
338 cairo_line_to(cr, x_max + amint, y_min + YDRAW *(l + log(k) / log(10.0)) / ylog);
339 break;
340 case 2:
341 cairo_move_to(cr, x_min, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
342 cairo_line_to(cr, x_min - amint, y_min + YDRAW *(l + log(k) / log(10.0)) / ylog);
343 cairo_move_to(cr, x_max, y_min + YDRAW * (l + log(k) / log(10.0)) / ylog);
344 cairo_line_to(cr, x_max + amint, y_min + YDRAW *(l + log(k) / log(10.0)) / ylog);
345 break;
346 }
347 }
348 }
349 cairo_stroke (cr);
350 }
351}
int tickpos
Definition curve.c:84
int labpos
Definition curve.c:84
double ay
Definition curve.c:71
double cxy[2]
Definition curve.c:72
int ylog
Definition curve.c:75
int dylog
Definition curve.c:76
double YDRAW
Definition curve.c:66
double mticks
Definition curve.c:73
const double pdashed[]
Definition curve.c:125
int amajt
Definition curve.c:83
double y_max
Definition curve.c:70
double x_max
Definition curve.c:69
gboolean dogrid
Definition curve.c:81
double ax
Definition curve.c:71
int lenp
Definition curve.c:126
double y_min
Definition curve.c:70
int nticks
Definition curve.c:74
int x_shift
Definition curve.c:82
int amint
Definition curve.c:83
double x_min
Definition curve.c:69
double ymax
Definition curve.c:68
int y_shift
Definition curve.c:82
Variable declarations for the curve widget Functions for interactions with the curve widget.
void label_curve(cairo_t *cr, double val, int axe, int p, Curve *this_curve)
draw axis label
Definition labels.c:56
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 RIN
Definition global.h:343
#define SPH
Definition global.h:345
#define CHA
Definition global.h:344
#define min(a, b)
Definition global.h:93
#define GDK
Definition global.h:340
#define MSD
Definition global.h:346
project * get_project_by_id(int p)
get project pointer using id number
Definition project.c:120
#define max(a, b)
Definition global.h:92
void setup_yaxis_linear(cairo_t *cr, Curve *this_curve)
setup y axis using a linear scale
Definition yaxis.c:118
void setup_yaxis_log(cairo_t *cr, Curve *this_curve, gboolean draw_it)
setup y axis using a log scale
Definition yaxis.c:224
void autoscale_axis(project *this_proj, Curve *this_curve, int rid, int cid, int aid)
autoscale axis
Definition yaxis.c:56