[gnome-usage/tracker-powered-storage-view-wip] storage: Introduce new storage graph



commit de763028e8defa328e4498aad21a3e4afe5553ae
Author: Petr Štětka <pstetka redhat com>
Date:   Mon Jul 23 13:08:58 2018 +0200

    storage: Introduce new storage graph

 data/interface/adwaita.css     |  20 +---
 src/meson.build                |   2 +-
 src/storage-graph.vala         | 238 -----------------------------------------
 src/storage/storage-graph.vala | 150 ++++++++++++++++++++++++++
 4 files changed, 153 insertions(+), 257 deletions(-)
---
diff --git a/data/interface/adwaita.css b/data/interface/adwaita.css
index fe25794..e60fa9c 100644
--- a/data/interface/adwaita.css
+++ b/data/interface/adwaita.css
@@ -89,24 +89,8 @@ PieChart.available, ColorRectangle.available {
     color: @theme_base_color;
 }
 
-ColorRectangle.system, StorageGraph.system {
-    color: #2e3436;
-}
-
-ColorRectangle.applications, StorageGraph.applications {
-    color: #4e9a06;
-}
-
-ColorRectangle.trash, StorageGraph.trash {
-    color: @theme_fg_color;
-}
-
-ColorRectangle.user, StorageGraph.user {
-    color: #ad7fa8;
-}
-
-ColorRectangle.available-storage, StorageGraph.available-storage {
-    color: #d3d7cf;
+StorageGraph {
+    color: @theme_base_color;
 }
 
 /* Speedometer */
diff --git a/src/meson.build b/src/meson.build
index c838def..d0fb1f5 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -28,6 +28,7 @@ vala_sources = [
   'quit-process-dialog.vala',
   'settings.vala',
   'speedometer.vala',
+  'storage/storage-graph.vala',
   'storage/query-builder.vala',
   'storage/storage-row-popover.vala',
   'storage/storage-view-item.vala',
@@ -35,7 +36,6 @@ vala_sources = [
   'storage/storage-view-row.vala',
   'storage/tracker-controller.vala',
   'storage/tracker-worker.vala',
-  'storage-graph.vala',
   'swap-speedometer.vala',
   'system-monitor.vala',
   'utils.vala',
diff --git a/src/storage/storage-graph.vala b/src/storage/storage-graph.vala
new file mode 100644
index 0000000..d01b963
--- /dev/null
+++ b/src/storage/storage-graph.vala
@@ -0,0 +1,150 @@
+/* storage-graph.vala
+ *
+ * Copyright (C) 2018 Red Hat, Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors: Petr Štětka <pstetka redhat com>
+ */
+
+using Gtk;
+
+namespace Usage
+{
+    public class StorageGraph : Gtk.DrawingArea
+    {
+        private GLib.ListStore _model;
+        public GLib.ListStore model {
+            set {
+                _model = value;
+                this.draw.connect(draw_storage_graph);
+                this.queue_draw ();
+                root = false;
+
+                for(int i = 0; i < value.get_n_items(); i++)
+                {
+                    var item = model.get_item(i) as StorageViewItem;
+                    if(item.custom_type == "os") {
+                        root = true;
+                        break;
+                    }
+                }
+            }
+            get { return _model; }
+        }
+        public uint min_percentage_shown_files { set; get; }
+        private bool root { private set; get; }
+
+        class construct
+        {
+            set_css_name("StorageGraph");
+        }
+
+        public enum Circle
+        {
+            HOME,
+            ROOT,
+            BASE
+        }
+
+        private void draw_circle(Cairo.Context context, GLib.ListStore model, double x, double y, double 
radius, int section, Circle circle)
+        {
+            double start_angle = 0;
+            double final_angle = - Math.PI / 2.0;
+            double ratio = 0;
+            uint shown_items_number = 0;
+            var background_color = 
get_toplevel().get_style_context().get_background_color(get_toplevel().get_style_context().get_state());
+            var foreground_color = get_style_context().get_color(get_style_context().get_state());
+
+            for(int i = 0; i < model.get_n_items(); i++) {
+                if((model.get_item(i) as StorageViewItem).percentage > min_percentage_shown_files)
+                    shown_items_number = shown_items_number + 1;
+            }
+
+            if(shown_items_number <= 3)
+                shown_items_number = model.get_n_items();
+
+            if(shown_items_number > 1) {
+                for(int i = 0; i < model.get_n_items(); i++)
+                {
+                    var item = model.get_item(i) as StorageViewItem;
+                    if(item.custom_type == "up-folder")
+                        continue;
+
+                    var style_context = get_style_context();
+                    style_context.add_class(item.style_class);
+                    var base_color = style_context.get_background_color(style_context.get_state());
+                    style_context.remove_class(item.style_class);
+
+                    Gdk.RGBA fill_color = base_color;
+
+                    if(!root)
+                        fill_color = Utils.generate_color(base_color, i, shown_items_number, true);
+
+                    context.set_line_width (2.0);
+                    start_angle = final_angle;
+
+                    if(item.percentage < 0.3)
+                        ratio = ratio + ((double) 0.3 / 100);
+                    else
+                        ratio = ratio + ((double) item.percentage / 100);
+
+                    final_angle = ratio * 2 * Math.PI - Math.PI / 2.0;
+                    if(final_angle >= (2 * Math.PI - Math.PI / 2.0))
+                        final_angle = 2 * Math.PI - Math.PI / 2.0;
+
+                    context.move_to (x, y);
+                    Gdk.cairo_set_source_rgba (context, fill_color);
+                    context.arc (x, y, radius, start_angle, final_angle);
+                    context.fill_preserve();
+                    Gdk.cairo_set_source_rgba (context, foreground_color);
+                    context.stroke();
+
+                    if(start_angle >= (2 * Math.PI - Math.PI / 2.0))
+                        break;
+                }
+
+                context.move_to (x, y);
+                context.line_to (x, y-(radius));
+                context.stroke();
+
+                context.arc (x, y, radius/1.8, 0, 2 * Math.PI);
+                Gdk.cairo_set_source_rgba (context, background_color);
+                context.fill_preserve();
+                Gdk.cairo_set_source_rgba (context, foreground_color);
+                context.stroke();
+            }
+        }
+
+        private bool draw_storage_graph(Cairo.Context context)
+        {
+            int height = this.get_allocated_height ();
+            int width = this.get_allocated_width ();
+
+            double x = 0;
+            double y = 0;
+            double radius = 0;
+
+            radius = int.min (width, height) / 2.0;
+            radius -= radius / 4;
+            x = width / 2.0;
+            y = height / 2.0;
+
+            draw_circle(context, model, x, y, radius, 0, Circle.BASE);
+
+            return true;
+        }
+
+    }
+}


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