]> git.street.me.uk Git - andy/viking.git/blobdiff - src/viktrwlayer_propwin.c
[QA] Fix clang warning: format string is not a string literal
[andy/viking.git] / src / viktrwlayer_propwin.c
index fcd3effbc63c4ffcb46e41a05958aab11136c8d0..be96f509a6786bd39a042e92ab5ca7d3dcf0d318 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
  * Copyright (C) 2005-2007, Alex Foobarian <foobarian@gmail.com>
  * Copyright (C) 2007-2008, Quy Tonthat <qtonthat@gmail.com>
  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
  * Copyright (C) 2005-2007, Alex Foobarian <foobarian@gmail.com>
  * Copyright (C) 2007-2008, Quy Tonthat <qtonthat@gmail.com>
- * Copyright (C) 2012, Rob Norris <rw_norris@hotmail.com>
+ * Copyright (C) 2012-2014, Rob Norris <rw_norris@hotmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -41,6 +41,8 @@
 #include "dems.h"
 #include "viking.h"
 #include "vikviewport.h" /* ugh */
 #include "dems.h"
 #include "viking.h"
 #include "vikviewport.h" /* ugh */
+#include "vikutils.h"
+#include "ui_util.h"
 #include <gdk-pixbuf/gdk-pixdata.h>
 
 typedef enum {
 #include <gdk-pixbuf/gdk-pixdata.h>
 
 typedef enum {
@@ -76,11 +78,39 @@ static const gdouble chunkss[] = {1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
                                  750.0, 1000.0, 10000.0};
 
 /* (Hopefully!) Human friendly distance grid sizes - note no fixed 'ratio' just numbers that look nice...*/
                                  750.0, 1000.0, 10000.0};
 
 /* (Hopefully!) Human friendly distance grid sizes - note no fixed 'ratio' just numbers that look nice...*/
-static const gdouble chunksd[] = {0.1, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
+static const gdouble chunksd[] = {0.1, 0.2, 0.5, 1.0, 2.0, 3.0, 4.0, 5.0, 8.0, 10.0,
                                  15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
                                  100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
                                  750.0, 1000.0, 10000.0};
 
                                  15.0, 20.0, 25.0, 40.0, 50.0, 75.0,
                                  100.0, 150.0, 200.0, 250.0, 375.0, 500.0,
                                  750.0, 1000.0, 10000.0};
 
+// Time chunks in seconds
+static const time_t chunkst[] = {
+  60,     // 1 minute
+  120,    // 2 minutes
+  300,    // 5 minutes
+  900,    // 15 minutes
+  1800,   // half hour
+  3600,   // 1 hour
+  10800,  // 3 hours
+  21600,  // 6 hours
+  43200,  // 12 hours
+  86400,  // 1 day
+  172800, // 2 days
+  604800, // 1 week
+  1209600,// 2 weeks
+  2419200,// 4 weeks
+};
+
+// Local show settings to restore on dialog opening
+static gboolean show_dem                = TRUE;
+static gboolean show_alt_gps_speed      = TRUE;
+static gboolean show_gps_speed          = TRUE;
+static gboolean show_gradient_gps_speed = TRUE;
+static gboolean show_dist_speed         = FALSE;
+static gboolean show_elev_speed         = FALSE;
+static gboolean show_elev_dem           = FALSE;
+static gboolean show_sd_gps_speed       = TRUE;
+
 typedef struct _propsaved {
   gboolean saved;
   GdkImage *img;
 typedef struct _propsaved {
   gboolean saved;
   GdkImage *img;
@@ -121,12 +151,15 @@ typedef struct _propwidgets {
   GtkWidget *w_cur_elevation;
   GtkWidget *w_cur_gradient_dist; /*< Current distance on gradient graph */
   GtkWidget *w_cur_gradient_gradient; /*< Current gradient on gradient graph */
   GtkWidget *w_cur_elevation;
   GtkWidget *w_cur_gradient_dist; /*< Current distance on gradient graph */
   GtkWidget *w_cur_gradient_gradient; /*< Current gradient on gradient graph */
-  GtkWidget *w_cur_time; /*< Current time */
+  GtkWidget *w_cur_time; /*< Current track time */
+  GtkWidget *w_cur_time_real; /*< Actual time as on a clock */
   GtkWidget *w_cur_speed;
   GtkWidget *w_cur_dist_dist; /*< Current distance on distance graph */
   GtkWidget *w_cur_speed;
   GtkWidget *w_cur_dist_dist; /*< Current distance on distance graph */
-  GtkWidget *w_cur_dist_time; /*< Current time on distance graph */
+  GtkWidget *w_cur_dist_time; /*< Current track time on distance graph */
+  GtkWidget *w_cur_dist_time_real; // Clock time
   GtkWidget *w_cur_elev_elev;
   GtkWidget *w_cur_elev_elev;
-  GtkWidget *w_cur_elev_time;
+  GtkWidget *w_cur_elev_time; // Track time
+  GtkWidget *w_cur_elev_time_real; // Clock time
   GtkWidget *w_cur_speed_dist;
   GtkWidget *w_cur_speed_speed;
   GtkWidget *w_show_dem;
   GtkWidget *w_cur_speed_dist;
   GtkWidget *w_cur_speed_speed;
   GtkWidget *w_show_dem;
@@ -135,6 +168,7 @@ typedef struct _propwidgets {
   GtkWidget *w_show_gradient_gps_speed;
   GtkWidget *w_show_dist_speed;
   GtkWidget *w_show_elev_speed;
   GtkWidget *w_show_gradient_gps_speed;
   GtkWidget *w_show_dist_speed;
   GtkWidget *w_show_elev_speed;
+  GtkWidget *w_show_elev_dem;
   GtkWidget *w_show_sd_gps_speed;
   gdouble   track_length;
   gdouble   track_length_inc_gaps;
   GtkWidget *w_show_sd_gps_speed;
   gdouble   track_length;
   gdouble   track_length_inc_gaps;
@@ -179,6 +213,8 @@ typedef struct _propwidgets {
   gboolean  is_marker_drawn;
   VikTrackpoint *blob_tp;
   gboolean  is_blob_drawn;
   gboolean  is_marker_drawn;
   VikTrackpoint *blob_tp;
   gboolean  is_blob_drawn;
+  time_t    duration;
+  gchar     *tz; // TimeZone at track's location
 } PropWidgets;
 
 static PropWidgets *prop_widgets_new()
 } PropWidgets;
 
 static PropWidgets *prop_widgets_new()
@@ -232,7 +268,8 @@ static void minmax_array(const gdouble *array, gdouble *min, gdouble *max, gbool
   }
 }
 
   }
 }
 
-#define MARGIN 70
+#define MARGIN_X 70
+#define MARGIN_Y 20
 #define LINES 5
 /**
  * get_new_min_and_chunk_index:
 #define LINES 5
 /**
  * get_new_min_and_chunk_index:
@@ -281,6 +318,55 @@ static void get_new_min_and_chunk_index (gdouble mina, gdouble maxa, const gdoub
   }
 }
 
   }
 }
 
+static guint get_time_chunk_index (time_t duration)
+{
+  // Grid split
+  time_t myduration = duration / LINES;
+
+  // Search nearest chunk index
+  guint ci = 0;
+  guint last_chunk = G_N_ELEMENTS(chunkst);
+
+  // Loop through to find best match
+  while (myduration > chunkst[ci]) {
+    ci++;
+    // Last Resort Check
+    if ( ci == last_chunk )
+      break;
+  }
+  // Use previous value
+  if ( ci != 0 )
+   ci--;
+
+  return ci;
+}
+
+/**
+ *
+ */
+static guint get_distance_chunk_index (gdouble length)
+{
+  // Grid split
+  gdouble mylength = length / LINES;
+
+  // Search nearest chunk index
+  guint ci = 0;
+  guint last_chunk = G_N_ELEMENTS(chunksd);
+
+  // Loop through to find best match
+  while (mylength > chunksd[ci]) {
+    ci++;
+    // Last Resort Check
+    if ( ci == last_chunk )
+      break;
+  }
+  // Use previous value
+  if ( ci != 0 )
+   ci--;
+
+  return ci;
+}
+
 static VikTrackpoint *set_center_at_graph_position(gdouble event_x,
                                                   gint img_width,
                                                   VikTrwLayer *vtl,
 static VikTrackpoint *set_center_at_graph_position(gdouble event_x,
                                                   gint img_width,
                                                   VikTrwLayer *vtl,
@@ -291,7 +377,7 @@ static VikTrackpoint *set_center_at_graph_position(gdouble event_x,
                                                   gint PROFILE_WIDTH)
 {
   VikTrackpoint *trackpoint;
                                                   gint PROFILE_WIDTH)
 {
   VikTrackpoint *trackpoint;
-  gdouble x = event_x - img_width / 2 + PROFILE_WIDTH / 2 - MARGIN / 2;
+  gdouble x = event_x - img_width / 2 + PROFILE_WIDTH / 2 - MARGIN_X / 2;
   if (x < 0)
     x = 0;
   if (x > PROFILE_WIDTH)
   if (x < 0)
     x = 0;
   if (x > PROFILE_WIDTH)
@@ -305,13 +391,13 @@ static VikTrackpoint *set_center_at_graph_position(gdouble event_x,
   if ( trackpoint ) {
     VikCoord coord = trackpoint->coord;
     if ( vlp ) {
   if ( trackpoint ) {
     VikCoord coord = trackpoint->coord;
     if ( vlp ) {
-      vik_viewport_set_center_coord ( vik_layers_panel_get_viewport(vlp), &coord );
+      vik_viewport_set_center_coord ( vik_layers_panel_get_viewport(vlp), &coord, TRUE );
       vik_layers_panel_emit_update ( vlp );
     }
     else {
       /* since vlp not set, vvp should be valid instead! */
       if ( vvp )
       vik_layers_panel_emit_update ( vlp );
     }
     else {
       /* since vlp not set, vvp should be valid instead! */
       if ( vvp )
-       vik_viewport_set_center_coord ( vvp, &coord );
+        vik_viewport_set_center_coord ( vvp, &coord, TRUE );
       vik_layer_emit_update ( VIK_LAYER(vtl) );
     }
   }
       vik_layer_emit_update ( VIK_LAYER(vtl) );
     }
   }
@@ -338,26 +424,26 @@ static void save_image_and_draw_graph_marks (GtkWidget *image,
 
   /* Restore previously saved image */
   if (saved_img->saved) {
 
   /* Restore previously saved image */
   if (saved_img->saved) {
-    gdk_draw_image(GDK_DRAWABLE(pix), gc, saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
+    gdk_draw_image(GDK_DRAWABLE(pix), gc, saved_img->img, 0, 0, 0, 0, MARGIN_X+PROFILE_WIDTH, MARGIN_Y+PROFILE_HEIGHT);
     saved_img->saved = FALSE;
   }
 
   // ATM always save whole image - as anywhere could have changed
   if (saved_img->img)
     saved_img->saved = FALSE;
   }
 
   // ATM always save whole image - as anywhere could have changed
   if (saved_img->img)
-    gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
+    gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN_X+PROFILE_WIDTH, MARGIN_Y+PROFILE_HEIGHT);
   else
   else
-    saved_img->img = gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN+PROFILE_WIDTH, PROFILE_HEIGHT);
+    saved_img->img = gdk_drawable_copy_to_image(GDK_DRAWABLE(pix), saved_img->img, 0, 0, 0, 0, MARGIN_X+PROFILE_WIDTH, MARGIN_Y+PROFILE_HEIGHT);
   saved_img->saved = TRUE;
 
   saved_img->saved = TRUE;
 
-  if ((marker_x >= MARGIN) && (marker_x < (PROFILE_WIDTH + MARGIN))) {
-    gdk_draw_line (GDK_DRAWABLE(pix), gc, marker_x, 0, marker_x, image->allocation.height);
+  if ((marker_x >= MARGIN_X) && (marker_x < (PROFILE_WIDTH + MARGIN_X))) {
+    gdk_draw_line (GDK_DRAWABLE(pix), gc, marker_x, MARGIN_Y, marker_x, PROFILE_HEIGHT + MARGIN_Y);
     *marker_drawn = TRUE;
   }
   else
     *marker_drawn = FALSE;
 
   // Draw a square blob to indicate where we are on track for this graph
     *marker_drawn = TRUE;
   }
   else
     *marker_drawn = FALSE;
 
   // Draw a square blob to indicate where we are on track for this graph
-  if ( (blob_x >= MARGIN) && (blob_x < (PROFILE_WIDTH + MARGIN)) && (blob_y < PROFILE_HEIGHT) ) {
+  if ( (blob_x >= MARGIN_X) && (blob_x < (PROFILE_WIDTH + MARGIN_X)) && (blob_y < PROFILE_HEIGHT+MARGIN_Y) ) {
     gdk_draw_rectangle (GDK_DRAWABLE(pix), gc, TRUE, blob_x-3, blob_y-3, 6, 6);
     *blob_drawn = TRUE;
   }
     gdk_draw_rectangle (GDK_DRAWABLE(pix), gc, TRUE, blob_x-3, blob_y-3, 6, 6);
     *blob_drawn = TRUE;
   }
@@ -414,7 +500,10 @@ static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, Prop
       graph_type == PROPWIN_GRAPH_TYPE_DISTANCE_TIME ||
       graph_type == PROPWIN_GRAPH_TYPE_ELEVATION_TIME );
 
       graph_type == PROPWIN_GRAPH_TYPE_DISTANCE_TIME ||
       graph_type == PROPWIN_GRAPH_TYPE_ELEVATION_TIME );
 
-  VikTrackpoint *trackpoint = set_center_at_graph_position(event->x, event_box->allocation.width, widgets->vtl, widgets->vlp, widgets->vvp, widgets->tr, is_time_graph, widgets->profile_width);
+  GtkAllocation allocation;
+  gtk_widget_get_allocation ( event_box, &allocation );
+
+  VikTrackpoint *trackpoint = set_center_at_graph_position(event->x, allocation.width, widgets->vtl, widgets->vlp, widgets->vvp, widgets->tr, is_time_graph, widgets->profile_width);
   // Unable to get the point so give up
   if ( trackpoint == NULL ) {
     gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
   // Unable to get the point so give up
   if ( trackpoint == NULL ) {
     gtk_dialog_set_response_sensitive(GTK_DIALOG(widgets->dialog), VIK_TRW_LAYER_PROPWIN_SPLIT_MARKER, FALSE);
@@ -483,7 +572,7 @@ static void track_graph_click( GtkWidget *event_box, GdkEventButton *event, Prop
        pc = tp_percentage_by_distance ( widgets->tr, trackpoint, widgets->track_length_inc_gaps );
 
       if (!isnan(pc)) {
        pc = tp_percentage_by_distance ( widgets->tr, trackpoint, widgets->track_length_inc_gaps );
 
       if (!isnan(pc)) {
-       gdouble marker_x = (pc * widgets->profile_width) + MARGIN;
+        gdouble marker_x = (pc * widgets->profile_width) + MARGIN_X;
        save_image_and_draw_graph_marks(image,
                                        marker_x,
                                        gtk_widget_get_style(window)->black_gc,
        save_image_and_draw_graph_marks(image,
                                        marker_x,
                                        gtk_widget_get_style(window)->black_gc,
@@ -639,7 +728,10 @@ void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, PropWidget
   else
     mouse_x = event->x;
 
   else
     mouse_x = event->x;
 
-  gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
+  GtkAllocation allocation;
+  gtk_widget_get_allocation ( event_box, &allocation );
+
+  gdouble x = mouse_x - allocation.width / 2 + widgets->profile_width / 2 - MARGIN_X / 2;
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
@@ -657,6 +749,9 @@ void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, PropWidget
     case VIK_UNITS_DISTANCE_MILES:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
       break;
     case VIK_UNITS_DISTANCE_MILES:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
       break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(meters_from_start) );
+      break;
     default:
       g_critical("Houston, we've had a problem. distance=%d", dist_units);
     }
     default:
       g_critical("Houston, we've had a problem. distance=%d", dist_units);
     }
@@ -688,15 +783,15 @@ void track_profile_move( GtkWidget *event_box, GdkEventMotion *event, PropWidget
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (!isnan(pc)) {
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (!isnan(pc)) {
-      marker_x = (pc * widgets->profile_width) + MARGIN;
+      marker_x = (pc * widgets->profile_width) + MARGIN_X;
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
-                                  MARGIN+x,
-                                  y_blob,
+                                  MARGIN_X+x,
+                                  MARGIN_Y+y_blob,
                                   &widgets->elev_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
                                   &widgets->elev_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
@@ -716,7 +811,10 @@ void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, PropWidge
   else
     mouse_x = event->x;
 
   else
     mouse_x = event->x;
 
-  gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
+  GtkAllocation allocation;
+  gtk_widget_get_allocation ( event_box, &allocation );
+
+  gdouble x = mouse_x - allocation.width / 2 + widgets->profile_width / 2 - MARGIN_X / 2;
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
@@ -734,6 +832,9 @@ void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, PropWidge
     case VIK_UNITS_DISTANCE_MILES:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
       break;
     case VIK_UNITS_DISTANCE_MILES:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
       break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(meters_from_start) );
+      break;
     default:
       g_critical("Houston, we've had a problem. distance=%d", dist_units);
     }
     default:
       g_critical("Houston, we've had a problem. distance=%d", dist_units);
     }
@@ -765,15 +866,15 @@ void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, PropWidge
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (!isnan(pc)) {
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (!isnan(pc)) {
-      marker_x = (pc * widgets->profile_width) + MARGIN;
+      marker_x = (pc * widgets->profile_width) + MARGIN_X;
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
-                                  MARGIN+x,
-                                  y_blob,
+                                  MARGIN_X+x,
+                                  MARGIN_Y+y_blob,
                                   &widgets->gradient_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
                                   &widgets->gradient_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
@@ -783,6 +884,31 @@ void track_gradient_move( GtkWidget *event_box, GdkEventMotion *event, PropWidge
   g_list_free(child);
 }
 
   g_list_free(child);
 }
 
+//
+static void time_label_update (GtkWidget *widget, time_t seconds_from_start)
+{
+  static gchar tmp_buf[20];
+  guint h = seconds_from_start/3600;
+  guint m = (seconds_from_start - h*3600)/60;
+  guint s = seconds_from_start - (3600*h) - (60*m);
+  g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
+  gtk_label_set_text(GTK_LABEL(widget), tmp_buf);
+}
+
+//
+static void real_time_label_update ( PropWidgets *widgets, GtkWidget *widget, VikTrackpoint *trackpoint)
+{
+  static gchar tmp_buf[64];
+  if ( trackpoint->has_timestamp ) {
+    // Alternatively could use %c format but I prefer a slightly more compact form here
+    //  The full date can of course be seen on the Statistics tab
+    strftime (tmp_buf, sizeof(tmp_buf), "%X %x %Z", localtime(&(trackpoint->timestamp)));
+  }
+  else
+    g_snprintf (tmp_buf, sizeof(tmp_buf), _("No Data"));
+  gtk_label_set_text(GTK_LABEL(widget), tmp_buf);
+}
+
 void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
 {
   int mouse_x, mouse_y;
 void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *widgets )
 {
   int mouse_x, mouse_y;
@@ -793,7 +919,9 @@ void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
   else
     mouse_x = event->x;
 
   else
     mouse_x = event->x;
 
-  gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
+  GtkAllocation allocation;
+  gtk_widget_get_allocation ( event_box, &allocation );
+  gdouble x = mouse_x - allocation.width / 2 + widgets->profile_width / 2 - MARGIN_X / 2;
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
@@ -802,14 +930,11 @@ void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
   time_t seconds_from_start;
   VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
   if (trackpoint && widgets->w_cur_time) {
   time_t seconds_from_start;
   VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
   if (trackpoint && widgets->w_cur_time) {
-    static gchar tmp_buf[20];
-    guint h, m, s;
-    h = seconds_from_start/3600;
-    m = (seconds_from_start - h*3600)/60;
-    s = seconds_from_start - (3600*h) - (60*m);
-    g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
+    time_label_update ( widgets->w_cur_time, seconds_from_start );
+  }
 
 
-    gtk_label_set_text(GTK_LABEL(widgets->w_cur_time), tmp_buf);
+  if (trackpoint && widgets->w_cur_time_real) {
+    real_time_label_update ( widgets, widgets->w_cur_time_real, trackpoint );
   }
 
   gint ix = (gint)x;
   }
 
   gint ix = (gint)x;
@@ -856,15 +981,15 @@ void track_vt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
     if (!isnan(pc)) {
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
     if (!isnan(pc)) {
-      marker_x = (pc * widgets->profile_width) + MARGIN;
+      marker_x = (pc * widgets->profile_width) + MARGIN_X;
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
-                                  MARGIN+x,
-                                  y_blob,
+                                  MARGIN_X+x,
+                                  MARGIN_Y+y_blob,
                                   &widgets->speed_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
                                   &widgets->speed_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
@@ -887,7 +1012,10 @@ void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
   else
     mouse_x = event->x;
 
   else
     mouse_x = event->x;
 
-  gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
+  GtkAllocation allocation;
+  gtk_widget_get_allocation ( event_box, &allocation );
+
+  gdouble x = mouse_x - allocation.width / 2 + widgets->profile_width / 2 - MARGIN_X / 2;
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
@@ -896,14 +1024,11 @@ void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
   time_t seconds_from_start;
   VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
   if (trackpoint && widgets->w_cur_dist_time) {
   time_t seconds_from_start;
   VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
   if (trackpoint && widgets->w_cur_dist_time) {
-    static gchar tmp_buf[20];
-    guint h, m, s;
-    h = seconds_from_start/3600;
-    m = (seconds_from_start - h*3600)/60;
-    s = seconds_from_start - (3600*h) - (60*m);
-    g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
+    time_label_update ( widgets->w_cur_dist_time, seconds_from_start );
+  }
 
 
-    gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_time), tmp_buf);
+  if (trackpoint && widgets->w_cur_dist_time_real) {
+    real_time_label_update ( widgets, widgets->w_cur_dist_time_real, trackpoint );
   }
 
   gint ix = (gint)x;
   }
 
   gint ix = (gint)x;
@@ -913,10 +1038,17 @@ void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
 
   if (trackpoint && widgets->w_cur_dist_dist) {
     static gchar tmp_buf[20];
 
   if (trackpoint && widgets->w_cur_dist_dist) {
     static gchar tmp_buf[20];
-    if ( a_vik_get_units_distance () == VIK_UNITS_DISTANCE_MILES )
+    switch ( a_vik_get_units_distance () ) {
+    case VIK_UNITS_DISTANCE_MILES:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", widgets->distances[ix]);
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", widgets->distances[ix]);
-    else
+      break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", widgets->distances[ix]);
+      break;
+    default:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", widgets->distances[ix]);
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f km", widgets->distances[ix]);
+      break;
+    }
     gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_dist), tmp_buf);
   }
 
     gtk_label_set_text(GTK_LABEL(widgets->w_cur_dist_dist), tmp_buf);
   }
 
@@ -935,15 +1067,15 @@ void track_dt_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
     if (!isnan(pc)) {
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
     if (!isnan(pc)) {
-      marker_x = (pc * widgets->profile_width) + MARGIN;
+      marker_x = (pc * widgets->profile_width) + MARGIN_X;
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
-                                  MARGIN+x,
-                                  y_blob,
+                                  MARGIN_X+x,
+                                  MARGIN_Y+y_blob,
                                   &widgets->dist_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
                                   &widgets->dist_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
@@ -966,7 +1098,10 @@ void track_et_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
   else
     mouse_x = event->x;
 
   else
     mouse_x = event->x;
 
-  gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
+  GtkAllocation allocation;
+  gtk_widget_get_allocation ( event_box, &allocation );
+
+  gdouble x = mouse_x - allocation.width / 2 + widgets->profile_width / 2 - MARGIN_X / 2;
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
@@ -975,14 +1110,11 @@ void track_et_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
   time_t seconds_from_start;
   VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
   if (trackpoint && widgets->w_cur_elev_time) {
   time_t seconds_from_start;
   VikTrackpoint *trackpoint = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, (gdouble) x / widgets->profile_width, &seconds_from_start );
   if (trackpoint && widgets->w_cur_elev_time) {
-    static gchar tmp_buf[20];
-    guint h, m, s;
-    h = seconds_from_start/3600;
-    m = (seconds_from_start - h*3600)/60;
-    s = seconds_from_start - (3600*h) - (60*m);
-    g_snprintf(tmp_buf, sizeof(tmp_buf), "%02d:%02d:%02d", h, m, s);
+    time_label_update ( widgets->w_cur_elev_time, seconds_from_start );
+  }
 
 
-    gtk_label_set_text(GTK_LABEL(widgets->w_cur_elev_time), tmp_buf);
+  if (trackpoint && widgets->w_cur_elev_time_real) {
+    real_time_label_update ( widgets, widgets->w_cur_elev_time_real, trackpoint );
   }
 
   gint ix = (gint)x;
   }
 
   gint ix = (gint)x;
@@ -1014,15 +1146,15 @@ void track_et_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
     if (!isnan(pc)) {
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
     if (!isnan(pc)) {
-      marker_x = (pc * widgets->profile_width) + MARGIN;
+      marker_x = (pc * widgets->profile_width) + MARGIN_X;
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
-                                  MARGIN+x,
-                                  y_blob,
+                                  MARGIN_X+x,
+                                  MARGIN_Y+y_blob,
                                   &widgets->elev_time_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
                                   &widgets->elev_time_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
@@ -1042,7 +1174,10 @@ void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
   else
     mouse_x = event->x;
 
   else
     mouse_x = event->x;
 
-  gdouble x = mouse_x - event_box->allocation.width / 2 + widgets->profile_width / 2 - MARGIN / 2;
+  GtkAllocation allocation;
+  gtk_widget_get_allocation ( event_box, &allocation );
+
+  gdouble x = mouse_x - allocation.width / 2 + widgets->profile_width / 2 - MARGIN_X / 2;
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
   if (x < 0)
     x = 0;
   if (x > widgets->profile_width)
@@ -1060,6 +1195,9 @@ void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
     case VIK_UNITS_DISTANCE_MILES:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
       break;
     case VIK_UNITS_DISTANCE_MILES:
       g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(meters_from_start) );
       break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(meters_from_start) );
+      break;
     default:
       g_critical("Houston, we've had a problem. distance=%d", dist_units);
     }
     default:
       g_critical("Houston, we've had a problem. distance=%d", dist_units);
     }
@@ -1110,15 +1248,15 @@ void track_sd_move( GtkWidget *event_box, GdkEventMotion *event, PropWidgets *wi
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (!isnan(pc)) {
   if (widgets->is_marker_drawn) {
     gdouble pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (!isnan(pc)) {
-      marker_x = (pc * widgets->profile_width) + MARGIN;
+      marker_x = (pc * widgets->profile_width) + MARGIN_X;
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
     }
   }
 
   save_image_and_draw_graph_marks (image,
                                   marker_x,
                                   gtk_widget_get_style(window)->black_gc,
-                                  MARGIN+x,
-                                  y_blob,
+                                  MARGIN_X+x,
+                                  MARGIN_Y+y_blob,
                                   &widgets->speed_dist_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
                                   &widgets->speed_dist_graph_saved_img,
                                   widgets->profile_width,
                                   widgets->profile_height,
@@ -1155,6 +1293,9 @@ static void draw_dem_alt_speed_dist(VikTrack *tr,
     max_speed = max_speed_in * 110 / 100;
 
   gdouble dist = 0;
     max_speed = max_speed_in * 110 / 100;
 
   gdouble dist = 0;
+  gint h2 = height + MARGIN_Y; // Adjust height for x axis labelling offset
+  gint achunk = chunksa[cia]*LINES;
+
   for (iter = tr->trackpoints->next; iter; iter = iter->next) {
     int x;
     dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
   for (iter = tr->trackpoints->next; iter; iter = iter->next) {
     int x;
     dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
@@ -1169,28 +1310,28 @@ static void draw_dem_alt_speed_dist(VikTrack *tr,
          elev =  VIK_METERS_TO_FEET(elev);
        // No conversion needed if already in metres
 
          elev =  VIK_METERS_TO_FEET(elev);
        // No conversion needed if already in metres
 
-       // consider chunk size
-       int y_alt = height - ((height * elev)/(chunksa[cia]*LINES) );
-       gdk_draw_rectangle(GDK_DRAWABLE(pix), alt_gc, TRUE, x-2, y_alt-2, 4, 4);
+        // consider chunk size
+        int y_alt = h2 - ((height * elev)/achunk );
+        gdk_draw_rectangle(GDK_DRAWABLE(pix), alt_gc, TRUE, x-2, y_alt-2, 4, 4);
       }
     }
     if (do_speed) {
       // This is just a speed indicator - no actual values can be inferred by user
       if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
       }
     }
     if (do_speed) {
       // This is just a speed indicator - no actual values can be inferred by user
       if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
-       int y_speed = height - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
-       gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
+        int y_speed = h2 - (height * VIK_TRACKPOINT(iter->data)->speed)/max_speed;
+        gdk_draw_rectangle(GDK_DRAWABLE(pix), speed_gc, TRUE, x-2, y_speed-2, 4, 4);
       }
     }
   }
 }
 
 /**
       }
     }
   }
 }
 
 /**
- * draw_grid:
+ * draw_grid_y:
  *
  * A common way to draw the grid with y axis labels
  *
  */
  *
  * A common way to draw the grid with y axis labels
  *
  */
-static void draw_grid ( GtkWidget *window, GtkWidget *image, PropWidgets *widgets, GdkPixmap *pix, gchar *ss, gint i )
+static void draw_grid_y ( GtkWidget *window, GtkWidget *image, PropWidgets *widgets, GdkPixmap *pix, gchar *ss, gint i )
 {
   PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
 
 {
   PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
 
@@ -1204,13 +1345,163 @@ static void draw_grid ( GtkWidget *window, GtkWidget *image, PropWidgets *widget
   int w, h;
   pango_layout_get_pixel_size ( pl, &w, &h );
 
   int w, h;
   pango_layout_get_pixel_size ( pl, &w, &h );
 
-  gdk_draw_layout ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0], MARGIN-w-3,
-                    CLAMP((int)i*widgets->profile_height/LINES - h/2, 0, widgets->profile_height-h), pl );
+  gdk_draw_layout ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0],
+                    MARGIN_X-w-3,
+                    CLAMP((int)i*widgets->profile_height/LINES - h/2 + MARGIN_Y, 0, widgets->profile_height-h+MARGIN_Y),
+                    pl );
+  g_object_unref ( G_OBJECT ( pl ) );
 
   gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
 
   gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
-                  MARGIN, widgets->profile_height/LINES * i, MARGIN + widgets->profile_width, widgets->profile_height/LINES * i );
-  g_object_unref ( G_OBJECT ( pl ) );
-  pl = NULL;
+                  MARGIN_X, MARGIN_Y + widgets->profile_height/LINES * i,
+                  MARGIN_X + widgets->profile_width, MARGIN_Y + widgets->profile_height/LINES * i );
+}
+
+/**
+ * draw_grid_x_time:
+ *
+ * A common way to draw the grid with x axis labels for time graphs
+ *
+ */
+static void draw_grid_x_time ( GtkWidget *window, GtkWidget *image, PropWidgets *widgets, GdkPixmap *pix, guint ii, guint tt, guint xx )
+{
+  gchar *label_markup = NULL;
+  switch (ii) {
+    case 0:
+    case 1:
+    case 2:
+    case 3:
+      // Minutes
+      label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", tt/60, _("mins") );
+      break;
+    case 4:
+    case 5:
+    case 6:
+    case 7:
+      // Hours
+      label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", (gdouble)tt/(60*60), _("h") );
+      break;
+    case 8:
+    case 9:
+    case 10:
+      // Days
+      label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", (gdouble)tt/(60*60*24), _("d") );
+      break;
+    case 11:
+    case 12:
+      // Weeks
+      label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", (gdouble)tt/(60*60*24*7), _("w") );
+      break;
+    case 13:
+      // 'Months'
+      label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", (gdouble)tt/(60*60*24*28), _("M") );
+      break;
+    default:
+      break;
+  }
+  if ( label_markup ) {
+
+    PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
+    pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
+
+    pango_layout_set_markup ( pl, label_markup, -1 );
+    g_free ( label_markup );
+    int ww, hh;
+    pango_layout_get_pixel_size ( pl, &ww, &hh );
+
+    gdk_draw_layout ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0],
+                      MARGIN_X+xx-ww/2, MARGIN_Y/2-hh/2, pl );
+    g_object_unref ( G_OBJECT ( pl ) );
+  }
+
+  gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
+                  MARGIN_X+xx, MARGIN_Y, MARGIN_X+xx, MARGIN_Y+widgets->profile_height );
+}
+
+/**
+ * draw_grid_x_distance:
+ *
+ * A common way to draw the grid with x axis labels for distance graphs
+ *
+ */
+static void draw_grid_x_distance ( GtkWidget *window, GtkWidget *image, PropWidgets *widgets, GdkPixmap *pix, guint ii, gdouble dd, guint xx, vik_units_distance_t dist_units )
+{
+  gchar *label_markup = NULL;
+  switch ( dist_units ) {
+  case VIK_UNITS_DISTANCE_MILES:
+    if ( ii > 4 )
+      label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("miles") );
+    else
+      label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("miles") );
+    break;
+  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+    if ( ii > 4 )
+      label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("NM") );
+    else
+      label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("NM") );
+    break;
+  default:
+    // VIK_UNITS_DISTANCE_KILOMETRES:
+    if ( ii > 4 )
+      label_markup = g_strdup_printf ( "<span size=\"small\">%d %s</span>", (guint)dd, _("km") );
+    else
+      label_markup = g_strdup_printf ( "<span size=\"small\">%.1f %s</span>", dd, _("km") );
+    break;
+  }
+
+  if ( label_markup ) {
+    PangoLayout *pl = gtk_widget_create_pango_layout (GTK_WIDGET(image), NULL);
+    pango_layout_set_font_description (pl, gtk_widget_get_style(window)->font_desc);
+
+    pango_layout_set_markup ( pl, label_markup, -1 );
+    g_free ( label_markup );
+    int ww, hh;
+    pango_layout_get_pixel_size ( pl, &ww, &hh );
+
+    gdk_draw_layout ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->fg_gc[0],
+                      MARGIN_X+xx-ww/2, MARGIN_Y/2-hh/2, pl );
+    g_object_unref ( G_OBJECT ( pl ) );
+  }
+
+  gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[0],
+                  MARGIN_X+xx, MARGIN_Y, MARGIN_X+xx, MARGIN_Y+widgets->profile_height );
+}
+
+/**
+ * clear the images (scale texts & actual graph)
+ */
+static void clear_images (GdkPixmap *pix, GtkWidget *window, PropWidgets *widgets)
+{
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
+                     TRUE, 0, 0, widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
+                     TRUE, 0, 0, widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y);
+}
+
+/**
+ *
+ */
+static void draw_distance_divisions ( GtkWidget *window, GtkWidget *image, GdkPixmap *pix, PropWidgets *widgets, vik_units_distance_t dist_units )
+{
+  // Set to display units from length in metres.
+  gdouble length = widgets->track_length_inc_gaps;
+  switch (dist_units) {
+    case VIK_UNITS_DISTANCE_MILES:
+      length = VIK_METERS_TO_MILES(length);
+      break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      length = VIK_METERS_TO_NAUTICAL_MILES(length);
+      break;
+    default:
+      // KM
+      length = length/1000.0;
+      break;
+  }
+  guint index = get_distance_chunk_index ( length );
+  gdouble dist_per_pixel = length/widgets->profile_width;
+
+  for (guint i=1; chunksd[index]*i <= length; i++) {
+    draw_grid_x_distance ( window, image, widgets, pix, index, chunksd[index]*i, (guint)(chunksd[index]*i/dist_per_pixel), dist_units );
+  }
 }
 
 /**
 }
 
 /**
@@ -1218,9 +1509,6 @@ static void draw_grid ( GtkWidget *window, GtkWidget *image, PropWidgets *widget
  */
 static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 {
  */
 static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 {
-  GtkWidget *window;
-  GdkPixmap *pix;
-  gdouble mina, maxa;
   guint i;
 
   GdkGC *no_alt_info;
   guint i;
 
   GdkGC *no_alt_info;
@@ -1250,12 +1538,10 @@ static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widget
   get_new_min_and_chunk_index (widgets->min_altitude, widgets->max_altitude, chunksa, G_N_ELEMENTS(chunksa), &widgets->draw_min_altitude, &widgets->cia);
 
   // Assign locally
   get_new_min_and_chunk_index (widgets->min_altitude, widgets->max_altitude, chunksa, G_N_ELEMENTS(chunksa), &widgets->draw_min_altitude, &widgets->cia);
 
   // Assign locally
-  mina = widgets->draw_min_altitude;
-  maxa = widgets->max_altitude;
-
-  window = gtk_widget_get_toplevel (widgets->elev_box);
+  gdouble mina = widgets->draw_min_altitude;
 
 
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  GtkWidget *window = gtk_widget_get_toplevel (widgets->elev_box);
+  GdkPixmap *pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
@@ -1263,12 +1549,9 @@ static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widget
   gdk_color_parse ( "yellow", &color );
   gdk_gc_set_rgb_fg_color ( no_alt_info, &color);
 
   gdk_color_parse ( "yellow", &color );
   gdk_gc_set_rgb_fg_color ( no_alt_info, &color);
 
-  /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
-                    TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
-                    TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
-  
+  // Reset before redrawing
+  clear_images (pix, window, widgets);
+
   /* draw grid */
   for (i=0; i<=LINES; i++) {
     gchar s[32];
   /* draw grid */
   for (i=0; i<=LINES; i++) {
     gchar s[32];
@@ -1286,17 +1569,20 @@ static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widget
       g_critical("Houston, we've had a problem. height=%d", height_units);
     }
 
       g_critical("Houston, we've had a problem. height=%d", height_units);
     }
 
-    draw_grid ( window, image, widgets, pix, s, i );
+    draw_grid_y ( window, image, widgets, pix, s, i );
   }
 
   }
 
