| Adding raphael_report_tag function since graphico is really slow - reportable -… | |
| Log | |
| Files | |
| Refs | |
| README | |
| --- | |
| commit d16881167c82bbcbeff255459571a6992f92b670 | |
| parent a74be968aec5e03c92624882e4bb0374116f2701 | |
| Author: Martin Kavalar <[email protected]> | |
| Date: Thu, 29 Apr 2010 19:00:51 +0200 | |
| Adding raphael_report_tag function since graphico is really slow | |
| Diffstat: | |
| M lib/saulabs/reportable/config.rb | 10 ++++++++++ | |
| M lib/saulabs/reportable/report_tag_… | 30 +++++++++++++++++++++++++++… | |
| 2 files changed, 39 insertions(+), 1 deletion(-) | |
| --- | |
| diff --git a/lib/saulabs/reportable/config.rb b/lib/saulabs/reportable/config.rb | |
| @@ -40,6 +40,16 @@ module Saulabs | |
| :curve_amount => 1, | |
| :focus_hint => false | |
| } | |
| + | |
| + mattr_accessor :raphael_options | |
| + | |
| + @@raphael_options = { | |
| + :width => 300, | |
| + :height => 100, | |
| + :dom_id => nil, | |
| + :format => 'to_i', | |
| + :shade => true | |
| + } | |
| end | |
| diff --git a/lib/saulabs/reportable/report_tag_helper.rb b/lib/saulabs/reportab… | |
| @@ -86,7 +86,7 @@ module Saulabs | |
| options.reverse_merge!(Config.grafico_options.slice(:width, :height, :… | |
| options.reverse_merge!(:dom_id => "#{data.model_name.downcase}_#{data.… | |
| grafico_options.reverse_merge!(Config.grafico_options.except(:width, :… | |
| - %Q{<div id="#{options[:dom_id] || "reportable_#{Time.now}"}" style="wi… | |
| + %Q{<div id="#{options[:dom_id]}" style="width: #{options[:width]}px; h… | |
| <script type="text/javascript" charset="utf-8"> | |
| new Grafico.AreaGraph( | |
| $('#{options[:dom_id]}'), | |
| @@ -94,6 +94,34 @@ module Saulabs | |
| #{grafico_options.to_json}); | |
| </script>} | |
| end | |
| + | |
| + def raphael_report_tag(data, options = {}, raphael_options = {}) | |
| + options.reverse_merge!(Config.raphael_options.slice(:width, :height, :… | |
| + options.reverse_merge!(:dom_id => "#{data.model_name.downcase}_#{data.… | |
| + raphael_options.reverse_merge!(Config.raphael_options.except(:width, :… | |
| + %Q{<div id="#{options[:dom_id]}" style="width:#{options[:width]}px;hei… | |
| + <script type="text/javascript"> | |
| + var graph = Raphael('#{options[:dom_id]}'); | |
| + graph.g.linechart( | |
| + -10, 4, #{options[:width]}, #{options[:height]}, | |
| + #{(0..data.size).to_a.to_json}, | |
| + #{data.map{|d| eval options[:format], d[1].send(:binding) }.to_jso… | |
| + #{raphael_options.to_json} | |
| + ).hover(function() { | |
| + this.disc = graph.g.disc(this.x, this.y, 3).attr({fill: "#2F69BF",… | |
| + this.flag = graph.g.flag(this.x, this.y, this.value || "0", 0).ins… | |
| + 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 | |
| end | |
| end |