| added the missing ReportTagHelper, fixed the method name, added a config module… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit bd08bb88bd992a5a86434d5b6c5e2509484acbc1 | |
| parent 8a273651bcfc2cf9b02681e4988bcf0f1c4654a0 | |
| Author: Marco Otte-Witte <[email protected]> | |
| Date: Sun, 18 Apr 2010 18:32:25 +0200 | |
| added the missing ReportTagHelper, fixed the method name, added a config module | |
| Diffstat: | |
| M README.md | 2 +- | |
| A lib/saulabs/reportable/config.rb | 3 +++ | |
| A lib/saulabs/reportable/report_tag_… | 64 +++++++++++++++++++++++++++… | |
| 3 files changed, 68 insertions(+), 1 deletion(-) | |
| --- | |
| diff --git a/README.md b/README.md | |
| @@ -48,7 +48,7 @@ The data is returned as an `Array` of `Array`s of `DateTime`s… | |
| Reportable provides a helper method to generate a sparkline image from this da… | |
| - <%= sparkline_tag(User.registrations_report) %> | |
| + <%= report_tag(User.registrations_report) %> | |
| Installation | |
| diff --git a/lib/saulabs/reportable/config.rb b/lib/saulabs/reportable/config.rb | |
| @@ -0,0 +1,3 @@ | |
| +module Config | |
| + | |
| +end | |
| diff --git a/lib/saulabs/reportable/report_tag_helper.rb b/lib/saulabs/reportab… | |
| @@ -0,0 +1,64 @@ | |
| +require 'saulabs/reportable/config' | |
| + | |
| +module Saulabs | |
| + | |
| + module Reportable | |
| + | |
| + module ReportTagHelper | |
| + | |
| + # Renders a sparkline with the given data. | |
| + # | |
| + # @param [Array<Array<DateTime, Float>>] data | |
| + # an array of report data as returned by {Saulabs::Reportable::Report#… | |
| + # @param [Hash] options | |
| + # options for the sparkline | |
| + # | |
| + # @option options [Fixnum] :width (300) | |
| + # the width of the generated image | |
| + # @option options [Fixnum] :height (34) | |
| + # the height of the generated image | |
| + # @option options [String] :line_color ('0077cc') | |
| + # the line color of the generated image | |
| + # @option options [String] :fill_color ('e6f2fa') | |
| + # the fill color of the generated image | |
| + # @option options [Array<Symbol>] :labels ([]) | |
| + # the axes to render lables for (Array of +:x+, +:y+, +:r+, +:t+; this… | |
| + # @option options [String] :alt ('') | |
| + # the alt attribute for the generated image | |
| + # @option options [String] :title ('') | |
| + # the title attribute for the generated image | |
| + # | |
| + # @return [String] | |
| + # an image tag showing a sparkline for the passed +data+ | |
| + # | |
| + # @example Rendering a sparkline tag for report data | |
| + # | |
| + # <%= report_tag(User.registrations_report, :width => 200, :height => … | |
| + # | |
| + def report_tag(data, options = {}) | |
| + options.reverse_merge!({ :width => 300, :height => 34, :line_color => … | |
| + data = data.collect { |d| d[1] } | |
| + labels = '' | |
| + unless options[:labels].empty? | |
| + 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 | |
| + title = '' | |
| + unless options[:title].empty? | |
| + title = "&chtt=#{options[:title]}" | |
| + end | |
| + image_tag( | |
| + "http://chart.apis.google.com/chart?cht=ls&chs=#{options[:width]}x#{… | |
| + :alt => options[:alt], | |
| + :title => options[:title] | |
| + ) | |
| + end | |
| + | |
| + end | |
| + | |
| + end | |
| + | |
| +end |