Author: justi9
Date: 2008-04-14 17:22:21 -0400 (Mon, 14 Apr 2008)
New Revision: 1909
Modified:
mgmt/cumin/python/cumin/charts.py
mgmt/cumin/python/cumin/stat.py
mgmt/cumin/python/cumin/stat.strings
Log:
Change the way intervals are computed and displayed in charts.
Shrink charts in preparation for using them in a new location.
Modified: mgmt/cumin/python/cumin/charts.py
===================================================================
--- mgmt/cumin/python/cumin/charts.py 2008-04-14 17:05:54 UTC (rev 1908)
+++ mgmt/cumin/python/cumin/charts.py 2008-04-14 21:22:21 UTC (rev 1909)
@@ -51,15 +51,17 @@
self.stroke(cr)
- def plot_x_axis(self, interval, step):
+ def plot_x_axis(self, intervals, step):
cr = Context(self.surface)
cr.set_line_width(0.2)
cr.set_source_rgb(0.6, 0.6, 0.6)
+ interval = self.width / float(intervals)
absmax = self.x_max - self.x_min
- i = 0
- for x in range(self.width, 0 - interval, -interval):
+ for i in range(0, intervals + 1):
+ x = self.width - (i * interval)
+
cr.move_to(x, 0)
cr.line_to(x, self.height + 10)
@@ -69,39 +71,33 @@
if text:
cr.show_text(text)
- i += 1
-
self.stroke(cr)
- def plot_y_axis(self, interval, step):
+ def plot_y_axis(self, intervals, step):
cr = Context(self.surface)
cr.set_line_width(0.2)
cr.set_source_rgb(0.6, 0.6, 0.6)
- i = 0
+ interval = self.height / float(intervals)
- for y in range(0, self.height, interval):
+ for i in range(0, intervals + 1):
+ y = self.height - (i * interval)
+
cr.move_to(0, y)
cr.line_to(self.width + 2, y)
if i % step == 0:
fraction = (self.height - y) / float(self.height)
value = fraction * self.y_max - self.y_min
- value = value + self.y_min
+ value = int(round(value + self.y_min))
- if value == 0:
- svalue = "0"
- elif value < 10:
- svalue = str(value)
- elif value > 10000:
- svalue = "%ik" % int(round(value / 1000, -1))
+ if value > 10000:
+ svalue = "%ik" % int(round(value / 1000.0, -1))
else:
- svalue = str(int(round(value, -1)))
+ svalue = str(value)
cr.show_text(svalue)
- i += 1
-
self.stroke(cr)
def stroke(self, cr):
Modified: mgmt/cumin/python/cumin/stat.py
===================================================================
--- mgmt/cumin/python/cumin/stat.py 2008-04-14 17:05:54 UTC (rev 1908)
+++ mgmt/cumin/python/cumin/stat.py 2008-04-14 21:22:21 UTC (rev 1909)
@@ -168,7 +168,7 @@
return (cls.get(id),)
def do_render(self, session, object):
- chart = LineChart(480, 120)
+ chart = LineChart(320, 80)
cls = self.class_.get(session)
stats = [getattr(cls, x) for x in self.stats.get(session)]
@@ -222,20 +222,20 @@
chart.y_max = max_value
chart.y_min = min_value
- x_interval = 40
+ x_intervals = 8
x_step = 2
if chart.x_max == 600:
- x_interval = 48
+ x_intervals = 10
- y_interval = 15
+ y_intervals = 6
y_step = 2
- if chart.y_max < 4:
- y_step = 4
+ if chart.y_max < 3:
+ y_step = 3
- chart.plot_x_axis(x_interval, x_step)
- chart.plot_y_axis(y_interval, y_step)
+ chart.plot_x_axis(x_intervals, x_step)
+ chart.plot_y_axis(y_intervals, y_step)
colors = ((1,0,0), (0,0,1), (0,1,0))
Modified: mgmt/cumin/python/cumin/stat.strings
===================================================================
--- mgmt/cumin/python/cumin/stat.strings 2008-04-14 17:05:54 UTC (rev 1908)
+++ mgmt/cumin/python/cumin/stat.strings 2008-04-14 21:22:21 UTC (rev 1909)
@@ -105,7 +105,7 @@
[StatValueChart.html]
<table class="StatValueChart" id="{id}">
<tr>
- <td><img id="{id}" src="{href}" height="140"
width="540"/></td>
+ <td><img id="{id}" src="{href}" height="100"
width="380"/></td>
<td>
<ul>{stats}</ul>
<br/>