svg-graph 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,6 +1,7 @@
1
- === 1.0.0 / 2009-08-01
1
+ === 1.0.1 / 2009-09-26
2
2
 
3
- * 1 major enhancement
3
+ * Work for Ruby version 1.8.6, 1.8.7 and 1.9
4
4
 
5
- * Birthday!
5
+ === 1.0.0 / 2009-08-01
6
6
 
7
+ * First version
data/README.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  = SVG::Graph
2
2
 
3
- Gem version of SVG::Graph, available on http://www.germane-software.com/software/SVG/SVG::Graph/
3
+ http://www.germane-software.com/software/SVG/SVG::Graph/
4
4
 
5
5
  == Author
6
6
 
@@ -11,8 +11,14 @@ This software is available under the Ruby license[LICENSE.txt]
11
11
 
12
12
  == DESCRIPTION:
13
13
 
14
+ Gem version of SVG:::Graph.
15
+
14
16
  SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar. SVG::Graph has a verry similar API to the Perl library SVG::TT::Graph, and the resulting charts also look the same. This isn't surprising, because SVG::Graph started as a loose port of SVG::TT::Graph, although the internal code no longer resembles the Perl original at all.
15
17
 
18
+ == FEATURES
19
+
20
+ * Tested for Ruby versions 1.8.6, 1.8.7 and 1.9.1
21
+
16
22
  == LICENSE:
17
23
 
18
24
  (The Ruby Licence)
data/Rakefile CHANGED
@@ -4,12 +4,12 @@ require 'rubygems'
4
4
  require 'hoe'
5
5
  $:.unshift("./lib")
6
6
  require 'svggraph'
7
- Hoe.spec 'svg-graph' do |p|
8
- p.version=SVG::Graph::VERSION
9
- p.developer('Sean Russell', 'ser_AT_germane-software.com')
10
- p.developer('Claudio Bustos', 'clbustos_AT_gmail.com')
11
- p.rubyforge_name = 'ruby-statsample' # if different than 'svg_graph'
12
- p.remote_rdoc_dir = 'svg-graph'
7
+ Hoe.spec 'svg-graph' do
8
+ self.version=SVG::Graph::VERSION
9
+ self.developer('Sean Russell', 'ser_AT_germane-software.com')
10
+ self.developer('Claudio Bustos', 'clbustos_AT_gmail.com')
11
+ self.rubyforge_name = 'ruby-statsample' # if different than 'svg_graph'
12
+ self.remote_rdoc_dir = 'svg-graph'
13
13
  end
14
14
 
15
15
  # vim: syntax=ruby
@@ -17,34 +17,32 @@ module SVG
17
17
  #
18
18
  class BarBase < SVG::Graph::Graph
19
19
  # Ensures that :fields are provided in the configuration.
20
- def initialize config
21
- raise "fields was not supplied or is empty" unless config[:fields] &&
22
- config[:fields].kind_of?(Array) &&
23
- config[:fields].length > 0
24
- super
25
- end
26
-
27
- # In addition to the defaults set in Graph::initialize, sets
28
- # [bar_gap] true
29
- # [stack] :overlap
30
- def set_defaults
31
- init_with( :bar_gap => true, :stack => :overlap )
32
- end
33
-
34
- # Whether to have a gap between the bars or not, default
35
- # is true, set to false if you don't want gaps.
36
- attr_accessor :bar_gap
37
- # How to stack data sets. :overlap overlaps bars with
38
- # transparent colors, :top stacks bars on top of one another,
39
- # :side stacks the bars side-by-side. Defaults to :overlap.
40
- attr_accessor :stack
41
-
20
+ def initialize config
21
+ raise "fields was not supplied or is empty" unless config[:fields] &&
22
+ config[:fields].kind_of?(Array) &&
23
+ config[:fields].length > 0
24
+ super
25
+ end
42
26
 
43
- protected
27
+ # In addition to the defaults set in Graph::initialize, sets
28
+ # [bar_gap] true
29
+ # [stack] :overlap
30
+ def set_defaults
31
+ init_with( :bar_gap => true, :stack => :overlap )
32
+ end
44
33
 
45
- def max_value
34
+ # Whether to have a gap between the bars or not, default
35
+ # is true, set to false if you don't want gaps.
36
+ attr_accessor :bar_gap
37
+ # How to stack data sets. :overlap overlaps bars with
38
+ # transparent colors, :top stacks bars on top of one another,
39
+ # :side stacks the bars side-by-side. Defaults to :overlap.
40
+ attr_accessor :stack
41
+ protected
42
+
43
+ def max_value
46
44
  @data.collect{|x| x[:data].max}.max
47
- end
45
+ end
48
46
 
49
47
  def min_value
50
48
  min = 0
@@ -99,7 +99,7 @@ module SVG
99
99
  # [add_popups] false
100
100
  def initialize( config )
