[rhmessaging-commits] rhmessaging commits: r1915 - mgmt/cumin/python/cumin.

rhmessaging-commits at lists.jboss.org rhmessaging-commits at lists.jboss.org
Tue Apr 15 13:41:20 EDT 2008


Author: justi9
Date: 2008-04-15 13:41:19 -0400 (Tue, 15 Apr 2008)
New Revision: 1915

Modified:
   mgmt/cumin/python/cumin/charts.py
   mgmt/cumin/python/cumin/stat.py
Log:
Add a method to draw legends on charts.

Eliminate an unused stroke wrapper.



Modified: mgmt/cumin/python/cumin/charts.py
===================================================================
--- mgmt/cumin/python/cumin/charts.py	2008-04-15 15:56:58 UTC (rev 1914)
+++ mgmt/cumin/python/cumin/charts.py	2008-04-15 17:41:19 UTC (rev 1915)
@@ -22,7 +22,7 @@
 
     def plot_values(self, samples, color=(0, 0, 0)):
         cr = Context(self.surface)
-        cr.set_line_width(2)
+        cr.set_line_width(1.5)
         cr.set_source_rgb(*color)
 
         tnow = time()
@@ -38,8 +38,30 @@
             y = self.height - (value / float(self.y_max)) * self.height
             cr.line_to(x, y)
 
-        self.stroke(cr)
+        cr.stroke()
 
+    def plot_legend(self, titles, colors):
+        cr = Context(self.surface)
+
+        for i, item in enumerate(zip(titles, colors)):
+            title, color = item
+            y = 16 + i * 16
+
+            cr.set_source_rgba(1, 1, 1, 0.75)
+            cr.rectangle(4, y - 12, 16 + 6.5 * len(title), 16)
+            cr.fill()
+            cr.stroke()
+
+            cr.set_source_rgb(*color)
+            cr.rectangle(8, y, 8, -8)
+            cr.fill()
+            cr.stroke()
+
+            cr.move_to(20, y)
+            cr.set_source_rgb(0, 0, 0)
+            cr.show_text(title)
+            cr.stroke()
+
     def plot_frame(self, color=(0.8, 0.8, 0.8)):
         cr = Context(self.surface)
         cr.set_line_width(1)
@@ -49,7 +71,7 @@
         cr.line_to(self.width, self.height)
         cr.line_to(0, self.height)
 
-        self.stroke(cr)
+        cr.stroke()
 
     def plot_x_axis(self, intervals, step):
         cr = Context(self.surface)
@@ -71,7 +93,7 @@
                 if text:
                     cr.show_text(text)
 
-        self.stroke(cr)
+        cr.stroke()
 
     def plot_y_axis(self, intervals, step):
         cr = Context(self.surface)
@@ -98,9 +120,6 @@
 
                 cr.show_text(svalue)
 
-        self.stroke(cr)
-
-    def stroke(self, cr):
         cr.stroke()
 
     def write(self, writer):

Modified: mgmt/cumin/python/cumin/stat.py
===================================================================
--- mgmt/cumin/python/cumin/stat.py	2008-04-15 15:56:58 UTC (rev 1914)
+++ mgmt/cumin/python/cumin/stat.py	2008-04-15 17:41:19 UTC (rev 1915)
@@ -244,6 +244,9 @@
         
         chart.plot_frame()
 
+        titles = [x.title for x in stats]
+        chart.plot_legend(titles, colors)
+
         writer = Writer()
         chart.write(writer)
         return writer.to_string()




More information about the rhmessaging-commits mailing list