Class: Ruport::Formatter::Graph::Gruff

Inherits:
Ruport::Formatter show all
Defined in:
lib/ruport/util/graph/gruff.rb

Instance Method Summary collapse

Constructor Details

#initializeGruff

Returns a new instance of Gruff.



8
9
10
# File 'lib/ruport/util/graph/gruff.rb', line 8

def initialize
  Ruport.quiet { require 'gruff' }
end

Instance Method Details

#apply_templateObject



12
13
14
15
16
17
# File 'lib/ruport/util/graph/gruff.rb', line 12

def apply_template
   options.min    = template.y_min
   options.max    = template.y_max
   options.width  = template.width
   options.height = template.height
end

#build_graphObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ruport/util/graph/gruff.rb', line 19

def build_graph   
  graph = ::Gruff::Line.new("#{options.width || 800}x#{options.height || 600}")
  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

#save_output(filename) ⇒ Object

Save the output to a file.



34
35
36
# File 'lib/ruport/util/graph/gruff.rb', line 34

def save_output(filename)
  File.open(filename,"wb") {|f| f << output }
end