+ set_source_rgba(gc, 1, 0.2, 0.2, 0.80);
+ cairo_stroke(cr);
+}
+
+static int setup_temperature_limits(struct dive *dive, struct graphics_context *gc)
+{
+ int i;
+ 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 (mkelvin > maxtemp)
+ maxtemp = mkelvin;
+ if (mkelvin < mintemp)
+ mintemp = mkelvin;
+ }
+
+ 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;
+
+ return maxtemp > mintemp;
+}
+
+static void plot_temperature_text(struct dive *dive, struct graphics_context *gc)
+{
+ int i;
+ static const text_render_options_t tro = {12, 0.2, 0.2, 1.0, LEFT, TOP};
+
+ int last = 0;
+
+ if (!setup_temperature_limits(dive, gc))
+ return;
+
+ for (i = 0; i < dive->samples; i++) {
+ const char *unit;
+ struct sample *sample = dive->sample+i;
+ int mkelvin = sample->temperature.mkelvin;
+ int sec, deg;
+ if (!mkelvin)
+ continue;
+ sec = sample->time.seconds;
+ if (sec < last)
+ continue;
+ last = sec + 300;
+ if (output_units.temperature == FAHRENHEIT) {
+ deg = to_F(sample->temperature);
+ unit = "F";
+ } else {
+ deg = to_C(sample->temperature);
+ unit = "C";
+ }
+ plot_text(gc, &tro, sec, mkelvin, "%d %s", deg, unit);
+ }
+}
+
+static void plot_temperature_profile(struct dive *dive, struct graphics_context *gc)
+{
+ int i;
+ cairo_t *cr = gc->cr;
+ int last = 0;
+
+ if (!setup_temperature_limits(dive, gc))
+ return;
+
+ set_source_rgba(gc, 0.2, 0.2, 1.0, 0.8);
+ for (i = 0; i < dive->samples; i++) {
+ struct sample *sample = dive->sample+i;
+ int mkelvin = sample->temperature.mkelvin;
+ if (!mkelvin) {
+ if (!last)
+ continue;
+ mkelvin = last;
+ }
+ if (last)
+ line_to(gc, sample->time.seconds, mkelvin);
+ else
+ move_to(gc, sample->time.seconds, mkelvin);
+ last = mkelvin;
+ }