+ 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;
+ }
+ cairo_stroke(cr);
+}
+
+/* gets both the actual start and end pressure as well as the scaling factors */
+static int get_cylinder_pressure_range(struct graphics_context *gc, struct plot_info *pi)
+{
+ gc->leftx = 0;
+ gc->rightx = get_maxtime(pi);
+
+ gc->bottomy = 0; gc->topy = pi->maxpressure * 1.5;
+ return pi->maxpressure != 0;
+}
+
+static void plot_cylinder_pressure(struct graphics_context *gc, struct plot_info *pi)
+{
+ int i;
+
+ if (!get_cylinder_pressure_range(gc, pi))
+ return;
+
+ set_source_rgba(gc, 0.2, 1.0, 0.2, 0.80);
+
+ move_to(gc, 0, pi->maxpressure);
+ for (i = 1; i < pi->nr; i++) {
+ int mbar;
+ struct plot_data *entry = pi->entry + i;
+
+ mbar = entry->pressure;
+ if (!mbar)
+ continue;
+ line_to(gc, entry->sec, mbar);
+ }
+ line_to(gc, pi->maxtime, pi->minpressure);
+ cairo_stroke(gc->cr);
+}
+
+static int mbar_to_PSI(int mbar)
+{
+ pressure_t p = {mbar};
+ return to_PSI(p);
+}
+
+static void plot_cylinder_pressure_text(struct graphics_context *gc, struct plot_info *pi)
+{
+ if (get_cylinder_pressure_range(gc, pi)) {
+ int start, end;
+ const char *unit = "bar";
+
+ switch (output_units.pressure) {
+ case PASCAL:
+ start = pi->maxpressure * 100;
+ end = pi->minpressure * 100;
+ unit = "pascal";
+ break;
+ case BAR:
+ start = (pi->maxpressure + 500) / 1000;
+ end = (pi->minpressure + 500) / 1000;
+ unit = "bar";
+ break;
+ case PSI:
+ start = mbar_to_PSI(pi->maxpressure);
+ end = mbar_to_PSI(pi->minpressure);
+ unit = "psi";
+ break;
+ }
+
+ text_render_options_t tro = {10, 0.2, 1.0, 0.2, LEFT, TOP};
+ plot_text(gc, &tro, 0, pi->maxpressure, "%d %s", start, unit);
+ plot_text(gc, &tro, pi->maxtime, pi->minpressure,
+ "%d %s", end, unit);
+ }
+}