Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Cervajz/google_visualr in…
Browse files Browse the repository at this point in the history
…to Cervajz-master

Conflicts:
	lib/google_visualr/base_chart.rb
  • Loading branch information
winston authored and Adam Scott and Winston Teo committed Aug 22, 2013
2 parents f89364c + 271a98e commit e555488
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/google_visualr/base_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ def chart_name
class_name
end

def chart_function_name(element_id)
"draw_#{element_id.gsub('-', '_')}"
end

def options
@options
end
Expand All @@ -32,20 +36,22 @@ def add_listener(event, callback)
#
# Parameters:
# *div_id [Required] The ID of the DIV element that the Google Chart should be rendered in.

def to_js(element_id)
js = "\n<script type='text/javascript'>"
js << "\n google.load('visualization','1', {packages: ['#{package_name}'], callback: function() {"
js << "\n google.load('visualization','1', {packages: ['#{package_name}']});"
js << "\n google.setOnLoadCallback(#{chart_function_name(element_id)});"
js << "\n function #{chart_function_name(element_id)}() {"
js << "\n #{@data_table.to_js}"
js << "\n var chart = new google.visualization.#{chart_name}(document.getElementById('#{element_id}'));"
@listeners.each do |listener|
js << "\n google.visualization.events.addListener(chart, '#{listener[:event]}', #{listener[:callback]});"
end
js << "\n chart.draw(data_table, #{js_parameters(@options)});"
js << "\n }});"
js << "\n };"
js << "\n</script>"
js
end

end

end

0 comments on commit e555488

Please sign in to comment.