[PATCH 3/9]: virt-manager: add sparkline "reversed" property

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

 



add "reversed" property to process data back to front

this way we don't have to reverse the list in place in python code so
it's more obvious which set is which when having multiple lines (see
follow up patch).
 -- Guido
add "reversed" property to process data back to front

this way we don't have to reverse the list in place in python code. This way
it's more obvious which set is which when having multiple lines (see follow up
patch).

diff -r 60adf3fb4647 src/graphWidgets/cellrenderersparkline.c
--- a/src/graphWidgets/cellrenderersparkline.c	Sat Oct 04 17:02:18 2008 +0200
+++ b/src/graphWidgets/cellrenderersparkline.c	Sat Oct 04 17:03:04 2008 +0200
@@ -55,8 +55,8 @@
 
 enum {
   PROP_0,
-  PROP_NUMDATAPOINTS,
-  PROP_DATAARRAY
+  PROP_DATAARRAY,
+  PROP_REVERSED,
 };
 
 static gpointer parent_class;
@@ -68,6 +68,7 @@
 struct _GtkCellRendererSparklinePrivate
 {
   gboolean filled;
+  gboolean reversed;
   GValueArray *data_array;
 };
 
@@ -137,6 +138,14 @@
 										 G_PARAM_READABLE | G_PARAM_WRITABLE),
 							     G_PARAM_READABLE | G_PARAM_WRITABLE));
 
+  g_object_class_install_property (object_class,
+				   PROP_REVERSED,
+				   g_param_spec_boolean ("reversed",
+						         "Reversed",
+						         "process data from back to front",
+						         FALSE,
+						         G_PARAM_READABLE | G_PARAM_WRITABLE));
+
   g_type_class_add_private (object_class, sizeof (GtkCellRendererSparklinePrivate));
 }
 
@@ -163,6 +172,10 @@
     {
     case PROP_DATAARRAY:
       g_value_set_boxed(value, priv->data_array);
+      break;
+
+    case PROP_REVERSED:
+      g_value_set_boolean(value, priv->reversed);
       break;
 
     default:
@@ -186,6 +199,10 @@
     case PROP_DATAARRAY:
       g_value_array_free(priv->data_array);
       priv->data_array = g_value_array_copy(g_value_get_boxed(value));
+      break;
+
+    case PROP_REVERSED:
+      priv->reversed = g_value_get_boolean(value);
       break;
 
     default:
@@ -225,12 +242,21 @@
   }
 }
 
-static double get_y (GdkRectangle *cell_area,
+static double get_y (GtkCellRendererSparklinePrivate *priv,
+		     GdkRectangle *cell_area,
 		     GValueArray *data,
 		     int index)
 {
+  int n;
   double baseline_y = cell_area->y + cell_area->height;
-  GValue *val = g_value_array_get_nth(data, index);
+  GValue *val;
+
+  if (priv->reversed) 
+    n = data->n_values - 1 - index;
+  else
+    n = index;
+
+  val = g_value_array_get_nth(data, n);
   return baseline_y - (cell_area->height * g_value_get_double(val));
 }
 
@@ -261,7 +287,7 @@
   points = g_new(GdkPoint, data->n_values);
   for (index=0;index<data->n_values;index++) {
     double cx = ((double)index * pixels_per_point);
-    double cy = get_y (cell_area, data, index);
+    double cy = get_y (priv, cell_area, data, index);
     
     points[index].x = cx + cell_area->x;
     points[index].y = cy;
diff -r 60adf3fb4647 src/graphWidgets/sparkline.c
--- a/src/graphWidgets/sparkline.c	Sat Oct 04 17:02:18 2008 +0200
+++ b/src/graphWidgets/sparkline.c	Sat Oct 04 17:03:04 2008 +0200
@@ -43,6 +43,7 @@
   PROP_0,
   PROP_DATAARRAY,
   PROP_FILLED,
+  PROP_REVERSED,
 };
 
 static gpointer parent_class;
@@ -53,6 +54,7 @@
 struct _GtkSparklinePrivate
 {
   gboolean filled;
+  gboolean reversed;
   GValueArray *data_array;
 };
 
@@ -89,6 +91,7 @@
   priv = GTK_SPARKLINE_GET_PRIVATE (sparkline);
 
   priv->filled = TRUE;
+  priv->reversed = FALSE;
   priv->data_array = g_value_array_new(0);
 
   g_signal_connect (G_OBJECT (sparkline), "expose_event",
@@ -131,6 +134,13 @@
 						         "fill space under sparcline",
 						         TRUE,
 						         G_PARAM_READABLE | G_PARAM_WRITABLE));
