]> git.tdb.fi Git - ext/subsurface.git/blobdiff - profile.c
Fix error when gaschange event is one second before next sample
[ext/subsurface.git] / profile.c
index 9fab8b2e89f5ae72cf4732f91e48d4a3cb73de00..47e12ba66352421b6cc36790ba1b293f43edf52f 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -669,10 +669,7 @@ static void plot_cylinder_pressure(struct graphics_context *gc, struct plot_info
                if (!last_entry) {
                        last = i;
                        last_entry = entry;
-                       if (first_plot) {
-                               /* don't start with a sac of 0, so just calculate the first one */
-                               sac = GET_LOCAL_SAC(entry, pi->entry + i + 1, dive);
-                       }
+                       sac = GET_LOCAL_SAC(entry, pi->entry + i + 1, dive);
                } else {
                        int j;
                        sac = 0;
@@ -717,7 +714,7 @@ static void plot_pressure_value(struct graphics_context *gc, int mbar, int sec,
        plot_text(gc, &tro, sec, mbar, "%d %s", pressure, unit);
 }
 
-static void plot_cylinder_pressure_text(struct graphics_context *gc, struct plot_info *pi)
+static void plot_cylinder_pressure_text(struct graphics_context *gc, struct plot_info *pi, struct dive *dive)
 {
        int i;
        int mbar, cyl;
@@ -763,7 +760,10 @@ static void plot_cylinder_pressure_text(struct graphics_context *gc, struct plot
 
        for (cyl = 0; cyl < MAX_CYLINDERS; cyl++) {
                if (last_time[cyl]) {
-                       plot_pressure_value(gc, last_pressure[cyl], last_time[cyl], CENTER, TOP);
+                       if (dive->cylinder[cyl].end.mbar)
+                               plot_pressure_value(gc, dive->cylinder[cyl].end.mbar, last_time[cyl], CENTER, TOP);
+                       else
+                               plot_pressure_value(gc, last_pressure[cyl], last_time[cyl], CENTER, TOP);
                }
        }
 }
@@ -1141,8 +1141,13 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
                while (ev && ev->time.seconds < sample->time.seconds) {
                        /* insert two fake plot info structures for the end of
                         * the old tank and the start of the new tank */
-                       entry->sec = ev->time.seconds;
-                       (entry+1)->sec = ev->time.seconds + 1;
+                       if (ev->time.seconds == sample->time.seconds - 1) {
+                               entry->sec = ev->time.seconds - 1;
+                               (entry+1)->sec = ev->time.seconds;
+                       } else {
+                               entry->sec = ev->time.seconds;
+                               (entry+1)->sec = ev->time.seconds + 1;
+                       }
                        /* we need a fake depth - let's interpolate */
                        if (i) {
                                entry->depth = sample->depth.mm -
@@ -1322,7 +1327,7 @@ void plot(struct graphics_context *gc, cairo_rectangle_int_t *drawing_area, stru
        /* Text on top of all graphs.. */
        plot_temperature_text(gc, pi);
        plot_depth_text(gc, pi);
-       plot_cylinder_pressure_text(gc, pi);
+       plot_cylinder_pressure_text(gc, pi, dive);
 
        /* Bounding box last */
        gc->leftx = 0; gc->rightx = 1.0;