+ analyze_plot_info_minmax_minute(entry, first, last, 0);
+ analyze_plot_info_minmax_minute(entry, first, last, 1);
+ analyze_plot_info_minmax_minute(entry, first, last, 2);
+}
+
+static struct plot_info *analyze_plot_info(struct plot_info *pi)
+{
+ int i;
+ int nr = pi->nr;
+
+ /* Smoothing function: 5-point triangular smooth */
+ for (i = 2; i < nr-2; i++) {
+ struct plot_data *entry = pi->entry+i;
+ int val;
+
+ val = entry[-2].val + 2*entry[-1].val + 3*entry[0].val + 2*entry[1].val + entry[2].val;
+ entry->smoothed = (val+4) / 9;
+ }
+
+ /* One-, two- and three-minute minmax data */
+ for (i = 0; i < nr; i++) {
+ struct plot_data *entry = pi->entry +i;
+ analyze_plot_info_minmax(entry, pi->entry, pi->entry+nr);
+ }
+
+ return pi;
+}
+
+/*
+ * Create a plot-info with smoothing and ranged min/max
+ *
+ * This also makes sure that we have extra empty events on both
+ * sides, so that you can do end-points without having to worry
+ * about it.
+ */
+static struct plot_info *depth_plot_info(struct dive *dive)
+{
+ int i, nr = dive->samples + 4, sec;
+ size_t alloc_size = plot_info_size(nr);
+ struct plot_info *pi;
+
+ pi = malloc(alloc_size);
+ if (!pi)
+ return pi;
+ memset(pi, 0, alloc_size);
+ pi->nr = nr;
+ sec = 0;
+ for (i = 0; i < dive->samples; i++) {
+ struct sample *sample = dive->sample+i;
+ struct plot_data *entry = pi->entry + i + 2;
+
+ sec = entry->sec = sample->time.seconds;
+ entry->val = sample->depth.mm;
+ }
+ /* Fill in the last two entries with empty values but valid times */
+ i = dive->samples + 2;
+ pi->entry[i].sec = sec + 20;
+ pi->entry[i+1].sec = sec + 40;
+
+ return analyze_plot_info(pi);
+}
+
+static void plot(struct graphics_context *gc, int w, int h, struct dive *dive)
+{
+ double topx, topy;
+ struct plot_info *pi = depth_plot_info(dive);