[libdazzle] graphing: fix creation of cpu graph



commit 81ec9be8464ef408c4796757097f36377ca13d54
Author: Christian Hergert <chergert redhat com>
Date:   Tue Jul 17 17:11:27 2018 -0700

    graphing: fix creation of cpu graph
    
    This drops the old dzl_cpu_graph_new() which could not create a usable
    widget and instead adds a replacement API which requires setting the
    appropriate properties as you would when using g_object_new().
    
    Fixes #19

 src/graphing/dzl-cpu-graph.c | 19 +++++++++++++++----
 src/graphing/dzl-cpu-graph.h |  5 +++--
 tests/test-cpu-graph.c       | 14 ++++++--------
 3 files changed, 24 insertions(+), 14 deletions(-)
---
diff --git a/src/graphing/dzl-cpu-graph.c b/src/graphing/dzl-cpu-graph.c
index 52b10bc..9a71a87 100644
--- a/src/graphing/dzl-cpu-graph.c
+++ b/src/graphing/dzl-cpu-graph.c
@@ -55,9 +55,19 @@ static const gchar *colors[] = {
 };
 
 GtkWidget *
-dzl_cpu_graph_new (void)
+dzl_cpu_graph_new_full (gint64 timespan,
+                        guint  max_samples)
 {
-  return g_object_new (DZL_TYPE_CPU_GRAPH, NULL);
+  if (timespan <= 0)
+    timespan = 60L * G_USEC_PER_SEC;
+
+  if (max_samples < 1)
+    max_samples = 120;
+
+  return g_object_new (DZL_TYPE_CPU_GRAPH,
+                       "max-samples", max_samples,
+                       "timespan", timespan,
+                       NULL);
 }
 
 static void
@@ -142,7 +152,8 @@ dzl_cpu_graph_set_property (GObject      *object,
       break;
 
     case PROP_TIMESPAN:
-      self->timespan = g_value_get_int64 (value);
+      if (!(self->timespan = g_value_get_int64 (value)))
+        self->timespan = 60L * G_USEC_PER_SEC;
       break;
 
     default:
@@ -164,7 +175,7 @@ dzl_cpu_graph_class_init (DzlCpuGraphClass *klass)
                          "Timespan",
                          "Timespan",
                          0, G_MAXINT64,
-                         0,
+                         60L * G_USEC_PER_SEC,
                          (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
 
   properties [PROP_MAX_SAMPLES] =
diff --git a/src/graphing/dzl-cpu-graph.h b/src/graphing/dzl-cpu-graph.h
index f2d3e83..4ddfb0e 100644
--- a/src/graphing/dzl-cpu-graph.h
+++ b/src/graphing/dzl-cpu-graph.h
@@ -21,7 +21,7 @@
 
 #include "dzl-version-macros.h"
 
-#include "dzl-graph-view.h"
+#include "graphing/dzl-graph-view.h"
 
 G_BEGIN_DECLS
 
@@ -31,7 +31,8 @@ DZL_AVAILABLE_IN_ALL
 G_DECLARE_FINAL_TYPE (DzlCpuGraph, dzl_cpu_graph, DZL, CPU_GRAPH, DzlGraphView)
 
 DZL_AVAILABLE_IN_ALL
-GtkWidget *dzl_cpu_graph_new (void);
+GtkWidget *dzl_cpu_graph_new_full (gint64 timespan,
+                                   guint  max_samples);
 
 G_END_DECLS
 
diff --git a/tests/test-cpu-graph.c b/tests/test-cpu-graph.c
index 6e97bab..41a0bd8 100644
--- a/tests/test-cpu-graph.c
+++ b/tests/test-cpu-graph.c
@@ -17,7 +17,6 @@ main (int argc,
   GOptionContext *context;
   GtkWindow *window;
   GtkBox *box;
-  DzlGraphView *graph;
   GtkCssProvider *provider;
   GError *error = NULL;
 
@@ -56,13 +55,12 @@ main (int argc,
 
   for (int i = 0; i < 3; i++)
     {
-      graph = g_object_new (DZL_TYPE_CPU_GRAPH,
-                            "visible", TRUE,
-                            "vexpand", TRUE,
-                            "timespan", timespan,
-                            "max-samples", max_samples,
-                            NULL);
-      gtk_container_add (GTK_CONTAINER (box), GTK_WIDGET (graph));
+      GtkWidget *graph = dzl_cpu_graph_new_full (timespan, max_samples);
+
+      gtk_widget_set_vexpand (graph, TRUE);
+      gtk_widget_set_visible (graph, TRUE);
+
+      gtk_container_add (GTK_CONTAINER (box), graph);
     }
 
   g_signal_connect (window, "delete-event", gtk_main_quit, NULL);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]