=== modified file 'src/load-graph.cpp'
--- src/load-graph.cpp	2007-12-29 13:32:06 +0000
+++ src/load-graph.cpp	2007-12-29 13:53:23 +0000
@@ -78,6 +78,7 @@
 			guint64 last_in, last_out;
 			GTimeVal time;
 			unsigned max;
+			gboolean max_valid;
 			unsigned values[NUM_POINTS];
 			size_t cur;
 		} net;
@@ -85,17 +86,84 @@
 };
 
 
+#define KILO_FACTOR 1000
+#define MEGA_FACTOR 1000000L
+#define GIGA_FACTOR 1000000000L
+
+/* Get the scale factor to be used for the network graph. Note that the parameter 
+ * val is given in Bytes per second. */
+static unsigned
+get_factor (unsigned val)
+{
+	unsigned bit_val = 8 * val;
+	if (bit_val < KILO_FACTOR)
+	{
+		return 1;
+	}
+	else if (bit_val < MEGA_FACTOR)
+	{
+		return KILO_FACTOR;
+	}
+	else if (bit_val < GIGA_FACTOR)
+	{
+		return MEGA_FACTOR;
+	}
+	else
+	{
+		return GIGA_FACTOR;
+	}
+}
+
+
+/* Format a network speed for use as an axis label. The parameter val is given
+ * in Bytes per second, and factor is a scale factor as described above. This 
+ * is necessary to ensure that the intermediate ticks are in the same units as 
+ * the maximum tick. */
+gchar *
+format_network_speed (unsigned val, unsigned factor)
+{
+	const char *format;
+
+	// 0 is always just 0
+	if (val == 0)
+	{
+		return g_strdup_printf (_("%d"), 0);
+	}
+
+	if (factor == 1)
+	{
+		format = _("%.3g b/s");
+	}
+	else if (factor == KILO_FACTOR)
+	{
+		format = _("%.3g kb/s");
+	}
+	else if (factor == MEGA_FACTOR)
+	{
+		format = _("%.3g Mb/s");
+	}
+	else if (factor == GIGA_FACTOR)
+	{
+		format = _("%.3g Gb/s");
+	}
+	else
+	{
+		return g_strdup ("");
+	}
+
+	return g_strdup_printf(format, (8.0 * val) / factor);
+}
+
 
 #define FRAME_WIDTH 4
 
-
 /* Redraws the backing buffer for the load graph and updates the window */
 void
 load_graph_draw (LoadGraph *g)
 {
 	const double fontsize = 8.0;
 	const double rmargin = 3.5 * fontsize;
-	const double indent = 8.0;
+	const double indent = 17.0;
 	double dash[2] = { 1.0, 2.0 };
 	cairo_t *cr;
 	int dely;
@@ -103,6 +171,7 @@
 	int real_draw_height;
 	guint i, j;
 	unsigned num_bars;
+	unsigned factor = 1;
 
 	// keep 100 % num_bars == 0
 	switch (static_cast<int>(g->draw_height / (fontsize + 14)))
@@ -146,6 +215,11 @@
 	cairo_set_dash (cr, dash, 2, 0);
 	cairo_set_font_size (cr, fontsize);
 
+	if (g->type == LOAD_GRAPH_NET)
+	{
+		factor = get_factor(g->net.max);
+	}
+
 	for (i = 0; i <= num_bars; ++i) {
 		char *caption;
 		double y;
@@ -158,7 +232,32 @@
 		else
 		  y = i * dely + fontsize / 2.0;
 
-		caption = g_strdup_printf("%d %%", 100 - i * (100 / num_bars));
+		if (g->type == LOAD_GRAPH_NET)
+		{
+			if (G_LIKELY (g->net.max_valid))
+			{
+				caption = format_network_speed ( 
+					(g->net.max - i * (g->net.max / num_bars)),
+					factor);
+			}
+			else
+			{
+				// No non-zero data has been logged yet
+				if (i == num_bars)
+				{
+					caption = g_strdup_printf (_("%d"), 0);
+				}
+				else
+				{
+					caption = g_strdup ("");
+				}
+			}
+		}
+		else
+		{
+			caption = g_strdup_printf("%3d %%", 100 - i * (100 / num_bars));
+		}
+
 		cairo_text_extents (cr, caption, &extents);
 		cairo_move_to (cr, indent - extents.width / 2, y);
 		cairo_show_text (cr, caption);
@@ -369,6 +468,37 @@
 	g->data[0][1] = swappercent;
 }
 
+/* Round up a maximum network speed so that it will result in "nice" axis label values. */
+static unsigned
+round_net_max (unsigned val)
+{
+	int i = 0;
+	for (i = 0; val > 100; i++)
+	{
+		val /= 10;
+	}
+	
+	if (val < 2)
+		val++;
+	else if (val < 5)
+		val = 5;
+	else if (val < 10)
+		val = 10;
+	else if (val < 25)
+		val = 25;
+	else if (val < 50)
+		val = 50;
+	else if (val < 75)
+		val = 75;
+
+	for (; i > 0; i--)
+	{
+		val *= 10;
+	}
+	return val;
+}
+
+
 static void
 net_scale (LoadGraph *g, unsigned din, unsigned dout)
 {
@@ -387,14 +517,16 @@
 		new_max = *std::max_element(&g->net.values[0],
 					    &g->net.values[NUM_POINTS]);
 
-	// round up
-	new_max = 11U * new_max / 10U;
+	new_max = round_net_max (new_max);
+
 	// make sure max is not 0 to avoid / 0
 	new_max = std::max(new_max, 1U);
 
 	if (new_max == g->net.max)
 		return;
 
+	g->net.max_valid = TRUE;
+	
 	// if max has decreased but not so much, don't do anything
 	// to avoid rescaling
 	if ((8U * g->net.max / 10U) < new_max && new_max < g->net.max)
@@ -620,6 +752,7 @@
 	case LOAD_GRAPH_NET:
 		g->n = 2;
 		g->net.max = 1;
+		g->net.max_valid = FALSE;
 		g->labels.net_in = gtk_label_new(NULL);
 		g->labels.net_in_total = gtk_label_new(NULL);
 		g->labels.net_out = gtk_label_new(NULL);

