X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=profile.c;h=6d6e1ff98ff345eeca162a9ba983a93998287167;hb=c7b9387d4bf624230ca2e317e7ac8cf5b4b81f0c;hp=551918b35518e8cfe2f0e1d8b69cbc62a863e46b;hpb=f4559ba9fa4610b56f27ffb20eb872908e987baf;p=ext%2Fsubsurface.git diff --git a/profile.c b/profile.c index 551918b..6d6e1ff 100644 --- a/profile.c +++ b/profile.c @@ -235,8 +235,6 @@ static void plot_depth_profile(struct dive *dive, struct graphics_context *gc, s struct plot_data *entry; int maxtime, maxdepth, marker; - cairo_set_line_width(gc->cr, 2); - /* Get plot scaling limits */ maxtime = round_seconds_up(dive->duration.seconds); maxdepth = round_depth_up(dive->maxdepth); @@ -297,11 +295,9 @@ static void plot_depth_profile(struct dive *dive, struct graphics_context *gc, s cairo_stroke(cr); } -static void plot_temperature_profile(struct dive *dive, struct graphics_context *gc) +static int setup_temperature_limits(struct dive *dive, struct graphics_context *gc) { int i; - cairo_t *cr = gc->cr; - int begins = 0, sec = 0; int maxtime, mintemp, maxtemp; /* Get plot scaling limits */ @@ -313,32 +309,75 @@ static void plot_temperature_profile(struct dive *dive, struct graphics_context int mkelvin = sample->temperature.mkelvin; if (!mkelvin) continue; - if (!begins) { - begins = mkelvin; - sec = sample->time.seconds; - } if (mkelvin > maxtemp) maxtemp = mkelvin; if (mkelvin < mintemp) mintemp = mkelvin; } - if (mintemp >= maxtemp) - return; gc->leftx = 0; gc->rightx = maxtime; /* Show temperatures in roughly the lower third */ gc->topy = maxtemp + (maxtemp - mintemp)*2; gc->bottomy = mintemp - (maxtemp - mintemp)/2; - cairo_set_source_rgba(cr, 0.2, 0.2, 1.0, 0.8); - move_to(gc, sec, begins); + return maxtemp > mintemp; +} + +static void plot_temperature_text(struct dive *dive, struct graphics_context *gc) +{ + int i; + static const text_render_options_t tro = {12, 0.2, 0.2, 1.0, LEFT, TOP}; + + int last = 0; + + if (!setup_temperature_limits(dive, gc)) + return; + for (i = 0; i < dive->samples; i++) { + const char *unit; struct sample *sample = dive->sample+i; int mkelvin = sample->temperature.mkelvin; + int sec, deg; if (!mkelvin) - mkelvin = begins; - line_to(gc, sample->time.seconds, mkelvin); - begins = mkelvin; + continue; + 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); + } +} + +static void plot_temperature_profile(struct dive *dive, struct graphics_context *gc) +{ + int i; + cairo_t *cr = gc->cr; + int last = 0; + + if (!setup_temperature_limits(dive, gc)) + return; + + cairo_set_source_rgba(cr, 0.2, 0.2, 1.0, 0.8); + for (i = 0; i < dive->samples; i++) { + struct sample *sample = dive->sample+i; + int mkelvin = sample->temperature.mkelvin; + if (!mkelvin) { + if (!last) + continue; + mkelvin = last; + } + if (last) + line_to(gc, sample->time.seconds, mkelvin); + else + move_to(gc, sample->time.seconds, mkelvin); + last = mkelvin; } cairo_stroke(cr); } @@ -614,6 +653,9 @@ static void plot(struct graphics_context *gc, int w, int h, struct dive *dive) topx = w / 20.0; topy = h / 20.0; cairo_translate(gc->cr, topx, topy); + cairo_set_line_width(gc->cr, 2); + cairo_set_line_cap(gc->cr, CAIRO_LINE_CAP_ROUND); + cairo_set_line_join(gc->cr, CAIRO_LINE_JOIN_ROUND); /* * We can use "cairo_translate()" because that doesn't @@ -625,16 +667,17 @@ static void plot(struct graphics_context *gc, int w, int h, struct dive *dive) gc->maxx = (w - 2*topx); gc->maxy = (h - 2*topy); + /* Temperature profile */ + plot_temperature_profile(dive, gc); + /* Cylinder pressure plot */ plot_cylinder_pressure(dive, gc); /* Depth profile */ plot_depth_profile(dive, gc, pi); - /* Temperature profile */ - plot_temperature_profile(dive, gc); - /* Text on top of all graphs.. */ + plot_temperature_text(dive, gc); plot_depth_text(dive, gc, pi); plot_cylinder_pressure_text(dive, gc);