| Merge branch 'master' into rails3 - reportable - Fork of reportable required by… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit ddd609dc1bc709dfdfa85a0cf42ccda2134504c2 | |
| parent e34734072141e90ea0ad4da84198fba36ad7f480 | |
| Author: Marco Otte-Witte <[email protected]> | |
| Date: Sun, 18 Apr 2010 18:37:25 +0200 | |
| Merge branch 'master' into rails3 | |
| Conflicts: | |
| rails/init.rb | |
| Diffstat: | |
| M README.md | 2 +- | |
| A lib/saulabs/reportable/config.rb | 3 +++ | |
| A lib/saulabs/reportable/report_tag_… | 64 +++++++++++++++++++++++++++… | |
| D lib/saulabs/reportable/sparkline_t… | 62 ---------------------------… | |
| M spec/other/sparkline_tag_helper_sp… | 16 ++++++++-------- | |
| 5 files changed, 76 insertions(+), 71 deletions(-) | |
| --- | |
| 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 | |
| diff --git a/lib/saulabs/reportable/sparkline_tag_helper.rb b/lib/saulabs/repor… | |
| @@ -1,62 +0,0 @@ | |
| -module Saulabs | |
| - | |
| - module Reportable | |
| - | |
| - module SparklineTagHelper | |
| - | |
| - # 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 | |
| - # | |
| - # <%= sparkline_tag(User.registrations_report, :width => 200, :height … | |
| - # | |
| - def sparkline_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 | |
| diff --git a/spec/other/sparkline_tag_helper_spec.rb b/spec/other/sparkline_tag… | |
| @@ -1,12 +1,12 @@ | |
| require File.join(File.dirname(__FILE__), '..', 'spec_helper') | |
| -describe Saulabs::Reportable::SparklineTagHelper do | |
| +describe Saulabs::Reportable::ReportTagHelper do | |
| before do | |
| @helper = TestHelper.new | |
| end | |
| - describe '#sparkline_tag' do | |
| + describe '#report_tag' do | |
| it 'should render an image with the correct source' do | |
| @helper.should_receive(:image_tag).once.with( | |
| @@ -14,7 +14,7 @@ describe Saulabs::Reportable::SparklineTagHelper do | |
| { :title => '', :alt => '' } | |
| ) | |
| - @helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTi… | |
| + @helper.report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.… | |
| end | |
| it 'should add parameters for labels to the source of the image if renderi… | |
| @@ -23,7 +23,7 @@ describe Saulabs::Reportable::SparklineTagHelper do | |
| { :title => '', :alt => '' } | |
| ) | |
| - @helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTi… | |
| + @helper.report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.… | |
| end | |
| it 'should set the parameters for custom colors if custom colors are speci… | |
| @@ -32,7 +32,7 @@ describe Saulabs::Reportable::SparklineTagHelper do | |
| { :title => '', :alt => '' } | |
| ) | |
| - @helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTi… | |
| + @helper.report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.… | |
| end | |
| it 'should set the parameters for a custom title if a title specified' do | |
| @@ -41,7 +41,7 @@ describe Saulabs::Reportable::SparklineTagHelper do | |
| { :title => 'title', :alt => '' } | |
| ) | |
| - @helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTi… | |
| + @helper.report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.… | |
| end | |
| it 'should use a specified alt text as alt text for the image' do | |
| @@ -50,7 +50,7 @@ describe Saulabs::Reportable::SparklineTagHelper do | |
| { :title => '', :alt => 'alt' } | |
| ) | |
| - @helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTi… | |
| + @helper.report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.… | |
| end | |
| end | |
| @@ -59,6 +59,6 @@ end | |
| class TestHelper | |
| - include Saulabs::Reportable::SparklineTagHelper | |
| + include Saulabs::Reportable::ReportTagHelper | |
| end |