+}
+
+static int get_cylinder_pressure_range(struct dive *dive, double *scalex, double *scaley)
+{
+ int i;
+ double min, max;
+
+ *scalex = round_seconds_up(dive->duration.seconds);
+
+ max = 0;
+ min = 5000;
+ for (i = 0; i < dive->samples; i++) {
+ struct sample *sample = dive->sample + i;
+ double bar;
+
+ if (!sample->cylinderpressure.mbar)
+ continue;
+ bar = sample->cylinderpressure.mbar;
+ if (bar < min)
+ min = bar;
+ if (bar > max)
+ max = bar;
+ }
+ if (!max)
+ return 0;
+ *scaley = max * 1.5;
+ return 1;
+}
+
+static void plot_cylinder_pressure(struct dive *dive, cairo_t *cr,
+ double topx, double topy, double maxx, double maxy)
+{
+ int i;
+ double scalex, scaley;
+
+ if (!get_cylinder_pressure_range(dive, &scalex, &scaley))
+ return;
+
+ cairo_set_source_rgba(cr, 0.2, 1.0, 0.2, 0.80);
+
+ cairo_move_to(cr, SCALE(0, dive->beginning_pressure.mbar));
+ for (i = 1; i < dive->samples; i++) {
+ int sec, mbar;
+ struct sample *sample = dive->sample + i;
+
+ sec = sample->time.seconds;
+ mbar = sample->cylinderpressure.mbar;
+ if (!mbar)
+ continue;
+ cairo_line_to(cr, SCALE(sec, mbar));
+ }
+ cairo_line_to(cr, SCALE(dive->duration.seconds, dive->end_pressure.mbar));
+ cairo_stroke(cr);
+}
+
+static void plot(cairo_t *cr, int w, int h, struct dive *dive)
+{
+ double topx, topy, maxx, maxy;
+ double scalex, scaley;
+
+ topx = w / 20.0;
+ topy = h / 20.0;
+ maxx = (w - 2*topx);
+ maxy = (h - 2*topy);
+
+ /* Depth profile */
+ plot_profile(dive, cr, topx, topy, maxx, maxy);
+
+ /* Cylinder pressure plot? */
+ plot_cylinder_pressure(dive, cr, topx, topy, maxx, maxy);