+  draw_distance_divisions ( window, image, pix, widgets, a_vik_get_units_distance() );
+
   /* draw elevations */
   /* draw elevations */
+  guint height = MARGIN_Y+widgets->profile_height;
   for ( i = 0; i < widgets->profile_width; i++ )
     if ( widgets->altitudes[i] == VIK_DEFAULT_ALTITUDE )
       gdk_draw_line ( GDK_DRAWABLE(pix), no_alt_info, 
   for ( i = 0; i < widgets->profile_width; i++ )
     if ( widgets->altitudes[i] == VIK_DEFAULT_ALTITUDE )
       gdk_draw_line ( GDK_DRAWABLE(pix), no_alt_info, 
-                     i + MARGIN, 0, i + MARGIN, widgets->profile_height );
+                      i + MARGIN_X, MARGIN_Y, i + MARGIN_X, height );
     else 
       gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
     else 
       gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
-                     i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->altitudes[i]-mina)/(chunksa[widgets->cia]*LINES) );
+                      i + MARGIN_X, height, i + MARGIN_X, height-widgets->profile_height*(widgets->altitudes[i]-mina)/(chunksa[widgets->cia]*LINES) );
 
   if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)) ||
        gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)) ) {
 
   if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)) ||
        gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)) ) {
@@ -1319,12 +1605,12 @@ static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widget
                            dem_alt_gc,
                            gps_speed_gc,
                            mina,
                            dem_alt_gc,
                            gps_speed_gc,
                            mina,
-                           maxa - mina,
+                           widgets->max_altitude - mina,
                            widgets->max_speed,
                            widgets->cia,
                            widgets->profile_width,
                            widgets->profile_height,
                            widgets->max_speed,
                            widgets->cia,
                            widgets->profile_width,
                            widgets->profile_height,
-                           MARGIN,
+                           MARGIN_X,
                            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)),
                            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
     
                            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_dem)),
                            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
     
