]> git.tdb.fi Git - ext/subsurface.git/blob - profile.c
Fix up printing some more
[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;
162         depth_t depth = { entry->val };
163         const char *fmt;
164         double d;
165
166         switch (output_units.length) {
167         case METERS:
168                 d = depth.mm / 1000.0;
169                 fmt = "%.1f";
170                 break;
171         case FEET:
172                 d = to_feet(depth);
173                 fmt = "%.0f";
174                 break;
175         }
176         plot_text(gc, tro, sec, depth.mm, fmt, d);
177 }
178
179 static void plot_text_samples(struct graphics_context *gc, struct plot_info *pi)
180 {
181         static const text_render_options_t deep = {14, 1.0, 0.2, 0.2, CENTER, TOP};
182         static const text_render_options_t shallow = {14, 1.0, 0.2, 0.2, CENTER, BOTTOM};
183         int i;
184
185         for (i = 0; i < pi->nr; i++) {
186                 struct plot_data *entry = pi->entry + i;
187
188                 if (entry->val < 2000)
189                         continue;
190
191                 if (entry == entry->max[2])
192                         render_depth_sample(gc, entry, &deep);
193
194                 if (entry == entry->min[2])
195                         render_depth_sample(gc, entry, &shallow);
196         }
197 }
198
199 static void plot_depth_text(struct graphics_context *gc, struct plot_info *pi)
200 {
201         int maxtime, maxdepth;
202
203         /* Get plot scaling limits */
204         maxtime = get_maxtime(pi);
205         maxdepth = get_maxdepth(pi);
206
207         gc->leftx = 0; gc->rightx = maxtime;
208         gc->topy = 0; gc->bottomy = maxdepth;
209
210         plot_text_samples(gc, pi);
211 }
212
213 static void plot_smoothed_profile(struct graphics_context *gc, struct plot_info *pi)
214 {
215         int i;
216         struct plot_data *entry = pi->entry;
217
218         set_source_rgba(gc, 1, 0.2, 0.2, 0.20);
219         move_to(gc, entry->sec, entry->smoothed);
220         for (i = 1; i < pi->nr; i++) {
221                 entry++;
222                 line_to(gc, entry->sec, entry->smoothed);
223         }
224         cairo_stroke(gc->cr);
225 }
226
227 static void plot_minmax_profile_minute(struct graphics_context *gc, struct plot_info *pi,
228                                 int index, double a)
229 {
230         int i;
231         struct plot_data *entry = pi->entry;
232
233         set_source_rgba(gc, 1, 0.2, 1, a);
234         move_to(gc, entry->sec, entry->min[index]->val);
235         for (i = 1; i < pi->nr; i++) {
236                 entry++;
237                 line_to(gc, entry->sec, entry->min[index]->val);
238         }
239         for (i = 1; i < pi->nr; i++) {
240                 line_to(gc, entry->sec, entry->max[index]->val);
241                 entry--;
242         }
243         cairo_close_path(gc->cr);
244         cairo_fill(gc->cr);
245 }
246
247 static void plot_minmax_profile(struct graphics_context *gc, struct plot_info *pi)
248 {
249         if (gc->printer)
250                 return;
251         plot_minmax_profile_minute(gc, pi, 2, 0.1);
252         plot_minmax_profile_minute(gc, pi, 1, 0.1);
253         plot_minmax_profile_minute(gc, pi, 0, 0.1);
254 }
255
256 static void plot_depth_profile(struct graphics_context *gc, struct plot_info *pi)
257 {
258         int i;
259         cairo_t *cr = gc->cr;
260         int sec, depth;
261         struct plot_data *entry;
262         int maxtime, maxdepth, marker;
263
264         /* Get plot scaling limits */
265         maxtime = get_maxtime(pi);
266         maxdepth = get_maxdepth(pi);
267
268         /* Time markers: every 5 min */
269         gc->leftx = 0; gc->rightx = maxtime;
270         gc->topy = 0; gc->bottomy = 1.0;
271         for (i = 5*60; i < maxtime; i += 5*60) {
272                 move_to(gc, i, 0);
273                 line_to(gc, i, 1);
274         }
275
276         /* Depth markers: every 30 ft or 10 m*/
277         gc->leftx = 0; gc->rightx = 1.0;
278         gc->topy = 0; gc->bottomy = maxdepth;
279         switch (output_units.length) {
280         case METERS: marker = 10000; break;
281         case FEET: marker = 9144; break;        /* 30 ft */
282         }
283
284         set_source_rgba(gc, 1, 1, 1, 0.5);
285         for (i = marker; i < maxdepth; i += marker) {
286                 move_to(gc, 0, i);
287                 line_to(gc, 1, i);
288         }
289         cairo_stroke(cr);
290
291         /* Show mean depth */
292         set_source_rgba(gc, 1, 0.2, 0.2, 0.40);
293         move_to(gc, 0, pi->meandepth);
294         line_to(gc, 1, pi->meandepth);
295         cairo_stroke(cr);
296
297         gc->leftx = 0; gc->rightx = maxtime;
298
299         /*
300          * These are good for debugging text placement etc,
301          * but not for actual display..
302          */
303         if (0) {
304                 plot_smoothed_profile(gc, pi);
305                 plot_minmax_profile(gc, pi);
306         }
307
308         set_source_rgba(gc, 1, 0.2, 0.2, 0.80);
309
310         /* Do the depth profile for the neat fill */
311         gc->topy = 0; gc->bottomy = maxdepth;
312         set_source_rgba(gc, 1, 0.2, 0.2, 0.20);
313
314         entry = pi->entry;
315         move_to(gc, 0, 0);
316         for (i = 0; i < pi->nr; i++, entry++)
317                 line_to(gc, entry->sec, entry->val);
318         cairo_close_path(gc->cr);
319         if (gc->printer) {
320                 set_source_rgba(gc, 1, 1, 1, 0.2);
321                 cairo_fill_preserve(cr);
322                 set_source_rgb(gc, 1, 1, 1);
323                 cairo_stroke(cr);
324                 return;
325         }
326         cairo_fill(gc->cr);
327
328         /* Now do it again for the velocity colors */
329         entry = pi->entry;
330         for (i = 1; i < pi->nr; i++) {
331                 entry++;
332                 sec = entry->sec;
333                 /* we want to draw the segments in different colors
334                  * representing the vertical velocity, so we need to
335                  * chop this into short segments */
336                 rgb_t color = rgb[entry->velocity];
337                 depth = entry->val;
338                 set_source_rgb(gc, color.r, color.g, color.b);
339                 move_to(gc, entry[-1].sec, entry[-1].val);
340                 line_to(gc, sec, depth);
341                 cairo_stroke(cr);
342         }
343 }
344
345 static int setup_temperature_limits(struct graphics_context *gc, struct plot_info *pi)
346 {
347         int maxtime, mintemp, maxtemp, delta;
348
349         /* Get plot scaling limits */
350         maxtime = get_maxtime(pi);
351         mintemp = pi->mintemp;
352         maxtemp = pi->maxtemp;
353
354         gc->leftx = 0; gc->rightx = maxtime;
355         /* Show temperatures in roughly the lower third, but make sure the scale
356            is at least somewhat reasonable */
357         delta = maxtemp - mintemp;
358         if (delta > 3000) { /* more than 3K in fluctuation */
359                 gc->topy = maxtemp + delta*2;
360                 gc->bottomy = mintemp - delta/2;
361         } else {
362                 gc->topy = maxtemp + 1500 + delta*2;
363                 gc->bottomy = mintemp - delta/2;
364         }
365
366         return maxtemp > mintemp;
367 }
368
369 static void plot_single_temp_text(struct graphics_context *gc, int sec, int mkelvin)
370 {
371         int deg;
372         const char *unit;
373         static const text_render_options_t tro = {12, 0.2, 0.2, 1.0, LEFT, TOP};
374         temperature_t temperature = { mkelvin };
375
376         if (output_units.temperature == FAHRENHEIT) {
377                 deg = to_F(temperature);
378                 unit = UTF8_DEGREE "F";
379         } else {
380                 deg = to_C(temperature);
381                 unit = UTF8_DEGREE "C";
382         }
383         plot_text(gc, &tro, sec, temperature.mkelvin, "%d%s", deg, unit);
384 }
385
386 static void plot_temperature_text(struct graphics_context *gc, struct plot_info *pi)
387 {
388         int i;
389         int last = 0, sec = 0;
390         int last_temperature = 0, last_printed_temp = 0;
391
392         if (!setup_temperature_limits(gc, pi))
393                 return;
394
395         for (i = 0; i < pi->nr; i++) {
396                 struct plot_data *entry = pi->entry+i;
397                 int mkelvin = entry->temperature;
398
399                 if (!mkelvin)
400                         continue;
401                 last_temperature = mkelvin;
402                 sec = entry->sec;
403                 if (sec < last + 300)
404                         continue;
405                 last = sec;
406                 plot_single_temp_text(gc,sec,mkelvin);
407                 last_printed_temp = mkelvin;
408         }
409         /* it would be nice to print the end temperature, if it's different */
410         if (abs(last_temperature - last_printed_temp) > 500)
411                 plot_single_temp_text(gc, sec, last_temperature);
412 }
413
414 static void plot_temperature_profile(struct graphics_context *gc, struct plot_info *pi)
415 {
416         int i;
417         cairo_t *cr = gc->cr;
418         int last = 0;
419
420         if (!setup_temperature_limits(gc, pi))
421                 return;
422
423         set_source_rgba(gc, 0.2, 0.2, 1.0, 0.8);
424         for (i = 0; i < pi->nr; i++) {
425                 struct plot_data *entry = pi->entry + i;
426                 int mkelvin = entry->temperature;
427                 int sec = entry->sec;
428                 if (!mkelvin) {
429                         if (!last)
430                                 continue;
431                         mkelvin = last;
432                 }
433                 if (last)
434                         line_to(gc, sec, mkelvin);
435                 else
436                         move_to(gc, sec, mkelvin);
437                 last = mkelvin;
438         }
439         cairo_stroke(cr);
440 }
441
442 /* gets both the actual start and end pressure as well as the scaling factors */
443 static int get_cylinder_pressure_range(struct graphics_context *gc, struct plot_info *pi)
444 {
445         gc->leftx = 0;
446         gc->rightx = get_maxtime(pi);
447
448         gc->bottomy = 0; gc->topy = pi->maxpressure * 1.5;
449         return pi->maxpressure != 0;
450 }
451
452 static void plot_cylinder_pressure(struct graphics_context *gc, struct plot_info *pi)
453 {
454         int i;
455
456         if (!get_cylinder_pressure_range(gc, pi))
457                 return;
458
459         set_source_rgba(gc, 0.2, 1.0, 0.2, 0.80);
460
461         move_to(gc, 0, pi->maxpressure);
462         for (i = 1; i < pi->nr; i++) {
463                 int mbar;
464                 struct plot_data *entry = pi->entry + i;
465
466                 mbar = entry->pressure;
467                 if (!mbar)
468                         continue;
469                 line_to(gc, entry->sec, mbar);
470         }
471         line_to(gc, pi->maxtime, pi->minpressure);
472         cairo_stroke(gc->cr);
473 }
474
475 static int mbar_to_PSI(int mbar)
476 {
477         pressure_t p = {mbar};
478         return to_PSI(p);
479 }
480
481 static void plot_cylinder_pressure_text(struct graphics_context *gc, struct plot_info *pi)
482 {
483         if (get_cylinder_pressure_range(gc, pi)) {
484                 int start, end;
485                 const char *unit = "bar";
486
487                 switch (output_units.pressure) {
488                 case PASCAL:
489                         start = pi->maxpressure * 100;
490                         end = pi->minpressure * 100;
491                         unit = "pascal";
492                         break;
493                 case BAR:
494                         start = (pi->maxpressure + 500) / 1000;
495                         end = (pi->minpressure + 500) / 1000;
496                         unit = "bar";
497                         break;
498                 case PSI:
499                         start = mbar_to_PSI(pi->maxpressure);
500                         end = mbar_to_PSI(pi->minpressure);
501                         unit = "psi";
502                         break;
503                 }
504
505                 text_render_options_t tro = {10, 0.2, 1.0, 0.2, LEFT, TOP};
506                 plot_text(gc, &tro, 0, pi->maxpressure, "%d %s", start, unit);
507                 plot_text(gc, &tro, pi->maxtime, pi->minpressure,
508                           "%d %s", end, unit);
509         }
510 }
511
512 static void analyze_plot_info_minmax_minute(struct plot_data *entry, struct plot_data *first, struct plot_data *last, int index)
513 {
514         struct plot_data *p = entry;
515         int time = entry->sec;
516         int seconds = 90*(index+1);
517         struct plot_data *min, *max;
518         int avg, nr;
519
520         /* Go back 'seconds' in time */
521         while (p > first) {
522                 if (p[-1].sec < time - seconds)
523                         break;
524                 p--;
525         }
526
527         /* Then go forward until we hit an entry past the time */
528         min = max = p;
529         avg = p->val;
530         nr = 1;
531         while (++p < last) {
532                 int val = p->val;
533                 if (p->sec > time + seconds)
534                         break;
535                 avg += val;
536                 nr ++;
537                 if (val < min->val)
538                         min = p;
539                 if (val > max->val)
540                         max = p;
541         }
542         entry->min[index] = min;
543         entry->max[index] = max;
544         entry->avg[index] = (avg + nr/2) / nr;
545 }
546
547 static void analyze_plot_info_minmax(struct plot_data *entry, struct plot_data *first, struct plot_data *last)
548 {
549         analyze_plot_info_minmax_minute(entry, first, last, 0);
550         analyze_plot_info_minmax_minute(entry, first, last, 1);
551         analyze_plot_info_minmax_minute(entry, first, last, 2);
552 }
553
554 static velocity_t velocity(int speed)
555 {
556         velocity_t v;
557
558         if (speed < -304) /* ascent faster than -60ft/min */
559                 v = CRAZY;
560         else if (speed < -152) /* above -30ft/min */
561                 v = FAST;
562         else if (speed < -76) /* -15ft/min */
563                 v = MODERATE;
564         else if (speed < -25) /* -5ft/min */
565                 v = SLOW;
566         else if (speed < 25) /* very hard to find data, but it appears that the recommendations
567                                 for descent are usually about 2x ascent rate; still, we want 
568                                 stable to mean stable */
569                 v = STABLE;
570         else if (speed < 152) /* between 5 and 30ft/min is considered slow */
571                 v = SLOW;
572         else if (speed < 304) /* up to 60ft/min is moderate */
573                 v = MODERATE;
574         else if (speed < 507) /* up to 100ft/min is fast */
575                 v = FAST;
576         else /* more than that is just crazy - you'll blow your ears out */
577                 v = CRAZY;
578
579         return v;
580 }
581 static struct plot_info *analyze_plot_info(struct plot_info *pi)
582 {
583         int i;
584         int nr = pi->nr;
585
586         /* Do pressure min/max based on the non-surface data */
587         for (i = 0; i < nr; i++) {
588                 struct plot_data *entry = pi->entry+i;
589                 int pressure = entry->pressure;
590                 int temperature = entry->temperature;
591
592                 if (pressure) {
593                         if (!pi->minpressure || pressure < pi->minpressure)
594                                 pi->minpressure = pressure;
595                         if (pressure > pi->maxpressure)
596                                 pi->maxpressure = pressure;
597                 }
598
599                 if (temperature) {
600                         if (!pi->mintemp || temperature < pi->mintemp)
601                                 pi->mintemp = temperature;
602                         if (temperature > pi->maxtemp)
603                                 pi->maxtemp = temperature;
604                 }
605         }
606
607         /* Smoothing function: 5-point triangular smooth */
608         for (i = 2; i < nr-1; i++) {
609                 struct plot_data *entry = pi->entry+i;
610                 int val;
611
612                 if (i < nr-2) {
613                         val = entry[-2].val + 2*entry[-1].val + 3*entry[0].val + 2*entry[1].val + entry[2].val;
614                         entry->smoothed = (val+4) / 9;
615                 }
616                 /* vertical velocity in mm/sec */
617                 /* Linus wants to smooth this - let's at least look at the samples that aren't FAST or CRAZY */
618                 if (entry[0].sec - entry[-1].sec) {
619                         entry->velocity = velocity((entry[0].val - entry[-1].val) / (entry[0].sec - entry[-1].sec));
620                         /* if our samples are short and we aren't too FAST*/
621                         if (entry[0].sec - entry[-1].sec < 30 && entry->velocity < FAST) { 
622                                 int past = -2;
623                                 while (pi->entry <= entry-past && entry[0].sec - entry[past].sec < 30)
624                                         past--;
625                                 entry->velocity = velocity((entry[0].val - entry[past].val) / 
626                                                         (entry[0].sec - entry[past].sec));
627                         }
628                 } else
629                         entry->velocity = STABLE;
630         }
631
632         /* One-, two- and three-minute minmax data */
633         for (i = 0; i < nr; i++) {
634                 struct plot_data *entry = pi->entry +i;
635                 analyze_plot_info_minmax(entry, pi->entry, pi->entry+nr);
636         }
637         
638         return pi;
639 }
640
641 /*
642  * Create a plot-info with smoothing and ranged min/max
643  *
644  * This also makes sure that we have extra empty events on both
645  * sides, so that you can do end-points without having to worry
646  * about it.
647  */
648 static struct plot_info *create_plot_info(struct dive *dive)
649 {
650         int lastdepth, lastindex;
651         int i, nr = dive->samples + 4, sec;
652         size_t alloc_size = plot_info_size(nr);
653         struct plot_info *pi;
654
655         pi = malloc(alloc_size);
656         if (!pi)
657                 return pi;
658         memset(pi, 0, alloc_size);
659         pi->nr = nr;
660         sec = 0;
661         lastindex = 0;
662         lastdepth = -1;
663         for (i = 0; i < dive->samples; i++) {
664                 int depth;
665                 struct sample *sample = dive->sample+i;
666                 struct plot_data *entry = pi->entry + i + 2;
667
668                 sec = entry->sec = sample->time.seconds;
669                 depth = entry->val = sample->depth.mm;
670                 entry->pressure = sample->cylinderpressure.mbar;
671                 entry->temperature = sample->temperature.mkelvin;
672
673                 if (depth || lastdepth)
674                         lastindex = i+2;
675
676                 lastdepth = depth;
677                 if (depth > pi->maxdepth)
678                         pi->maxdepth = depth;
679         }
680         if (lastdepth)
681                 lastindex = i + 2;
682         /* Fill in the last two entries with empty values but valid times */
683         i = dive->samples + 2;
684         pi->entry[i].sec = sec + 20;
685         pi->entry[i+1].sec = sec + 40;
686
687         pi->nr = lastindex+1;
688         pi->maxtime = pi->entry[lastindex].sec;
689
690         pi->minpressure = dive->cylinder[0].end.mbar;
691         pi->maxpressure = dive->cylinder[0].start.mbar;
692
693         pi->meandepth = dive->meandepth.mm;
694
695         return analyze_plot_info(pi);
696 }
697
698 void plot(struct graphics_context *gc, int w, int h, struct dive *dive)
699 {
700         double topx, topy;
701         struct plot_info *pi = create_plot_info(dive);
702
703         topx = w / 20.0;
704         topy = h / 20.0;
705         cairo_translate(gc->cr, topx, topy);
706         cairo_set_line_width(gc->cr, 2);
707         cairo_set_line_cap(gc->cr, CAIRO_LINE_CAP_ROUND);
708         cairo_set_line_join(gc->cr, CAIRO_LINE_JOIN_ROUND);
709
710         /*
711          * We can use "cairo_translate()" because that doesn't
712          * scale line width etc. But the actual scaling we need
713          * do set up ourselves..
714          *
715          * Snif. What a pity.
716          */
717         gc->maxx = (w - 2*topx);
718         gc->maxy = (h - 2*topy);
719
720         /* Temperature profile */
721         plot_temperature_profile(gc, pi);
722
723         /* Cylinder pressure plot */
724         plot_cylinder_pressure(gc, pi);
725
726         /* Depth profile */
727         plot_depth_profile(gc, pi);
728
729         /* Text on top of all graphs.. */
730         plot_temperature_text(gc, pi);
731         plot_depth_text(gc, pi);
732         plot_cylinder_pressure_text(gc, pi);
733
734         /* Bounding box last */
735         gc->leftx = 0; gc->rightx = 1.0;
736         gc->topy = 0; gc->bottomy = 1.0;
737
738         set_source_rgb(gc, 1, 1, 1);
739         move_to(gc, 0, 0);
740         line_to(gc, 0, 1);
741         line_to(gc, 1, 1);
742         line_to(gc, 1, 0);
743         cairo_close_path(gc->cr);
744         cairo_stroke(gc->cr);
745
746 }