Introduction
Introduction Statistics Contact Development Disclaimer Help
Adding ReportTagHelper#flot_report_tag method with specs and default options - …
Log
Files
Refs
README
---
commit 1dfd44c050bf717b8d3c49acbe66f6154901bf67
parent fac089b11bc3cd41fe1897bc71f3cf26cfa4e55e
Author: Martin Kavalar <[email protected]>
Date: Wed, 26 May 2010 10:36:38 +0200
Adding ReportTagHelper#flot_report_tag method with specs and default options
Diffstat:
M generators/reportable_raphael_asse… | 3 +--
M lib/saulabs/reportable/config.rb | 20 ++++++++++++++++++++
M lib/saulabs/reportable/report_tag_… | 44 +++++++++++++++++++++++++++…
M spec/other/report_tag_helper_spec.… | 27 +++++++++++++++++++++++++++
4 files changed, 92 insertions(+), 2 deletions(-)
---
diff --git a/generators/reportable_raphael_assets/templates/NOTES b/generators/…
@@ -1,3 +1,2 @@
- ** Don't forget to include raphael.min.js as well as g.raphael.min.js and g.…
-
+ ** Don't forget to include Raphael as well as gRaphaels javascripts in your …
diff --git a/lib/saulabs/reportable/config.rb b/lib/saulabs/reportable/config.rb
@@ -25,6 +25,26 @@ module Saulabs
:hover_line_color => '2f69bf',
:hover_fill_color => '2f69bf'
}
+
+ mattr_accessor :flot_options
+
+ @@flot_options = {
+ :width => 300,
+ :height => 100,
+ :dom_id => nil,
+ :colors => ['rgba(6,122,205,1)'],
+ :grid => {
+ :show => false
+ },
+ :series => {
+ :lines => {
+ :fill => true,
+ :fillColor => 'rgba(6,122,205,.5)',
+ :lineWidth => 2
+ },
+ :shadowSize => 0
+ }
+ }
end
diff --git a/lib/saulabs/reportable/report_tag_helper.rb b/lib/saulabs/reportab…
@@ -111,6 +111,50 @@ module Saulabs
});
</script>}
end
+
+ # Renders a sparkline with the given data using the jquery flot plugin.
+ #
+ # @param [Array<Array<DateTime, Float>>] data
+ # an array of report data as returned by {Saulabs::Reportable::Report#…
+ # @param [Hash] options
+ # options for width, height, the dom id and the format
+ # @param [Hash] flot_options
+ # options that are passed directly to Raphael as JSON
+ #
+ # @option options [Fixnum] :width (300)
+ # the width of the generated graph
+ # @option options [Fixnum] :height (34)
+ # the height of the generated graph
+ # @option options [Array<Symbol>] :dom_id ("reportable_#{Time.now.to_i}")
+ # the dom id of the generated div
+ #
+ # @return [String]
+ # an div tag and the javascript code showing a sparkline for the passe…
+ #
+ # @example Rendering a sparkline tag for report data
+ #
+ # <%= flot_report_tag(User.registrations_report) %>
+ #
+
+ def flot_report_tag(data, options = {}, flot_options = {})
+ @__flot_report_tag_count ||= -1
+ @__flot_report_tag_count += 1
+ default_dom_id = "#{data.model_name.downcase}_#{data.report_name}#{@__…
+ options.reverse_merge!(Config.flot_options.slice(:width, :height, :for…
+ options.reverse_merge!(:dom_id => default_dom_id)
+ flot_options.reverse_merge!(Config.flot_options.except(:width, :height…
+ %Q{<div id="#{options[:dom_id]}" style="width:#{options[:width]}px;hei…
+ <script type="text\/javascript" charset="utf-8">
+ $(function() {
+ var set = #{data.to_json},
+ data = [];
+ for (var i = 0; i < set.length; i++) {
+ data.push([i, set[i]]);
+ }
+ $.plot($('#interactive_graph'), [data], );
+ });
+ </script>}
+ end
end
end
diff --git a/spec/other/report_tag_helper_spec.rb b/spec/other/report_tag_helpe…
@@ -32,6 +32,33 @@ describe Saulabs::Reportable::ReportTagHelper do
end
end
+
+ describe '#flot_report_tag' do
+
+ data_set = Saulabs::Reportable::ResultSet.new([[DateTime.now, 1.0], [DateT…
+
+ it 'should return a string' do
+ @helper.flot_report_tag(data_set).class.should == String
+ end
+
+ it 'should contain a div tag' do
+ @helper.flot_report_tag(data_set).should =~ /^<div id=".*">.*<\/div>/
+ end
+
+ it 'should contain a script tag' do
+ @helper.flot_report_tag(data_set).should =~ /<script type="text\/javascr…
+ end
+
+ it 'should assign a default dom id to the the div tag if none is specified…
+ @helper.flot_report_tag(data_set).should =~ /^<div id="#{data_set.model_…
+ end
+
+ it 'should assign correct default dom ids to the the div tag if none is sp…
+ @helper.flot_report_tag(data_set).should =~ /^<div id="#{data_set.model_…
+ @helper.flot_report_tag(data_set).should =~ /^<div id="#{data_set.model_…
+ end
+
+ end
describe '#google_report_tag' do
You are viewing proxied material from jay.scot. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.