@@ -1333,7 +1619,7 @@ static void draw_elevations (GtkWidget *image, VikTrack *tr, PropWidgets *widget
   }
 
   /* draw border */
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN_X, MARGIN_Y, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
   g_object_unref ( G_OBJECT(no_alt_info) );
 
   g_object_unref ( G_OBJECT(pix) );
   g_object_unref ( G_OBJECT(no_alt_info) );
@@ -1365,7 +1651,7 @@ static void draw_speed_dist(VikTrack *tr,
     int x;
     dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
                             &(VIK_TRACKPOINT(iter->prev->data)->coord) );
     int x;
     dist += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord),
                             &(VIK_TRACKPOINT(iter->prev->data)->coord) );
-    x = (width * dist)/total_length + margin;
+    x = (width * dist)/total_length + MARGIN_X;
     if (do_speed) {
       // This is just a speed indicator - no actual values can be inferred by user
       if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
     if (do_speed) {
       // This is just a speed indicator - no actual values can be inferred by user
       if (!isnan(VIK_TRACKPOINT(iter->data)->speed)) {
@@ -1381,13 +1667,8 @@ static void draw_speed_dist(VikTrack *tr,
  */
 static void draw_gradients (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 {
  */
 static void draw_gradients (GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 {
-  GtkWidget *window;
-  GdkPixmap *pix;
-  gdouble mina;
   guint i;
 
   guint i;
 
-  GdkColor color;
-
   // Free previous allocation
   if ( widgets->gradients )
     g_free ( widgets->gradients );
   // Free previous allocation
   if ( widgets->gradients )
     g_free ( widgets->gradients );
@@ -1402,37 +1683,37 @@ static void draw_gradients (GtkWidget *image, VikTrack *tr, PropWidgets *widgets
   get_new_min_and_chunk_index (widgets->min_gradient, widgets->max_gradient, chunksg, G_N_ELEMENTS(chunksg), &widgets->draw_min_gradient, &widgets->cig);
 
   // Assign locally
   get_new_min_and_chunk_index (widgets->min_gradient, widgets->max_gradient, chunksg, G_N_ELEMENTS(chunksg), &widgets->draw_min_gradient, &widgets->cig);
 
   // Assign locally
-  mina = widgets->draw_min_gradient;
-
-  window = gtk_widget_get_toplevel (widgets->gradient_box);
+  gdouble mina = widgets->draw_min_gradient;
 
 
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  GtkWidget *window = gtk_widget_get_toplevel (widgets->gradient_box);
+  GdkPixmap *pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
-  /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
-                    TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
-                    TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
-  
+  // Reset before redrawing
+  clear_images (pix, window, widgets);
+
   /* draw grid */
   for (i=0; i<=LINES; i++) {
     gchar s[32];
 
     sprintf(s, "%8d%%", (int)(mina + (LINES-i)*chunksg[widgets->cig]));
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
     gchar s[32];
 
     sprintf(s, "%8d%%", (int)(mina + (LINES-i)*chunksg[widgets->cig]));
 
-    draw_grid ( window, image, widgets, pix, s, i );
+    draw_grid_y ( window, image, widgets, pix, s, i );
   }
 
   }
 
+  draw_distance_divisions ( window, image, pix, widgets, a_vik_get_units_distance() );
+
   /* draw gradients */
   /* draw gradients */
+  guint height = widgets->profile_height + MARGIN_Y;
   for ( i = 0; i < widgets->profile_width; i++ )
     gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
   for ( i = 0; i < widgets->profile_width; i++ )
     gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
-                     i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->gradients[i]-mina)/(chunksg[widgets->cig]*LINES) );
+                    i + MARGIN_X, height, i + MARGIN_X, height - widgets->profile_height*(widgets->gradients[i]-mina)/(chunksg[widgets->cig]*LINES) );
 
   if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_gradient_gps_speed)) ) {
     GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
 
 
   if ( gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_gradient_gps_speed)) ) {
     GdkGC *gps_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
 
+    GdkColor color;
     gdk_color_parse ( "red", &color );
     gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
 
     gdk_color_parse ( "red", &color );
     gdk_gc_set_rgb_fg_color ( gps_speed_gc, &color);
 
@@ -1446,26 +1727,37 @@ static void draw_gradients (GtkWidget *image, VikTrack *tr, PropWidgets *widgets
                            widgets->max_speed,
                            widgets->profile_width,
                            widgets->profile_height,
                            widgets->max_speed,
                            widgets->profile_width,
                            widgets->profile_height,
-                           MARGIN,
+                           MARGIN_X,
                            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
     
     g_object_unref ( G_OBJECT(gps_speed_gc) );
   }
 
   /* draw border */
                            gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed)));
     
     g_object_unref ( G_OBJECT(gps_speed_gc) );
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN_X, MARGIN_Y, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
 }
 
 
   g_object_unref ( G_OBJECT(pix) );
 }
 
