Matt Williams
Posts: 466
Nickname: aetherical
Registered: Feb, 2008
Matt Williams is a jack-of-all trades living in Columbus, OH.
Ruport Graphs
Posted: Feb 12, 2008 10:08 AM
This post originated from an RSS feed registered with Ruby Buzz
by Matt Williams.
Original Post: Ruport Graphs
Feed Title: Ruby Blender
Feed URL: http://feeds2.feedburner.com/RubyBlender
Feed Description: This blog contains short-ish ruby tips, hints, and techniques.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Matt Williams
Latest Posts From Ruby Blender
Advertisement
ruport comes with an extension, ruport-util which adds, among other things, the ability to create graphs from reports. However, it's hardcoded to do line graphs. This is a code snippet which will (for png and jpg graphs, the others should follow) allow you to create other types -- it's just bar graphs, but the others would follow....
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require ' ruport '
require ' ruport/util '
require ' entry '
class Ruport::Formatter
module Graph
class Gruff < Ruport ::Formatter
def build_graph
height = " #{ options.width || 600 } "
width = " #{ options.height || 800 } "
dimensions = " #{ width} x #{ height} "
type = options.graph_type || :line
graph = case type
when :line
::Gruff ::Line .new(dimensions)
when :bar
::Gruff ::Bar .new(dimensions)
end
graph.title = options.title if options.title
graph.labels = options.labels if options.labels
data.each do |r|
graph.data(r.gid,r.to_a)
end
graph.maximum_value = options.max if options.max
graph.minimum_value = options.min if options.min
output << graph.to_blob(format.to_s)
end
end
end
end
As I said, it's nothing special, but might be of some utility.
Read: Ruport Graphs