Class: Ruport::Formatter::Graph::Scruffy

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeScruffy

generates a scruffy graph object



22
23
24
25
# File 'lib/ruport/util/graph/scruffy.rb', line 22

def initialize
  Ruport.quiet { require 'scruffy' }   
  @graph = ::Scruffy::Graph.new
end

Instance Attribute Details

#graphObject (readonly)

the Scruffy::Graph object



28
29
30
# File 'lib/ruport/util/graph/scruffy.rb', line 28

def graph
  @graph
end

Instance Method Details

#add_line(row, label) ⇒ Object

Uses Scruffy::Graph#add to add a new line to the graph.

Line style is determined by options.style



66
67
68
# File 'lib/ruport/util/graph/scruffy.rb', line 66

def add_line(row,label)
  @graph.add( options.style || :line, label, row )
end

#apply_templateObject



55
56
57
58
59
60
# File 'lib/ruport/util/graph/scruffy.rb', line 55

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

#build_graphObject

Generates an SVG using Scruffy.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ruport/util/graph/scruffy.rb', line 43

def build_graph    

  data.each_with_index do |r,i|
    add_line(r.to_a,r.gid||"series #{i+1}")
  end

  output << @graph.render( 
    :size => [options.width||500, options.height||300],
    :min_value => options.min, :max_value => options.max
  )
end

#prepare_graphObject

sets the graph title, theme, and column_names

column_names are defined by the Data::Table, theme may be specified by options.theme (see SVG#themes) title may be specified by options.title



36
37
38
39
40
# File 'lib/ruport/util/graph/scruffy.rb', line 36

def prepare_graph 
  @graph.title ||= options.title
  @graph.theme = themes[options.theme] if options.theme
  @graph.point_markers ||= data.x_labels
end

#themesObject

a hash of Scruffy themes.

You can use these by setting options.theme like this:

Graph.render_svg(:theme => :mephisto)

Available themes: ( :mephisto, :keynote, :ruby_blog )



15
16
17
18
19
# File 'lib/ruport/util/graph/scruffy.rb', line 15

def themes
  { :mephisto => Scruffy::Themes::Mephisto.new,
    :keynote  => Scruffy::Themes::Keynote.new,
    :ruby_blog => Scruffy::Themes::RubyBlog.new }
end