101
101
  @config = config
102
-
102
+ @data = nil
103
103
  self.top_align = self.top_font = self.right_align = self.right_font = 0
104
104
 
105
105
  init_with({
@@ -148,9 +148,7 @@ module SVG
148
148
  :no_css =>false,
149
149
  :add_popups =>false,
150
150
  })
151
-
152
- set_defaults if methods.include? "set_defaults"
153
-
151
+ set_defaults if self.respond_to? :set_defaults
154
152
  init_with config
155
153
  end
156
154
 
@@ -165,7 +163,7 @@ module SVG
165
163
  # :title => 'Sales 2002'
166
164
  # })
167
165
  def add_data conf
168
- @data = [] unless defined? @data
166
+ @data = [] unless (defined? @data and !@data.nil?)
169
167
 
170
168
  if conf[:data] and conf[:data].kind_of? Array
171
169
  @data << conf
@@ -354,7 +352,7 @@ module SVG
354
352
  # by subclasses.
355
353
  def init_with config
356
354
  config.each { |key, value|
357
- self.send( key.to_s+"=", value ) if methods.include? key.to_s
355
+ self.send( key.to_s+"=", value ) if self.respond_to? key
358
356
  }
359
357
  end
360
358
 
@@ -78,55 +78,55 @@ module SVG
78
78
  # Fill in the area under the plot if true
79
79
  attr_accessor :area_fill
80
80
 
81
- # The constructor takes a hash reference, fields (the names for each
82
- # field on the X axis) MUST be set, all other values are defaulted to
83
- # those shown above - with the exception of style_sheet which defaults
84
- # to using the internal style sheet.
85
- def initialize config
86
- raise "fields was not supplied or is empty" unless config[:fields] &&
87
- config[:fields].kind_of?(Array) &&
88
- config[:fields].length > 0
89
- super
90
- end
81
+ # The constructor takes a hash reference, fields (the names for each
82
+ # field on the X axis) MUST be set, all other values are defaulted to
83
+ # those shown above - with the exception of style_sheet which defaults
84
+ # to using the internal style sheet.
85
+ def initialize config
86
+ raise "fields was not supplied or is empty" unless config[:fields] &&
87
+ config[:fields].kind_of?(Array) &&
88
+ config[:fields].length > 0
89
+ super
90
+ end
91
91
 
92
92
  # In addition to the defaults set in Graph::initialize, sets
93
93
  # [show_data_points] true
94
94
  # [show_data_values] true
95
95
  # [stacked] false
96
96
  # [area_fill] false
97
- def set_defaults
97
+ def set_defaults
98
98
  init_with(
99
- :show_data_points => true,
100
- :show_data_values => true,
101
- :stacked => false,
102
- :area_fill => false
99
+ :show_data_points => true,
100
+ :show_data_values => true,
101
+ :stacked => false,
102
+ :area_fill => false
103
103
  )
104
-
104
+
105
105
  self.top_align = self.top_font = self.right_align = self.right_font = 1
106
- end
106
+ end
107
107
 
108
108
  protected
109
109
 
110
- def max_value
111
- max = 0
112
-
113
- if (stacked == true) then
114
- sums = Array.new(@config[:fields].length).fill(0)
115
-
116
- @data.each do |data|
117
- sums.each_index do |i|
118
- sums[i] += data[:data][i].to_f
110
+ def max_value
111
+ max = 0
112
+
113
+ if (stacked == true) then
114
+ sums = Array.new(@config[:fields].length).fill(0)
115
+
116
+ @data.each do |data|
117
+ sums.each_index do |i|
118
+ sums[i] += data[:data][i].to_f
119
+ end
120
+ end
121
+
122
+ max = sums.max
123
+ else
124
+ max = @data.collect{|x| x[:data].max}.max
119
125
  end
120
- end
121
-
122
- max = sums.max
123
- else
124
- max = @data.collect{|x| x[:data].max}.max
126
+
127
+ return max
125
128
  end
126
129
 
127
- return max
128
- end
129
-
130
130
  def min_value
131
131
  min = 0
132
132
 
data/lib/svggraph.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module SVG
2
2
  module Graph
3
- VERSION = '1.0.0'
3
+ VERSION = '1.0.1'
4
4
  ORIGINAL_VERSION='0.6.1'
5
5
  autoload(:Bar, 'SVG/Graph/Bar')
6
6
  autoload(:BarBase, 'SVG/Graph/BarBase')
@@ -2,54 +2,54 @@ require "test/unit"
2
2
  require "svggraph"
3
3
 
4
4
  class TestSvgGraph < Test::Unit::TestCase
