X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=profile.c;h=0e5361704fc88cca0214919732b63894b4bb7fa5;hb=f4d50ffa3b4237447093c1cef9cbe945d22ceb84;hp=f2cc526dd7ff4f15e33d2f85be1d080d6452cd8d;hpb=6eefcf40e68c2a5cf35c35b92ed7529072e5da64;p=ext%2Fsubsurface.git diff --git a/profile.c b/profile.c index f2cc526..0e53617 100644 --- a/profile.c +++ b/profile.c @@ -156,24 +156,41 @@ static void plot_text(struct graphics_context *gc, const text_render_options_t * cairo_show_text(cr, buffer); } +static void plot_one_event(struct graphics_context *gc, struct plot_info *pi, struct event *event, const text_render_options_t *tro) +{ + int i, depth = 0; + + for (i = 0; i < pi->nr; i++) { + struct plot_data *data = pi->entry + i; + if (event->time.seconds < data->sec) + break; + depth = data->val; + } + plot_text(gc, tro, event->time.seconds, depth, "%s", event->name); +} + +static void plot_events(struct graphics_context *gc, struct plot_info *pi, struct dive *dive) +{ + static const text_render_options_t tro = {14, 1.0, 0.2, 0.2, CENTER, TOP}; + struct event *event = dive->events; + + if (gc->printer) + return; + + while (event) { + plot_one_event(gc, pi, event, &tro); + event = event->next; + } +} + static void render_depth_sample(struct graphics_context *gc, struct plot_data *entry, const text_render_options_t *tro) { - int sec = entry->sec; - depth_t depth = { entry->val }; - const char *fmt; + int sec = entry->sec, decimals; double d; - switch (output_units.length) { - case METERS: - d = depth.mm / 1000.0; - fmt = "%.1f"; - break; - case FEET: - d = to_feet(depth); - fmt = "%.0f"; - break; - } - plot_text(gc, tro, sec, depth.mm, fmt, d); + d = get_depth_units(entry->val, &decimals, NULL); + + plot_text(gc, tro, sec, entry->val, "%.*f", decimals, d); } static void plot_text_samples(struct graphics_context *gc, struct plot_info *pi) @@ -620,7 +637,7 @@ static struct plot_info *analyze_plot_info(struct plot_info *pi) /* if our samples are short and we aren't too FAST*/ if (entry[0].sec - entry[-1].sec < 30 && entry->velocity < FAST) { int past = -2; - while (pi->entry <= entry-past && entry[0].sec - entry[past].sec < 30) + while (i+past > 0 && entry[0].sec - entry[past].sec < 30) past--; entry->velocity = velocity((entry[0].val - entry[past].val) / (entry[0].sec - entry[past].sec)); @@ -725,6 +742,7 @@ void plot(struct graphics_context *gc, int w, int h, struct dive *dive) /* Depth profile */ plot_depth_profile(gc, pi); + plot_events(gc, pi, dive); /* Text on top of all graphs.. */ plot_temperature_text(gc, pi);