[gnome-boxes] mini-graph: Ensure ymax is always set



commit cfaa944223e4fd9fcd2ff79d6961076999261eb8
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Dec 10 23:24:11 2014 +0000

    mini-graph: Ensure ymax is always set
    
    Since all users of MiniGraph always set ymax anyway, there is no reason
    to keep around code that deals with the case of it not being set.
    Instead simply make it a constuctor parameter to ensure its always set.

 src/libvirt-machine-properties.vala |    9 +++------
 src/mini-graph.vala                 |   19 ++-----------------
 2 files changed, 5 insertions(+), 23 deletions(-)
---
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index f7a3737..4470665 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -373,23 +373,20 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
         grid.column_homogeneous = true;
 
         // CPU
-        var cpu_graph = new MiniGraph ();
-        cpu_graph.ymax = 100;
+        var cpu_graph = new MiniGraph (100);
         cpu_graph.npoints = 20;
         grid.attach (cpu_graph, 0, 0, 1, 1);
         var label = new Gtk.Label (_("CPU"));
         grid.attach (label, 0, 1, 1, 1);
 
         // I/O
-        var io_graph = new MiniGraph ();
-        io_graph.ymax = 20;
+        var io_graph = new MiniGraph (20);
         grid.attach (io_graph, 1, 0, 1, 1);
         label = new Gtk.Label (_("I/O"));
         grid.attach (label, 1, 1, 1, 1);
 
         // Network
-        var net_graph = new MiniGraph ();
-        net_graph.ymax = 20;
+        var net_graph = new MiniGraph (20);
         grid.attach (net_graph, 2, 0, 1, 1);
         label = new Gtk.Label (_("Network"));
         grid.attach (label, 2, 1, 1, 1);
diff --git a/src/mini-graph.vala b/src/mini-graph.vala
index e1fbecc..1b2d0a3 100644
--- a/src/mini-graph.vala
+++ b/src/mini-graph.vala
@@ -15,30 +15,16 @@ private class Boxes.MiniGraph: Gtk.DrawingArea {
     public double ymax { get { return _ymax; }
         set {
             _ymax = value;
-            ymax_set = true;
         }
     }
-    private bool ymax_set = false;
 
-    public MiniGraph () {
+    public MiniGraph (double ymax) {
+        this.ymax = ymax;
         width_request = 120;
         height_request = 60;
         expand = true;
     }
 
-    private double max () {
-        if (points.length == 0)
-            return 1.0;
-
-        double max = points[0];
-        foreach (var p in points) {
-            if (p > max)
-                max = p;
-        }
-
-        return max;
-    }
-
     public override bool draw (Cairo.Context cr) {
         var width = get_allocated_width ();
         var height = get_allocated_height ();
@@ -49,7 +35,6 @@ private class Boxes.MiniGraph: Gtk.DrawingArea {
         cr.fill ();
 
         var nstep = (npoints == -1 ? points.length : npoints) - 1;
-        var ymax = ymax_set ? ymax : max ();
         var dy = 0.0;
         var dx = 0.0;
         if (nstep != 0)


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