diff --git a/lib/SVG/__init__.py b/lib/SVG/__init__.py index 02e702c..7173e76 100644 --- a/lib/SVG/__init__.py +++ b/lib/SVG/__init__.py @@ -1,3 +1,4 @@ +#!python # -*- coding: UTF-8 -*- __all__ = ( 'Plot', 'TimeSeries' ) @@ -66,7 +67,7 @@ Stephen Morgan for creating the TT template and SVG. Jason R. Coombs -Copyright 2005 Sandia National Laboratories +Copyright © 2008 Jason R. Coombs """ width= 500 height= 300 @@ -78,42 +79,43 @@ Copyright 2005 Sandia National Laboratories stagger_x_labels= False rotate_x_labels= False step_x_labels= 1 - step_include_first_x_label= True + step_include_first_x_label= True show_y_labels= True - rotate_y_labels= False - stagger_y_labels= False + rotate_y_labels= False + stagger_y_labels= False step_include_first_y_label= True - step_y_labels= 1 - scale_integers= False - show_x_title= False - x_title= 'X Field names' - show_y_title= False - y_title_text_direction= 'bt' # 'bt' for bottom to top; 'tb' for top to bottom - y_title= 'Y Scale' - show_graph_title= False - graph_title= 'Graph Title' - show_graph_subtitle= False - graph_subtitle= 'Graph Subtitle' - key= True - key_position= 'right' # 'bottom' or 'right', + step_y_labels= 1 + scale_integers= False + show_x_title= False + x_title= 'X Field names' + show_y_title= False + y_title_text_direction= 'bt' # 'bt' for bottom to top; 'tb' for top to bottom + y_title= 'Y Scale' + show_graph_title= False + graph_title= 'Graph Title' + show_graph_subtitle= False + graph_subtitle= 'Graph Subtitle' + key= True + key_position= 'right' # 'bottom' or 'right', - font_size= 12 - title_font_size= 16 - subtitle_font_size= 14 - x_label_font_size= 12 - x_title_font_size= 14 - y_label_font_size= 12 - y_title_font_size= 14 - key_font_size= 10 + font_size= 12 + title_font_size= 16 + subtitle_font_size= 14 + x_label_font_size= 12 + x_title_font_size= 14 + y_label_font_size= 12 + y_title_font_size= 14 + key_font_size= 10 - no_css= False - add_popups= False + no_css= False + add_popups= False top_align = top_font = right_align = right_font = 0 def __init__( self, config = {} ): - """Initialize the graph object with the graph settings. You won't - instantiate this class directly; see the subclass for options.""" + """Initialize the graph object with the graph settings.""" + if self.__class__ is Graph: + raise NotImplementedError, "Graph is an abstract base class" self.load_config( config ) self.clear_data() @@ -476,26 +478,26 @@ Copyright 2005 Sandia National Laboratories def draw_graph_subtitle( self ): raise NotImplementedError - def draw_x_title( self ): - raise NotImplementedError - - def draw_y_title( self ): - x = self.y_title_font_size - if self.y_title_text_direction=='bt': - x += 3 - rotate = -90 - else: - x -= 3 - rotate = 90 - y = self.height / 2 - text = self._create_element( 'text', { - 'x': str( x ), - 'y': str( y ), - 'class': 'yAxisTitle', - } ) - text.appendChild( self._doc.createTextNode( self.y_title ) ) - text.setAttribute( 'transform', 'rotate( %(rotate)d, %(x)s, %(y)s )' % vars() ) - self.root.appendChild( text ) + def draw_x_title( self ): + raise NotImplementedError + + def draw_y_title( self ): + x = self.y_title_font_size + if self.y_title_text_direction=='bt': + x += 3 + rotate = -90 + else: + x -= 3 + rotate = 90 + y = self.height / 2 + text = self._create_element( 'text', { + 'x': str( x ), + 'y': str( y ), + 'class': 'yAxisTitle', + } ) + text.appendChild( self._doc.createTextNode( self.y_title ) ) + text.setAttribute( 'transform', 'rotate( %(rotate)d, %(x)s, %(y)s )' % vars() ) + self.root.appendChild( text ) def keys( self ): return map( itemgetter( 'title' ), self.data ) @@ -563,7 +565,6 @@ Copyright 2005 Sandia National Laboratories def start_svg( self ): "Base SVG Document Creation" impl = dom.getDOMImplementation() - #dt = impl.createDocumentType( 'svg', 'PUBLIC' self._doc = impl.createDocument( None, 'svg', None ) self.root = self._doc.documentElement if hasattr( self, 'style_sheet' ): diff --git a/test/testing.py b/test/testing.py index 29728e0..052d38f 100644 --- a/test/testing.py +++ b/test/testing.py @@ -1,9 +1,5 @@ import sys, os -#sys.path.insert( 0, 'c:\documents and settings\jaraco\my documents\projects\jaraco' ) -import SVG from SVG import Plot -reload( SVG ) -reload( Plot ) g = Plot.Plot( { 'min_x_value': 0, 'min_y_value': 0, @@ -12,25 +8,24 @@ g = Plot.Plot( { 'stagger_y_labels': True, 'show_x_guidelines': True }) -g.add_data( { 'data': [ 1, 25, 2, 30, 3, 45 ], 'title': 'foo' } ) -g.add_data( { 'data': [ 1,30, 2, 31, 3, 40 ], 'title': 'foo2' } ) -g.add_data( { 'data': [ .5,35, 1, 20, 3, 10.5 ], 'title': 'foo2' } ) +g.add_data( { 'data': [ 1, 25, 2, 30, 3, 45 ], 'title': 'series 1' } ) +g.add_data( { 'data': [ 1,30, 2, 31, 3, 40 ], 'title': 'series 2' } ) +g.add_data( { 'data': [ .5,35, 1, 20, 3, 10.5 ], 'title': 'series 3' } ) res = g.burn() -f = open( r'c:\sample.svg', 'w' ) +f = open( r'Plot.py.svg', 'w' ) f.write( res ) f.close() from SVG import TimeSeries -reload( TimeSeries ) g = TimeSeries.Plot( { } ) g.timescale_divisions = '4 hours' g.stagger_x_labels = True -g.x_label_format = '%d-%b' -#g.max_y_value = 200 +g.x_label_format = '%d-%b %H:%M' +g.max_y_value = 200 -g.add_data( { 'data': [ '2005-12-21T00:00:00', 20, '2005-12-22T00:00:00', 21 ], 'title': 'foo' } ) +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 @@ -39,6 +34,6 @@ print g.right_font print g.right_align print g.get_x_labels() -f = open( r'c:\timeseries.py.svg', 'w' ) +f = open( r'TimeSeries.py.svg', 'w' ) f.write( res ) f.close()