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

adding support for embedded functions inside the google visualization #74

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
10 changes: 9 additions & 1 deletion lib/google_visualr/base_chart.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ class BaseChart
include GoogleVisualr::Packages
include GoogleVisualr::ParamHelpers

attr_accessor :data_table, :listeners
attr_accessor :data_table, :listeners, :functions

def initialize(data_table, options={})
@data_table = data_table
send(:options=, options)
@listeners = []
@functions = []
end

def chart_name
Expand All @@ -32,6 +33,10 @@ def add_listener(event, callback)
@listeners << { :event => event.to_s, :callback => callback }
end

def add_function(callback)
@functions << { :callback => callback }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

end

# Generates JavaScript and renders the Google Chart in the final HTML output.
#
# Parameters:
Expand Down Expand Up @@ -66,6 +71,9 @@ def draw_js(element_id)
js << "\n google.visualization.events.addListener(chart, '#{listener[:event]}', #{listener[:callback]});"
end
js << "\n chart.draw(data_table, #{js_parameters(@options)});"
@functions.each do |efunction|
js << "\n\n #{efunction[:callback]}"
end
js << "\n };"
js
end
Expand Down
8 changes: 8 additions & 0 deletions spec/google_visualr/base_chart_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@
@chart.listeners.should == [{ :event => "select", :callback => "function() {test_event(chart);}" }]
end
end

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace detected.

describe '#add_function' do
it 'adds to embedded functions array' do
@chart.add_function("function() {alert(\"Nothing to see here\");}")
@chart.functions.should == [{ :callback => "function()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.
Trailing whitespace detected.

{alert(\"Nothing to see here\");}" }]
end
end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 52, 2 is not aligned with describe "#add_function" do at 47, 4


describe "#to_js" do
it "generates JS" do
Expand Down