Module: Sinatra::ChartTopper
- Defined in:
- lib/sinatra/chart_topper.rb
Constant Summary collapse
- GRAPH_TYPES =
These graph types are available as top level methods and proxied through to draw() e.g. graph_type() -> draw(Gruff::GraphType)
[:accumulator_bar, :area, :bar, :bar_conversion, :dot, :line, :pie, :side_stacked_bar, :side_bar, :spider, :stacked_area, :stacked_bar]
- GRAPH_DELEGATIONS =
Delegate(?) these methods to the graph
[:data, :add_color, :theme_37signals, :theme_greyscale, :theme_keynote, :theme_odeo, :theme_pastel, :theme_rails_keynote]
Class Method Summary collapse
Instance Method Summary collapse
-
#draw(type, title, options = {}, &block) ⇒ Object
Define a route to draw a particualar graph.
-
#filename(title) ⇒ Object
Make filename from title.
-
#graph(size = nil) ⇒ Object
Create / return graph object.
-
#set_graph(graph) ⇒ Object
Set the graph object.
-
#size(dimensions) ⇒ Object
Create graph of size (reset’s any previous graph!).
Class Method Details
.registered(app) ⇒ Object
60 61 62 |
# File 'lib/sinatra/chart_topper.rb', line 60 def self.registered(app) app.helpers Sinatra::ChartTopper end |
Instance Method Details
#draw(type, title, options = {}, &block) ⇒ Object
Define a route to draw a particualar graph
65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/sinatra/chart_topper.rb', line 65 def draw(type, title, = {}, &block) prefix = [:prefix] || "/" get "#{prefix}#{filename(title)}.png" do content_type "image/png" set_graph type.new instance_eval(&block) graph.title = title graph.to_blob end end |
#filename(title) ⇒ Object
Make filename from title
40 41 42 |
# File 'lib/sinatra/chart_topper.rb', line 40 def filename(title) title.gsub(/[^a-zA-Z0-9_\s]/, '').gsub(/\s/, '_').downcase end |
#graph(size = nil) ⇒ Object
Create / return graph object
51 52 53 |
# File 'lib/sinatra/chart_topper.rb', line 51 def graph(size = nil) @graph end |
#set_graph(graph) ⇒ Object
Set the graph object
56 57 58 |
# File 'lib/sinatra/chart_topper.rb', line 56 def set_graph(graph) @graph = graph end |
#size(dimensions) ⇒ Object
Create graph of size (reset’s any previous graph!)
45 46 47 48 |
# File 'lib/sinatra/chart_topper.rb', line 45 def size(dimensions) type = graph.class set_graph type.new(dimensions) end |