From 082987c417dbf5a546c6760d651b8b3f67187bb9 Mon Sep 17 00:00:00 2001 From: jaraco Date: Tue, 12 Feb 2008 14:14:12 +0000 Subject: [PATCH] Improved vertical bar axis and test; it now nearly matches the Ruby test of the same data --- lib/SVG/Bar.py | 7 ++++--- test/testing.py | 14 ++++++-------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/SVG/Bar.py b/lib/SVG/Bar.py index 02858f9..619033b 100644 --- a/lib/SVG/Bar.py +++ b/lib/SVG/Bar.py @@ -187,13 +187,14 @@ class VerticalBar( Bar ): scale_division = self.scale_divisions or ( scale_range / 10.0 ) if self.scale_integers: - scale_division = scale_division.round() or 1 + scale_division = round(scale_division) or 1 return min_value, max_value, scale_division # adapted from Plot def get_data_values( self ): - return tuple( float_range( *self.data_range( ) ) ) + min_value, max_value, scale_division = self.data_range() + return tuple( float_range( min_value, max_value + scale_division, scale_division ) ) # adapted from Plot def get_y_labels( self ): @@ -238,7 +239,7 @@ class VerticalBar( Bar ): # top is 0 if value is negative top = bottom - (( max(value,0) - min_value ) * unit_size ) if self.stack == 'side': - left += self.bar_width * dataset_count + left += bar_width * dataset_count rect = self._create_element( 'rect', { 'x': str(left), diff --git a/test/testing.py b/test/testing.py index aae6c71..c74d24c 100644 --- a/test/testing.py +++ b/test/testing.py @@ -28,11 +28,6 @@ g.max_y_value = 200 g.add_data( { 'data': [ '2005-12-21T00:00:00', 20, '2005-12-22T00:00:00', 21 ], 'title': 'series 1' } ) res = g.burn() -print g.field_width -print g.font_size -print g.right_font -print g.right_align -print g.get_x_labels() f = open( r'TimeSeries.py.svg', 'w' ) f.write( res ) @@ -40,10 +35,13 @@ f.close() from SVG import Bar -g = Bar.VerticalBar(['foo','bar','baz']) +g = Bar.VerticalBar(['Internet', 'TV', 'Newspaper', 'Magazine', 'Radio']) -g.stack = False +g.stack = 'side' +g.scale_integers = True +g.width, g.height = 640,480 -g.add_data( { 'data': [ 1, 2, 3 ], 'title': 'series 1' } ) +g.add_data( { 'data': [ -2, 3, 1, 3, 1 ], 'title': 'Female' } ) +g.add_data( { 'data': [ 0, 2, 1, 5, 4 ], 'title': 'Male' } ) open( r'VerticalBar.svg', 'w' ).write( g.burn() )