+static void draw_time_lines ( GtkWidget *window, GtkWidget *image, GdkPixmap *pix, PropWidgets *widgets )
+{
+  guint index = get_time_chunk_index ( widgets->duration );
+  gdouble time_per_pixel = (gdouble)(widgets->duration)/widgets->profile_width;
+
+  // If stupidly long track in time - don't bother trying to draw grid lines
+  if ( widgets->duration > chunkst[G_N_ELEMENTS(chunkst)-1]*LINES*LINES )
+    return;
+
+  for (guint i=1; chunkst[index]*i <= widgets->duration; i++) {
+    draw_grid_x_time ( window, image, widgets, pix, index, chunkst[index]*i, (guint)(chunkst[index]*i/time_per_pixel) );
+  }
+}
+
 /**
  * Draw just the speed (velocity)/time image
  */
 static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
 {
 /**
  * Draw just the speed (velocity)/time image
  */
 static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
 {
-  GtkWidget *window;
-  GdkPixmap *pix;
-  gdouble mins;
   guint i;
 
   // Free previous allocation
   guint i;
 
   // Free previous allocation
@@ -1476,6 +1768,11 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
   if ( widgets->speeds == NULL )
     return;
 
   if ( widgets->speeds == NULL )
     return;
 
+  widgets->duration = vik_track_get_duration ( tr );
+  // Negative time or other problem
+  if ( widgets->duration <= 0 )
+    return;
+
   // Convert into appropriate units
   vik_units_speed_t speed_units = a_vik_get_units_speed ();
   switch (speed_units) {
   // Convert into appropriate units
   vik_units_speed_t speed_units = a_vik_get_units_speed ();
   switch (speed_units) {
@@ -1500,9 +1797,8 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
     break;
   }
 
     break;
   }
 
-  window = gtk_widget_get_toplevel (widgets->speed_box);
-
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  GtkWidget *window = gtk_widget_get_toplevel (widgets->speed_box);
+  GdkPixmap *pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
@@ -1514,13 +1810,10 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
   get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed, chunkss, G_N_ELEMENTS(chunkss), &widgets->draw_min_speed, &widgets->cis);
 
   // Assign locally
   get_new_min_and_chunk_index (widgets->min_speed, widgets->max_speed, chunkss, G_N_ELEMENTS(chunkss), &widgets->draw_min_speed, &widgets->cis);
 
   // Assign locally
-  mins = widgets->draw_min_speed;
-  
-  /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
-                    TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
-                    TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
+  gdouble mins = widgets->draw_min_speed;
+
+  // Reset before redrawing
+  clear_images (pix, window, widgets);
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
@@ -1545,15 +1838,16 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
 
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
 
-    draw_grid ( window, image, widgets, pix, s, i );
+    draw_grid_y ( window, image, widgets, pix, s, i );
   }
   }
-  
+
+  draw_time_lines ( window, image, pix, widgets );
 
   /* draw speeds */
 
   /* draw speeds */
+  guint height = widgets->profile_height + MARGIN_Y;
   for ( i = 0; i < widgets->profile_width; i++ )
     gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
   for ( i = 0; i < widgets->profile_width; i++ )
     gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
