| Adding alt tag Dynamic labels according to actual presence and order of label a… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit 11f18a2208ec2ba6e7983fba47a671290fbf3ac4 | |
| parent dd5ce7bf2dd86866f616621ed9798b5d259b37e3 | |
| Author: Jan Bromberger <[email protected]> | |
| Date: Tue, 29 Dec 2009 17:08:18 +0800 | |
| Adding alt tag | |
| Dynamic labels according to actual presence and order of label axes | |
| Negative labels | |
| Diffstat: | |
| M lib/simplabs/reports_as_sparkline/… | 12 +++++++++--- | |
| 1 file changed, 9 insertions(+), 3 deletions(-) | |
| --- | |
| diff --git a/lib/simplabs/reports_as_sparkline/sparkline_tag_helper.rb b/lib/si… | |
| @@ -17,18 +17,24 @@ module Simplabs #:nodoc: | |
| # * <tt>line_color</tt> - The line color of the sparkline (hex code) | |
| # * <tt>fill_color</tt> - The color to fill the area below the sparkline… | |
| # * <tt>labels</tt> - The axes to render lables for (Array of <tt>:x</tt… | |
| + # * <tt>alt</tt> - The HTML img alt tag | |
| # | |
| # ==== Example | |
| # <tt><%= sparkline_tag(User.registrations_report, :width => 200, :heigh… | |
| def sparkline_tag(data, options = {}) | |
| - options.reverse_merge!({ :width => 300, :height => 34, :line_color => … | |
| + options.reverse_merge!({ :width => 300, :height => 34, :line_color => … | |
| data = data.collect { |d| d[1] } | |
| labels = "" | |
| unless options[:labels].empty? | |
| - labels = "&chxt=#{options[:labels].map(&:to_s).join(',')}&chxr=0,0,#… | |
| + chxr = {} | |
| + options[:labels].each_with_index do |l, i| | |
| + chxr[l] = "#{i}," + ([:x, :t].include?(l) ? "0,#{data.length}" : "… | |
| + end | |
| + labels = "&chxt=#{options[:labels].map(&:to_s).join(',')}&chxr=#{opt… | |
| end | |
| image_tag( | |
| - "http://chart.apis.google.com/chart?cht=ls&chs=#{options[:width]}x#{… | |
| + "http://chart.apis.google.com/chart?cht=ls&chs=#{options[:width]}x#{… | |
| + :alt => options[:alt] | |
| ) | |
| end | |