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

0 views
Skip to first unread message

codesite...@google.com

unread,
Jan 13, 2009, 1:13:10 AM1/13/09
to gra...@googlegroups.com
Author: bugmaster
Date: Mon Jan 12 19:40:07 2009
New Revision: 73

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

Log:
Fixed stylistic comments.

I've tried to explain color interpolation a bit better, but I don't know
how to do it properly without using math... any ideas ?


Modified: trunk/graphy/backends/google_chart_api/encoders.py
==============================================================================
--- trunk/graphy/backends/google_chart_api/encoders.py (original)
+++ trunk/graphy/backends/google_chart_api/encoders.py Mon Jan 12 19:40:07
2009
@@ -368,18 +368,19 @@
super(PieChartEncoder, self).__init__(chart)
self.is3d = is3d
self.angle = None
-
+
def _GetFormatters(self):
"""Add a formatter for the chart angle."""
formatters = super(PieChartEncoder, self)._GetFormatters()
formatters.append(self._GetAngleParams)
- return formatters
+ return formatters

def _GetType(self, chart):
if len(chart.data) > 1:
if self.is3d:
- warnings.warn('3d charts with more than one pie not supported',
- RuntimeWarning, stacklevel=2)
+ warnings.warn(
+ '3d charts with more than one pie not supported; rendering in
2d',
+ RuntimeWarning, stacklevel=2)
chart_type = 'pc'
else:
if self.is3d:
@@ -421,10 +422,9 @@
if segment and segment.color:
colors.append(segment.color)
return util.JoinLists(color = colors)
-
+
def _GetAngleParams(self, chart):
"""If the user specified an angle, add it to the params."""
if self.angle:
return {'chp' : str(self.angle)}
- else:
- return {}
+ return {}

Modified: trunk/graphy/pie_chart.py
==============================================================================
--- trunk/graphy/pie_chart.py (original)
+++ trunk/graphy/pie_chart.py Mon Jan 12 19:40:07 2009
@@ -83,8 +83,10 @@
TODO: Allow the user to pass in None as one of
the labels in order to skip that label.
colors: A list of colors for the pie segments, as hex strings
- (f.ex. '0000ff' for blue). Missing colors will be
- automatically interpolated by the server.
+ (f.ex. '0000ff' for blue). If there are less colors than pie
+ segments, the Google Chart API will attempt to produce a
smooth
+ color transition between segments by spreading the colors
across
+ them.
"""
super(PieChart, self).__init__()
self.formatters = []
@@ -133,9 +135,9 @@
def AddSegment(self, size, label=None, color=None, pie_index=0):
"""Add a pie segment to this chart, and return the segment.

- size: The size of the segment
- label: The label for the segment
- color: The color of the segment, or None to automatically choose the
color
+ size: The size of the segment.
+ 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.

Modified: trunk/graphy/pie_chart_test.py
==============================================================================
--- trunk/graphy/pie_chart_test.py (original)
+++ trunk/graphy/pie_chart_test.py Mon Jan 12 19:40:07 2009
@@ -63,9 +63,9 @@

# New order
chart.AddSegment(1, 'label', '0000FF')
- self.assertEquals('label', chart.data[0][0].label)
- self.assertEquals('0000FF', chart.data[0][0].color)
-
+ self.assertEqual('label', chart.data[0][0].label)
+ self.assertEqual('0000FF', chart.data[0][0].color)
+
# TODO: remove once the deprecation warning is removed
def testAddSegmentsOrder(self):
chart = pie_chart.PieChart()
@@ -81,29 +81,29 @@

def testAddPie(self):
chart = pie_chart.PieChart()
- idx = chart.AddPie([1], ['A'], ['ff0000'])
- self.assertEquals(idx, 0)
- self.assertEquals(len(chart.data), 1)
- self.assertEquals(len(chart.data[0]), 1)
- self.assertEquals(chart.data[0][0].size, 1)
- idx = chart.AddPie([2], ['B'], ['0000ff'])
- self.assertEquals(idx, 1)
- self.assertEquals(len(chart.data), 2)
- self.assertEquals(len(chart.data[0]), 1)
- self.assertEquals(chart.data[0][0].size, 1)
- self.assertEquals(len(chart.data[1]), 1)
- self.assertEquals(chart.data[1][0].size, 2)
-
- def testAddSegmentToPie(self):
+ i = chart.AddPie([1], ['A'], ['ff0000'])
+ self.assertEqual(i, 0)
+ self.assertEqual(len(chart.data), 1)
+ self.assertEqual(len(chart.data[0]), 1)
+ self.assertEqual(chart.data[0][0].size, 1)
+ i = chart.AddPie([2], ['B'], ['0000ff'])
+ self.assertEqual(i, 1)
+ self.assertEqual(len(chart.data), 2)
+ self.assertEqual(len(chart.data[0]), 1)
+ self.assertEqual(chart.data[0][0].size, 1)
+ self.assertEqual(len(chart.data[1]), 1)
+ self.assertEqual(chart.data[1][0].size, 2)
+
+ def testAddSegmentToPie(self):
chart = pie_chart.PieChart()
chart.AddPie([1], ['A'], ['ff0000'])
chart.AddPie([2], ['B'], ['0000ff'])
chart.AddSegment([10], ['AA'])
- self.assertEquals(len(chart.data[0]), 2)
- self.assertEquals(len(chart.data[1]), 1)
+ self.assertEqual(len(chart.data[0]), 2)
+ self.assertEqual(len(chart.data[1]), 1)
chart.AddSegment([20], ['BB'], pie_index=1)
- self.assertEquals(len(chart.data[0]), 2)
- self.assertEquals(len(chart.data[1]), 2)
+ self.assertEqual(len(chart.data[0]), 2)
+ self.assertEqual(len(chart.data[1]), 2)


if __name__ == '__main__':

Reply all
Reply to author
Forward
0 new messages