From 50f8cf5bd8d03e2b501bfec713fb788a3ea3125d Mon Sep 17 00:00:00 2001 From: Robert Hall Date: Thu, 12 Jun 2014 23:22:03 -0400 Subject: [PATCH 1/6] adding support for embedded functions inside the google visualization routine + specs --- lib/google_visualr/base_chart.rb | 10 +++++++++- spec/google_visualr/base_chart_spec.rb | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/google_visualr/base_chart.rb b/lib/google_visualr/base_chart.rb index cf7743d..9401b47 100644 --- a/lib/google_visualr/base_chart.rb +++ b/lib/google_visualr/base_chart.rb @@ -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 @@ -32,6 +33,10 @@ def add_listener(event, callback) @listeners << { :event => event.to_s, :callback => callback } end + def add_function(callback) + @functions << {:callback=> callback} + end + # Generates JavaScript and renders the Google Chart in the final HTML output. # # Parameters: @@ -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 diff --git a/spec/google_visualr/base_chart_spec.rb b/spec/google_visualr/base_chart_spec.rb index cd87413..95046d3 100644 --- a/spec/google_visualr/base_chart_spec.rb +++ b/spec/google_visualr/base_chart_spec.rb @@ -43,6 +43,14 @@ @chart.listeners.should == [{ :event => "select", :callback => "function() {test_event(chart);}" }] end end + + 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() {alert(\"Nothing to see here\");}"}] + end + end + describe "#to_js" do it "generates JS" do From 51c2fa79b103aa2e7309a84a2078f03e0cd32408 Mon Sep 17 00:00:00 2001 From: Robert Hall Date: Fri, 13 Jun 2014 09:54:32 -0400 Subject: [PATCH 2/6] Made changes to correct HoundCI suggestions --- lib/google_visualr/base_chart.rb | 2 +- spec/google_visualr/base_chart_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/google_visualr/base_chart.rb b/lib/google_visualr/base_chart.rb index 9401b47..384674b 100644 --- a/lib/google_visualr/base_chart.rb +++ b/lib/google_visualr/base_chart.rb @@ -34,7 +34,7 @@ def add_listener(event, callback) end def add_function(callback) - @functions << {:callback=> callback} + @functions << { :callback=> callback } end # Generates JavaScript and renders the Google Chart in the final HTML output. diff --git a/spec/google_visualr/base_chart_spec.rb b/spec/google_visualr/base_chart_spec.rb index 95046d3..7ebe973 100644 --- a/spec/google_visualr/base_chart_spec.rb +++ b/spec/google_visualr/base_chart_spec.rb @@ -44,10 +44,10 @@ end end - describe "#add_function" do - it "adds to embedded functions array" do + 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() {alert(\"Nothing to see here\");}"}] + @chart.functions.should == [{ :callback => "function() {alert(\"Nothing to see here\");}" }] end end From cc7734ea32d50edd70ce6a1db67897aa172c520e Mon Sep 17 00:00:00 2001 From: golsombe Date: Fri, 13 Jun 2014 10:06:53 -0400 Subject: [PATCH 3/6] Second pass to correct HoundCI suggestions --- lib/google_visualr/base_chart.rb | 2 +- spec/google_visualr/base_chart_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/google_visualr/base_chart.rb b/lib/google_visualr/base_chart.rb index 384674b..643d99b 100644 --- a/lib/google_visualr/base_chart.rb +++ b/lib/google_visualr/base_chart.rb @@ -34,7 +34,7 @@ def add_listener(event, callback) end def add_function(callback) - @functions << { :callback=> callback } + @functions << { :callback => callback } end # Generates JavaScript and renders the Google Chart in the final HTML output. diff --git a/spec/google_visualr/base_chart_spec.rb b/spec/google_visualr/base_chart_spec.rb index 7ebe973..2705aa0 100644 --- a/spec/google_visualr/base_chart_spec.rb +++ b/spec/google_visualr/base_chart_spec.rb @@ -47,11 +47,11 @@ 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() {alert(\"Nothing to see here\");}" }] + @chart.functions.should == [{ :callback => "function() + {alert(\"Nothing to see here\");}" }] end end - describe "#to_js" do it "generates JS" do js = @chart.to_js("body") From 609a6b7bc77880a4b9b4bf539f0f80bc65142e41 Mon Sep 17 00:00:00 2001 From: golsombe Date: Fri, 13 Jun 2014 10:20:04 -0400 Subject: [PATCH 4/6] Third pass corrected ruby syntax and hopefully line-to-long Hound complaint --- lib/google_visualr/base_chart.rb | 2 +- spec/google_visualr/base_chart_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/google_visualr/base_chart.rb b/lib/google_visualr/base_chart.rb index 643d99b..5ea2e11 100644 --- a/lib/google_visualr/base_chart.rb +++ b/lib/google_visualr/base_chart.rb @@ -34,7 +34,7 @@ def add_listener(event, callback) end def add_function(callback) - @functions << { :callback => callback } + @functions << { callback: callback } end # Generates JavaScript and renders the Google Chart in the final HTML output. diff --git a/spec/google_visualr/base_chart_spec.rb b/spec/google_visualr/base_chart_spec.rb index 2705aa0..a42e65d 100644 --- a/spec/google_visualr/base_chart_spec.rb +++ b/spec/google_visualr/base_chart_spec.rb @@ -47,8 +47,8 @@ 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() - {alert(\"Nothing to see here\");}" }] + @chart.functions.should == [{ callback: "function() + {alert(\"Nothing to see here\");}" }] end end From 4e48588c2f084302160499e64da535fee90c268a Mon Sep 17 00:00:00 2001 From: golsombe Date: Fri, 13 Jun 2014 11:26:47 -0400 Subject: [PATCH 5/6] Adding support for Calendar Chart --- lib/google_visualr.rb | 1 + lib/google_visualr/interactive/calendar_chart.rb | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 lib/google_visualr/interactive/calendar_chart.rb diff --git a/lib/google_visualr.rb b/lib/google_visualr.rb index 626f747..c09c01d 100644 --- a/lib/google_visualr.rb +++ b/lib/google_visualr.rb @@ -38,6 +38,7 @@ require "#{lib_path}/google_visualr/interactive/motion_chart" require "#{lib_path}/google_visualr/interactive/org_chart" require "#{lib_path}/google_visualr/interactive/timeline" +require "#{lib_path}/google_visualr/interactive/calendar_chart" # Image Charts require "#{lib_path}/google_visualr/image/spark_line" diff --git a/lib/google_visualr/interactive/calendar_chart.rb b/lib/google_visualr/interactive/calendar_chart.rb new file mode 100644 index 0000000..2dc9db9 --- /dev/null +++ b/lib/google_visualr/interactive/calendar_chart.rb @@ -0,0 +1,11 @@ +module GoogleVisualr + module Interactive + + # https://developers.google.com/chart/interactive/docs/gallery/timeline + class CalendarChart < BaseChart + # For Configuration Options, please refer to: + # https://developers.google.com/chart/interactive/docs/gallery/calendar#Overview + end + + end +end From 6cc866dffa3ecb2c18f761772c8cb6f0acaab09e Mon Sep 17 00:00:00 2001 From: golsombe Date: Fri, 13 Jun 2014 13:17:08 -0400 Subject: [PATCH 6/6] Had to rename the calendar_chart back to calendar becuase of the package_name syntax --- lib/google_visualr.rb | 2 +- .../interactive/{calendar_chart.rb => calendar.rb} | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename lib/google_visualr/interactive/{calendar_chart.rb => calendar.rb} (88%) diff --git a/lib/google_visualr.rb b/lib/google_visualr.rb index c09c01d..3415433 100644 --- a/lib/google_visualr.rb +++ b/lib/google_visualr.rb @@ -38,7 +38,7 @@ require "#{lib_path}/google_visualr/interactive/motion_chart" require "#{lib_path}/google_visualr/interactive/org_chart" require "#{lib_path}/google_visualr/interactive/timeline" -require "#{lib_path}/google_visualr/interactive/calendar_chart" +require "#{lib_path}/google_visualr/interactive/calendar" # Image Charts require "#{lib_path}/google_visualr/image/spark_line" diff --git a/lib/google_visualr/interactive/calendar_chart.rb b/lib/google_visualr/interactive/calendar.rb similarity index 88% rename from lib/google_visualr/interactive/calendar_chart.rb rename to lib/google_visualr/interactive/calendar.rb index 2dc9db9..2460f1d 100644 --- a/lib/google_visualr/interactive/calendar_chart.rb +++ b/lib/google_visualr/interactive/calendar.rb @@ -2,7 +2,7 @@ module GoogleVisualr module Interactive # https://developers.google.com/chart/interactive/docs/gallery/timeline - class CalendarChart < BaseChart + class Calendar < BaseChart # For Configuration Options, please refer to: # https://developers.google.com/chart/interactive/docs/gallery/calendar#Overview end