Ruport Graphs

Posted by Matt Williams

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.

Comments

Leave a response