[hamster-applet] setting legend width in fractions. fixes bug 619821



commit d4e1edceca205fab84bcda1649f3e38e43675441
Author: Toms Bauģis <toms baugis gmail com>
Date:   Sat Jun 5 20:07:27 2010 +0100

    setting legend width in fractions. fixes bug 619821

 data/overview_totals.ui        |    3 +--
 src/hamster/charting.py        |    9 +++++++--
 src/hamster/overview_totals.py |   14 +++++++-------
 3 files changed, 15 insertions(+), 11 deletions(-)
---
diff --git a/data/overview_totals.ui b/data/overview_totals.ui
index 51f9207..6c3b4e4 100644
--- a/data/overview_totals.ui
+++ b/data/overview_totals.ui
@@ -8,6 +8,7 @@
         <property name="visible">True</property>
         <property name="border_width">12</property>
         <property name="orientation">vertical</property>
+        <property name="spacing">12</property>
         <child>
           <object class="GtkHBox" id="hbox1">
             <property name="visible">True</property>
@@ -166,7 +167,6 @@
                                 </child>
                               </object>
                               <packing>
-                                <property name="expand">False</property>
                                 <property name="position">0</property>
                               </packing>
                             </child>
@@ -201,7 +201,6 @@
                                 </child>
                               </object>
                               <packing>
-                                <property name="expand">False</property>
                                 <property name="position">1</property>
                               </packing>
                             </child>
diff --git a/src/hamster/charting.py b/src/hamster/charting.py
index ceee57e..944b1bb 100644
--- a/src/hamster/charting.py
+++ b/src/hamster/charting.py
@@ -172,11 +172,15 @@ class Chart(graphics.Scene):
     def on_enter_frame(self, scene, context):
         # adjust sizes and positions on redraw
 
+        legend_width = self.legend_width
+        if legend_width < 1: # allow fractions
+            legend_width = int(self.width * legend_width)
+
         self.find_colors()
 
         self.plot_area.y = 0
         self.plot_area.height = self.height - self.plot_area.y
-        self.plot_area.x = self.legend_width + 8
+        self.plot_area.x = legend_width + 8
         self.plot_area.width = self.width - self.plot_area.x
 
         y = 0
@@ -208,8 +212,9 @@ class Chart(graphics.Scene):
                 bar.label_background.fill = None
 
             label.y = y + (bar_width - label.height) / 2 + self.plot_area.y
+
+            label.width = legend_width
             if not label.color:
-                label.width = self.legend_width
                 label.color = self.label_color
 
             y += bar_width + 1
diff --git a/src/hamster/overview_totals.py b/src/hamster/overview_totals.py
index 1c8de34..a5794ec 100644
--- a/src/hamster/overview_totals.py
+++ b/src/hamster/overview_totals.py
@@ -46,7 +46,7 @@ class TotalsBox(gtk.VBox):
         self.start_date, self.end_date = None, None
 
         #graphs
-        x_offset = 100 # align all graphs to the left edge
+        x_offset = 0.4 # align all graphs to the left edge
 
 
         self.category_chart = charting.Chart(max_bar_width = 20,
@@ -111,7 +111,7 @@ class TotalsBox(gtk.VBox):
             self.selected_tags.append(key)
         self.calculate_totals()
         self.do_charts()
-        
+
 
     def search(self, start_date, end_date, facts):
         self.facts = facts
@@ -206,22 +206,22 @@ class TotalsBox(gtk.VBox):
     def do_charts(self):
         self.get_widget("totals_by_category").set_size_request(10,10)
         if self.category_sums:
-            self.get_widget("totals_by_category").set_size_request(280, len(self.category_sums[0]) * 20)
+            self.get_widget("totals_by_category").set_size_request(-1, len(self.category_sums[0]) * 20)
             self.category_chart.plot(*self.category_sums)
         else:
-            self.get_widget("totals_by_category").set_size_request(280, 10)
+            self.get_widget("totals_by_category").set_size_request(-1, 10)
             self.category_chart.plot([],[])
 
         self.get_widget("totals_by_activity").set_size_request(10,10)
-        self.get_widget("totals_by_activity").set_size_request(280, len(self.activity_sums[0]) * 20)
+        self.get_widget("totals_by_activity").set_size_request(-1, len(self.activity_sums[0]) * 20)
         self.activity_chart.plot(*self.activity_sums)
 
         self.get_widget("totals_by_tag").set_size_request(10,10)
         if self.tag_sums:
-            self.get_widget("totals_by_tag").set_size_request(280, len(self.tag_sums[0]) * 20)
+            self.get_widget("totals_by_tag").set_size_request(-1, len(self.tag_sums[0]) * 20)
             self.tag_chart.plot(*self.tag_sums)
         else:
-            self.get_widget("totals_by_tag").set_size_request(280, 10)
+            self.get_widget("totals_by_tag").set_size_request(-1, 10)
             self.tag_chart.plot([],[])
 
 



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