Module: Saulabs::Reportable::ReportTagHelper
- Defined in:
- lib/saulabs/reportable/report_tag_helper.rb
Instance Method Summary collapse
-
#flot_report_tag(data, options = {}, flot_options = {}) ⇒ String
Renders a sparkline with the given data using the jquery flot plugin.
-
#google_report_tag(data, options = {}) ⇒ String
Renders a sparkline with the given data using the google drawing api.
-
#raphael_report_tag(data, options = {}, raphael_options = {}) ⇒ String
Renders a sparkline with the given data using Raphael.
Instance Method Details
#flot_report_tag(data, options = {}, flot_options = {}) ⇒ String
Renders a sparkline with the given data using the jquery flot plugin.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/saulabs/reportable/report_tag_helper.rb', line 139 def flot_report_tag(data, = {}, = {}) @__flot_report_tag_count ||= -1 @__flot_report_tag_count += 1 default_dom_id = "#{data.model_class_name.downcase}_#{data.report_name}#{@__flot_report_tag_count > 0 ? @__flot_report_tag_count : ''}" .reverse_merge!(Config..slice(:width, :height, :format)) .reverse_merge!(:dom_id => default_dom_id) .reverse_merge!(Config..except(:width, :height, :format)) %Q{<div id="#{[:dom_id]}" style="width:#{[:width]}px;height:#{[:height]}px;"></div> <script type="text\/javascript" charset="utf-8"> $(function() { var set = #{data.to_a.map{|d| d[1] }.to_json}, data = []; for (var i = 0; i < set.length; i++) { data.push([i, set[i]]); } $.plot($('##{[:dom_id]}'), [data], #{.to_json}); }); </script>} end |
#google_report_tag(data, options = {}) ⇒ String
Renders a sparkline with the given data using the google drawing api.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/saulabs/reportable/report_tag_helper.rb', line 38 def google_report_tag(data, = {}) .reverse_merge!(Config.) data = data.to_a.collect { |d| d[1] } labels = '' unless [:labels].empty? chxr = {} [: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=#{[:labels].map(&:to_s).join(',')}&chxr=#{[:labels].collect{|l| chxr[l]}.join('|')}" end title = '' unless [:title].blank? title = "&chtt=#{[:title]}" end image_tag( "http://chart.apis.google.com/chart?cht=ls&chs=#{[:width]}x#{[:height]}&chd=t:#{data.join(',')}&chco=#{[:line_color]}&chm=B,#{[:fill_color]},0,0,0&chls=1,0,0&chds=#{data.min},#{data.max}#{labels}#{title}", :alt => [:alt], :title => [:title] ) end |
#raphael_report_tag(data, options = {}, raphael_options = {}) ⇒ String
Renders a sparkline with the given data using Raphael.
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/saulabs/reportable/report_tag_helper.rb', line 84 def raphael_report_tag(data, = {}, = {}) @__raphael_report_tag_count ||= -1 @__raphael_report_tag_count += 1 default_dom_id = "#{data.model_class_name.downcase}_#{data.report_name}#{@__raphael_report_tag_count > 0 ? @__raphael_report_tag_count : ''}" .reverse_merge!(Config..slice(:width, :height, :format)) .reverse_merge!(:dom_id => default_dom_id) .reverse_merge!(Config..except(:width, :height, :format)) %Q{<div id="#{[:dom_id]}" style="width:#{[:width]}px;height:#{[:height]}px;"></div> <script type="text\/javascript" charset="utf-8"> var graph = Raphael('#{[:dom_id]}'); graph.g.linechart( -10, 4, #{[:width]}, #{[:height]}, #{(0..data.to_a.size).to_a.to_json}, #{data.to_a.map { |d| d[1].send(:eval, [:format]) }.to_json}, #{.to_json} ).hover(function() { this.disc = graph.g.disc(this.x, this.y, 3).attr({fill: "#{[:hover_fill_color]}", stroke: '#{[:hover_line_color]}' }).insertBefore(this); this.flag = graph.g.flag(this.x, this.y, this.value || "0", 0).insertBefore(this); if (this.x + this.flag.getBBox().width > this.paper.width) { this.flag.rotate(-180); this.flag.translate(-this.flag.getBBox().width, 0); this.flag.items[1].rotate(180); this.flag.items[1].translate(-5, 0); } }, function() { this.disc.remove(); this.flag.remove(); }); </script>} end |