+  g_object_class_install_property (object_class,
+				   PROP_REVERSED,
+				   g_param_spec_boolean ("reversed",
+						         "Reversed",
+						         "process data from back to front",
+						         FALSE,
+						         G_PARAM_READABLE | G_PARAM_WRITABLE));
 
   g_type_class_add_private (object_class, sizeof (GtkSparklinePrivate));
 }
@@ -162,6 +172,10 @@
       g_value_set_boolean(value, priv->filled);
       break;
 
+    case PROP_REVERSED:
+      g_value_set_boolean(value, priv->reversed);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       break;
@@ -190,6 +204,10 @@
       priv->filled = g_value_get_boolean(value);
       break;
 
+    case PROP_REVERSED:
+      priv->reversed = g_value_get_boolean(value);
+      break;
+
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
       break;
@@ -214,10 +232,17 @@
 
 static double get_y (GtkAllocation *cell_area,
 		     GValueArray *data,
-		     int index)
+		     int index, int reversed)
 {
   double baseline_y = cell_area->height;
-  GValue *val = g_value_array_get_nth(data, index);
+  int n;
+
+  if (reversed) 
+    n = data->n_values - 1 - index;
+  else
+    n = index;
+
+  GValue *val = g_value_array_get_nth(data, n);
   return baseline_y - ((cell_area->height-1) * g_value_get_double(val));
 }
 
@@ -245,7 +270,7 @@
   points = g_new(GdkPoint, data->n_values);
   for (index=0;index<data->n_values;index++) {
     double cx = ((double)index * pixels_per_point);
-    double cy = get_y (cell_area, data, index);
+    double cy = get_y (cell_area, data, index, priv->reversed);
     points[index].x = cx;
     points[index].y = cy;
   }
diff -r 60adf3fb4647 src/virtManager/details.py
--- a/src/virtManager/details.py	Sat Oct 04 17:02:18 2008 +0200
+++ b/src/virtManager/details.py	Sat Oct 04 17:03:04 2008 +0200
@@ -182,12 +182,15 @@
         self.choose_cd = None
         
         self.cpu_usage_graph = sparkline.Sparkline()
+        self.cpu_usage_graph.set_property("reversed", True)
         self.window.get_widget("graph-table").attach(self.cpu_usage_graph, 1, 2, 0, 1)
 
         self.memory_usage_graph = sparkline.Sparkline()
+        self.memory_usage_graph.set_property("reversed", True)
         self.window.get_widget("graph-table").attach(self.memory_usage_graph, 1, 2, 1, 2)
 
         self.network_traffic_graph = sparkline.Sparkline()
+        self.network_traffic_graph.set_property("reversed", True)
         self.window.get_widget("graph-table").attach(self.network_traffic_graph, 1, 2, 3, 4)
 
 
@@ -806,15 +809,12 @@
 
         history_len = self.config.get_stats_history_length()
         cpu_vector = self.vm.cpu_time_vector()
-        cpu_vector.reverse()
         self.cpu_usage_graph.set_property("data_array", cpu_vector)
 
         memory_vector = self.vm.current_memory_vector()
-        memory_vector.reverse()
         self.memory_usage_graph.set_property("data_array", memory_vector)
 
         network_vector = self.vm.network_traffic_vector()
-        network_vector.reverse()
         self.network_traffic_graph.set_property("data_array", network_vector)
 
     def refresh_config_cpu(self):
_______________________________________________
et-mgmt-tools mailing list
et-mgmt-tools@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/et-mgmt-tools

[Index of Archives]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux