Module: Saulabs::Reportable::SparklineTagHelper
- Defined in:
- lib/saulabs/reportable/sparkline_tag_helper.rb
Instance Method Summary collapse
-
#sparkline_tag(data, options = {}) ⇒ String
Renders a sparkline with the given data.
Instance Method Details
#sparkline_tag(data, options = {}) ⇒ String
Renders a sparkline with the given data.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/saulabs/reportable/sparkline_tag_helper.rb', line 36 def sparkline_tag(data, = {}) .reverse_merge!({ :width => 300, :height => 34, :line_color => '0077cc', :fill_color => 'e6f2fa', :labels => [], :alt => '', :title => '' }) data = data.collect { |d| d[1] } labels = '' unless [:labels].empty? chxr = {} [:labels].each_with_index do |l, i| chxr[l] = "#{i}," + ([:x, :t].include?(l) ? "0,#{data.length}" : "#{[data.min, 0].min},#{data.max}") end labels = "&chxt=#{[:labels].map(&:to_s).join(',')}&chxr=#{[:labels].collect{|l| chxr[l]}.join('|')}" end title = '' unless [:title].empty? title = "&chtt=#{[:title]}" end image_tag( "http://chart.apis.google.com/chart?cht=ls&chs=#{[:width]}x#{[:height]}&chd=t:#{data.join(',')}&chco=#{[:line_color]}&chm=B,#{[:fill_color]},0,0,0&chls=1,0,0&chds=#{data.min},#{data.max}#{labels}#{title}", :alt => [:alt], :title => [:title] ) end |