]> projects.mako.cc - selectricity-live/blob - app/controllers/sparklines_controller.rb
Explicity make FP links white instead of inheriting.
[selectricity-live] / app / controllers / sparklines_controller.rb
1 class SparklinesController < ApplicationController
2     # Handles requests for sparkline graphs from views.
3     #
4     # Params are generated by the sparkline_tag helper method.
5     #
6         def index
7                 # Make array from comma-delimited list of data values
8                 ary = []
9                 if params.has_key?('results') && !params['results'].nil?
10                   params['results'].split(',').each do |s|
11                           ary << s.to_i
12                   end
13                 end
14
15                 send_data( Sparklines.plot( ary, params ), 
16                                         :disposition => 'inline',
17                                         :type => 'image/png',
18                                         :filename => "spark_#{params[:type]}.png" )
19         end
20     
21     def spark_pie
22       send_data(Sparklines.plot( ))
23     end
24     # Use this type of method for sparklines that can be cached. (Doesn't work with the helper.)
25     #
26     # To make caching easier, add a line like this to config/routes.rb:
27     # map.sparklines "sparklines/:action/:id/image.png", :controller => "sparklines"
28     #
29     # Then reference it with the named route:
30     #   image_tag sparklines_url(:action => 'show', :id => 42)
31     def show
32       send_data(Sparklines.plot(
33                   [42, 37, 89, 74, 70, 50, 40, 30, 40, 50],
34                   :type => 'bar', :above_color => 'orange'
35                 ), 
36                 :disposition => 'inline', 
37                 :type => 'image/png', 
38                 :filename => "sparkline.png")
39     end
40   
41   
42   
43 end

Benjamin Mako Hill || Want to submit a patch?