Class: GoogleVisualr::DataTable
- Inherits:
-
Object
- Object
- GoogleVisualr::DataTable
- Includes:
- Display, GenerateJavascript, ParamHelpers
- Defined in:
- lib/daru/view/adapters/googlecharts/google_visualr.rb,
lib/daru/view/adapters/googlecharts/data_table_iruby.rb
Instance Attribute Summary collapse
-
#data ⇒ Array, ...
Holds a value only when generate_body or show_in_iruby method is invoked in googlecharts.rb.
-
#listeners ⇒ Object
options will enable us to give some styling for table.
-
#options ⇒ Object
options will enable us to give some styling for table.
-
#user_options ⇒ Hash
Various options created to facilitate more features.
Attributes included from Display
Instance Method Summary collapse
-
#add_listener(event, callback) ⇒ Array
Adds a listener to the array of listeners.
- #chart_function_name(element_id) ⇒ Object
-
#draw_js(element_id) ⇒ String
Generates JavaScript function for rendering the google chart table.
-
#draw_js_spreadsheet(data, element_id) ⇒ String
Generates JavaScript function for rendering the google chart table when data is URL of the google spreadsheet.
-
#extract_option_view ⇒ String
Returns value of the view option provided by the user and ” otherwise.
- #google_table_version ⇒ Object
-
#initialize(options = {}) ⇒ DataTable
constructor
overiding the current initialze method (of the google_visualr).
-
#load_js(element_id) ⇒ String
Generates JavaScript for loading the appropriate Google Visualization package, with callback to render chart.
- #package_name ⇒ Object
-
#to_js_full_script(element_id = SecureRandom.uuid) ⇒ String
Generates JavaScript and renders the Google Chart DataTable in the final HTML output.
Methods included from GenerateJavascript
#add_listeners_js, #append_data, #draw_js_chart_editor, #draw_js_chart_wrapper, #draw_wrapper, #extract_chart_wrapper_options, #extract_export_png_code, #query_response_function_name, #save_chart_function_name, #to_js_chart_wrapper, #to_js_spreadsheet
Methods included from Display
#add_listener_to_chart, #export, #export_iruby, #extract_chart_wrapper_editor_js, #extract_export_code, #get_html, #get_html_chart_editor, #get_html_chart_wrapper, #get_html_spreadsheet, #show_in_iruby, #show_script, #show_script_with_script_tag, #to_html
Constructor Details
#initialize(options = {}) ⇒ DataTable
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 26 def initialize(={}) @cols = [] @rows = [] @listeners = [] @options = return if .empty? new_columns([:cols]) unless [:cols].nil? return if [:rows].nil? rows = [:rows] rows.each do |row| add_row(row[:c]) end end |
Instance Attribute Details
#data ⇒ Array, ...
Holds a value only when generate_body or show_in_iruby method
is invoked in googlecharts.rb
10 11 12 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 10 def data @data end |
#listeners ⇒ Object
options will enable us to give some styling for table. E.g. pagination, row numbers, etc
13 14 15 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 13 def listeners @listeners end |
#options ⇒ Object
options will enable us to give some styling for table. E.g. pagination, row numbers, etc
13 14 15 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 13 def @options end |
#user_options ⇒ Hash
Returns Various options created to facilitate more features. These will be provided by the user.
16 17 18 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 16 def @user_options end |
Instance Method Details
#add_listener(event, callback) ⇒ Array
Adds a listener to the array of listeners
48 49 50 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 48 def add_listener(event, callback) @listeners << {event: event.to_s, callback: callback} end |
#chart_function_name(element_id) ⇒ Object
67 68 69 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 67 def chart_function_name(element_id) "draw_#{element_id.tr('-', '_')}" end |
#draw_js(element_id) ⇒ String
Generates JavaScript function for rendering the google chart table.
109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 109 def draw_js(element_id) js = '' js << "\n function #{chart_function_name(element_id)}() {" js << "\n #{to_js}" js << "\n var table = new google.visualization.Table(" js << "document.getElementById('#{element_id}'));" js << add_listeners_js('table') js << "\n table.draw(data_table, #{js_parameters(@options)}); " js << "\n };" js end |
#draw_js_spreadsheet(data, element_id) ⇒ String
Generates JavaScript function for rendering the google chart table when
data is URL of the google spreadsheet
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 127 def draw_js_spreadsheet(data, element_id) js = '' js << "\n function #{chart_function_name(element_id)}() {" js << "\n var query = new google.visualization.Query('#{data}');" js << "\n query.send(#{query_response_function_name(element_id)});" js << "\n }" js << "\n function #{query_response_function_name(element_id)}(response) {" js << "\n var data_table = response.getDataTable();" js << "\n var table = new google.visualization.Table"\ "(document.getElementById('#{element_id}'));" js << add_listeners_js('table') js << "\n table.draw(data_table, #{js_parameters(@options)});" js << "\n };" js end |
#extract_option_view ⇒ String
Returns value of the view option provided by the user and ” otherwise
84 85 86 87 88 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 84 def extract_option_view return js_parameters(@options.delete(:view)) unless @options[:view].nil? '\'\'' end |
#google_table_version ⇒ Object
71 72 73 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 71 def google_table_version '1.0'.freeze end |
#load_js(element_id) ⇒ String
Generates JavaScript for loading the appropriate Google Visualization
package, with callback to render chart.
96 97 98 99 100 101 102 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 96 def load_js(element_id) js = '' js << "\n google.load('visualization', #{google_table_version}, " js << " {packages: ['#{package_name}'], callback:" js << " #{chart_function_name(element_id)}});" js end |
#package_name ⇒ Object
75 76 77 78 79 80 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 75 def package_name return 'table' unless && [:chart_class].to_s.capitalize == 'Charteditor' 'charteditor' end |
#to_js_full_script(element_id = SecureRandom.uuid) ⇒ String
Generates JavaScript and renders the Google Chart DataTable in the
final HTML output
58 59 60 61 62 63 64 65 |
# File 'lib/daru/view/adapters/googlecharts/data_table_iruby.rb', line 58 def to_js_full_script(element_id=SecureRandom.uuid) js = '' js << '\n<script type=\'text/javascript\'>' js << load_js(element_id) js << draw_js(element_id) js << '\n</script>' js end |