Browse Source

Improved test scripts.

Fixed bug in Bar.py where coordinates weren't being calculated correctly.
pull/8/head
jaraco 17 years ago
parent
commit
375d985e88
  1. 2
      lib/SVG/Bar.py
  2. 23
      test/testing.py
  3. 74
      test/testing.rb

2
lib/SVG/Bar.py

@ -209,7 +209,7 @@ class VerticalBar( Bar ):
def draw_data( self ): def draw_data( self ):
min_value = self.data_min() min_value = self.data_min()
unit_size = (float(self.graph_height) - self.font_size*2*self.top_font) unit_size = (float(self.graph_height) - self.font_size*2*self.top_font)
unit_size /= ( self.data_max() - self.data_min() ) unit_size /= (max(self.get_data_values()) - min(self.get_data_values()) )
bar_gap = 0 bar_gap = 0
if self.bar_gap: if self.bar_gap:

23
test/testing.py

@ -35,13 +35,32 @@ f.close()
from SVG import Bar from SVG import Bar
g = Bar.VerticalBar(['Internet', 'TV', 'Newspaper', 'Magazine', 'Radio']) fields = ['Internet', 'TV', 'Newspaper', 'Magazine', 'Radio']
g = Bar.VerticalBar(fields)
g.stack = 'side' g.stack = 'side'
g.scale_integers = True g.scale_integers = True
g.width, g.height = 640,480 g.width, g.height = 640,480
g.graph_title = 'Question 7'
g.show_graph_title = True
g.add_data( { 'data': [ -2, 3, 1, 3, 1 ], 'title': 'Female' } ) g.add_data( { 'data': [ -2, 3, 1, 3, 1 ], 'title': 'Female' } )
g.add_data( { 'data': [ 0, 2, 1, 5, 4 ], 'title': 'Male' } ) g.add_data( { 'data': [ 0, 2, 1, 5, 4 ], 'title': 'Male' } )
open( r'VerticalBar.svg', 'w' ).write( g.burn() ) open(r'VerticalBar.py.svg', 'w').write(g.burn())
g = Bar.VerticalBar(fields)
options = dict(
scale_integers=True,
stack='side',
width=640,
height=480,
graph_title='Question 8',
show_graph_title=True,
no_css=False, )
g.__dict__.update(options)
g.add_data(dict(data=[2,22,98,143,82], title='intermediate'))
g.add_data(dict(data=[2,26,106,193,105], title='old'))
open('VerticalBarLarge.py.svg', 'w').write(g.burn())

74
test/testing.rb

@ -1,23 +1,22 @@
require 'SVG/Graph/Graph' require 'SVG/Graph/Graph'
require 'SVG/Graph/Plot' require 'SVG/Graph/Plot'
graph = SVG::Graph::Plot.new( { g = SVG::Graph::Plot.new( {
:min_x_value=>0, :min_x_value=>0,
:min_y_value=>0, :min_y_value=>0,
:area_fill=> true, :area_fill=> true,
:stagger_x_labels=>true, :stagger_x_labels=>true,
:stagger_y_labels=>true :stagger_y_labels=>true,
:show_x_guidelines=>true,
}) })
#data1 = [ 1,25, 2,30, 3,45 ] 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=>[ 0.5, 35, 1, 20, 3, 10.5], :title=>'series 3' } )
graph.add_data( { :data=>[ 1,25, 2,30, 3,45 ], :title=>'foo' } ) res = g.burn()
graph.add_data( { :data=>[ 1,30, 2, 31, 3, 40 ], :title=>'foo2' } )
res = graph.burn()
f = File.new( 'c:\ruby.svg', 'w' ) f = File.new( 'Plot.rb.svg', 'w' )
f.write( res ) f.write( res )
f.close() f.close()
@ -26,20 +25,53 @@ require 'SVG/Graph/TimeSeries'
g = SVG::Graph::TimeSeries.new( { g = SVG::Graph::TimeSeries.new( {
:timescale_divisions => '4 hours', :timescale_divisions => '4 hours',
:stagger_x_labels => true, :stagger_x_labels => true,
:x_label_format => '%d-%b', :x_label_format => '%d-%b %H:%M',
: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() res = g.burn()
print g.field_width
print "\n" f = File.new( 'TimeSeries.rb.svg', 'w' )
print g.inspect
print g.get_x_labels.length
print "\n"
print g.right_align
print "\n"
print g.get_x_labels
print "\n"
f = File.new( 'c:\timeseries.rb.svg', 'w' )
f.write( res ) f.write( res )
f.close() f.close()
require 'SVG/Graph/Bar'
fields = ['Internet', 'TV', 'Newspaper', 'Magazine', 'Radio']
g = SVG::Graph::Bar.new( {
:scale_integers=>true,
:stack=>:side,
:width=>640,
:height=>480,
:fields=>fields,
:graph_title=>'Question 7',
:show_graph_title=>true,
:no_css=>false
})
g.add_data({:data=>[-2,3,1,3,1], :title=>'Female'})
g.add_data({:data=>[0,2,1,5,4], :title=>'Male'})
f = File.new('VerticalBar.rb.svg', 'w')
f.write(g.burn())
f.close()
g = SVG::Graph::Bar.new({
:scale_integers=>true,
:stack=>:side,
:width=>640,
:height=>480,
:fields=>fields,
:graph_title=>'Question 8',
:show_graph_title=>true,
:no_css=>false,
})
g.add_data({:data=>[2,22,98,143,82], :title=>'intermediate'})
g.add_data({:data=>[2,26,106,193,105], :title=>'old'})
f = File.new('VerticalBarLarge.rb.svg', 'w')
f.write(g.burn())
f.close()
Loading…
Cancel
Save