Class: ReportBuilder::Graph::HtmlJqplot
- Inherits:
-
ElementBuilder
- Object
- ElementBuilder
- ReportBuilder::Graph::HtmlJqplot
- Defined in:
- lib/reportbuilder/graph/html_jqplot.rb
Instance Method Summary collapse
- #axes_defaults ⇒ Object
- #generate ⇒ Object
- #grid ⇒ Object
- #hash_to_camel(h) ⇒ Object
- #jqplot_options ⇒ Object
- #legend ⇒ Object
- #series_defaults ⇒ Object
- #series_js(in_opt) ⇒ Object
-
#series_options ⇒ Object
Transform data options on jqPlot ones.
- #set_color(t, out_opt, v) ⇒ Object
- #set_type(opt, v) ⇒ Object
- #to_camel(k) ⇒ Object
- #xaxis ⇒ Object
- #yaxis ⇒ Object
Methods inherited from ElementBuilder
Constructor Details
This class inherits a constructor from ReportBuilder::ElementBuilder
Instance Method Details
#axes_defaults ⇒ Object
52 53 54 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 52 def axes_defaults hash_to_camel(@element.axes_defaults) end |
#generate ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 5 def generate() @builder.js(ReportBuilder::DATA_DIR+"/jqplot/excanvas.min.js") @builder.js(ReportBuilder::DATA_DIR+"/jqplot/jquery-1.4.2.min.js") @builder.js(ReportBuilder::DATA_DIR+"/jqplot/jquery.jqplot.min.js") @builder.css(ReportBuilder::DATA_DIR+"/jqplot/jquery.jqplot.css") anchor=@builder.graph_entry(@element.name) out="<a name='#{anchor}'></a><div id='graph_#{anchor}' style='width:#{@element.width}px; height:#{@element.height}px'> </div>" out+=" <script> $.jqplot('graph_#{anchor}', #{@builder.parse_js(@element.series_data)}, "+@builder.parse_js()+"); </script>" @builder.html(out) end |
#grid ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 69 def grid replace={:show=>:drawGridLine, :color=>:gridLineColor, :background_color=>:background} out=Hash.new @element.grid.each do |k,v| if replace.include? k out[replace[k]]=v else out[to_camel(k)]=v end end out end |
#hash_to_camel(h) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 81 def hash_to_camel(h) out=Hash.new h.each do |k,v| out[to_camel(k)]=v end out end |
#jqplot_options ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 21 def opts=Hash.new opts[:title]=@element.title opts[:series]= opts[:axesDefaults]=axes_defaults if @element.axes_defaults.size>0 if @element.xaxis.size>0 or @element.yaxis.size>0 opts[:axes]={:xaxis=>xaxis, :yaxis=>yaxis} end opts[:seriesDefaults]= series_defaults if @element.series_defaults.size>0 opts[:legend]=legend if @element.legend.size>0 opts[:grid]=grid if @element.grid.size>0 opts end |
#legend ⇒ Object
61 62 63 64 65 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 61 def legend lo=@element.legend lo[:location]=lo.delete(:position) if lo[:position] hash_to_camel(lo) end |
#series_defaults ⇒ Object
66 67 68 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 66 def series_defaults series_js(@element.series_defaults) end |
#series_js(in_opt) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 91 def series_js(in_opt) out_opt=Hash.new out_opt[:markerOptions]=Hash.new out_opt[:rendererOptions]=Hash.new in_opt.each_pair do |k,v| case k when :type set_type(out_opt, v) when :lines out_opt[:showLines]=v[:show] if v[:show] v.each do |k1,v1| out_opt[to_camel(k1)]=v1 end when :markers out_opt[:showMarker]=v[:show] if v[:show] v.each do |k1,v1| out_opt[:markerOptions][to_camel(k1)]=v1 end when :bars v.each do |k1,v1| k1=("bar_"+k1.to_s) if [:padding, :margin, :direction, :width].include? k1 out_opt[:rendererOptions][to_camel(k1)]=v1 end when :color if in_opt[:type] set_color(in_opt[:type], out_opt,v) else out_opt[k]=v end else out_opt[k]=v end end out_opt end |
#series_options ⇒ Object
Transform data options on jqPlot ones
138 139 140 141 142 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 138 def @element..map do |in_opt| series_js(in_opt) end end |
#set_color(t, out_opt, v) ⇒ Object
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 126 def set_color(t,out_opt,v) case t when :line out_opt[:color]=v when :scatter out_opt[:markerOptions][:color]=v when :bar out_opt[:rendererOptions][:color]=v end end |
#set_type(opt, v) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 35 def set_type(opt,v) case v when :line when :pie @builder.js(ReportBuilder::DATA_DIR+"/jqplot/plugins/jqplot.pieRenderer.min.js") opt[:renderer]="$.jqplot.PieRenderer".to_sym when :scatter opt[:showLine]=false opt[:showMarker]=true when :bar @builder.js(ReportBuilder::DATA_DIR+"/jqplot/plugins/jqplot.categoryAxisRenderer.min.js") @builder.js(ReportBuilder::DATA_DIR+"/jqplot/plugins/jqplot.barRenderer.min.js") opt[:renderer]="$.jqplot.BarRenderer".to_sym else raise "Type doesn't exists" end end |
#to_camel(k) ⇒ Object
88 89 90 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 88 def to_camel(k) k.to_s.gsub(/_([a-z])/) {|s| s.upcase[1,1]}.to_sym end |
#xaxis ⇒ Object
55 56 57 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 55 def xaxis hash_to_camel(@element.xaxis) end |
#yaxis ⇒ Object
58 59 60 |
# File 'lib/reportbuilder/graph/html_jqplot.rb', line 58 def yaxis hash_to_camel(@element.yaxis) end |