+static void plot_temperature_profile(struct dive *dive, struct graphics_context *gc)
+{
+ int i;
+ cairo_t *cr = gc->cr;
+ int begins = 0, sec = 0;
+ int maxtime, mintemp, maxtemp;
+
+ /* Get plot scaling limits */
+ maxtime = round_seconds_up(dive->duration.seconds);
+ mintemp = INT_MAX;
+ maxtemp = 0;
+ for (i = 0; i < dive->samples; i++) {
+ struct sample *sample = dive->sample+i;
+ int mkelvin = sample->temperature.mkelvin;
+ if (!mkelvin)
+ continue;
+ if (!begins) {
+ begins = mkelvin;
+ sec = sample->time.seconds;
+ }
+ if (mkelvin > maxtemp)
+ maxtemp = mkelvin;
+ if (mkelvin < mintemp)
+ mintemp = mkelvin;
+ }
+ if (mintemp >= maxtemp)
+ return;
+
+ gc->leftx = 0; gc->rightx = maxtime;
+ /* Show temperatures in roughly the lower third */
+ gc->topy = maxtemp + (maxtemp - mintemp)*2;
+ gc->bottomy = mintemp - (maxtemp - mintemp)/2;
+
+ cairo_set_source_rgba(cr, 0.2, 0.2, 1.0, 0.8);
+ move_to(gc, sec, begins);
+ for (i = 0; i < dive->samples; i++) {
+ struct sample *sample = dive->sample+i;
+ int mkelvin = sample->temperature.mkelvin;
+ if (!mkelvin)
+ mkelvin = begins;
+ line_to(gc, sample->time.seconds, mkelvin);
+ begins = mkelvin;
+ }
+ cairo_stroke(cr);
+}
+