]> git.tdb.fi Git - ext/subsurface.git/blobdiff - profile.c
Improve temperature text plotting in profile display
[ext/subsurface.git] / profile.c
index 173032a130a85088c10dfd26e0a0bae2dbd64bd2..f1f3761506fc1f5b65cbc6255b7c00ec4ef14ed2 100644 (file)
--- a/profile.c
+++ b/profile.c
@@ -513,7 +513,7 @@ static void plot_single_temp_text(struct graphics_context *gc, int sec, int mkel
 {
        double deg;
        const char *unit;
-       static const text_render_options_t tro = {12, 0.2, 0.2, 1.0, LEFT, TOP};
+       static const text_render_options_t tro = {12, 0.6, 0.6, 1.0, LEFT, TOP};
 
        deg = get_temp_units(mkelvin, &unit);
 
@@ -523,7 +523,7 @@ static void plot_single_temp_text(struct graphics_context *gc, int sec, int mkel
 static void plot_temperature_text(struct graphics_context *gc, struct plot_info *pi)
 {
        int i;
-       int last = 0, sec = 0;
+       int last = -300, sec = 0;
        int last_temperature = 0, last_printed_temp = 0;
 
        if (!setup_temperature_limits(gc, pi))
@@ -537,14 +537,23 @@ static void plot_temperature_text(struct graphics_context *gc, struct plot_info
                        continue;
                last_temperature = mkelvin;
                sec = entry->sec;
-               if (sec < last + 300)
+               /* don't print a temperature
+                * if it's been less than 5min and less than a 2K change OR
+                * if it's been less than 2min OR if the change from the
+                * last print is less than .4K (and therefore less than 1F */
+               if (((sec < last + 300) && (abs(mkelvin - last_printed_temp) < 2000)) ||
+                       (sec < last + 120) ||
+                       (abs(mkelvin - last_printed_temp) < 400))
                        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)
+       /* it would be nice to print the end temperature, if it's
+        * different or if the last temperature print has been more
+        * than a quarter of the dive back */
+       if ((abs(last_temperature - last_printed_temp) > 500) ||
+               ((double)last / (double)sec < 0.75))
                plot_single_temp_text(gc, sec, last_temperature);
 }
 
@@ -1098,7 +1107,7 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
                entry->temperature = sample->temperature.mkelvin;
 
                if (depth || lastdepth)
-                       lastindex = i+pi_idx;
+                       lastindex = i + pi_idx;
 
                lastdepth = depth;
                if (depth > pi->maxdepth)
@@ -1162,9 +1171,12 @@ static struct plot_info *create_plot_info(struct dive *dive, int nr_samples, str
        i = nr + 2;
        pi->entry[i].sec = sec + 20;
        pi->entry[i+1].sec = sec + 40;
-       /* the number of actual entries - we may have allocated more if there
-        * were gas change events, but this is how many were filled */
+       /* the number of actual entries - some computers have lots of
+        * depth 0 samples at the end of a dive, we want to make sure
+        * we have exactly one of them at the end */
        pi->nr = lastindex+1;
+       while (pi->nr <= i+2 && pi->entry[pi->nr-1].depth > 0)
+               pi->nr++;
        pi->maxtime = pi->entry[lastindex].sec;
 
        pi->endpressure = pi->minpressure = dive->cylinder[0].end.mbar;