5
- def test_bar_line_and_pie
6
- fields = %w(Jan Feb Mar);
7
- data_sales_02 = [12, 45, 21]
8
- [SVG::Graph::Bar, SVG::Graph::BarHorizontal, SVG::Graph::Line, SVG::Graph::Pie].each do
9
- |klass|
10
- graph = klass.new(
11
- :height => 500,
12
- :width => 300,
13
- :fields => fields
14
- )
15
- graph.add_data(
16
- :data => data_sales_02,
17
- :title => 'Sales 2002'
18
- )
19
- out=graph.burn
20
- assert(out=~/Created with SVG::Graph/)
21
- end
22
- end
23
- def test_plot
24
-
25
- projection = [
5
+ def test_bar_line_and_pie
6
+ fields = %w(Jan Feb Mar);
7
+ data_sales_02 = [12, 45, 21]
8
+ [SVG::Graph::Bar, SVG::Graph::BarHorizontal, SVG::Graph::Line, SVG::Graph::Pie].each do
9
+ |klass|
10
+ graph = klass.new(
11
+ :height => 500,
12
+ :width => 300,
13
+ :fields => fields
14
+ )
15
+ graph.add_data(
16
+ :data => data_sales_02,
17
+ :title => 'Sales 2002'
18
+ )
19
+ out=graph.burn
20
+ assert(out=~/Created with SVG::Graph/)
21
+ end
22
+ end
23
+ def test_plot
24
+
25
+ projection = [
26
26
  6, 11, 0, 5, 18, 7, 1, 11, 13, 9, 1, 2, 19, 0, 3, 13,
27
27
  7, 9
28
- ]
29
- actual = [
28
+ ]
29
+ actual = [
30
30
  0, 18, 8, 15, 9, 4, 18, 14, 10, 2, 11, 6, 14, 12,
31
31
  15, 6, 4, 17, 2, 12
32
- ]
33
-
34
- graph = SVG::Graph::Plot.new({
35
- :height => 500,
36
- :width => 300,
32
+ ]
33
+
34
+ graph = SVG::Graph::Plot.new({
35
+ :height => 500,
36
+ :width => 300,
37
37
  :key => true,
38
38
  :scale_x_integers => true,
39
39
  :scale_y_integerrs => true,
40
- })
41
-
42
- graph.add_data({
43
- :data => projection,
44
- :title => 'Projected',
45
- })
46
-
47
- graph.add_data({
48
- :data => actual,
49
- :title => 'Actual',
50
- })
51
-
52
- out=graph.burn()
53
- assert(out=~/Created with SVG::Graph/)
54
- end
40
+ })
41
+
42
+ graph.add_data({
43
+ :data => projection,
44
+ :title => 'Projected',
45
+ })
46
+
47
+ graph.add_data({
48
+ :data => actual,
49
+ :title => 'Actual',
50
+ })
51
+
52
+ out=graph.burn()
53
+ assert(out=~/Created with SVG::Graph/)
54
+ end
55
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svg-graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Russell
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2009-08-01 00:00:00 -04:00
13
+ date: 2009-09-26 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -21,9 +21,12 @@ dependencies:
21
21
  requirements:
22
22
  - - ">="
23
23
  - !ruby/object:Gem::Version
24
- version: 2.3.2
24
+ version: 2.3.3
25
25
  version:
26
- description: SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar. SVG::Graph has a verry similar API to the Perl library SVG::TT::Graph, and the resulting charts also look the same. This isn't surprising, because SVG::Graph started as a loose port of SVG::TT::Graph, although the internal code no longer resembles the Perl original at all.
26
+ description: |-
27
+ Gem version of SVG:::Graph.
28
+
29
+ SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar. SVG::Graph has a verry similar API to the Perl library SVG::TT::Graph, and the resulting charts also look the same. This isn't surprising, because SVG::Graph started as a loose port of SVG::TT::Graph, although the internal code no longer resembles the Perl original at all.
27
30
  email:
28
31
  - ser_AT_germane-software.com
29
32
  - clbustos_AT_gmail.com
@@ -56,7 +59,9 @@ files:
56
59
  - lib/SVG/Graph/TimeSeries.rb
57
60
  - test/test_svg_graph.rb
58
61
  has_rdoc: true
59
- homepage: Gem version of SVG::Graph, available on http://www.germane-software.com/software/SVG/SVG::Graph/
62
+ homepage: http://www.germane-software.com/software/SVG/SVG::Graph/
63
+ licenses: []
64
+
60
65
  post_install_message:
61
66
  rdoc_options:
62
67
  - --main
@@ -78,9 +83,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
78
83
  requirements: []
79
84
 
80
85
  rubyforge_project: ruby-statsample
81
- rubygems_version: 1.3.1
86
+ rubygems_version: 1.3.5
82
87
  signing_key:
83
- specification_version: 2
84
- summary: SVG:::Graph is a pure Ruby library for generating charts, which are a type of graph where the values of one axis are not scalar
88
+ specification_version: 3
89
+ summary: Gem version of SVG:::Graph
85
90
  test_files:
86
91
  - test/test_svg_graph.rb