+ /* Show mean depth */
+ if (! gc->printer) {
+ set_source_rgba(gc, 1, 0.2, 0.2, 0.40);
+ move_to(gc, 0, pi->meandepth);
+ line_to(gc, 1, pi->meandepth);
+ cairo_stroke(cr);
+ }
+
+ gc->leftx = 0; gc->rightx = maxtime;
+
+ /*
+ * These are good for debugging text placement etc,
+ * but not for actual display..
+ */
+ if (0) {
+ plot_smoothed_profile(gc, pi);
+ plot_minmax_profile(gc, pi);
+ }
+
+ set_source_rgba(gc, 1, 0.2, 0.2, 0.80);
+
+ /* Do the depth profile for the neat fill */
+ gc->topy = 0; gc->bottomy = maxdepth;
+ set_source_rgba(gc, 1, 0.2, 0.2, 0.20);
+
+ entry = pi->entry;
+ move_to(gc, 0, 0);
+ for (i = 0; i < pi->nr; i++, entry++)
+ line_to(gc, entry->sec, entry->val);
+ cairo_close_path(gc->cr);
+ if (gc->printer) {
+ set_source_rgba(gc, 1, 1, 1, 0.2);
+ cairo_fill_preserve(cr);
+ set_source_rgb(gc, 1, 1, 1);
+ cairo_stroke(cr);
+ return;
+ }
+ cairo_fill(gc->cr);
+
+ /* Now do it again for the velocity colors */
+ entry = pi->entry;
+ for (i = 1; i < pi->nr; i++) {
+ entry++;
+ sec = entry->sec;
+ /* we want to draw the segments in different colors
+ * representing the vertical velocity, so we need to
+ * chop this into short segments */
+ rgb_t color = rgb[entry->velocity];
+ depth = entry->val;
+ set_source_rgb(gc, color.r, color.g, color.b);
+ move_to(gc, entry[-1].sec, entry[-1].val);
+ line_to(gc, sec, depth);
+ cairo_stroke(cr);
+ }
+}
+
+static int setup_temperature_limits(struct graphics_context *gc, struct plot_info *pi)
+{
+ int maxtime, mintemp, maxtemp, delta;
+
+ /* Get plot scaling limits */
+ maxtime = get_maxtime(pi);
+ mintemp = pi->mintemp;
+ maxtemp = pi->maxtemp;
+
+ gc->leftx = 0; gc->rightx = maxtime;
+ /* Show temperatures in roughly the lower third, but make sure the scale
+ is at least somewhat reasonable */
+ delta = maxtemp - mintemp;
+ if (delta > 3000) { /* more than 3K in fluctuation */
+ gc->topy = maxtemp + delta*2;
+ gc->bottomy = mintemp - delta/2;
+ } else {
+ gc->topy = maxtemp + 1500 + delta*2;
+ gc->bottomy = mintemp - delta/2;
+ }
+
+ return maxtemp > mintemp;
+}
+
+static void plot_single_temp_text(struct graphics_context *gc, int sec, int mkelvin)
+{
+ int deg;
+ const char *unit;
+ static const text_render_options_t tro = {12, 0.2, 0.2, 1.0, LEFT, TOP};
+ temperature_t temperature = { mkelvin };
+
+ if (output_units.temperature == FAHRENHEIT) {
+ deg = to_F(temperature);
+ unit = UTF8_DEGREE "F";
+ } else {
+ deg = to_C(temperature);
+ unit = UTF8_DEGREE "C";
+ }
+ plot_text(gc, &tro, sec, temperature.mkelvin, "%d%s", deg, unit);
+}
+
+static void plot_temperature_text(struct graphics_context *gc, struct plot_info *pi)
+{
+ int i;
+ int last = 0, sec = 0;
+ int last_temperature = 0, last_printed_temp = 0;
+
+ if (!setup_temperature_limits(gc, pi))
+ return;
+
+ for (i = 0; i < pi->nr; i++) {
+ struct plot_data *entry = pi->entry+i;
+ int mkelvin = entry->temperature;
+
+ if (!mkelvin)
+ continue;
+ last_temperature = mkelvin;
+ sec = entry->sec;
+ if (sec < last + 300)
+ continue;
+ last = sec;
+ plot_single_temp_text(gc,sec,mkelvin);
+ last_printed_temp = mkelvin;
+ }
+ /* it would be nice to print the end temperature, if it's different */
+ if (abs(last_temperature - last_printed_temp) > 500)
+ plot_single_temp_text(gc, sec, last_temperature);
+}
+
+static void plot_temperature_profile(struct graphics_context *gc, struct plot_info *pi)
+{
+ int i;
+ cairo_t *cr = gc->cr;
+ int last = 0;
+
+ if (!setup_temperature_limits(gc, pi))
+ return;
+
+ set_source_rgba(gc, 0.2, 0.2, 1.0, 0.8);
+ for (i = 0; i < pi->nr; i++) {
+ struct plot_data *entry = pi->entry + i;
+ int mkelvin = entry->temperature;
+ int sec = entry->sec;
+ if (!mkelvin) {
+ if (!last)
+ continue;
+ mkelvin = last;
+ }
+ if (last)
+ line_to(gc, sec, mkelvin);
+ else
+ move_to(gc, sec, mkelvin);
+ last = mkelvin;
+ }