-                     i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds[i]-mins)/(chunkss[widgets->cis]*LINES) );
-
+                    i + MARGIN_X, height, i + MARGIN_X, height - widgets->profile_height*(widgets->speeds[i]-mins)/(chunkss[widgets->cis]*LINES) );
 
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_gps_speed)) ) {
 
 
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_gps_speed)) ) {
 
@@ -1585,15 +1879,15 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
        // No need to convert as already in m/s
        break;
       }
        // No need to convert as already in m/s
        break;
       }
-      int x = MARGIN + widgets->profile_width * (VIK_TRACKPOINT(iter->data)->timestamp - beg_time) / dur;
-      int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cis]*LINES);
+      int x = MARGIN_X + widgets->profile_width * (VIK_TRACKPOINT(iter->data)->timestamp - beg_time) / dur;
+      int y = height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cis]*LINES);
       gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
     }
     g_object_unref ( G_OBJECT(gps_speed_gc) );
   }
 
   /* draw border */
       gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
     }
     g_object_unref ( G_OBJECT(gps_speed_gc) );
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN_X, MARGIN_Y, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
 }
 
   g_object_unref ( G_OBJECT(pix) );
 }
@@ -1603,9 +1897,6 @@ static void draw_vt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
  */
 static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 {
  */
 static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 {
-  GtkWidget *window;
-  GdkPixmap *pix;
-  gdouble maxd;
   guint i;
 
   // Free previous allocation
   guint i;
 
   // Free previous allocation
@@ -1618,58 +1909,84 @@ static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 
   // Convert into appropriate units
   vik_units_distance_t dist_units = a_vik_get_units_distance ();
 
   // Convert into appropriate units
   vik_units_distance_t dist_units = a_vik_get_units_distance ();
-  if ( dist_units == VIK_UNITS_DISTANCE_MILES ) {
-    for ( i = 0; i < widgets->profile_width; i++ ) {
-      widgets->distances[i] = VIK_METERS_TO_MILES(widgets->distances[i]);
-    }
-  }
-  else {
-    // Metres - but want in kms
-    for ( i = 0; i < widgets->profile_width; i++ ) {
-      widgets->distances[i] = widgets->distances[i]/1000.0;
-    }
+  switch ( dist_units ) {
+    case VIK_UNITS_DISTANCE_MILES:
+      for ( i = 0; i < widgets->profile_width; i++ ) {
+        widgets->distances[i] = VIK_METERS_TO_MILES(widgets->distances[i]);
+      }
+      break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      for ( i = 0; i < widgets->profile_width; i++ ) {
+        widgets->distances[i] = VIK_METERS_TO_NAUTICAL_MILES(widgets->distances[i]);
+      }
+      break;
+    default:
+      // Metres - but want in kms
+      for ( i = 0; i < widgets->profile_width; i++ ) {
+        widgets->distances[i] = widgets->distances[i]/1000.0;
+      }
+      break;
   }
 
   }
 
-  window = gtk_widget_get_toplevel (widgets->dist_box);
+  widgets->duration = vik_track_get_duration ( widgets->tr );
+  // Negative time or other problem
+  if ( widgets->duration <= 0 )
+    return;
 
 
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  GtkWidget *window = gtk_widget_get_toplevel (widgets->dist_box);
+  GdkPixmap *pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
   // easy to work out min / max of distance!
   // Assign locally
   // mind = 0.0; - Thus not used
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
   // easy to work out min / max of distance!
   // Assign locally
   // mind = 0.0; - Thus not used
-  if ( dist_units == VIK_UNITS_DISTANCE_MILES )
+  gdouble maxd;
+  switch ( dist_units ) {
+  case VIK_UNITS_DISTANCE_MILES:
     maxd = VIK_METERS_TO_MILES(vik_track_get_length_including_gaps (tr));
     maxd = VIK_METERS_TO_MILES(vik_track_get_length_including_gaps (tr));
-  else
+    break;
+  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+    maxd = VIK_METERS_TO_NAUTICAL_MILES(vik_track_get_length_including_gaps (tr));
+    break;
+  default:
     maxd = vik_track_get_length_including_gaps (tr) / 1000.0;
     maxd = vik_track_get_length_including_gaps (tr) / 1000.0;
+    break;
+  }
 
   /* Find suitable chunk index */
   gdouble dummy = 0.0; // expect this to remain the same! (not that it's used)
   get_new_min_and_chunk_index (0, maxd, chunksd, G_N_ELEMENTS(chunksd), &dummy, &widgets->cid);
 
 
   /* Find suitable chunk index */
   gdouble dummy = 0.0; // expect this to remain the same! (not that it's used)
   get_new_min_and_chunk_index (0, maxd, chunksd, G_N_ELEMENTS(chunksd), &dummy, &widgets->cid);
 
-  /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
-                    TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
-                    TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
+  // Reset before redrawing
+  clear_images (pix, window, widgets);
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
     gchar s[32];
 
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
     gchar s[32];
 
-    if ( dist_units == VIK_UNITS_DISTANCE_MILES )
+    switch ( dist_units ) {
+    case VIK_UNITS_DISTANCE_MILES:
       sprintf(s, _("%.1f miles"), ((LINES-i)*chunksd[widgets->cid]));
       sprintf(s, _("%.1f miles"), ((LINES-i)*chunksd[widgets->cid]));
-    else
+      break;
+    case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+      sprintf(s, _("%.1f NM"), ((LINES-i)*chunksd[widgets->cid]));
+      break;
+    default:
       sprintf(s, _("%.1f km"), ((LINES-i)*chunksd[widgets->cid]));
       sprintf(s, _("%.1f km"), ((LINES-i)*chunksd[widgets->cid]));
+      break;
+    }
 
 
-    draw_grid ( window, image, widgets, pix, s, i );
+    draw_grid_y ( window, image, widgets, pix, s, i );
   }
   
   }
   
+  draw_time_lines ( window, image, pix, widgets );
+
   /* draw distance */
   /* draw distance */
+  guint height = widgets->profile_height + MARGIN_Y;
   for ( i = 0; i < widgets->profile_width; i++ )
     gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
   for ( i = 0; i < widgets->profile_width; i++ )
     gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
-                     i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->distances[i])/(chunksd[widgets->cid]*LINES) );
+                    i + MARGIN_X, height, i + MARGIN_X, height - widgets->profile_height*(widgets->distances[i])/(chunksd[widgets->cid]*LINES) );
 
   // Show speed indicator
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_dist_speed)) ) {
 
   // Show speed indicator
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_dist_speed)) ) {
@@ -1682,16 +1999,15 @@ static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
     max_speed = widgets->max_speed * 110 / 100;
 
     // This is just an indicator - no actual values can be inferred by user
     max_speed = widgets->max_speed * 110 / 100;
 
     // This is just an indicator - no actual values can be inferred by user
-    gint i;
     for ( i = 0; i < widgets->profile_width; i++ ) {
       int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
     for ( i = 0; i < widgets->profile_width; i++ ) {
       int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
-      gdk_draw_rectangle(GDK_DRAWABLE(pix), dist_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
+      gdk_draw_rectangle(GDK_DRAWABLE(pix), dist_speed_gc, TRUE, i+MARGIN_X-2, y_speed-2, 4, 4);
     }
     g_object_unref ( G_OBJECT(dist_speed_gc) );
   }
 
   /* draw border */
     }
     g_object_unref ( G_OBJECT(dist_speed_gc) );
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN_X, MARGIN_Y, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
 
 
   g_object_unref ( G_OBJECT(pix) );
 
@@ -1702,9 +2018,6 @@ static void draw_dt ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
  */
 static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 {
  */
 static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
 {
-  GtkWidget *window;
-  GdkPixmap *pix;
-  gdouble mina;
   guint i;
 
   // Free previous allocation
   guint i;
 
   // Free previous allocation
@@ -1731,19 +2044,20 @@ static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
   get_new_min_and_chunk_index (widgets->min_altitude, widgets->max_altitude, chunksa, G_N_ELEMENTS(chunksa), &widgets->draw_min_altitude_time, &widgets->ciat);
 
   // Assign locally
   get_new_min_and_chunk_index (widgets->min_altitude, widgets->max_altitude, chunksa, G_N_ELEMENTS(chunksa), &widgets->draw_min_altitude_time, &widgets->ciat);
 
   // Assign locally
-  mina = widgets->draw_min_altitude_time;
+  gdouble mina = widgets->draw_min_altitude_time;
 
 
-  window = gtk_widget_get_toplevel (widgets->elev_time_box);
+  widgets->duration = vik_track_get_duration ( widgets->tr );
+  // Negative time or other problem
+  if ( widgets->duration <= 0 )
+    return;
 
 
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  GtkWidget *window = gtk_widget_get_toplevel (widgets->elev_time_box);
+  GdkPixmap *pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
-  /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
-                    TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
-                    TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
+  // Reset before redrawing
+  clear_images (pix, window, widgets);
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
@@ -1762,38 +2076,70 @@ static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
       g_critical("Houston, we've had a problem. height=%d", height_units);
     }
 
       g_critical("Houston, we've had a problem. height=%d", height_units);
     }
 
-    draw_grid ( window, image, widgets, pix, s, i );
+    draw_grid_y ( window, image, widgets, pix, s, i );
   }
 
   }
 
+  draw_time_lines ( window, image, pix, widgets );
+
   /* draw elevations */
   /* draw elevations */
+  guint height = widgets->profile_height + MARGIN_Y;
   for ( i = 0; i < widgets->profile_width; i++ )
     gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
   for ( i = 0; i < widgets->profile_width; i++ )
     gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
-                     i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->ats[i]-mina)/(chunksa[widgets->ciat]*LINES) );
+                    i + MARGIN_X, height, i + MARGIN_X, height-widgets->profile_height*(widgets->ats[i]-mina)/(chunksa[widgets->ciat]*LINES) );
 
 
-  // Show speed indicator
+  // Show DEMS
+  if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_elev_dem)) )  {
+    GdkColor color;
+    GdkGC *dem_alt_gc = gdk_gc_new ( gtk_widget_get_window(window) );
+    gdk_color_parse ( "green", &color );
+    gdk_gc_set_rgb_fg_color ( dem_alt_gc, &color);
+
+    gint h2 = widgets->profile_height + MARGIN_Y; // Adjust height for x axis labelling offset
+    gint achunk = chunksa[widgets->ciat]*LINES;
+
+    for ( i = 0; i < widgets->profile_width; i++ ) {
+      // This could be slow doing this each time...
+      VikTrackpoint *tp = vik_track_get_closest_tp_by_percentage_time ( widgets->tr, ((gdouble)i/(gdouble)widgets->profile_width), NULL );
+      if ( tp ) {
+        gint16 elev = a_dems_get_elev_by_coord(&(tp->coord), VIK_DEM_INTERPOL_SIMPLE);
+        elev -= mina; //?
+        if ( elev != VIK_DEM_INVALID_ELEVATION ) {
+          // Convert into height units
+          if ( a_vik_get_units_height () == VIK_UNITS_HEIGHT_FEET )
+            elev = VIK_METERS_TO_FEET(elev);
+          // No conversion needed if already in metres
+
+          // consider chunk size
+          int y_alt = h2 - ((widgets->profile_height * elev)/achunk );
+          gdk_draw_rectangle(GDK_DRAWABLE(pix), dem_alt_gc, TRUE, i+MARGIN_X-2, y_alt-2, 4, 4);
+        }
+      }
+    }
+    g_object_unref ( G_OBJECT(dem_alt_gc) );
+  }
+
+  // Show speeds
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_elev_speed)) ) {
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_elev_speed)) ) {
-    GdkGC *elev_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
     GdkColor color;
     GdkColor color;
+    // This is just an indicator - no actual values can be inferred by user
+    GdkGC *elev_speed_gc = gdk_gc_new ( gtk_widget_get_window(window) );
     gdk_color_parse ( "red", &color );
     gdk_gc_set_rgb_fg_color ( elev_speed_gc, &color);
 
     gdk_color_parse ( "red", &color );
     gdk_gc_set_rgb_fg_color ( elev_speed_gc, &color);
 
-    gdouble max_speed = 0;
-    max_speed = widgets->max_speed * 110 / 100;
+    gdouble max_speed = widgets->max_speed * 110 / 100;
 
 
-    // This is just an indicator - no actual values can be inferred by user
-    gint i;
     for ( i = 0; i < widgets->profile_width; i++ ) {
       int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
     for ( i = 0; i < widgets->profile_width; i++ ) {
       int y_speed = widgets->profile_height - (widgets->profile_height * widgets->speeds[i])/max_speed;
-      gdk_draw_rectangle(GDK_DRAWABLE(pix), elev_speed_gc, TRUE, i+MARGIN-2, y_speed-2, 4, 4);
+      gdk_draw_rectangle(GDK_DRAWABLE(pix), elev_speed_gc, TRUE, i+MARGIN_X-2, y_speed-2, 4, 4);
     }
     }
+
     g_object_unref ( G_OBJECT(elev_speed_gc) );
   }
 
   /* draw border */
     g_object_unref ( G_OBJECT(elev_speed_gc) );
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN_X, MARGIN_Y, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
 
   g_object_unref ( G_OBJECT(pix) );
