]> git.tdb.fi Git - ext/subsurface.git/blobdiff - profile.c
Print the end temperature of the dive
[ext/subsurface.git] / profile.c
index 2ddc933d072feef452fd086296a089a8c458c732..fdbbcdf165fe1746b3dbc85aeb7afe35a788ee09 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -43,10 +43,11 @@ static void line_to(struct graphics_context *gc, double x, double y)
 static void set_source_rgba(struct graphics_context *gc, double r, double g, double b, double a)
 {
        if (gc->printer) {
-               a = 1;
-               if (r+g+b > 1)
+               /* Black is white and white is black */
+               double sum = r+g+b;
+               if (sum > 2)
                        r = g = b = 0;
-               else
+               else if (sum < 1)
                        r = g = b = 1;
        }
        cairo_set_source_rgba(gc->cr, r, g, b, a);
@@ -293,10 +294,8 @@ static void plot_depth_profile(struct dive *dive, struct graphics_context *gc, s
        line_to(gc, MIN(sec,maxtime), 0);
        line_to(gc, begins, 0);
        cairo_close_path(cr);
-       if (!gc->printer) {
-               set_source_rgba(gc, 1, 0.2, 0.2, 0.20);
-               cairo_fill_preserve(cr);
-       }
+       set_source_rgba(gc, 1, 0.2, 0.2, 0.20);
+       cairo_fill_preserve(cr);
        set_source_rgba(gc, 1, 0.2, 0.2, 0.80);
        cairo_stroke(cr);
 }
@@ -329,35 +328,50 @@ static int setup_temperature_limits(struct dive *dive, struct graphics_context *
        return maxtemp > mintemp;
 }
 
-static void plot_temperature_text(struct dive *dive, struct graphics_context *gc)
+static void plot_single_temp_text(struct graphics_context *gc, int sec, temperature_t temperature)
 {
-       int i;
+       int deg;
+       const char *unit;
        static const text_render_options_t tro = {12, 0.2, 0.2, 1.0, LEFT, TOP};
 
+       if (output_units.temperature == FAHRENHEIT) {
+               deg = to_F(temperature);
+               unit = "F";
+       } else {
+               deg = to_C(temperature);
+               unit = "C";
+       }
+       plot_text(gc, &tro, sec, temperature.mkelvin, "%d %s", deg, unit);
+}
+
+static void plot_temperature_text(struct dive *dive, struct graphics_context *gc)
+{
+       int i;
        int last = 0;
+       temperature_t last_temperature, last_printed_temp;
 
        if (!setup_temperature_limits(dive, gc))
                return;
 
        for (i = 0; i < dive->samples; i++) {
-               const char *unit;
                struct sample *sample = dive->sample+i;
+               if (sample->time.seconds > dive->duration.seconds)
+                       break; /* let's not plot surface temp events */
                int mkelvin = sample->temperature.mkelvin;
-               int sec, deg;
+               int sec;
                if (!mkelvin)
                        continue;
+               last_temperature = sample->temperature;
                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);
+               plot_single_temp_text(gc,sec,sample->temperature);
+               last_printed_temp = last_temperature ;
+       }
+       /* it would be nice to print the end temperature, if it's different */
+       if (last_temperature.mkelvin != last_printed_temp.mkelvin) {
+               plot_single_temp_text(gc,dive->duration.seconds,last_temperature);
        }
 }
 
@@ -373,6 +387,8 @@ static void plot_temperature_profile(struct dive *dive, struct graphics_context
        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;
+               if (sample->time.seconds > dive->duration.seconds)
+                       break; /* let's not plot surface temp events */
                int mkelvin = sample->temperature.mkelvin;
                if (!mkelvin) {
                        if (!last)