Merge branch 'master' into rails3 - reportable - Fork of reportable required by WarVox, from hdm/reportable.
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
       ---
 (DIR) commit ddd609dc1bc709dfdfa85a0cf42ccda2134504c2
 (DIR) parent e34734072141e90ea0ad4da84198fba36ad7f480
 (HTM) Author: Marco Otte-Witte <marco.otte-witte@simplabs.com>
       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(-)
       ---
 (DIR) 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 and `Float`s, e.g.
        
        Reportable provides a helper method to generate a sparkline image from this data that you can use in your views:
        
       -    <%= sparkline_tag(User.registrations_report) %>
       +    <%= report_tag(User.registrations_report) %>
        
        
        Installation
 (DIR) diff --git a/lib/saulabs/reportable/config.rb b/lib/saulabs/reportable/config.rb
       @@ -0,0 +1,3 @@
       +module Config
       +
       +end
 (DIR) diff --git a/lib/saulabs/reportable/report_tag_helper.rb b/lib/saulabs/reportable/report_tag_helper.rb
       @@ -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#run}
       +      # @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 is x axis, y axis, right, top)
       +      # @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 => 100, :color => '000') %>
       +      #
       +      def report_tag(data, options = {})
       +        options.reverse_merge!({ :width => 300, :height => 34, :line_color => '0077cc', :fill_color => 'e6f2fa', :labels => [], :alt => '', :title => '' })
       +        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}" : "#{[data.min, 0].min},#{data.max}")
       +          end
       +          labels = "&chxt=#{options[:labels].map(&:to_s).join(',')}&chxr=#{options[:labels].collect{|l| chxr[l]}.join('|')}"
       +        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#{options[:height]}&chd=t:#{data.join(',')}&chco=#{options[:line_color]}&chm=B,#{options[:fill_color]},0,0,0&chls=1,0,0&chds=#{data.min},#{data.max}#{labels}#{title}",
       +          :alt   => options[:alt],
       +          :title => options[:title]
       +        )
       +      end
       +
       +    end
       +
       +  end
       +
       +end
 (DIR) diff --git a/lib/saulabs/reportable/sparkline_tag_helper.rb b/lib/saulabs/reportable/sparkline_tag_helper.rb
       @@ -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#run}
       -      # @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 is x axis, y axis, right, top)
       -      # @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 => 100, :color => '000') %>
       -      #
       -      def sparkline_tag(data, options = {})
       -        options.reverse_merge!({ :width => 300, :height => 34, :line_color => '0077cc', :fill_color => 'e6f2fa', :labels => [], :alt => '', :title => '' })
       -        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}" : "#{[data.min, 0].min},#{data.max}")
       -          end
       -          labels = "&chxt=#{options[:labels].map(&:to_s).join(',')}&chxr=#{options[:labels].collect{|l| chxr[l]}.join('|')}"
       -        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#{options[:height]}&chd=t:#{data.join(',')}&chco=#{options[:line_color]}&chm=B,#{options[:fill_color]},0,0,0&chls=1,0,0&chds=#{data.min},#{data.max}#{labels}#{title}",
       -          :alt   => options[:alt],
       -          :title => options[:title]
       -        )
       -      end
       -
       -    end
       -
       -  end
       -
       -end
 (DIR) diff --git a/spec/other/sparkline_tag_helper_spec.rb b/spec/other/sparkline_tag_helper_spec.rb
       @@ -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], [DateTime.now, 3.0]])
       +      @helper.report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]])
            end
        
            it 'should add parameters for labels to the source of the image if rendering of lables is specified' do
       @@ -23,7 +23,7 @@ describe Saulabs::Reportable::SparklineTagHelper do
                { :title => '', :alt => '' }
              )
        
       -      @helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :labels => [:x, :y, :r, :t])
       +      @helper.report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :labels => [:x, :y, :r, :t])
            end
        
            it 'should set the parameters for custom colors if custom colors are specified' do
       @@ -32,7 +32,7 @@ describe Saulabs::Reportable::SparklineTagHelper do
                { :title => '', :alt => '' }
              )
        
       -      @helper.sparkline_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :line_color => '000000', :fill_color => 'ffffff')
       +      @helper.report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :line_color => '000000', :fill_color => 'ffffff')
            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], [DateTime.now, 3.0]], :title => 'title')
       +      @helper.report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :title => 'title')
            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], [DateTime.now, 3.0]], :alt => 'alt')
       +      @helper.report_tag([[DateTime.now, 1.0], [DateTime.now, 2.0], [DateTime.now, 3.0]], :alt => 'alt')
            end
        
          end
       @@ -59,6 +59,6 @@ end
        
        class TestHelper
        
       -  include Saulabs::Reportable::SparklineTagHelper
       +  include Saulabs::Reportable::ReportTagHelper
        
        end