-
 }
 
 /**
 }
 
 /**
@@ -1801,8 +2147,6 @@ static void draw_et ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets )
  */
 static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
 {
  */
 static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
 {
-  GtkWidget *window;
-  GdkPixmap *pix;
   gdouble mins;
   guint i;
 
   gdouble mins;
   guint i;
 
@@ -1838,9 +2182,8 @@ static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
     break;
   }
 
     break;
   }
 
-  window = gtk_widget_get_toplevel (widgets->speed_dist_box);
-
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  GtkWidget *window = gtk_widget_get_toplevel (widgets->speed_dist_box);
+  GdkPixmap *pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
 
   gtk_image_set_from_pixmap ( GTK_IMAGE(image), pix, NULL );
 
@@ -1855,11 +2198,8 @@ static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
   // Assign locally
   mins = widgets->draw_min_speed;
   
   // Assign locally
   mins = widgets->draw_min_speed;
   
-  /* clear the image */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->bg_gc[0],
-                    TRUE, 0, 0, MARGIN, widgets->profile_height);
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->mid_gc[0],
-                    TRUE, MARGIN, 0, widgets->profile_width, widgets->profile_height);
+  // Reset before redrawing
+  clear_images (pix, window, widgets);
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
 
   /* draw grid */
   for (i=0; i<=LINES; i++) {
@@ -1884,13 +2224,16 @@ static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
 
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
 
-    draw_grid ( window, image, widgets, pix, s, i );
+    draw_grid_y ( window, image, widgets, pix, s, i );
   }
 
   }
 
+  draw_distance_divisions ( window, image, pix, widgets, a_vik_get_units_distance() );
+
   /* draw speeds */
   /* draw speeds */
+  guint height = widgets->profile_height + MARGIN_Y;
   for ( i = 0; i < widgets->profile_width; i++ )
     gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
   for ( i = 0; i < widgets->profile_width; i++ )
     gdk_draw_line ( GDK_DRAWABLE(pix), gtk_widget_get_style(window)->dark_gc[3],
-                     i + MARGIN, widgets->profile_height, i + MARGIN, widgets->profile_height-widgets->profile_height*(widgets->speeds_dist[i]-mins)/(chunkss[widgets->cisd]*LINES) );
+                    i + MARGIN_X, height, i + MARGIN_X, height - widgets->profile_height*(widgets->speeds_dist[i]-mins)/(chunkss[widgets->cisd]*LINES) );
 
 
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_sd_gps_speed)) ) {
 
 
   if ( gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->w_show_sd_gps_speed)) ) {
@@ -1924,15 +2267,15 @@ static void draw_sd ( GtkWidget *image, VikTrack *tr, PropWidgets *widgets)
        break;
       }
       dist_tp += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord), &(VIK_TRACKPOINT(iter->prev->data)->coord) );
        break;
       }
       dist_tp += vik_coord_diff ( &(VIK_TRACKPOINT(iter->data)->coord), &(VIK_TRACKPOINT(iter->prev->data)->coord) );
-      int x = MARGIN + (widgets->profile_width * dist_tp / dist);
-      int y = widgets->profile_height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cisd]*LINES);
+      int x = MARGIN_X + (widgets->profile_width * dist_tp / dist);
+      int y = height - widgets->profile_height*(gps_speed - mins)/(chunkss[widgets->cisd]*LINES);
       gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
     }
     g_object_unref ( G_OBJECT(gps_speed_gc) );
   }
 
   /* draw border */
       gdk_draw_rectangle(GDK_DRAWABLE(pix), gps_speed_gc, TRUE, x-2, y-2, 4, 4);
     }
     g_object_unref ( G_OBJECT(gps_speed_gc) );
   }
 
   /* draw border */
-  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN, 0, widgets->profile_width-1, widgets->profile_height-1);
+  gdk_draw_rectangle(GDK_DRAWABLE(pix), gtk_widget_get_style(window)->black_gc, FALSE, MARGIN_X, MARGIN_Y, widgets->profile_width-1, widgets->profile_height-1);
 
   g_object_unref ( G_OBJECT(pix) );
 }
 
   g_object_unref ( G_OBJECT(pix) );
 }
@@ -1971,7 +2314,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
       pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
       pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
-      gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
+      gdouble x_blob = -MARGIN_X - 1.0; // i.e. Don't draw unless we get a valid value
       gint y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
       gint y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
@@ -1983,14 +2326,14 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
-       marker_x = (pc * widgets->profile_width) + MARGIN;
+        marker_x = (pc * widgets->profile_width) + MARGIN_X;
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
-                                      x_blob+MARGIN,
-                                      y_blob,
+                                      x_blob+MARGIN_X,
+                                      y_blob+MARGIN_Y,
                                       &widgets->elev_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
                                       &widgets->elev_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
@@ -2019,7 +2362,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
       pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
       pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
-      gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
+      gdouble x_blob = -MARGIN_X - 1.0; // i.e. Don't draw unless we get a valid value
       gint y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
       gint y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
@@ -2031,14 +2374,14 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
-       marker_x = (pc * widgets->profile_width) + MARGIN;
+        marker_x = (pc * widgets->profile_width) + MARGIN_X;
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
-                                      x_blob+MARGIN,
-                                      y_blob,
+                                      x_blob+MARGIN_X,
+                                      y_blob+MARGIN_Y,
                                       &widgets->gradient_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
                                       &widgets->gradient_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
@@ -2068,7 +2411,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
 
 
       pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
 
-      gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
+      gdouble x_blob = -MARGIN_X - 1.0; // i.e. Don't draw unless we get a valid value
       gint    y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
       gint    y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
@@ -2081,14 +2424,14 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
-       marker_x = (pc * widgets->profile_width) + MARGIN;
+        marker_x = (pc * widgets->profile_width) + MARGIN_X;
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
-                                      x_blob+MARGIN,
-                                      y_blob,
+                                      x_blob+MARGIN_X,
+                                      y_blob+MARGIN_Y,
                                       &widgets->speed_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
                                       &widgets->speed_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
@@ -2118,7 +2461,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
 
 
       pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
 
-      gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
+      gdouble x_blob = -MARGIN_X - 1.0; // i.e. Don't draw unless we get a valid value
       gint    y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
       gint    y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
@@ -2131,14 +2474,14 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
-       marker_x = (pc * widgets->profile_width) + MARGIN;
+        marker_x = (pc * widgets->profile_width) + MARGIN_X;
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
-                                      x_blob+MARGIN,
-                                      y_blob,
+                                      x_blob+MARGIN_X,
+                                      y_blob+MARGIN_Y,
                                       &widgets->dist_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
                                       &widgets->dist_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
@@ -2168,7 +2511,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
 
 
       pc = tp_percentage_by_time ( widgets->tr, widgets->marker_tp );
 
-      gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
+      gdouble x_blob = -MARGIN_X - 1.0; // i.e. Don't draw unless we get a valid value
       gint    y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
       gint    y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_time ( widgets->tr, widgets->blob_tp );
@@ -2180,14 +2523,14 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
-       marker_x = (pc * widgets->profile_width) + MARGIN;
+        marker_x = (pc * widgets->profile_width) + MARGIN_X;
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
-                                      x_blob+MARGIN,
-                                      y_blob,
+                                      x_blob+MARGIN_X,
+                                      y_blob+MARGIN_Y,
                                       &widgets->elev_time_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
                                       &widgets->elev_time_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
@@ -2216,7 +2559,7 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
       pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
     if (widgets->is_marker_drawn || widgets->is_blob_drawn) {
 
       pc = tp_percentage_by_distance ( widgets->tr, widgets->marker_tp, widgets->track_length_inc_gaps );
-      gdouble x_blob = -MARGIN - 1.0; // i.e. Don't draw unless we get a valid value
+      gdouble x_blob = -MARGIN_X - 1.0; // i.e. Don't draw unless we get a valid value
       gint y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
       gint y_blob = 0;
       if (widgets->is_blob_drawn) {
        pc_blob = tp_percentage_by_distance ( widgets->tr, widgets->blob_tp, widgets->track_length_inc_gaps );
@@ -2228,14 +2571,14 @@ static void draw_all_graphs ( GtkWidget *widget, PropWidgets *widgets, gboolean
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
 
       gdouble marker_x = -1.0; // i.e. Don't draw unless we get a valid value
       if (!isnan(pc)) {
-       marker_x = (pc * widgets->profile_width) + MARGIN;
+        marker_x = (pc * widgets->profile_width) + MARGIN_X;
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
       }
 
       save_image_and_draw_graph_marks (image,
                                       marker_x,
                                       gtk_widget_get_style(window)->black_gc,
-                                      x_blob+MARGIN,
-                                      y_blob,
+                                      x_blob+MARGIN_X,
+                                      y_blob+MARGIN_Y,
                                       &widgets->speed_dist_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
                                       &widgets->speed_dist_graph_saved_img,
                                       widgets->profile_width,
                                       widgets->profile_height,
@@ -2304,7 +2647,7 @@ GtkWidget *vik_trw_layer_create_profile ( GtkWidget *window, PropWidgets *widget
 
   minmax_array(widgets->altitudes, min_alt, max_alt, TRUE, widgets->profile_width);
   
 
   minmax_array(widgets->altitudes, min_alt, max_alt, TRUE, widgets->profile_width);
   
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
@@ -2334,7 +2677,7 @@ GtkWidget *vik_trw_layer_create_gradient ( GtkWidget *window, PropWidgets *widge
     return NULL;
   }
 
     return NULL;
   }
 
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
@@ -2362,7 +2705,7 @@ GtkWidget *vik_trw_layer_create_vtdiag ( GtkWidget *window, PropWidgets *widgets
   if ( widgets->speeds == NULL )
     return NULL;
 
   if ( widgets->speeds == NULL )
     return NULL;
 
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
 #if 0
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
 #if 0
@@ -2413,7 +2756,7 @@ GtkWidget *vik_trw_layer_create_dtdiag ( GtkWidget *window, PropWidgets *widgets
   if ( widgets->distances == NULL )
     return NULL;
 
   if ( widgets->distances == NULL )
     return NULL;
 
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
@@ -2442,7 +2785,7 @@ GtkWidget *vik_trw_layer_create_etdiag ( GtkWidget *window, PropWidgets *widgets
   if ( widgets->ats == NULL )
     return NULL;
 
   if ( widgets->ats == NULL )
     return NULL;
 
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
@@ -2470,7 +2813,7 @@ GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, PropWidgets *widgets
   if ( widgets->speeds_dist == NULL )
     return NULL;
 
   if ( widgets->speeds_dist == NULL )
     return NULL;
 
-  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width + MARGIN, widgets->profile_height, -1 );
+  pix = gdk_pixmap_new( gtk_widget_get_window(window), widgets->profile_width+MARGIN_X, widgets->profile_height+MARGIN_Y, -1 );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
   image = gtk_image_new_from_pixmap ( pix, NULL );
 
   g_object_unref ( G_OBJECT(pix) );
@@ -2483,15 +2826,26 @@ GtkWidget *vik_trw_layer_create_sddiag ( GtkWidget *window, PropWidgets *widgets
 
   return eventbox;
 }
 
   return eventbox;
 }
-#undef MARGIN
+#undef MARGIN_X
 
 #define VIK_SETTINGS_TRACK_PROFILE_WIDTH "track_profile_display_width"
 #define VIK_SETTINGS_TRACK_PROFILE_HEIGHT "track_profile_display_height"
 
 static void save_values ( PropWidgets *widgets )
 {
 
 #define VIK_SETTINGS_TRACK_PROFILE_WIDTH "track_profile_display_width"
 #define VIK_SETTINGS_TRACK_PROFILE_HEIGHT "track_profile_display_height"
 
 static void save_values ( PropWidgets *widgets )
 {
+  // Session settings
   a_settings_set_integer ( VIK_SETTINGS_TRACK_PROFILE_WIDTH, widgets->profile_width );
   a_settings_set_integer ( VIK_SETTINGS_TRACK_PROFILE_HEIGHT, widgets->profile_height );
   a_settings_set_integer ( VIK_SETTINGS_TRACK_PROFILE_WIDTH, widgets->profile_width );
   a_settings_set_integer ( VIK_SETTINGS_TRACK_PROFILE_HEIGHT, widgets->profile_height );
+
+  // Just for this session ATM
+  show_dem                = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(widgets->w_show_dem) );
+  show_alt_gps_speed      = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(widgets->w_show_alt_gps_speed) );
+  show_gps_speed          = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(widgets->w_show_gps_speed) );
+  show_gradient_gps_speed = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(widgets->w_show_gradient_gps_speed) );
+  show_dist_speed         = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(widgets->w_show_dist_speed) );
+  show_elev_dem           = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(widgets->w_show_elev_dem) );
+  show_elev_speed         = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(widgets->w_show_elev_speed) );
+  show_sd_gps_speed       = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON(widgets->w_show_sd_gps_speed) );
 }
 
 static void destroy_cb ( GtkDialog *dialog, PropWidgets *widgets )
 }
 
 static void destroy_cb ( GtkDialog *dialog, PropWidgets *widgets )
