Class: Ruport::Formatter::Graph::Scruffy
- Inherits:
-
Ruport::Formatter
- Object
- Ruport::Formatter
- Ruport::Formatter::Graph::Scruffy
- Defined in:
- lib/ruport/util/graph/scruffy.rb
Instance Attribute Summary collapse
-
#graph ⇒ Object
readonly
the Scruffy::Graph object.
Instance Method Summary collapse
-
#add_line(row, label) ⇒ Object
Uses Scruffy::Graph#add to add a new line to the graph.
- #apply_template ⇒ Object
-
#build_graph ⇒ Object
Generates an SVG using Scruffy.
-
#initialize ⇒ Scruffy
constructor
generates a scruffy graph object.
-
#prepare_graph ⇒ Object
sets the graph title, theme, and column_names.
-
#themes ⇒ Object
a hash of Scruffy themes.
Constructor Details
Instance Attribute Details
#graph ⇒ Object (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( .style || :line, label, row ) end |
#apply_template ⇒ Object
55 56 57 58 59 60 |
# File 'lib/ruport/util/graph/scruffy.rb', line 55 def apply_template .min = template.y_min .max = template.y_max .width = template.width .height = template.height end |
#build_graph ⇒ Object
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 => [.width||500, .height||300], :min_value => .min, :max_value => .max ) end |
#prepare_graph ⇒ Object
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 ||= .title @graph.theme = themes[.theme] if .theme @graph.point_markers ||= data.x_labels end |
#themes ⇒ Object
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 |