Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make graph variables accesible with the window scope #101

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/google_visualr/base_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ def chart_function_name(element_id)
"draw_#{element_id.gsub('-', '_')}"
end

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

def options
@options
end
Expand Down Expand Up @@ -91,7 +95,12 @@ def draw_js(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 options = #{js_parameters(@options)}"
js << "\n chart.draw(data_table, options);"
js << "\n window.formatter_#{global_name(element_id)} = formatter;"
js << "\n window.options_#{global_name(element_id)} = options;"
js << "\n window.data_table_#{global_name(element_id)} = data_table;"
js << "\n window.#{global_name(element_id)} = chart;"
js << "\n };"
js
end
Expand Down