Adding raphael_report_tag function since graphico is really slow - reportable - Fork of reportable required by WarVox, from hdm/reportable.
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) commit d16881167c82bbcbeff255459571a6992f92b670
(DIR) parent a74be968aec5e03c92624882e4bb0374116f2701
(HTM) Author: Martin Kavalar <martin@sauspiel.de>
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(-)
---
(DIR) 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
(DIR) diff --git a/lib/saulabs/reportable/report_tag_helper.rb b/lib/saulabs/reportable/report_tag_helper.rb
@@ -86,7 +86,7 @@ module Saulabs
options.reverse_merge!(Config.grafico_options.slice(:width, :height, :format))
options.reverse_merge!(:dom_id => "#{data.model_name.downcase}_#{data.report_name}")
grafico_options.reverse_merge!(Config.grafico_options.except(:width, :height, :format))
- %Q{<div id="#{options[:dom_id] || "reportable_#{Time.now}"}" style="width: #{options[:width]}px; height: #{options[:height]}px;"></div>
+ %Q{<div id="#{options[:dom_id]}" style="width: #{options[:width]}px; height: #{options[:height]}px;"></div>
<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, :format))
+ options.reverse_merge!(:dom_id => "#{data.model_name.downcase}_#{data.report_name}")
+ raphael_options.reverse_merge!(Config.raphael_options.except(:width, :height, :format))
+ %Q{<div id="#{options[:dom_id]}" style="width:#{options[:width]}px;height:#{options[:height]}px;"></div>
+ <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_json},
+ #{raphael_options.to_json}
+ ).hover(function() {
+ this.disc = graph.g.disc(this.x, this.y, 3).attr({fill: "#2F69BF", stroke: '#2F69BF' }).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
end
end