ruport-util 0.9.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -33,7 +33,7 @@ end
33
33
 
34
34
  spec = Gem::Specification.new do |spec|
35
35
  spec.name = "ruport-util"
36
- spec.version = "0.9.0"
36
+ spec.version = "0.10.0"
37
37
  spec.platform = Gem::Platform::RUBY
38
38
  spec.summary = "A set of tools and helper libs for Ruby Reports"
39
39
  spec.files = Dir.glob("{example,lib,test,bin}/**/**/*") +
@@ -48,7 +48,7 @@ spec = Gem::Specification.new do |spec|
48
48
  spec.extra_rdoc_files = %w{INSTALL}
49
49
  spec.rdoc_options << '--title' << 'ruport-util Documentation' <<
50
50
  '--main' << 'INSTALL' << '-q'
51
- spec.add_dependency('ruport', ">=1.2.2")
51
+ spec.add_dependency('ruport', ">=1.2.3")
52
52
  spec.add_dependency('mailfactory',">=1.2.3")
53
53
  spec.add_dependency('rubyzip','>=0.9.1')
54
54
  spec.author = "Gregory Brown"
@@ -0,0 +1,307 @@
1
+ class OpenFlashChart
2
+ def initialize
3
+ @data = []
4
+ @x_labels = []
5
+ @y_min = 0
6
+ @y_max = 20
7
+ @y_label_steps = 5
8
+ @title = ""
9
+ @title_style = ""
10
+ @title_size = 30
11
+ @x_tick_size = -1
12
+ @y2_max = ''
13
+ @y2_min = ''
14
+
15
+ # GRID styles
16
+ @y_axis_color = @x_axis_color = @x_grid_color = @y_grid_color = ""
17
+ @x_axis_3d = ''
18
+ @x_axis_steps = -1
19
+ @y2_axis_color = ''
20
+
21
+ # AXIS LABEL styles
22
+ @x_label_style = ''
23
+ @y_label_style = ''
24
+ @y_label_style_right = ''
25
+
26
+ # AXIS LEGEND styles
27
+ @x_legend = ''
28
+ @y_legend = ''
29
+ @y_legend_right = ''
30
+
31
+ @lines = []
32
+ @y2_lines = []
33
+ @line_default = "&line=3,#87421F" + "& \n"
34
+
35
+ @bg_color = ''
36
+ @bg_image = ''
37
+
38
+ @inner_bg_color = ''
39
+ @inner_bg_color_2 = ''
40
+ @inner_bg_angle = ''
41
+
42
+ # PIE chart
43
+ @pie = ''
44
+ @pie_values = ''
45
+ @pie_colors = ''
46
+ @pie_labels = ''
47
+
48
+ @tool_tip = ''
49
+ end
50
+
51
+ def set_data(data)
52
+ if @data.size == 0
53
+ @data << '&values=' + data.join(',') + "& \n"
54
+ else
55
+ @data << '&values_' + (@data.size + 1).to_s + "=" + data.join(',') + "& \n"
56
+ end
57
+ end
58
+
59
+ # create the set methods for these instance variables in a loop since they are all the same
60
+ %w(tool_tip x_labels bg_color y_max y_min y_label_steps x_tick_size x_axis_steps x_axis_3d).each do |method|
61
+ define_method("set_#{method}") do |a|
62
+ self.instance_variable_set("@#{method}", a)
63
+ end
64
+ end
65
+
66
+ def set_x_label_style(size, color='', orientation=0, step=-1, grid_color='')
67
+ @x_label_style = "&x_label_style=#{size}"
68
+ @x_label_style << ",#{color}" if color.size > 0
69
+ @x_label_style += ",#{orientation}" if orientation > -1
70
+ @x_label_style += ",#{step}" if step > 0
71
+ @x_label_style += ",#{grid_color}" if grid_color.size > 0
72
+
73
+ end
74
+
75
+ def set_bg_image(url, x='center', y='center')
76
+ @bg_image = url
77
+ @bg_image_x = x
78
+ @bg_image_y = y
79
+ end
80
+
81
+ def attach_to_y_right_axis(data_number)
82
+ @y2_lines << data_number
83
+ end
84
+
85
+ def set_inner_background(col, col2='', angle=-1)
86
+ @inner_bg_color = col
87
+ @inner_bg_color2 = col2 if col2.size > 0
88
+ @inner_bg_angle = angle if angle != -1
89
+ end
90
+
91
+ %w(y_label_style y_right_label_style).each do |method|
92
+ define_method("set_#{method}") do |size, color|
93
+ color ||= ''
94
+ temp = "&#{method}=" + size.to_s
95
+ temp += "," + color if color.size > 0
96
+ temp += "& \n"
97
+ self.instance_variable_set("@#{method}", temp)
98
+ end
99
+ end
100
+
101
+ %w(max min).each do |m|
102
+ define_method("set_y_right_#{m}") do |x|
103
+ temp = "&y2_#{m}=#{x}& \n"
104
+ self.instance_variable_set("@y2_#{m}", temp)
105
+ end
106
+ end
107
+
108
+ def title(title, style='')
109
+ @title = title
110
+ @title_style = style if style.size > 0
111
+ end
112
+
113
+ %w(x_legend y_legend y_right_legend).each do |method|
114
+ define_method("set_" + method) do |text, size, color|
115
+ size ||= -1
116
+ color ||= ''
117
+ # next three lines will only be needed if defining y_rigth_legend
118
+ method = "y_legend_right" if method =~ /right/
119
+ label = method
120
+ label = "y2_legend" if method =~ /right/
121
+ self.instance_variable_set("@#{method}", "&#{label}=#{text}")
122
+ self.instance_variable_set("@#{method}" + "_size", size) if size > 0
123
+ self.instance_variable_set("@#{method}" + "_color", color) if color.size > 0
124
+ end
125
+ end
126
+
127
+ def line(width, color='', text='', size=-1, circles=-1)
128
+ temp = '&line'
129
+ temp += '_' + (@lines.size + 1).to_s if @lines.size > 0
130
+ temp += '='
131
+ temp += width.to_s if width > 0
132
+ temp += ',' + color if width > 0
133
+ temp += ',' + text if text.size > 0
134
+ temp += ',' + size.to_s if text.size > 0
135
+ temp += ',' + circles.to_s if circles > 0
136
+ temp += "& \n"
137
+
138
+ @lines << temp
139
+ end
140
+
141
+ %w(line_dot line_hollow).each do |method|
142
+ define_method(method) do |width, dot_size, color, text, font_size|
143
+ text ||= ''
144
+ font_size ||= ''
145
+ temp = "&#{method}"
146
+ temp += '_' + (@lines.size + 1).to_s if @lines.size > 0
147
+ temp += "=#{width},#{color},#{text}"
148
+ temp += ",#{font_size},#{dot_size}" if font_size.size > 0
149
+ temp += "& \n"
150
+
151
+ @lines << temp
152
+ end
153
+ end
154
+
155
+ def area_hollow(width, dot_size, color, alpha, text='', font_size='')
156
+ temp = "&area_hollow"
157
+ temp += '_' + (@lines.size + 1).to_s if @lines.size > 0
158
+ temp += "=#{width},#{dot_size},#{color},#{alpha}"
159
+ temp += ",#{text},#{font_size}" if text.size > 0
160
+ temp += "& \n"
161
+
162
+ @lines << temp
163
+ end
164
+
165
+
166
+ %w(bar bar_3d bar_fade).each do |method|
167
+ define_method(method) do |alpha, color, text, size|
168
+ text ||= ""
169
+ size ||= -1
170
+ temp = "&#{method}"
171
+ temp += "_" + (@lines.size + 1).to_s if @lines.size > 0
172
+ temp += "="
173
+ temp += "#{alpha},#{color},#{text},#{size}"
174
+ temp += "& \n"
175
+
176
+ @lines << temp
177
+ end
178
+ end
179
+
180
+ %w(bar_glass bar_filled).each do |method|
181
+ define_method(method) do |alpha, color, color_outline, text, size|
182
+ text ||= ""
183
+ size ||= -1
184
+ method = "filled_bar" if method == "bar_filled"
185
+ temp = "&#{method}"
186
+ temp += "_" + (@lines.size + 1).to_s if @lines.size > 0
187
+ temp += "="
188
+ temp += "#{alpha},#{color},#{color_outline},#{text},#{size}"
189
+ temp += "& \n"
190
+ @lines << temp
191
+
192
+ end
193
+ end
194
+
195
+ %w(x y).each do |method|
196
+ define_method(method + "_axis_color") do |axis, grid|
197
+ grid ||= ''
198
+ self.instance_variable_set("@#{method}_axis_color", axis)
199
+ self.instance_variable_set("@#{method}_grid_color", grid)
200
+ end
201
+ end
202
+
203
+ def pie(alpha, line_color, label_color)
204
+ @pie = "#{alpha},#{line_color},#{label_color}"
205
+ end
206
+
207
+ def pie_values(values, labels)
208
+ @pie_values = values.join(',')
209
+ @pie_labels = labels.join(',')
210
+ end
211
+
212
+ def pie_slice_colors(colors)
213
+ @pie_colors = colors.join(",")
214
+ end
215
+
216
+ def render
217
+ temp = ""
218
+
219
+ {"title" => [@title, @title_style],
220
+ "x_legend" => [@x_legend, @x_legend_size, @x_legend_color],
221
+ "x_ticks" => [@x_tick_size],
222
+ "x_axis_steps" => [@x_axis_steps, @x_axis_3d],
223
+ "bg_colour" => [@bg_color],
224
+ "tool_tip" => [@tool_tip]
225
+ }.each do |k,v|
226
+ next if (v[0].class == String ? v[0].size <= 0 : v[0] && v[0] < 0)
227
+ temp += "&#{k}="
228
+ # added compact to remove nil values from the array
229
+ temp += v.compact.join(",")
230
+ temp += "& \n"
231
+ end
232
+
233
+ temp += @x_label_style if @x_label_style.size > 0
234
+
235
+ %w(y_legend y_legend_right).each do |x|
236
+ temp += self.instance_variable_get("@#{x}")
237
+ temp += "," + self.instance_variable_get("@#{x}_size").to_s if
238
+ self.instance_variable_get("@#{x}_size")
239
+ temp += "," + self.instance_variable_get("@#{x}_color") if
240
+ self.instance_variable_get("@#{x}_color")
241
+
242
+ end
243
+
244
+ temp += "&y_ticks=5,10," + "#{@y_label_steps}& \n"
245
+
246
+ if @lines.size == 0
247
+ temp += @line_default
248
+ else
249
+ temp += @lines.to_s
250
+ end
251
+
252
+ temp += @data.to_s
253
+
254
+ if @y2_lines.size > 0
255
+ temp += "&y2_lines="
256
+ temp += @y2_lines.join(",")
257
+ temp += "& \n"
258
+ temp += "&show_y2=true& \n"
259
+ end
260
+
261
+ temp += "&x_labels=#{@x_labels.join(',')}& \n" if @x_labels.size > 0
262
+
263
+ temp += "&y_min=#{@y_min}& \n"
264
+ temp += "&y_max=#{@y_max}& \n"
265
+
266
+ if @bg_image.size > 0
267
+ temp += "&bg_image=#{@bg_image}& \n"
268
+ temp += "&bg_image_x=#{@bg_image_x}& \n"
269
+ temp += "&bg_image_y=#{@bg_image_y}& \n"
270
+ end
271
+
272
+ %w(x y).each do |axis|
273
+ if self.instance_variable_get("@#{axis}_axis_color").size > 0
274
+ temp += "&#{axis}_axis_colour=#{self.instance_variable_get("@#{axis}_axis_color")}& \n"
275
+ temp += "&#{axis}_grid_colour=#{self.instance_variable_get("@#{axis}_grid_color")}& \n"
276
+ temp += "&#{axis}2_axis_colour=#{self.instance_variable_get("@#{axis}2_axis_color")}& \n" if axis == 'y'
277
+ end
278
+ end
279
+ if @inner_bg_color.size > 0
280
+ temp += "&inner_background=#{@inner_bg_color}"
281
+ if @inner_bg_color_2.size > 0
282
+ temp += "," + @inner_bg_color_2
283
+ temp += "," + @inner_bg_angle
284
+ end
285
+ temp += "& \n"
286
+ end
287
+
288
+ if @pie.size > 0
289
+ temp += "&pie=#{@pie}& \n"
290
+ temp += "&values=#{@pie_values}& \n"
291
+ temp += "&pie_labels=#{@pie_labels}& \n"
292
+ temp += "&colours=#{@pie_colors}& \n"
293
+ end
294
+
295
+ return temp
296
+ end
297
+
298
+ def self.swf_object(width, height, url)
299
+ url = CGI::escape(url)
300
+ output = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\" width=\"#{width}\" height=\"#{height}\" id=\"graph\" align=\"middle\">"
301
+ output += '<param name="allowScriptAccess" value="sameDomain" />'
302
+ output += "<param name=\"movie\" value=\"/open-flash-chart.swf?width=#{width.to_s} &height=#{height.to_s} &data=#{url}\" /><param name=\"quality\" value=\"high\" /><param name=\"bgcolor\" value=\"#FFFFFF\" />"
303
+ output += '<embed src="/open-flash-chart.swf?width=' + width.to_s + '&height=' + height.to_s + '&data=' + url.to_s + '" quality="high" bgcolor="#FFFFFF" width="' + width.to_s + '" height="' + height.to_s + '" name="open-flash-chart" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
304
+ output += '</object>'
305
+ return output
306
+ end
307
+ end
@@ -1,6 +1,6 @@
1
1
  module Ruport
