Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Minor fixes. Zero values aren't drawn.

  • Loading branch information...
commit d5054d4298d144114c279e6e722e464336e497c9 1 parent ac77881
Geir Freysson geirfreysson authored

Showing 1 changed file with 25 additions and 7 deletions. Show diff stats Hide diff stats

  1. +25 7 lib/google_visualization.rb
32 lib/google_visualization.rb
@@ -16,6 +16,7 @@ def initialize(view_instance, collection, options={}, *args)
16 16 @helpers = view_instance
17 17 @collection = collection
18 18 @collection_methods = collection_methods
  19 + @draw_zeros = options.delete(:draw_zeros) || false
19 20 @options = options.reverse_merge({:width => 600, :height => 300})
20 21 @columns = []
21 22 @rows = []
@@ -160,7 +161,8 @@ def render_data
160 161 add_row(row_count, 0, date)
161 162 @lines.each do |line_hash|
162 163 if line_hash[:collection][index]
163   - add_row(row_count, line_hash[:column_start], line_hash[:collection][index].send(line_hash[:method_hash][:value]))
  164 + add_row(row_count, line_hash[:column_start], get_value(line_hash,index))
  165 + #add_row(row_count, line_hash[:column_start], line_hash[:collection][index].send(line_hash[:method_hash][:value]))
164 166 add_row(row_count, line_hash[:column_start]+1, line_hash[:collection][index].send(line_hash[:method_hash][:title])) if line_hash[:method_hash][:title] and line_hash[:collection][index].send(line_hash[:method_hash][:title])
165 167 add_row(row_count, line_hash[:column_start]+2, line_hash[:collection][index].send(line_hash[:method_hash][:notes])) if line_hash[:method_hash][:notes] and line_hash[:collection][index].send(line_hash[:method_hash][:notes])
166 168 else
@@ -172,6 +174,19 @@ def render_data
172 174 @data
173 175 end
174 176
  177 + def get_value(line_hash,index)
  178 + if line_hash[:method_hash].empty?
  179 + result = line_hash[:collection][index]
  180 + else
  181 + result =line_hash[:collection][index].send(line_hash[:method_hash][:value])
  182 + end
  183 + if !@draw_zeroes && result.to_i == 0
  184 + nil
  185 + else
  186 + result
  187 + end
  188 + end
  189 +
175 190 def render
176 191 render_head + render_headings + "#{@name}_data.addRows(#{@row_length});\n" + render_data + render_foot
177 192 end
@@ -195,8 +210,7 @@ def add_row(row, column, value)
195 210 @data += "#{@name}_data.setValue(#{row}, #{column}, #{Mappings.ruby_to_javascript_object(value)});\n"
196 211 end
197 212
198   - def add_line(title, collection, method_hash)
199   - required_methods_supplied? method_hash
  213 + def add_line(title, collection, method_hash={})
200 214 collection.size > @row_length ? @row_length = collection.size : @row_length
201 215 @lines.push({:title => title, :collection => collection,:method_hash => method_hash})
202 216 end
@@ -227,9 +241,13 @@ def self.ruby_to_javascript_object(value)
227 241 :String => lambda {|v| "'#{v}'"},
228 242 :Date => lambda {|v| "new Date(#{[v.year,(v.month.to_i - 1),v.day].join(',')})"},
229 243 :Fixnum => lambda {|v| v },
230   - :Float => lambda {|v| v }
  244 + :Float => lambda {|v| v }
231 245 }
232   - value_hash[value.class.to_s.to_sym].call(value)
  246 + if value.nil?
  247 + "null"
  248 + else
  249 + value_hash[value.class.to_s.to_sym].call(value)
  250 + end
233 251 end
234 252
235 253 def self.columns
@@ -305,8 +323,8 @@ def chart_for(google_chart_name,dates,options={}, *args, &block)
305 323 chart = Chart.new(self,dates,options)
306 324 chart.google_chart_name = google_chart_name
307 325 yield chart
308   - chart.render
309   -
  326 + #chart.render
  327 + concat(chart.render)
310 328 end
311 329
312 330 end

0 comments on commit d5054d4

Please sign in to comment.
Something went wrong with that request. Please try again.