gfio: allow graph to stretch or shrink as window expands or contracts
authorStephen M. Cameron <stephenmcameron@gmail.com>
Wed, 7 Mar 2012 18:40:58 +0000 (19:40 +0100)
committerJens Axboe <axboe@kernel.dk>
Wed, 7 Mar 2012 18:40:58 +0000 (19:40 +0100)
Signed-off-by: Stephen M. Cameron <stephenmcameron@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
gfio.c
graph.c
graph.h

diff --git a/gfio.c b/gfio.c
index 787c40f..859d178 100644 (file)
--- a/gfio.c
+++ b/gfio.c
@@ -94,6 +94,8 @@ struct gui {
 #define DRAWING_AREA_XDIM 1000
 #define DRAWING_AREA_YDIM 400
        GtkWidget *drawing_area;
+       int drawing_area_xdim;
+       int drawing_area_ydim;
        GtkWidget *error_info_bar;
        GtkWidget *error_label;
        GtkWidget *results_notebook;
@@ -995,11 +997,22 @@ static void gfio_group_stats_op(struct fio_client *client,
        gdk_threads_leave();
 }
 
+static gint on_config_drawing_area(GtkWidget *w, GdkEventConfigure *event)
+{
+       ui.drawing_area_xdim = w->allocation.width;
+       ui.drawing_area_ydim = w->allocation.height;
+       return TRUE;
+}
+
 static int on_expose_drawing_area(GtkWidget *w, GdkEvent *event, gpointer p)
 {
        struct gui *ui = (struct gui *) p;
        cairo_t *cr;
 
+       graph_set_size(ui->iops_graph, ui->drawing_area_xdim / 2.0,
+                                       ui->drawing_area_ydim);
+       graph_set_size(ui->bandwidth_graph, ui->drawing_area_xdim / 2.0,
+                                       ui->drawing_area_ydim);
        cr = gdk_cairo_create(w->window);
 
        cairo_set_source_rgb(cr, 0, 0, 0);
@@ -1011,8 +1024,7 @@ static int on_expose_drawing_area(GtkWidget *w, GdkEvent *event, gpointer p)
        cairo_restore(cr);
 
        cairo_save(cr);
-       cairo_translate(cr, DRAWING_AREA_XDIM / 2.0, 0);
-                               // DRAWING_AREA_YDIM * 0.05);
+       cairo_translate(cr, ui->drawing_area_xdim / 2.0, 0);
        line_graph_draw(ui->iops_graph, cr);
        cairo_stroke(cr);
        cairo_restore(cr);
@@ -1911,11 +1923,15 @@ static void init_ui(int *argc, char **argv[], struct gui *ui)
         */
        gdk_color_parse("white", &white);
        ui->drawing_area = gtk_drawing_area_new();
+       ui->drawing_area_xdim = DRAWING_AREA_XDIM;
+       ui->drawing_area_ydim = DRAWING_AREA_YDIM;
        gtk_widget_set_size_request(GTK_WIDGET(ui->drawing_area), 
-                       DRAWING_AREA_XDIM, DRAWING_AREA_YDIM);
+                       ui->drawing_area_xdim, ui->drawing_area_ydim);
        gtk_widget_modify_bg(ui->drawing_area, GTK_STATE_NORMAL, &white);
        g_signal_connect(G_OBJECT(ui->drawing_area), "expose_event",
                                G_CALLBACK (on_expose_drawing_area), ui);
+       g_signal_connect(G_OBJECT(ui->drawing_area), "configure_event",
+                               G_CALLBACK (on_config_drawing_area), ui);
        ui->scrolled_window = gtk_scrolled_window_new(NULL, NULL);
        gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ui->scrolled_window),
                                        GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
diff --git a/graph.c b/graph.c
index 4a3a993..e9fce95 100644 (file)
--- a/graph.c
+++ b/graph.c
@@ -60,13 +60,18 @@ struct graph {
        const char *font;
 };
 
+void graph_set_size(struct graph *g, unsigned int xdim, unsigned int ydim)
+{
+       g->xdim = xdim;
+       g->ydim = ydim;
+}
+
 struct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font)
 {
        struct graph *g;
 
        g = calloc(1, sizeof(*g));
-       g->xdim = xdim;
-       g->ydim = ydim;
+       graph_set_size(g, xdim, ydim);
        g->per_label_limit = -1;
        g->font = font;
        if (!g->font)
diff --git a/graph.h b/graph.h
index 872e60e..39dd2b0 100644 (file)
--- a/graph.h
+++ b/graph.h
@@ -6,6 +6,7 @@ struct graph;
 #define INVISIBLE_COLOR (-1.0)
 
 struct graph *graph_new(unsigned int xdim, unsigned int ydim, const char *font);
+void graph_set_size(struct graph *g, unsigned int xdim, unsigned int ydim);
 void bar_graph_draw(struct graph *g, cairo_t *cr);
 void line_graph_draw(struct graph *g, cairo_t *cr);
 void line_graph_set_data_count_limit(struct graph *g, int per_label_limit);