2
2
  module Util
3
- VERSION = "0.9.0"
3
+ VERSION = "0.10.0"
4
4
 
5
5
  file = __FILE__
6
6
  file = File.readlink(file) if File.symlink?(file)
@@ -1,11 +1,12 @@
1
- require "rubygems"
2
- require "hpricot"
3
-
4
1
  class Ruport::Formatter
5
2
  module Graph
6
3
  class Amline < Ruport::Formatter
7
4
  renders :amline, :for => Ruport::Renderer::Graph
8
5
 
6
+ def initialize
7
+ Ruport.quiet { require "hpricot" }
8
+ end
9
+
9
10
  def build_graph
10
11
  generate_config_file
11
12
  data_out << "<chart>"
@@ -0,0 +1,191 @@
1
+ # o_f_c.rb
2
+ # Generalized graphing support for Ruby Reports with Open Flash Chart
3
+ #
4
+ # This class used :
5
+ # - Open Flash Chart (http://teethgrinder.co.uk/open-flash-chart/) is Licensed by GPL (http://www.gnu.org/copyleft/gpl.html)
6
+ # - Open Flash Chart for Rails (http://pullmonkey.com/projects/open_flash_chart/) is licensed by MIT (http://www.opensource.org/licenses/mit-license.php)
7
+ # This is free software. See LICENSE and COPYING for details.
8
+ #
9
+ class Ruport::Formatter
10
+ module Graph
11
+ # This class implements the open flash chart engine for Ruport.
12
+ #
13
+ # Depend of the OpenFlashChart plugin
14
+ # == Options
15
+ #
16
+ # * title #=> Title of the Graph
17
+ # * title_style #=> Style of the title
18
+ # * bg_color #=> '#DFFFDF'
19
+ # * y_label_steps #=>
20
+ # * x_tick_size #=>
21
+ # * tool_tips #=>
22
+ # * x_axis_3d #=>
23
+ # * y_right_min #=>
24
+ # * y_right_max #=>
25
+ # * attach_to_y_right_axis #=>
26
+ # * x_labels #=>
27
+ # * y_max #=>
28
+ # * y_min #=>
29
+ # * x_axis_steps #=> 3
30
+ # X Label Style :
31
+ # * label_style #=>
32
+ # * x_label_color #=> ''
33
+ # * x_orientation #=> 0
34
+ # * x_label_step #=> -1
35
+ # * x_label_grid_color #=> ''
36
+ # X Legend Text :
37
+ # * x_legend_text #=>
38
+ # * x_legend_size #=> -1
39
+ # * x_legend_color #=> ''
40
+ # X Legend Text :
41
+ # * y_legend_text #=>
42
+ # * y_legend_size #=> -1
43
+ # * y_legend_color #=> ''
44
+ # Y Label Style :
45
+ # * y_label_size #=>
46
+ # * y_label_color #=> ''
47
+ # X Label Style :
48
+ # * x_label_size #=>
49
+ # * x_label_color #=> ''
50
+ # * x_label_orientation #=> 0
51
+ # * x_label_step #=> -1
52
+ # * x_label_grid_color #=> ''
53
+ # Y Right Label Style :
54
+ # * y_right_label_size #=>
55
+ # * y_right_label_color #=> ''
56
+ # Y Right Legend Text :
57
+ # * y_right_legend_text #=>
58
+ # * y_right_legend_size #=> -1
59
+ # * y_right_legend_color #=> ''
60
+ # Background Image :
61
+ # * bg_image #=>
62
+ # * bg_image_x #=> 'center'
63
+ # * bg_image_y #=> 'center'
64
+ # Inner background Color
65
+ # * inner_bg_color #=>
66
+ # * inner_bg_color2 #=> ''
67
+ # * inner_bg_angle #=> -1
68
+ #
69
+ # Chart Type :
70
+ # * chart_type : Table of table, with the first cell, the type of the chart, and the other cells parameters
71
+ # * line => (width, color='', text='', size=-1, circles=-1)
72
+ # * line_dot => (width, dot_size, color, text='', font_size=-1)
73
+ # * line hollow => (width, dot_size, color, text='', font_size=-1)
74
+ # * bar => (alpha, color, text='', font_size=-1)
75
+ # * bar_3d => (alpha, color, text='', font_size=-1)
76
+ # * bar_fade => (alpha, color, text='', font_size=-1)
77
+ # * bar_glass => (alpha, color, color_outline, text='', font_size=-1)
78
+ # * bar_filled => (alpha, color, color_outline, text='', font_size=-1)
79
+ # * area_hollow => (width, dot_size, color, alpha, text='', font_size=-1)
80
+ # * pie => (alpha, line_color, label_color)
81
+ # == Plugin hooks called (in order)
82
+ #
83
+ # * prepare_graph
84
+ # * build_graph
85
+ # * finalize_graph
86
+ class OFC < Ruport::Formatter
87
+ renders :ofc, :for => Ruport::Renderer::Graph
88
+
89
+ # Attribute of the OpenFlashChart object
90
+ attr_reader :graph
91
+
92
+ # Initialize the OpenFlashChart
93
+ def initialize
94
+ Ruport.quiet { require 'open_flash_chart' }
95
+ @graph = OpenFlashChart.new
96
+ @graph_pie = false
97
+ end
98
+
99
+ # Prepare the Graph
100
+ def prepare_graph
101
+ @graph.title(options.title || "#{options.style} Report",
102
+ options.title_style || 'font-weight:bold; font-size: 25px;')
103
+ @graph.set_bg_color(options.bg_color || '#DFFFDF')
104
+ @graph.set_y_label_steps(options.y_label_steps) if options.y_label_steps
105
+ @graph.set_x_tick_size(options.x_tick_size) if options.x_tick_size
106
+ @graph.set_tool_tips(options.tool_tips) if options.tool_tips
107
+ @graph.set_x_axis_3d(options.x_axis_3d) if options.x_axis_3d
108
+ @graph.set_y_right_min(options.y_right_min) if options.y_right_min
109
+ @graph.set_y_right_max(options.y_right_max) if options.y_right_max
110
+ @graph.attach_to_y_right_axis(options.attach_to_y_right_axis) if options.attach_to_y_right_axis
111
+ if options.x_label_size
112
+ @graph.set_x_label_style(options.x_label_size,
113
+ options.x_label_color || '',
114
+ options.x_orientation || 0,
115
+ options.x_label_step || -1,
116
+ options.x_label_grid_color || '')
117
+ end
118
+ if options.x_legend_text
119
+ @graph.set_x_legend(options.x_legend_text,
120
+ options.x_legend_size || -1,
121
+ options.x_legend_color || '')
122
+ end
123
+ if options.y_legend_text
124
+ @graph.set_y_legend(options.y_legend_text,
125
+ options.y_legend_size || -1,
126
+ options.y_legend_color || '')
127
+ end
128
+ if options.y_label_size
129
+ @graph.set_y_label_style( options.y_label_size,
130
+ options.y_label_color || '')
131
+ end
132
+ if options.x_label_size
133
+ @graph.set_x_label_style( options.x_label_size,
134
+ options.x_label_color || '',
135
+ options.x_label_orientation || 0,
136
+ options.x_label_step || -1,
137
+ options.x_label_grid_color || '')
138
+ end
139
+ if options.y_right_label_size
140
+ @graph.set_y_right_label_style( options.y_right_label_size,
141
+ options.y_right_label_color || '')
142
+ end
143
+ if options.y_right_legend_text
144
+ @graph.set_y_right_legend(options.y_right_legend_text,
145
+ options.y_right_legend_size || -1,
146
+ options.y_right_legend_color || '')
147
+ end
148
+ if options.bg_image
149
+ @graph.set_bg_image(options.bg_image,
150
+ options.bg_image_x || 'center',
151
+ options.bg_image_y || 'center')
152
+ end
153
+ if options.inner_bg_color
154
+ @graph.set_inner_background(options.inner_bg_color,
155
+ options.inner_bg_color2 || '',
156
+ options.inner_bg_angle || -1)
157
+ end
158
+ (options.chart_types || []).each{ |ct|
159
+ if [:line, :line_dot, :line_hollow, :bar, :bar_3d, :bar_fade, :bar_glass, :bar_filled, :area_hollow].include?(ct[0])
160
+ @graph.send(*ct)
161
+ end
162
+ if ct[0] == :pie
163
+ @graph_pie = true
164
+ @graph.pie_slice_colors(options.pie_slice_colors) if options.pie_slice_colors
165
+ @graph.pie(ct[1] || 50, ct[2] || '#DFFFDF', ct[3] || '#DFFFDF')
166
+ end
167
+ }
168
+
169
+ @graph.set_x_labels((options.x_labels || data.column_names).map{|l| l.nil? ? '' : l})
170
+ all_val = data.inject([]) {|ac, t| ac += t.to_a }.flatten
171
+ @graph.set_y_max(options.y_max || all_val.max)
172
+ @graph.set_y_min(options.y_min || all_val.min)
173
+ @graph.set_x_axis_steps(options.x_axis_step || 3)
174
+ end
175
+
176
+ # Build the Graph
177
+ def build_graph
178
+ if (@graph_pie)
179
+ @graph.pie_values(data.data.first.to_a, (options.x_labels || data.column_names).map{|l| l.nil? ? '' : l})
180
+ else
181
+ data.each_with_index do |r,i|
182
+ @graph.set_data(r.to_a)
183
+ end
184
+ end
185
+
186
+ output << @graph.render
187
+ end
188
+
189
+ end
190
+ end
191
+ end
@@ -0,0 +1,84 @@
1
+ require 'test/helper'
2
+
3
+ Ruport.quiet { testcase_requires 'open_flash_chart' }
4
+
5
+ require "ruport/util/graph/o_f_c"
6
+
7
+ describe 'Graph OpenFlashCharts' do
8
+ before :all do
9
+ @renderer = Ruport::Renderer::Graph
10
+ end
11
+
12
+ it 'Render Bar chart' do
13
+ @renderer = Ruport::Renderer::Graph
14
+ @renderer.should_not be_nil
15
+ @table = Table(%w(name))
16
+ @table << [[3,2,6,7,1,3,2,7,9,1,15,14]]
17
+ @table.should_not be_nil
18
+ @report = @renderer.render(:ofc, :data => @table,
19
+ :chart_types => [[:bar_glass, 50, '#9933CC', '#8010A0', 'PAGE VIEWS', 10]],
20
+ :x_labels => %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec),
21
+ :title => 'Page views By Visitor',
22
+ :title_style => "{font-size: 25px; font-color:#736AFF",
23
+ :bg_color => '#FFFFFF',
24
+ :x_label_size => 10,
25
+ :x_label_color => 'Ox9933CC',
26
+ :x_label_orientation => 0,
27
+ :x_max => 12,
28
+ :y_max => 15,
29
+ :y_label_steps => 3,
30
+ :y_label_size => 12,
31
+ :y_label_color => '#000000',
32
+ :y_legend_text => 'Open flash Chart for Ruport',
33
+ :y_legend_size => 12,
34
+ :y_legend_color => '#736AFF'
35
+ )
36
+ @report.should == "&title=Page views By Visitor,{font-size: 25px; font-color:#736AFF& \n&x_axis_steps=3,& \n&bg_colour=#FFFFFF& \n&x_label_style=10,Ox9933CC,0&y_legend=Open flash Chart for Ruport,12,#736AFF&y_ticks=5,10,3& \n&bar_glass=50,#9933CC,#8010A0,PAGE VIEWS,10& \n&values=3,2,6,7,1,3,2,7,9,1,15,14& \n&x_labels=Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec& \n&y_min=1& \n&y_max=15& \n"
37
+ end
38
+
39
+ it 'Render Multiline' do
40
+ @renderer = Ruport::Renderer::Graph
41
+ @table = Table(%w(name))
42
+ @table << [(1..12).to_a.map{|x| x * 1.3}]
43
+ @table << [(1..12).to_a.map{|x| Math.sin(x) + 3}]
44
+ @table << [(1..6).to_a + (1..6).to_a.reverse]
45
+ @table << [(1..2).to_a + (1..2).to_a.reverse + (3..8).to_a]
46
+ @renderer.should_not be_nil
47
+ @table.should_not be_nil
48
+ @report = @renderer.render(:ofc, :data => @table,
49
+ :chart_types => [[:line, 2, '#9933CC', 'Page Views', 12],
50
+ [:area_hollow, 2, 3, 25, '#CC3399', 'Visitors', 12],
51
+ [:line_dot, 3,5,'0xCC3399', 'Downloads', 12],
52
+ [:line_hollow, 2,4,'0x80a033', 'Bounces', 12]],
53
+ :x_labels => %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec),
54
+ :title => 'Pages Views',
55
+ :title_style => "{font-size: 25px;}",
56
+ :bg_color => '#FFFFFF',
57
+ :x_label_size => 12,
58
+ :x_label_color => 'Ox000000',
59
+ :x_label_orientation => 0,
60
+ :x_label_step => 2,
61
+ :y_max => 12,
62
+ :y_label_steps => 12,
63
+ :y_label_size => 12,
64
+ :y_label_color => '#000000',
65
+ :y_legend_text => 'Open flash Chart for Ruport',
66
+ :y_legend_size => 12,
67
+ :y_legend_color => '#736AFF'
68
+ )
69
+ @report.should == "&title=Pages Views,{font-size: 25px;}& \n&x_axis_steps=3,& \n&bg_colour=#FFFFFF& \n&x_label_style=12,Ox000000,0,2&y_legend=Open flash Chart for Ruport,12,#736AFF&y_ticks=5,10,12& \n&line=2,#9933CC,Page Views,12& \n&area_hollow_2=2,3,25,#CC3399,Visitors,12& \n&line_dot_3=3,0xCC3399,Downloads,12,5& \n&line_hollow_4=2,0x80a033,Bounces,12,4& \n&values=1.3,2.6,3.9,5.2,6.5,7.8,9.1,10.4,11.7,13.0,14.3,15.6& \n&values_2=3.8414709848079,3.90929742682568,3.14112000805987,2.24319750469207,2.04107572533686,2.72058450180107,3.65698659871879,3.98935824662338,3.41211848524176,2.45597888911063,2.0000097934493,2.46342708199957& \n&values_3=1,2,3,4,5,6,6,5,4,3,2,1& \n&values_4=1,2,2,1,3,4,5,6,7,8& \n&x_labels=Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec& \n&y_min=1& \n&y_max=12& \n"
70
+ end
71
+
72
+ it 'Render Pie' do
73
+ @renderer = Ruport::Renderer::Graph
74
+ @table = Table(%w(name))
75
+ @table << [(1..12).to_a.map{|x| x * 1.3}]
76
+ @renderer.should_not be_nil
77
+ @table.should_not be_nil
78
+ @report = @renderer.render(:ofc, :data => @table,
79
+ :chart_types => [[:pie, 80, '#9933CC', '#8010A0']],
80
+ :x_labels => %w(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec),
81
+ :pie_slice_colors => ['#d01f3c','#356aa0','#C79810'])
82
+ @report.should == "&title= Report,font-weight:bold; font-size: 25px;& \n&x_axis_steps=3,& \n&bg_colour=#DFFFDF& \n&y_ticks=5,10,5& \n&line=3,#87421F& \n&x_labels=Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec& \n&y_min=1.3& \n&y_max=15.6& \n&pie=80,#9933CC,#8010A0& \n&values=1.3,2.6,3.9,5.2,6.5,7.8,9.1,10.4,11.7,13.0,14.3,15.6& \n&pie_labels=Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec& \n&colours=#d01f3c,#356aa0,#C79810& \n"
83
+ end
84
+ end
@@ -1,6 +1,6 @@
1
1
  require 'test/helper'