@@ -2600,6 +2954,7 @@ static void propwin_response_cb( GtkDialog *dialog, gint resp, PropWidgets *widg
           vik_trw_layer_add_route(vtl, r_name, tr_right);
         else
           vik_trw_layer_add_track(vtl, r_name, tr_right);
           vik_trw_layer_add_route(vtl, r_name, tr_right);
         else
           vik_trw_layer_add_track(vtl, r_name, tr_right);
+        vik_track_calculate_bounds ( tr );
         vik_track_calculate_bounds ( tr_right );
 
         g_free ( r_name );
         vik_track_calculate_bounds ( tr_right );
 
         g_free ( r_name );
@@ -2637,6 +2992,8 @@ static GtkWidget *create_graph_page ( GtkWidget *graph,
                                      GtkWidget *value,
                                      const gchar *markup2,
                                      GtkWidget *value2,
                                      GtkWidget *value,
                                      const gchar *markup2,
                                      GtkWidget *value2,
+                                     const gchar *markup3,
+                                     GtkWidget *value3,
                                      GtkWidget *checkbutton1,
                                      gboolean checkbutton1_default,
                                      GtkWidget *checkbutton2,
                                      GtkWidget *checkbutton1,
                                      gboolean checkbutton1_default,
                                      GtkWidget *checkbutton2,
@@ -2646,13 +3003,19 @@ static GtkWidget *create_graph_page ( GtkWidget *graph,
   GtkWidget *vbox = gtk_vbox_new ( FALSE, 10 );
   GtkWidget *label = gtk_label_new (NULL);
   GtkWidget *label2 = gtk_label_new (NULL);
   GtkWidget *vbox = gtk_vbox_new ( FALSE, 10 );
   GtkWidget *label = gtk_label_new (NULL);
   GtkWidget *label2 = gtk_label_new (NULL);
+  GtkWidget *label3 = gtk_label_new (NULL);
   gtk_box_pack_start (GTK_BOX(vbox), graph, FALSE, FALSE, 0);
   gtk_label_set_markup ( GTK_LABEL(label), markup );
   gtk_label_set_markup ( GTK_LABEL(label2), markup2 );
   gtk_box_pack_start (GTK_BOX(vbox), graph, FALSE, FALSE, 0);
   gtk_label_set_markup ( GTK_LABEL(label), markup );
   gtk_label_set_markup ( GTK_LABEL(label2), markup2 );
+  gtk_label_set_markup ( GTK_LABEL(label3), markup3 );
   gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(hbox), value, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(hbox), label2, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(hbox), value2, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(hbox), label, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(hbox), value, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(hbox), label2, FALSE, FALSE, 0);
   gtk_box_pack_start (GTK_BOX(hbox), value2, FALSE, FALSE, 0);
+  if ( value3 ) {
+    gtk_box_pack_start (GTK_BOX(hbox), label3, FALSE, FALSE, 0);
+    gtk_box_pack_start (GTK_BOX(hbox), value3, FALSE, FALSE, 0);
+  }
   if (checkbutton2) {
     gtk_box_pack_end (GTK_BOX(hbox), checkbutton2, FALSE, FALSE, 0);
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton2), checkbutton2_default);
   if (checkbutton2) {
     gtk_box_pack_end (GTK_BOX(hbox), checkbutton2, FALSE, FALSE, 0);
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(checkbutton2), checkbutton2_default);
@@ -2834,21 +3197,24 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
   case VIK_UNITS_DISTANCE_MILES:
     g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(tr_len) );
     break;
   case VIK_UNITS_DISTANCE_MILES:
     g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f miles", VIK_METERS_TO_MILES(tr_len) );
     break;
+  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+    g_snprintf(tmp_buf, sizeof(tmp_buf), "%.2f NM", VIK_METERS_TO_NAUTICAL_MILES(tr_len) );
+    break;
   default:
     g_critical("Houston, we've had a problem. distance=%d", dist_units);
   }
   default:
     g_critical("Houston, we've had a problem. distance=%d", dist_units);
   }
-  widgets->w_track_length = content[cnt++] = gtk_label_new ( tmp_buf );
+  widgets->w_track_length = content[cnt++] = ui_label_new_selectable ( tmp_buf );
 
   tp_count = vik_track_get_tp_count(tr);
   g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", tp_count );
 
   tp_count = vik_track_get_tp_count(tr);
   g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", tp_count );
-  widgets->w_tp_count = content[cnt++] = gtk_label_new ( tmp_buf );
+  widgets->w_tp_count = content[cnt++] = ui_label_new_selectable ( tmp_buf );
 
   seg_count = vik_track_get_segment_count(tr) ;
   g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", seg_count );
 
   seg_count = vik_track_get_segment_count(tr) ;
   g_snprintf(tmp_buf, sizeof(tmp_buf), "%u", seg_count );
-  widgets->w_segment_count = content[cnt++] = gtk_label_new ( tmp_buf );
+  widgets->w_segment_count = content[cnt++] = ui_label_new_selectable ( tmp_buf );
 
   g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", vik_track_get_dup_point_count(tr) );
 
   g_snprintf(tmp_buf, sizeof(tmp_buf), "%lu", vik_track_get_dup_point_count(tr) );
-  widgets->w_duptp_count = content[cnt++] = gtk_label_new ( tmp_buf );
+  widgets->w_duptp_count = content[cnt++] = ui_label_new_selectable ( tmp_buf );
 
   vik_units_speed_t speed_units = a_vik_get_units_speed ();
   tmp_speed = vik_track_get_max_speed(tr);
 
   vik_units_speed_t speed_units = a_vik_get_units_speed ();
   tmp_speed = vik_track_get_max_speed(tr);
@@ -2873,7 +3239,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
   }
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
   }
-  widgets->w_max_speed = content[cnt++] = gtk_label_new ( tmp_buf );
+  widgets->w_max_speed = content[cnt++] = ui_label_new_selectable ( tmp_buf );
 
   tmp_speed = vik_track_get_average_speed(tr);
   if ( tmp_speed == 0 )
 
   tmp_speed = vik_track_get_average_speed(tr);
   if ( tmp_speed == 0 )
@@ -2897,7 +3263,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
   }
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
   }
-  widgets->w_avg_speed = content[cnt++] = gtk_label_new ( tmp_buf );
+  widgets->w_avg_speed = content[cnt++] = ui_label_new_selectable ( tmp_buf );
 
   // Use 60sec as the default period to be considered stopped
   //  this is the TrackWaypoint draw stops default value 'vtl->stop_length'
 
   // Use 60sec as the default period to be considered stopped
   //  this is the TrackWaypoint draw stops default value 'vtl->stop_length'
@@ -2925,7 +3291,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
   }
       g_critical("Houston, we've had a problem. speed=%d", speed_units);
     }
   }
-  widgets->w_mvg_speed = content[cnt++] = gtk_label_new ( tmp_buf );
+  widgets->w_mvg_speed = content[cnt++] = ui_label_new_selectable ( tmp_buf );
 
   switch (dist_units) {
   case VIK_UNITS_DISTANCE_KILOMETRES:
 
   switch (dist_units) {
   case VIK_UNITS_DISTANCE_KILOMETRES:
@@ -2935,10 +3301,13 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
   case VIK_UNITS_DISTANCE_MILES:
     g_snprintf(tmp_buf, sizeof(tmp_buf), "%.3f miles", (tp_count - seg_count) == 0 ? 0 : VIK_METERS_TO_MILES(tr_len / ( tp_count - seg_count )) );
     break;
   case VIK_UNITS_DISTANCE_MILES:
     g_snprintf(tmp_buf, sizeof(tmp_buf), "%.3f miles", (tp_count - seg_count) == 0 ? 0 : VIK_METERS_TO_MILES(tr_len / ( tp_count - seg_count )) );
     break;
+  case VIK_UNITS_DISTANCE_NAUTICAL_MILES:
+    g_snprintf(tmp_buf, sizeof(tmp_buf), "%.3f NM", (tp_count - seg_count) == 0 ? 0 : VIK_METERS_TO_NAUTICAL_MILES(tr_len / ( tp_count - seg_count )) );
+    break;
   default:
     g_critical("Houston, we've had a problem. distance=%d", dist_units);
   }
   default:
     g_critical("Houston, we've had a problem. distance=%d", dist_units);
   }
-  widgets->w_avg_dist = content[cnt++] = gtk_label_new ( tmp_buf );
+  widgets->w_avg_dist = content[cnt++] = ui_label_new_selectable ( tmp_buf );
 
   vik_units_height_t height_units = a_vik_get_units_height ();
   if ( min_alt == VIK_DEFAULT_ALTITUDE )
 
   vik_units_height_t height_units = a_vik_get_units_height ();
   if ( min_alt == VIK_DEFAULT_ALTITUDE )
@@ -2956,7 +3325,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
       g_critical("Houston, we've had a problem. height=%d", height_units);
     }
   }
       g_critical("Houston, we've had a problem. height=%d", height_units);
     }
   }
-  widgets->w_elev_range = content[cnt++] = gtk_label_new ( tmp_buf );
+  widgets->w_elev_range = content[cnt++] = ui_label_new_selectable ( tmp_buf );
 
   vik_track_get_total_elevation_gain(tr, &max_alt, &min_alt );
   if ( min_alt == VIK_DEFAULT_ALTITUDE )
 
   vik_track_get_total_elevation_gain(tr, &max_alt, &min_alt );
   if ( min_alt == VIK_DEFAULT_ALTITUDE )
@@ -2974,7 +3343,7 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
       g_critical("Houston, we've had a problem. height=%d", height_units);
     }
   }
       g_critical("Houston, we've had a problem. height=%d", height_units);
     }
   }
-  widgets->w_elev_gain = content[cnt++] = gtk_label_new ( tmp_buf );
+  widgets->w_elev_gain = content[cnt++] = ui_label_new_selectable ( tmp_buf );
 
 #if 0
 #define PACK(w) gtk_box_pack_start (GTK_BOX(right_vbox), w, FALSE, FALSE, 0);
 
 #if 0
 #define PACK(w) gtk_box_pack_start (GTK_BOX(right_vbox), w, FALSE, FALSE, 0);
