gfio: make empty graph show grid lines, not "No good data"

This is done by adding a bit of "invisible data" to the graph
at the beginning.

Signed-off-by: Stephen M. Cameron <scameron@beardog.cce.hp.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/gfio.c b/gfio.c
index e190d89..b1caa67 100644
--- a/gfio.c
+++ b/gfio.c
@@ -121,6 +121,18 @@
 	GtkWidget *disk_util_frame;
 };
 
+static void add_invisible_data(struct graph *g)
+{
+	/*
+	 * This puts some invisible data into a graph so that it will
+	 * initially have some grid lines instead of "No good data"
+	 */
+	graph_add_label(g, "invisible");
+	graph_set_color(g, "invisible", INVISIBLE_COLOR, 0.0, 0.7);
+	graph_add_xy_data(g, "invisible", 0.0, 0.0);
+	graph_add_xy_data(g, "invisible", 1.0, 100.0);
+}
+
 static void setup_iops_graph(struct gui *ui)
 {
 	if (ui->iops_graph)
@@ -134,6 +146,7 @@
 	graph_add_label(ui->iops_graph, "Write IOPS");
 	graph_set_color(ui->iops_graph, "Read IOPS", 0.7, 0.0, 0.0);
 	graph_set_color(ui->iops_graph, "Write IOPS", 0.0, 0.0, 0.7);
+	add_invisible_data(ui->iops_graph);
 }
 
 static void setup_bandwidth_graph(struct gui *ui)
@@ -149,6 +162,7 @@
 	graph_add_label(ui->bandwidth_graph, "Write Bandwidth");
 	graph_set_color(ui->bandwidth_graph, "Read Bandwidth", 0.7, 0.0, 0.0);
 	graph_set_color(ui->bandwidth_graph, "Write Bandwidth", 0.0, 0.0, 0.7);
+	add_invisible_data(ui->bandwidth_graph);
 }
 
 static void clear_ui_info(struct gui *ui)
diff --git a/graph.c b/graph.c
index 1cd2caa..d97da59 100644
--- a/graph.c
+++ b/graph.c
@@ -431,6 +431,8 @@
 	cairo_set_line_width(cr, 1.5);
 	for (i = g->labels; i; i = i->next) {
 		first = 1;
+		if (i->r < 0) /* invisible data */
+			continue;
 		cairo_set_source_rgb(cr, i->r, i->g, i->b);
 		for (j = i->values; j; j = j->next) {
 			tx = ((getx(j) - minx) / (maxx - minx)) * (x2 - x1) + x1;
@@ -588,16 +590,22 @@
 	struct graph_label *i;
 	double r, g, b;
 
-	r = fabs(red);
-	g = fabs(green);
-	b = fabs(blue);
+	if (red < 0.0) { /* invisible color */
+		r = -1.0;
+		g = -1.0;
+		b = -1.0;
+	} else {
+		r = fabs(red);
+		g = fabs(green);
+		b = fabs(blue);
 
-	if (r > 1.0)
-		r = 1.0;
-	if (g > 1.0)
-		g = 1.0;
-	if (b > 1.0)
-		b =1.0;
+		if (r > 1.0)
+			r = 1.0;
+		if (g > 1.0)
+			g = 1.0;
+		if (b > 1.0)
+			b =1.0;
+	}
 
 	for (i = gr->labels; i; i = i->next)
 		if (strcmp(i->label, label) == 0) {
diff --git a/graph.h b/graph.h
index 8202fe6..872e60e 100644
--- a/graph.h
+++ b/graph.h
@@ -3,6 +3,8 @@
 
 struct graph;
 
+#define INVISIBLE_COLOR (-1.0)
+
 struct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font);
 void bar_graph_draw(struct graph *g, cairo_t *cr);
 void line_graph_draw(struct graph *g, cairo_t *cr);