2
2
  require 'ruport/util/graph/amline'
3
- require 'hpricot'
3
+ Ruport.quiet { testcase_requires 'hpricot' }
4
4
 
5
5
  describe "A simple traversal" do
6
6
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: ruport-util
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.9.0
7
- date: 2007-11-09 00:00:00 -05:00
6
+ version: 0.10.0
7
+ date: 2007-11-24 00:00:00 -05:00
8
8
  summary: A set of tools and helper libs for Ruby Reports
9
9
  require_paths:
10
10
  - lib
@@ -41,6 +41,7 @@ files:
41
41
  - example/data/amline_graph.xml
42
42
  - example/data/amline_settings.xml
43
43
  - example/data/blank.ods
44
+ - lib/open_flash_chart.rb
44
45
  - lib/ruport
45
46
  - lib/ruport/util
46
47
  - lib/ruport/util.rb
@@ -56,12 +57,14 @@ files:
56
57
  - lib/ruport/util/report_manager.rb
57
58
  - lib/ruport/util/graph/amline.rb
58
59
  - lib/ruport/util/graph/gruff.rb
60
+ - lib/ruport/util/graph/o_f_c.rb
59
61
  - lib/ruport/util/graph/scruffy.rb
60
62
  - lib/ruport/util/pdf/form.rb
61
63
  - test/helper
62
64
  - test/helper.rb
63
65
  - test/samples
64
66
  - test/test_format_ods.rb
67
+ - test/test_graph_ofc.rb
65
68
  - test/test_graph_renderer.rb
66
69
  - test/test_hpricot_traverser.rb
67
70
  - test/test_invoice.rb
@@ -78,6 +81,7 @@ files:
78
81
  - INSTALL
79
82
  test_files:
80
83
  - test/test_format_ods.rb
84
+ - test/test_graph_ofc.rb
81
85
  - test/test_graph_renderer.rb
82
86
  - test/test_hpricot_traverser.rb
83
87
  - test/test_invoice.rb
@@ -107,7 +111,7 @@ dependencies:
107
111
  requirements:
108
112
  - - ">="
109
113
  - !ruby/object:Gem::Version
110
- version: 1.2.2
114
+ version: 1.2.3
111
115
  version:
112
116
  - !ruby/object:Gem::Dependency
113
117
  name: mailfactory