]> git.tdb.fi Git - ext/subsurface.git/blob - profile.c
Add helper function for doing depth unit calculations
[ext/subsurface.git] / profile.c
1 /* profile.c */
2 /* creates all the necessary data for drawing the dive profile 
3  * uses cairo to draw it
4  */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <stdarg.h>
8 #include <string.h>
9 #include <time.h>
10
11 #include "dive.h"
12 #include "display.h"
13 #include "divelist.h"
14
15 int selected_dive = 0;
16
17 typedef enum { STABLE, SLOW, MODERATE, FAST, CRAZY } velocity_t;
18 /* Plot info with smoothing, velocity indication
19  * and one-, two- and three-minute minimums and maximums */
20 struct plot_info {
21         int nr;
22         int maxtime;
23         int meandepth, maxdepth;
24         int minpressure, maxpressure;
25         int mintemp, maxtemp;
26         struct plot_data {
27                 int sec;
28                 int pressure, temperature;
29                 /* Depth info */
30                 int val;
31                 int smoothed;
32                 velocity_t velocity;
33                 struct plot_data *min[3];
34                 struct plot_data *max[3];
35                 int avg[3];
36         } entry[];
37 };
38
39 /* convert velocity to colors */
40 typedef struct { double r, g, b; } rgb_t;
41 static const rgb_t rgb[] = {
42         [STABLE]   = {0.0, 0.4, 0.0},
43         [SLOW]     = {0.4, 0.8, 0.0},
44         [MODERATE] = {0.8, 0.8, 0.0},
45         [FAST]     = {0.8, 0.5, 0.0},
46         [CRAZY]    = {1.0, 0.0, 0.0},
47 };
48
49 #define plot_info_size(nr) (sizeof(struct plot_info) + (nr)*sizeof(struct plot_data))
50
51 /* Scale to 0,0 -> maxx,maxy */
52 #define SCALEX(gc,x)  (((x)-gc->leftx)/(gc->rightx-gc->leftx)*gc->maxx)
53 #define SCALEY(gc,y)  (((y)-gc->topy)/(gc->bottomy-gc->topy)*gc->maxy)
54 #define SCALE(gc,x,y) SCALEX(gc,x),SCALEY(gc,y)
55
56 static void move_to(struct graphics_context *gc, double x, double y)
57 {
58         cairo_move_to(gc->cr, SCALE(gc, x, y));
59 }
60
61 static void line_to(struct graphics_context *gc, double x, double y)
62 {
63         cairo_line_to(gc->cr, SCALE(gc, x, y));
64 }
65
66 static void set_source_rgba(struct graphics_context *gc, double r, double g, double b, double a)
67 {
68         /*
69          * For printers, we still honor 'a', but ignore colors
70          * for now. Black is white and white is black
71          */
72         if (gc->printer) {
73                 double sum = r+g+b;
74                 if (sum > 0.8)
75                         r = g = b = 0;
76                 else
77                         r = g = b = 1;
78         }
79         cairo_set_source_rgba(gc->cr, r, g, b, a);
80 }
81
82 void set_source_rgb(struct graphics_context *gc, double r, double g, double b)
83 {
84         set_source_rgba(gc, r, g, b, 1);
85 }
86
87 #define ROUND_UP(x,y) ((((x)+(y)-1)/(y))*(y))
88
89 /*
90  * When showing dive profiles, we scale things to the
91  * current dive. However, we don't scale past less than
92  * 30 minutes or 90 ft, just so that small dives show
93  * up as such.
94  * we also need to add 180 seconds at the end so the min/max
95  * plots correctly
96  */
97 static int get_maxtime(struct plot_info *pi)
98 {
99         int seconds = pi->maxtime;
100         /* min 30 minutes, rounded up to 5 minutes, with at least 2.5 minutes to spare */
101         return MAX(30*60, ROUND_UP(seconds+150, 60*5));
102 }
103
104 static int get_maxdepth(struct plot_info *pi)
105 {
106         unsigned mm = pi->maxdepth;
107         /* Minimum 30m, rounded up to 10m, with at least 3m to spare */
108         return MAX(30000, ROUND_UP(mm+3000, 10000));
109 }
110
111 typedef struct {
112         int size;
113         double r,g,b;
114         double hpos, vpos;
115 } text_render_options_t;
116
117 #define RIGHT (-1.0)
118 #define CENTER (-0.5)
119 #define LEFT (0.0)
120
121 #define TOP (1)
122 #define MIDDLE (0)
123 #define BOTTOM (-1)
124
125 static void plot_text(struct graphics_context *gc, const text_render_options_t *tro,
126                       double x, double y, const char *fmt, ...)
127 {
128         cairo_t *cr = gc->cr;
129         cairo_font_extents_t fe;
130         cairo_text_extents_t extents;
131         double dx, dy;
132         char buffer[80];
133         va_list args;
134
135         va_start(args, fmt);
136         vsnprintf(buffer, sizeof(buffer), fmt, args);
137         va_end(args);
138
139         cairo_set_font_size(cr, tro->size);
140         cairo_font_extents(cr, &fe);
141         cairo_text_extents(cr, buffer, &extents);
142         dx = tro->hpos * extents.width + extents.x_bearing;
143         dy = tro->vpos * extents.height + fe.descent;
144
145         move_to(gc, x, y);
146         cairo_rel_move_to(cr, dx, dy);
147
148         cairo_text_path(cr, buffer);
149         set_source_rgb(gc, 0, 0, 0);
150         cairo_stroke(cr);
151
152         move_to(gc, x, y);
153         cairo_rel_move_to(cr, dx, dy);
154
155         set_source_rgb(gc, tro->r, tro->g, tro->b);
156         cairo_show_text(cr, buffer);
157 }
158
159 static void render_depth_sample(struct graphics_context *gc, struct plot_data *entry, const text_render_options_t *tro)
160 {
161         int sec = entry->sec, decimals;
162         double d;
163
164         d = get_depth_units(entry->val, &decimals, NULL);
165
166         plot_text(gc, tro, sec, entry->val, "%.*f", decimals, d);
167 }
168
169 static void plot_text_samples(struct graphics_context *gc, struct plot_info *pi)
170 {
171         static const text_render_options_t deep = {14, 1.0, 0.2, 0.2, CENTER, TOP};
172         static const text_render_options_t shallow = {14, 1.0, 0.2, 0.2, CENTER, BOTTOM};
173         int i;
174
175         for (i = 0; i < pi->nr; i++) {
176                 struct plot_data *entry = pi->entry + i;
177
178                 if (entry->val < 2000)
179                         continue;
180
181                 if (entry == entry->max[2])
182                         render_depth_sample(gc, entry, &deep);
183
184                 if (entry == entry->min[2])
185                         render_depth_sample(gc, entry, &shallow);
186         }
187 }
188
189 static void plot_depth_text(struct graphics_context *gc, struct plot_info *pi)
190 {
191         int maxtime, maxdepth;
192
193         /* Get plot scaling limits */
194         maxtime = get_maxtime(pi);
195         maxdepth = get_maxdepth(pi);
196
197         gc->leftx = 0; gc->rightx = maxtime;
198         gc->topy = 0; gc->bottomy = maxdepth;
199
200         plot_text_samples(gc, pi);
201 }
202
203 static void plot_smoothed_profile(struct graphics_context *gc, struct plot_info *pi)
204 {
205         int i;
206         struct plot_data *entry = pi->entry;
207
208         set_source_rgba(gc, 1, 0.2, 0.2, 0.20);
209         move_to(gc, entry->sec, entry->smoothed);
210         for (i = 1; i < pi->nr; i++) {
211                 entry++;
212                 line_to(gc, entry->sec, entry->smoothed);
213         }
214         cairo_stroke(gc->cr);
215 }
216
217 static void plot_minmax_profile_minute(struct graphics_context *gc, struct plot_info *pi,
218                                 int index, double a)
219 {
220         int i;
221         struct plot_data *entry = pi->entry;
222
223         set_source_rgba(gc, 1, 0.2, 1, a);
224         move_to(gc, entry->sec, entry->min[index]->val);
225         for (i = 1; i < pi->nr; i++) {
226                 entry++;
227                 line_to(gc, entry->sec, entry->min[index]->val);
228         }
229         for (i = 1; i < pi->nr; i++) {
230                 line_to(gc, entry->sec, entry->max[index]->val);
231                 entry--;
232         }
233         cairo_close_path(gc->cr);
234         cairo_fill(gc->cr);
235 }
236
237 static void plot_minmax_profile(struct graphics_context *gc, struct plot_info *pi)
238 {
239         if (gc->printer)
240                 return;
241         plot_minmax_profile_minute(gc, pi, 2, 0.1);
242         plot_minmax_profile_minute(gc, pi, 1, 0.1);
243         plot_minmax_profile_minute(gc, pi, 0, 0.1);
244 }
245
246 static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi)
247 {
248         int i;
249         cairo_t *cr = gc->cr;
250         int sec, depth;
251         struct plot_data *entry;
252         int maxtime, maxdepth, marker;
253
254         /* Get plot scaling limits */
255         maxtime = get_maxtime(pi);
256         maxdepth = get_maxdepth(pi);
257
258         /* Time markers: every 5 min */
259         gc->leftx = 0; gc->rightx = maxtime;
260         gc->topy = 0; gc->bottomy = 1.0;
261         for (i = 5*60; i < maxtime; i += 5*60) {
262                 move_to(gc, i, 0);
263                 line_to(gc, i, 1);
264         }
265
266         /* Depth markers: every 30 ft or 10 m*/
267         gc->leftx = 0; gc->rightx = 1.0;
268         gc->topy = 0; gc->bottomy = maxdepth;
269         switch (output_units.length) {
270         case METERS: marker = 10000; break;
271         case FEET: marker = 9144; break;        /* 30 ft */
272         }
273
274         set_source_rgba(gc, 1, 1, 1, 0.5);
275         for (i = marker; i < maxdepth; i += marker) {
276                 move_to(gc, 0, i);
277                 line_to(gc, 1, i);
278         }
279         cairo_stroke(cr);
280
281         /* Show mean depth */
282         set_source_rgba(gc, 1, 0.2, 0.2, 0.40);
283         move_to(gc, 0, pi->meandepth);
284         line_to(gc, 1, pi->meandepth);
285         cairo_stroke(cr);
286
287         gc->leftx = 0; gc->rightx = maxtime;
288
289         /*
290          * These are good for debugging text placement etc,
291          * but not for actual display..
292          */
293         if (0) {
294                 plot_smoothed_profile(gc, pi);
295                 plot_minmax_profile(gc, pi);
296         }
297
298         set_source_rgba(gc, 1, 0.2, 0.2, 0.80);
299
300         /* Do the depth profile for the neat fill */
301         gc->topy = 0; gc->bottomy = maxdepth;
302         set_source_rgba(gc, 1, 0.2, 0.2, 0.20);
303
304         entry = pi->entry;
305         move_to(gc, 0, 0);
306         for (i = 0; i < pi->nr; i++, entry++)
307                 line_to(gc, entry->sec, entry->val);
308         cairo_close_path(gc->cr);
309         if (gc->printer) {
310                 set_source_rgba(gc, 1, 1, 1, 0.2);
311                 cairo_fill_preserve(cr);
312                 set_source_rgb(gc, 1, 1, 1);
313                 cairo_stroke(cr);
314                 return;
315         }
316         cairo_fill(gc->cr);
317
318         /* Now do it again for the velocity colors */
319         entry = pi->entry;
320         for (i = 1; i < pi->nr; i++) {
321                 entry++;
322                 sec = entry->sec;
323                 /* we want to draw the segments in different colors
324                  * representing the vertical velocity, so we need to
325                  * chop this into short segments */
326                 rgb_t color = rgb[entry->velocity];
327                 depth = entry->val;
328                 set_source_rgb(gc, color.r, color.g, color.b);
329                 move_to(gc, entry[-1].sec, entry[-1].val);
330                 line_to(gc, sec, depth);
331                 cairo_stroke(cr);
332         }
333 }
334
335 static int setup_temperature_limits(struct graphics_context *gc, struct plot_info *pi)
336 {
337         int maxtime, mintemp, maxtemp, delta;
338
339         /* Get plot scaling limits */
340         maxtime = get_maxtime(pi);
341         mintemp = pi->mintemp;
342         maxtemp = pi->maxtemp;
343
344         gc->leftx = 0; gc->rightx = maxtime;
345         /* Show temperatures in roughly the lower third, but make sure the scale
346            is at least somewhat reasonable */
347         delta = maxtemp - mintemp;
348         if (delta > 3000) { /* more than 3K in fluctuation */
349                 gc->topy = maxtemp + delta*2;
350                 gc->bottomy = mintemp - delta/2;
351         } else {
352                 gc->topy = maxtemp + 1500 + delta*2;
353                 gc->bottomy = mintemp - delta/2;
354         }
355
356         return maxtemp > mintemp;
357 }
358
359 static void plot_single_temp_text(struct graphics_context *gc, int sec, int mkelvin)
360 {
361         int deg;
362         const char *unit;
363         static const text_render_options_t tro = {12, 0.2, 0.2, 1.0, LEFT, TOP};
364         temperature_t temperature = { mkelvin };
365
366         if (output_units.temperature == FAHRENHEIT) {
367                 deg = to_F(temperature);
368                 unit = UTF8_DEGREE "F";
369         } else {
370                 deg = to_C(temperature);
371                 unit = UTF8_DEGREE "C";
372         }
373         plot_text(gc, &tro, sec, temperature.mkelvin, "%d%s", deg, unit);
374 }
375
376 static void plot_temperature_text(struct graphics_context *gc, struct plot_info *pi)
377 {
378         int i;
379         int last = 0, sec = 0;
380         int last_temperature = 0, last_printed_temp = 0;
381
382         if (!setup_temperature_limits(gc, pi))
383                 return;
384
385         for (i = 0; i < pi->nr; i++) {
386                 struct plot_data *entry = pi->entry+i;
387                 int mkelvin = entry->temperature;
388
389                 if (!mkelvin)
390                         continue;
391                 last_temperature = mkelvin;
392                 sec = entry->sec;
393                 if (sec < last + 300)
394                         continue;
395                 last = sec;
396                 plot_single_temp_text(gc,sec,mkelvin);
397                 last_printed_temp = mkelvin;
398         }
399         /* it would be nice to print the end temperature, if it's different */
400         if (abs(last_temperature - last_printed_temp) > 500)
401                 plot_single_temp_text(gc, sec, last_temperature);
402 }
403
404 static void plot_temperature_profile(struct graphics_context *gc, struct plot_info *pi)
405 {
406         int i;
407         cairo_t *cr = gc->cr;
408         int last = 0;
409
410         if (!setup_temperature_limits(gc, pi))
411                 return;
412
413         set_source_rgba(gc, 0.2, 0.2, 1.0, 0.8);
414         for (i = 0; i < pi->nr; i++) {
415                 struct plot_data *entry = pi->entry + i;
416                 int mkelvin = entry->temperature;
417                 int sec = entry->sec;
418                 if (!mkelvin) {
419                         if (!last)
420                                 continue;
421                         mkelvin = last;
422                 }
423                 if (last)
424                         line_to(gc, sec, mkelvin);
425                 else
426                         move_to(gc, sec, mkelvin);
427                 last = mkelvin;
428         }
429         cairo_stroke(cr);
430 }
431
432 /* gets both the actual start and end pressure as well as the scaling factors */
433 static int get_cylinder_pressure_range(struct graphics_context *gc, struct plot_info *pi)
434 {
435         gc->leftx = 0;
436         gc->rightx = get_maxtime(pi);
437
438         gc->bottomy = 0; gc->topy = pi->maxpressure * 1.5;
439         return pi->maxpressure != 0;
440 }
441
442 static void plot_cylinder_pressure(struct graphics_context *gc, struct plot_info *pi)
443 {
444         int i;
445
446         if (!get_cylinder_pressure_range(gc, pi))
447                 return;
448
449         set_source_rgba(gc, 0.2, 1.0, 0.2, 0.80);
450
451         move_to(gc, 0, pi->maxpressure);
452         for (i = 1; i < pi->nr; i++) {
453                 int mbar;
454                 struct plot_data *entry = pi->entry + i;
455
456                 mbar = entry->pressure;
457                 if (!mbar)
458                         continue;
459                 line_to(gc, entry->sec, mbar);
460         }
461         line_to(gc, pi->maxtime, pi->minpressure);
462         cairo_stroke(gc->cr);
463 }
464
465 static int mbar_to_PSI(int mbar)
466 {
467         pressure_t p = {mbar};
468         return to_PSI(p);
469 }
470
471 static void plot_cylinder_pressure_text(struct graphics_context *gc, struct plot_info *pi)
472 {
473         if (get_cylinder_pressure_range(gc, pi)) {
474                 int start, end;
475                 const char *unit = "bar";
476
477                 switch (output_units.pressure) {
478                 case PASCAL:
479                         start = pi->maxpressure * 100;
480                         end = pi->minpressure * 100;
481                         unit = "pascal";
482                         break;
483                 case BAR:
484                         start = (pi->maxpressure + 500) / 1000;
485                         end = (pi->minpressure + 500) / 1000;
486                         unit = "bar";
487                         break;
488                 case PSI:
489                         start = mbar_to_PSI(pi->maxpressure);
490                         end = mbar_to_PSI(pi->minpressure);
491                         unit = "psi";
492                         break;
493                 }
494
495                 text_render_options_t tro = {10, 0.2, 1.0, 0.2, LEFT, TOP};
496                 plot_text(gc, &tro, 0, pi->maxpressure, "%d %s", start, unit);
497                 plot_text(gc, &tro, pi->maxtime, pi->minpressure,
498                           "%d %s", end, unit);
499         }
500 }
501
502 static void analyze_plot_info_minmax_minute(struct plot_data *entry, struct plot_data *first, struct plot_data *last, int index)
503 {
504         struct plot_data *p = entry;
505         int time = entry->sec;
506         int seconds = 90*(index+1);
507         struct plot_data *min, *max;
508         int avg, nr;
509
510         /* Go back 'seconds' in time */
511         while (p > first) {
512                 if (p[-1].sec < time - seconds)
513                         break;
514                 p--;
515         }
516
517         /* Then go forward until we hit an entry past the time */
518         min = max = p;
519         avg = p->val;
520         nr = 1;
521         while (++p < last) {
522                 int val = p->val;
523                 if (p->sec > time + seconds)
524                         break;
525                 avg += val;
526                 nr ++;
527                 if (val < min->val)
528                         min = p;
529                 if (val > max->val)
530                         max = p;
531         }
532         entry->min[index] = min;
533         entry->max[index] = max;
534         entry->avg[index] = (avg + nr/2) / nr;
535 }
536
537 static void analyze_plot_info_minmax(struct plot_data *entry, struct plot_data *first, struct plot_data *last)
538 {
539         analyze_plot_info_minmax_minute(entry, first, last, 0);
540         analyze_plot_info_minmax_minute(entry, first, last, 1);
541         analyze_plot_info_minmax_minute(entry, first, last, 2);
542 }
543
544 static velocity_t velocity(int speed)
545 {
546         velocity_t v;
547
548         if (speed < -304) /* ascent faster than -60ft/min */
549                 v = CRAZY;
550         else if (speed < -152) /* above -30ft/min */
551                 v = FAST;
552         else if (speed < -76) /* -15ft/min */
553                 v = MODERATE;
554         else if (speed < -25) /* -5ft/min */
555                 v = SLOW;
556         else if (speed < 25) /* very hard to find data, but it appears that the recommendations
557                                 for descent are usually about 2x ascent rate; still, we want 
558                                 stable to mean stable */
559                 v = STABLE;
560         else if (speed < 152) /* between 5 and 30ft/min is considered slow */
561                 v = SLOW;
562         else if (speed < 304) /* up to 60ft/min is moderate */
563                 v = MODERATE;
564         else if (speed < 507) /* up to 100ft/min is fast */
565                 v = FAST;
566         else /* more than that is just crazy - you'll blow your ears out */
567                 v = CRAZY;
568
569         return v;
570 }
571 static struct plot_info *analyze_plot_info(struct plot_info *pi)
572 {
573         int i;
574         int nr = pi->nr;
575
576         /* Do pressure min/max based on the non-surface data */
577         for (i = 0; i < nr; i++) {
578                 struct plot_data *entry = pi->entry+i;
579                 int pressure = entry->pressure;
580                 int temperature = entry->temperature;
581
582                 if (pressure) {
583                         if (!pi->minpressure || pressure < pi->minpressure)
584                                 pi->minpressure = pressure;
585                         if (pressure > pi->maxpressure)
586                                 pi->maxpressure = pressure;
587                 }
588
589                 if (temperature) {
590                         if (!pi->mintemp || temperature < pi->mintemp)
591                                 pi->mintemp = temperature;
592                         if (temperature > pi->maxtemp)
593                                 pi->maxtemp = temperature;
594                 }
595         }
596
597         /* Smoothing function: 5-point triangular smooth */
598         for (i = 2; i < nr-1; i++) {
599                 struct plot_data *entry = pi->entry+i;
600                 int val;
601
602                 if (i < nr-2) {
603                         val = entry[-2].val + 2*entry[-1].val + 3*entry[0].val + 2*entry[1].val + entry[2].val;
604                         entry->smoothed = (val+4) / 9;
605                 }
606                 /* vertical velocity in mm/sec */
607                 /* Linus wants to smooth this - let's at least look at the samples that aren't FAST or CRAZY */
608                 if (entry[0].sec - entry[-1].sec) {
609                         entry->velocity = velocity((entry[0].val - entry[-1].val) / (entry[0].sec - entry[-1].sec));
610                         /* if our samples are short and we aren't too FAST*/
611                         if (entry[0].sec - entry[-1].sec < 30 && entry->velocity < FAST) { 
612                                 int past = -2;
613                                 while (i+past > 0 && entry[0].sec - entry[past].sec < 30)
614                                         past--;
615                                 entry->velocity = velocity((entry[0].val - entry[past].val) / 
616                                                         (entry[0].sec - entry[past].sec));
617                         }
618                 } else
619                         entry->velocity = STABLE;
620         }
621
622         /* One-, two- and three-minute minmax data */
623         for (i = 0; i < nr; i++) {
624                 struct plot_data *entry = pi->entry +i;
625                 analyze_plot_info_minmax(entry, pi->entry, pi->entry+nr);
626         }
627         
628         return pi;
629 }
630
631 /*
632  * Create a plot-info with smoothing and ranged min/max
633  *
634  * This also makes sure that we have extra empty events on both
635  * sides, so that you can do end-points without having to worry
636  * about it.
637  */
638 static struct plot_info *create_plot_info(struct dive *dive)
639 {
640         int lastdepth, lastindex;
641         int i, nr = dive->samples + 4, sec;
642         size_t alloc_size = plot_info_size(nr);
643         struct plot_info *pi;
644
645         pi = malloc(alloc_size);
646         if (!pi)
647                 return pi;
648         memset(pi, 0, alloc_size);
649         pi->nr = nr;
650         sec = 0;
651         lastindex = 0;
652         lastdepth = -1;
653         for (i = 0; i < dive->samples; i++) {
654                 int depth;
655                 struct sample *sample = dive->sample+i;
656                 struct plot_data *entry = pi->entry + i + 2;
657
658                 sec = entry->sec = sample->time.seconds;
659                 depth = entry->val = sample->depth.mm;
660                 entry->pressure = sample->cylinderpressure.mbar;
661                 entry->temperature = sample->temperature.mkelvin;
662
663                 if (depth || lastdepth)
664                         lastindex = i+2;
665
666                 lastdepth = depth;
667                 if (depth > pi->maxdepth)
668                         pi->maxdepth = depth;
669         }
670         if (lastdepth)
671                 lastindex = i + 2;
672         /* Fill in the last two entries with empty values but valid times */
673         i = dive->samples + 2;
674         pi->entry[i].sec = sec + 20;
675         pi->entry[i+1].sec = sec + 40;
676
677         pi->nr = lastindex+1;
678         pi->maxtime = pi->entry[lastindex].sec;
679
680         pi->minpressure = dive->cylinder[0].end.mbar;
681         pi->maxpressure = dive->cylinder[0].start.mbar;
682
683         pi->meandepth = dive->meandepth.mm;
684
685         return analyze_plot_info(pi);
686 }
687
688 void plot(struct graphics_context *gc, int w, int h, struct dive *dive)
689 {
690         double topx, topy;
691         struct plot_info *pi = create_plot_info(dive);
692
693         topx = w / 20.0;
694         topy = h / 20.0;
695         cairo_translate(gc->cr, topx, topy);
696         cairo_set_line_width(gc->cr, 2);
697         cairo_set_line_cap(gc->cr, CAIRO_LINE_CAP_ROUND);
698         cairo_set_line_join(gc->cr, CAIRO_LINE_JOIN_ROUND);
699
700         /*
701          * We can use "cairo_translate()" because that doesn't
702          * scale line width etc. But the actual scaling we need
703          * do set up ourselves..
704          *
705          * Snif. What a pity.
706          */
707         gc->maxx = (w - 2*topx);
708         gc->maxy = (h - 2*topy);
709
710         /* Temperature profile */
711         plot_temperature_profile(gc, pi);
712
713         /* Cylinder pressure plot */
714         plot_cylinder_pressure(gc, pi);
715
716         /* Depth profile */
717         plot_depth_profile(gc, pi);
718
719         /* Text on top of all graphs.. */
720         plot_temperature_text(gc, pi);
721         plot_depth_text(gc, pi);
722         plot_cylinder_pressure_text(gc, pi);
723
724         /* Bounding box last */
725         gc->leftx = 0; gc->rightx = 1.0;
726         gc->topy = 0; gc->bottomy = 1.0;
727
728         set_source_rgb(gc, 1, 1, 1);
729         move_to(gc, 0, 0);
730         line_to(gc, 0, 1);
731         line_to(gc, 1, 1);
732         line_to(gc, 1, 0);
733         cairo_close_path(gc->cr);
734         cairo_stroke(gc->cr);
735
736         free(pi);
737 }