Module: SparklinesHelper
- Defined in:
- lib/sparklines_helper.rb
Overview
Provides a tag for embedding sparklines graphs into your Rails app.
Instance Method Summary collapse
-
#sparkline_tag(results = [], options = {}) ⇒ Object
You can also pass :class => ‘some_css_class’ (‘sparkline’ by default).
Instance Method Details
#sparkline_tag(results = [], options = {}) ⇒ Object
You can also pass :class => ‘some_css_class’ (‘sparkline’ by default).
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sparklines_helper.rb', line 11 def sparkline_tag(results=[], ={}) url = { :controller => 'sparklines' } url[:results] = results.join(',') unless results.nil? = url.merge() attributes = %(class="#{[:class] || 'sparkline'}" alt="Sparkline Graph" ) attributes << %(title="#{[:title]}" ) if [:title] # prefer to use a "data" URL scheme as described in {RFC 2397}[http://www.ietf.org/rfc/rfc2397.txt] # data_url = "data:image/png;base64,#{Base64.encode64(Sparklines.plot(results,options))}" # tag = %(<img src="#{data_url}" #{attributes}/>) # # respect some limits noted in RFC 2397 since the data: url is supposed to be 'short' # data_url.length <= 1024 && tag.length <= 2100 ? tag : %(<img src="#{ url_for }" #{attributes}/>) end |