atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
xaxis.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: 'xaxis.c'
24*
25* Contains:
26*
27
28 - The functions to draw the x axis
29
30*
31* List of functions:
32
33 void setup_xaxis_linear (cairo_t * cr, project * this_proj, int rid, int cid);
34 void setup_xaxis_log (cairo_t * cr, project * this_proj, int rid, int cid, gboolean draw_it);
35
36*/
37
38#include <math.h>
39#include <cairo.h>
40
41#include "global.h"
42#include "curve.h"
43
54void setup_xaxis_linear (cairo_t * cr, project * this_proj, int rid, int cid)
55{
56 int k;
57 double u, v;
58
59 k = cxy[0] / mticks;
60 v = cxy[0] - k * mticks;
61 if (k * mticks < cxy[0]) v = mticks - v;
62 v = fabs(v);
63 for ( u = 0.0 ; u < xmax; u = u + mticks )
64 {
65 if (x_min + (u + v) * XDRAW / xmax <= x_max)
66 {
67 switch (labpos)
68 {
69 case 0:
70 ax = x_min - x_shift + (u + v) * XDRAW / xmax;
71 ay = y_min + y_shift;
72 label (cr, cxy[0] + u + v, 0, 0, this_proj);
73 break;
74 case 1:
75 ax = x_min - x_shift + (u + v) * XDRAW / xmax;
76 ay = y_max - y_shift;
77 label (cr, cxy[0] + u + v, 0, 1, this_proj);
78 break;
79 case 2:
80 ax = x_min - x_shift + (u + v) * XDRAW / xmax;
81 ay = y_min + y_shift;
82 label (cr, cxy[0] + u + v, 0, 0, this_proj);
83 ax = x_min - x_shift + (u + v) * XDRAW / xmax;
84 ay = y_max - y_shift;
85 label (cr, cxy[0] + u + v, 0, 1, this_proj);
86 break;
87 }
88 switch (tickpos)
89 {
90 case 0:
91 cairo_move_to(cr, x_min + (u + v) * XDRAW / xmax, y_min);
92 cairo_line_to(cr, x_min + (u + v) * XDRAW / xmax, y_min + amajt);
93 break;
94 case 1:
95 cairo_move_to(cr, x_min + (u + v) * XDRAW / xmax, y_max);
96 cairo_line_to(cr, x_min + (u + v) * XDRAW / xmax, y_max - amajt);
97 break;
98 case 2:
99 cairo_move_to(cr, x_min + (u + v) * XDRAW / xmax, y_min);
100 cairo_line_to(cr, x_min + (u + v) * XDRAW / xmax, y_min + amajt);
101 cairo_move_to(cr, x_min + (u + v) * XDRAW / xmax, y_max);
102 cairo_line_to(cr, x_min + (u + v) * XDRAW / xmax, y_max - amajt);
103 break;
104 }
105 }
106 }
107 cairo_stroke (cr);
108
109 for (u = v ; u > mticks / nticks ; u -= mticks / nticks);
110 v = u;
111 for ( u = 0.0 ; u < xmax ; u = u + mticks / nticks )
112 {
113 if (x_min + (u + v) * XDRAW / xmax <= x_max)
114 {
115 if (dogrid)
116 {
117 cairo_stroke(cr);
118 cairo_set_dash (cr, pdashed, lenp, 0.0);
119 cairo_set_line_width (cr, GRIDSIZE);
120 cairo_move_to(cr, x_min + (u + v) * XDRAW / xmax, y_min);
121 cairo_line_to(cr, x_min + (u + v)* XDRAW / xmax, y_max);
122 cairo_stroke(cr);
123 prep_frame (cr, this_proj -> curves[rid][cid] -> frame_dash,
124 this_proj -> curves[rid][cid] -> frame_thickness,
125 this_proj -> curves[rid][cid] -> frame_color);
126 }
127 if (fmod(u+v, mticks) != 0.0)
128 {
129 switch (tickpos)
130 {
131 case 0:
132 cairo_move_to(cr, x_min + (u + v) * XDRAW / xmax, y_min);
133 cairo_line_to(cr, x_min + (u + v) * XDRAW / xmax, y_min + amint);
134 break;
135 case 1:
136 cairo_move_to(cr, x_min + (u + v) * XDRAW / xmax, y_max);
137 cairo_line_to(cr, x_min + (u + v) * XDRAW / xmax, y_max - amint);
138 break;
139 case 2:
140 cairo_move_to(cr, x_min + (u + v) * XDRAW / xmax, y_min);
141 cairo_line_to(cr, x_min + (u + v) * XDRAW / xmax, y_min + amint);
142 cairo_move_to(cr, x_min + (u + v) * XDRAW / xmax, y_max);
143 cairo_line_to(cr, x_min + (u + v) * XDRAW / xmax, y_max - amint);
144 break;
145 }
146 }
147 }
148 cairo_stroke(cr);
149 }
150}
151
163void setup_xaxis_log (cairo_t * cr, project * this_proj, int rid, int cid, gboolean draw_it)
164{
165 int i, k, l;
166 gboolean istrue;
167 double v;
168 istrue = TRUE;
169 xlog = 1;
170 if (cxy[0] != 0.0)
171 {
172 k = (xmax+cxy[0])/cxy[0];
173 }
174 while (istrue)
175 {
176 k = k/10;
177 if (k > 0)
178 {
179 xlog ++;
180 }
181 else
182 {
183 istrue = FALSE;
184 }
185 }
186 istrue = TRUE;
187 dxlog = 0;
188 i = 100;
189 while (istrue)
190 {
191 if (cxy[0] >= pow(10, i))
192 {
193 istrue = FALSE;
194 dxlog --;
195 }
196 else
197 {
198 dxlog ++;
199 i=i-1;
200 }
201 }
202 dxlog = dxlog - 100;
203 if (draw_it)
204 {
205 for ( l = 0 ; l < xlog ; l = l + 1 )
206 {
207 v = pow (10, l-dxlog);
208 if (dogrid)
209 {
210 cairo_stroke(cr);
211 cairo_set_line_width (cr, GRIDSIZE);
212 cairo_set_dash (cr, pdashed, lenp, 0.0);
213 cairo_move_to(cr, x_min + l * XDRAW / xlog, y_min);
214 cairo_line_to(cr, x_min + l * XDRAW / xlog, y_max);
215 cairo_stroke(cr);
216 prep_frame (cr, this_proj -> curves[rid][cid] -> frame_dash,
217 this_proj -> curves[rid][cid] -> frame_thickness,
218 this_proj -> curves[rid][cid] -> frame_color);
219 }
220 switch (labpos)
221 {
222 case 0:
223 ax = x_min - x_shift + l * XDRAW / xlog;
224 ay = y_min + y_shift;
225 label (cr, v, 0, 0, this_proj);
226 break;
227 case 1:
228 ax = x_min - x_shift + l * XDRAW / xlog;
229 ay = y_max - y_shift;
230 label (cr, v, 0, 1, this_proj);
231 break;
232 case 2:
233 ax = x_min - x_shift + l * XDRAW / xlog;
234 ay = y_min + y_shift;
235 label (cr, v, 0, 0, this_proj);
236 ax = x_min - x_shift + l * XDRAW / xlog;
237 ay = y_max - y_shift;
238 label (cr, v, 0, 1, this_proj);
239 break;
240 }
241 switch (tickpos)
242 {
243 case 0:
244 cairo_move_to(cr, x_min + l * XDRAW / xlog, y_min);
245 cairo_line_to(cr, x_min + l * XDRAW / xlog, y_min + amajt);
246 break;
247 case 1:
248 cairo_move_to(cr, x_min + l * XDRAW / xlog, y_max);
249 cairo_line_to(cr, x_min + l * XDRAW / xlog, y_max - amajt);
250 break;
251 case 2:
252 cairo_move_to(cr, x_min + l * XDRAW / xlog, y_min);
253 cairo_line_to(cr, x_min + l * XDRAW / xlog, y_min + amajt);
254 cairo_move_to(cr, x_min + l * XDRAW / xlog, y_max);
255 cairo_line_to(cr, x_min + l * XDRAW / xlog, y_max - amajt);
256 break;
257 }
258 for ( k = 2 ; k < 10 ; k = k + 1 )
259 {
260 if (dogrid)
261 {
262 cairo_stroke(cr);
263 cairo_set_line_width (cr, GRIDSIZE);
264 cairo_set_dash (cr, pdashed, lenp, 0.0);
265 cairo_move_to(cr, x_min + XDRAW * (l + log(k) / log(10.0)) / xlog, y_min);
266 cairo_line_to(cr, x_min + XDRAW * (l + log(k) / log(10.0)) / xlog, y_max);
267 cairo_stroke(cr);
268 prep_frame (cr, this_proj -> curves[rid][cid] -> frame_dash,
269 this_proj -> curves[rid][cid] -> frame_thickness,
270 this_proj -> curves[rid][cid] -> frame_color);
271 }
272 switch (tickpos)
273 {
274 case 0:
275 cairo_move_to(cr, x_min + XDRAW * (l + log(k) / log(10.0)) / xlog, y_min);
276 cairo_line_to(cr, x_min + XDRAW * (l + log(k) / log(10.0)) / xlog, y_min + amint);
277 break;
278 case 1:
279 cairo_move_to(cr, x_min + XDRAW * (l + log(k) / log(10.0)) / xlog, y_max);
280 cairo_line_to(cr, x_min + XDRAW * (l + log(k) / log(10.0)) / xlog, y_max - amint);
281 break;
282 case 2:
283 cairo_move_to(cr, x_min + XDRAW * (l + log(k) / log(10.0)) / xlog, y_min);
284 cairo_line_to(cr, x_min + XDRAW * (l + log(k) / log(10.0)) / xlog, y_min + amint);
285 cairo_move_to(cr, x_min + XDRAW * (l + log(k) / log(10.0)) / xlog, y_max);
286 cairo_line_to(cr, x_min + XDRAW * (l + log(k) / log(10.0)) / xlog, y_max - amint);
287 break;
288 }
289 }
290 }
291 cairo_stroke (cr);
292 }
293}
int tickpos
Definition curve.c:83
int xlog
Definition curve.c:74
int labpos
Definition curve.c:83
double ay
Definition curve.c:70
double cxy[2]
Definition curve.c:71
double xmax
Definition curve.c:67
double mticks
Definition curve.c:72
const double pdashed[]
Definition curve.c:124
double XDRAW
Definition curve.c:65
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 dxlog
Definition curve.c:75
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
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
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...
void setup_xaxis_log(cairo_t *cr, project *this_proj, int rid, int cid, gboolean draw_it)
setup x axis using a log scale
Definition xaxis.c:163
void setup_xaxis_linear(cairo_t *cr, project *this_proj, int rid, int cid)
setup x axis using a linear scale
Definition xaxis.c:54