[graphy commit] r72 - in trunk/graphy: . backends/google_chart_api

0 views
Skip to first unread message

codesite...@google.com

unread,
Jan 8, 2009, 8:05:22 PM1/8/09
to gra...@googlegroups.com
Author: bugmaster
Date: Thu Jan 8 16:58:34 2009
New Revision: 72

Modified:
trunk/graphy/backends/google_chart_api/pie_chart_test.py
trunk/graphy/pie_chart.py
trunk/graphy/pie_chart_test.py

Log:
Restored the PieChart.AddSegments and PieChart.AddSeries methods, as well
as their associated tests.


Modified: trunk/graphy/backends/google_chart_api/pie_chart_test.py
==============================================================================
--- trunk/graphy/backends/google_chart_api/pie_chart_test.py (original)
+++ trunk/graphy/backends/google_chart_api/pie_chart_test.py Thu Jan 8
16:58:34 2009
@@ -65,6 +65,21 @@
self.chart.AddSegment(4, label='Horse')
self.assertEqual(self.Param('chd'), 's:Pfu9')
self.assertEqual(self.Param('chl'), 'Mouse|Cat|Dog|Horse')
+
+ # TODO: Remove this when AddSegments is removed
+ def testAddMultipleSegments(self):
+ warnings.filterwarnings('ignore')
+ self.chart.AddSegments([1,2,3],
+ ['Mouse', 'Cat', 'Dog'],
+ ['ff0000', '00ff00', '0000ff'])
+ self.assertEqual(self.Param('chd'), 's:Up9')
+ self.assertEqual(self.Param('chl'), 'Mouse|Cat|Dog')
+ self.assertEqual(self.Param('chco'), 'ff0000,00ff00,0000ff')
+ # skip two colors
+ self.chart.AddSegments([4,5,6], ['Horse', 'Moose', 'Elephant'],
['cccccc'])
+ self.assertEqual(self.Param('chd'), 's:KUfpz9')
+ self.assertEqual(self.Param('chl'), 'Mouse|Cat|Dog|Horse|Moose|
Elephant')
+ self.assertEqual(self.Param('chco'), 'ff0000,00ff00,0000ff,cccccc')

def testMultiplePies(self):
self.chart.AddPie([1,2,3],

Modified: trunk/graphy/pie_chart.py
==============================================================================
--- trunk/graphy/pie_chart.py (original)
+++ trunk/graphy/pie_chart.py Thu Jan 8 16:58:34 2009
@@ -106,9 +106,8 @@
num_colors = len(colors or [])
num_labels = len(labels or [])
pie_index = len(self.data)
- self.data.append(list())
+ self.data.append([])
for i, pt in enumerate(points):
- assert pt >= 0
label = None
if i < num_labels:
label = labels[i]
@@ -118,6 +117,19 @@
self.AddSegment(pt, label=label, color=color, pie_index=pie_index)
return pie_index

+ def AddSegments(self, points, labels, colors):
+ """DEPRECATED."""
+ warnings.warn('PieChart.AddSegments is deprecated. Call AddPie
instead. ',
+ DeprecationWarning, stacklevel=2)
+ num_colors = len(colors or [])
+ for i, pt in enumerate(points):
+ assert pt >= 0
+ label = labels[i]
+ color = None
+ if i < num_colors:
+ color = colors[i]
+ self.AddSegment(pt, label=label, color=color)
+
def AddSegment(self, size, label=None, color=None, pie_index=0):
"""Add a pie segment to this chart, and return the segment.

@@ -125,6 +137,8 @@
label: The label for the segment
color: The color of the segment, or None to automatically choose the
color
pie_index: The index of the pie that will receive the new segment.
+ By default, the chart has one pie (pie #0); use the AddPie method to
+ add more pies.
"""
if isinstance(size, Segment):
warnings.warn("AddSegment(segment) is deprecated. Use
AddSegment(size, "
@@ -135,10 +149,22 @@
assert segment.size >= 0
if pie_index == 0 and not self.data:
# Create the default pie
- self.data.append(list())
+ self.data.append([])
+ assert (pie_index >= 0 and pie_index < len(self.data))
self.data[pie_index].append(segment)
return segment

+ def AddSeries(self, points, color=None, style=None, markers=None,
label=None):
+ """DEPRECATED
+
+ Add a new segment to the chart and return it.
+
+ The segment must contain exactly one data point; all parameters
+ other than color and label are ignored.
+ """
+ warnings.warn('PieChart.AddSeries is deprecated. Call AddSegment or '
+ 'AddSegments instead.', DeprecationWarning)
+ return self.AddSegment(Segment(points[0], color=color, label=label))

def SetColors(self, *colors):
"""Change the colors of this chart to the specified list of colors.

Modified: trunk/graphy/pie_chart_test.py
==============================================================================
--- trunk/graphy/pie_chart_test.py (original)
+++ trunk/graphy/pie_chart_test.py Thu Jan 8 16:58:34 2009
@@ -65,6 +65,19 @@
chart.AddSegment(1, 'label', '0000FF')
self.assertEquals('label', chart.data[0][0].label)
self.assertEquals('0000FF', chart.data[0][0].color)
+
+ # TODO: remove once the deprecation warning is removed
+ def testAddSegmentsOrder(self):
+ chart = pie_chart.PieChart()
+ # Deprecated approach
+ warnings.filterwarnings('error')
+ self.assertRaises(DeprecationWarning, chart.AddSegments, [1],
+ ['0000FF'], ['label'])
+ # New order
+ warnings.filterwarnings('ignore')
+ chart.AddSegments([1], ['label'], ['0000FF'])
+ self.assertEqual('label', chart.data[0][0].label)
+ self.assertEqual('0000FF', chart.data[0][0].color)

def testAddPie(self):
chart = pie_chart.PieChart()

Reply all
Reply to author
Forward
0 new messages