@@ -2997,14 +3366,24 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
     t1 = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
     t2 = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp;
 
     t1 = VIK_TRACKPOINT(tr->trackpoints->data)->timestamp;
     t2 = VIK_TRACKPOINT(g_list_last(tr->trackpoints)->data)->timestamp;
 
-    strftime (tmp_buf, sizeof(tmp_buf), "%c", localtime(&(t1)));
-    widgets->w_time_start = content[cnt++] = gtk_label_new(tmp_buf);
+    VikCoord vc;
+    // Notional center of a track is simply an average of the bounding box extremities
+    struct LatLon center = { (tr->bbox.north+tr->bbox.south)/2, (tr->bbox.east+tr->bbox.west)/2 };
+    vik_coord_load_from_latlon ( &vc, vik_trw_layer_get_coord_mode(vtl), &center );
+
+    widgets->tz = vu_get_tz_at_location ( &vc );
+
+    gchar *msg;
+    msg = vu_get_time_string ( &t1, "%c", &vc, widgets->tz );
+    widgets->w_time_start = content[cnt++] = ui_label_new_selectable(msg);
+    g_free ( msg );
 
 
-    strftime (tmp_buf, sizeof(tmp_buf), "%c", localtime(&(t2)));
-    widgets->w_time_end = content[cnt++] = gtk_label_new(tmp_buf);
+    msg = vu_get_time_string ( &t2, "%c", &vc, widgets->tz );
+    widgets->w_time_end = content[cnt++] = ui_label_new_selectable(msg);
+    g_free ( msg );
 
     g_snprintf(tmp_buf, sizeof(tmp_buf), _("%d minutes"), (int)(t2-t1)/60);
 
     g_snprintf(tmp_buf, sizeof(tmp_buf), _("%d minutes"), (int)(t2-t1)/60);
-    widgets->w_time_dur = content[cnt++] = gtk_label_new(tmp_buf);
+    widgets->w_time_dur = content[cnt++] = ui_label_new_selectable(tmp_buf);
   } else {
     widgets->w_time_start = content[cnt++] = gtk_label_new(_("No Data"));
     widgets->w_time_end = content[cnt++] = gtk_label_new(_("No Data"));
   } else {
     widgets->w_time_start = content[cnt++] = gtk_label_new(_("No Data"));
     widgets->w_time_end = content[cnt++] = gtk_label_new(_("No Data"));
@@ -3017,15 +3396,16 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
 
   if ( widgets->elev_box ) {
     GtkWidget *page = NULL;
 
   if ( widgets->elev_box ) {
     GtkWidget *page = NULL;
-    widgets->w_cur_dist = gtk_label_new(_("No Data"));
-    widgets->w_cur_elevation = gtk_label_new(_("No Data"));
+    widgets->w_cur_dist = ui_label_new_selectable(_("No Data"));
+    widgets->w_cur_elevation = ui_label_new_selectable(_("No Data"));
     widgets->w_show_dem = gtk_check_button_new_with_mnemonic(_("Show D_EM"));
     widgets->w_show_alt_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
     page = create_graph_page (widgets->elev_box,
     widgets->w_show_dem = gtk_check_button_new_with_mnemonic(_("Show D_EM"));
     widgets->w_show_alt_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
     page = create_graph_page (widgets->elev_box,
-                             _("<b>Track Distance:</b>"), widgets->w_cur_dist,
-                             _("<b>Track Height:</b>"), widgets->w_cur_elevation,
-                             widgets->w_show_dem, TRUE,
-                             widgets->w_show_alt_gps_speed, TRUE);
+                              _("<b>Track Distance:</b>"), widgets->w_cur_dist,
+                              _("<b>Track Height:</b>"), widgets->w_cur_elevation,
+                              NULL, NULL,
+                              widgets->w_show_dem, show_dem,
+                              widgets->w_show_alt_gps_speed, show_alt_gps_speed);
     g_signal_connect (widgets->w_show_dem, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     g_signal_connect (widgets->w_show_alt_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-distance")));
     g_signal_connect (widgets->w_show_dem, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     g_signal_connect (widgets->w_show_alt_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-distance")));
@@ -3033,70 +3413,80 @@ void vik_trw_layer_propwin_run ( GtkWindow *parent,
 
   if ( widgets->gradient_box ) {
     GtkWidget *page = NULL;
 
   if ( widgets->gradient_box ) {
     GtkWidget *page = NULL;
-    widgets->w_cur_gradient_dist = gtk_label_new(_("No Data"));
-    widgets->w_cur_gradient_gradient = gtk_label_new(_("No Data"));
+    widgets->w_cur_gradient_dist = ui_label_new_selectable(_("No Data"));
+    widgets->w_cur_gradient_gradient = ui_label_new_selectable(_("No Data"));
     widgets->w_show_gradient_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
     page = create_graph_page (widgets->gradient_box,
     widgets->w_show_gradient_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
     page = create_graph_page (widgets->gradient_box,
-                             _("<b>Track Distance:</b>"), widgets->w_cur_gradient_dist,
-                             _("<b>Track Gradient:</b>"), widgets->w_cur_gradient_gradient,
-                             widgets->w_show_gradient_gps_speed, TRUE,
-                  NULL, FALSE);
+                              _("<b>Track Distance:</b>"), widgets->w_cur_gradient_dist,
+                              _("<b>Track Gradient:</b>"), widgets->w_cur_gradient_gradient,
+                              NULL, NULL,
+                              widgets->w_show_gradient_gps_speed, show_gradient_gps_speed,
+                              NULL, FALSE);
     g_signal_connect (widgets->w_show_gradient_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Gradient-distance")));
   }
 
   if ( widgets->speed_box ) {
     GtkWidget *page = NULL;
     g_signal_connect (widgets->w_show_gradient_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Gradient-distance")));
   }
 
   if ( widgets->speed_box ) {
     GtkWidget *page = NULL;
-    widgets->w_cur_time = gtk_label_new(_("No Data"));
-    widgets->w_cur_speed = gtk_label_new(_("No Data"));
+    widgets->w_cur_time = ui_label_new_selectable(_("No Data"));
+    widgets->w_cur_speed = ui_label_new_selectable(_("No Data"));
+    widgets->w_cur_time_real = ui_label_new_selectable(_("No Data"));
     widgets->w_show_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
     page = create_graph_page (widgets->speed_box,
     widgets->w_show_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
     page = create_graph_page (widgets->speed_box,
-                             _("<b>Track Time:</b>"), widgets->w_cur_time,
-                             _("<b>Track Speed:</b>"), widgets->w_cur_speed,
-                             widgets->w_show_gps_speed, TRUE,
-                             NULL, FALSE);
+                              _("<b>Track Time:</b>"), widgets->w_cur_time,
+                              _("<b>Track Speed:</b>"), widgets->w_cur_speed,
+                              _("<b>Time/Date:</b>"), widgets->w_cur_time_real,
+                              widgets->w_show_gps_speed, show_gps_speed,
+                              NULL, FALSE);
     g_signal_connect (widgets->w_show_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-time")));
   }
 
   if ( widgets->dist_box ) {
     GtkWidget *page = NULL;
     g_signal_connect (widgets->w_show_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-time")));
   }
 
   if ( widgets->dist_box ) {
     GtkWidget *page = NULL;
-    widgets->w_cur_dist_time = gtk_label_new(_("No Data"));
-    widgets->w_cur_dist_dist = gtk_label_new(_("No Data"));
+    widgets->w_cur_dist_time = ui_label_new_selectable(_("No Data"));
+    widgets->w_cur_dist_dist = ui_label_new_selectable(_("No Data"));
+    widgets->w_cur_dist_time_real = ui_label_new_selectable(_("No Data"));
     widgets->w_show_dist_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
     page = create_graph_page (widgets->dist_box,
     widgets->w_show_dist_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
     page = create_graph_page (widgets->dist_box,
-                             _("<b>Track Distance:</b>"), widgets->w_cur_dist_dist,
-                             _("<b>Track Time:</b>"), widgets->w_cur_dist_time,
-                             widgets->w_show_dist_speed, FALSE,
-                             NULL, FALSE);
+                              _("<b>Track Distance:</b>"), widgets->w_cur_dist_dist,
+                              _("<b>Track Time:</b>"), widgets->w_cur_dist_time,
+                              _("<b>Time/Date:</b>"), widgets->w_cur_dist_time_real,
+                              widgets->w_show_dist_speed, show_dist_speed,
+                              NULL, FALSE);
     g_signal_connect (widgets->w_show_dist_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Distance-time")));
   }
 
   if ( widgets->elev_time_box ) {
     GtkWidget *page = NULL;
     g_signal_connect (widgets->w_show_dist_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Distance-time")));
   }
 
   if ( widgets->elev_time_box ) {
     GtkWidget *page = NULL;
-    widgets->w_cur_elev_time = gtk_label_new(_("No Data"));
-    widgets->w_cur_elev_elev = gtk_label_new(_("No Data"));
+    widgets->w_cur_elev_time = ui_label_new_selectable(_("No Data"));
+    widgets->w_cur_elev_elev = ui_label_new_selectable(_("No Data"));
+    widgets->w_cur_elev_time_real = ui_label_new_selectable(_("No Data"));
     widgets->w_show_elev_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
     widgets->w_show_elev_speed = gtk_check_button_new_with_mnemonic(_("Show S_peed"));
+    widgets->w_show_elev_dem = gtk_check_button_new_with_mnemonic(_("Show D_EM"));
     page = create_graph_page (widgets->elev_time_box,
     page = create_graph_page (widgets->elev_time_box,
-                             _("<b>Track Time:</b>"), widgets->w_cur_elev_time,
-                             _("<b>Track Height:</b>"), widgets->w_cur_elev_elev,
-                             widgets->w_show_elev_speed, FALSE,
-                             NULL, FALSE);
+                              _("<b>Track Time:</b>"), widgets->w_cur_elev_time,
+                              _("<b>Track Height:</b>"), widgets->w_cur_elev_elev,
+                              _("<b>Time/Date:</b>"), widgets->w_cur_elev_time_real,
+                              widgets->w_show_elev_dem, show_elev_dem,
+                              widgets->w_show_elev_speed, show_elev_speed);
+    g_signal_connect (widgets->w_show_elev_dem, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     g_signal_connect (widgets->w_show_elev_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-time")));
   }
 
   if ( widgets->speed_dist_box ) {
     GtkWidget *page = NULL;
     g_signal_connect (widgets->w_show_elev_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Elevation-time")));
   }
 
   if ( widgets->speed_dist_box ) {
     GtkWidget *page = NULL;
-    widgets->w_cur_speed_dist = gtk_label_new(_("No Data"));
-    widgets->w_cur_speed_speed = gtk_label_new(_("No Data"));
+    widgets->w_cur_speed_dist = ui_label_new_selectable(_("No Data"));
+    widgets->w_cur_speed_speed = ui_label_new_selectable(_("No Data"));
     widgets->w_show_sd_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
     page = create_graph_page (widgets->speed_dist_box,
     widgets->w_show_sd_gps_speed = gtk_check_button_new_with_mnemonic(_("Show _GPS Speed"));
     page = create_graph_page (widgets->speed_dist_box,
-                             _("<b>Track Distance:</b>"), widgets->w_cur_speed_dist,
-                             _("<b>Track Speed:</b>"), widgets->w_cur_speed_speed,
-                             widgets->w_show_sd_gps_speed, TRUE,
-                             NULL, FALSE);
+                              _("<b>Track Distance:</b>"), widgets->w_cur_speed_dist,
+                              _("<b>Track Speed:</b>"), widgets->w_cur_speed_speed,
+                              NULL, NULL,
+                              widgets->w_show_sd_gps_speed, show_sd_gps_speed,
+                              NULL, FALSE);
     g_signal_connect (widgets->w_show_sd_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-distance")));
   }
     g_signal_connect (widgets->w_show_sd_gps_speed, "toggled", G_CALLBACK (checkbutton_toggle_cb), widgets);
     gtk_notebook_append_page(GTK_NOTEBOOK(graphs), page, gtk_label_new(_("Speed-distance")));
   }