diff --git a/lib/google_visualr.rb b/lib/google_visualr.rb index 626f747..3415433 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" # Image Charts require "#{lib_path}/google_visualr/image/spark_line" diff --git a/lib/google_visualr/base_chart.rb b/lib/google_visualr/base_chart.rb index cf7743d..5ea2e11 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/lib/google_visualr/interactive/calendar.rb b/lib/google_visualr/interactive/calendar.rb new file mode 100644 index 0000000..2460f1d --- /dev/null +++ b/lib/google_visualr/interactive/calendar.rb @@ -0,0 +1,11 @@ +module GoogleVisualr + module Interactive + + # https://developers.google.com/chart/interactive/docs/gallery/timeline + class Calendar < BaseChart + # For Configuration Options, please refer to: + # https://developers.google.com/chart/interactive/docs/gallery/calendar#Overview + end + + end +end diff --git a/spec/google_visualr/base_chart_spec.rb b/spec/google_visualr/base_chart_spec.rb index cd87413..a42e65d 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