class GoogleVisualr::BaseChart
Attributes
Holds a value only when generate_body or show_in_iruby method
is invoked in googlecharts.rb
@return [Array, Daru::DataFrame, Daru::Vector, Daru::View::Table
, String]
Data of GoogleVisualr Chart
@return [Hash] Various options created to facilitate more features.
These will be provided by the user
Public Instance Methods
Taken from `draw_js` in googlevisualr. While adding the listener,
the callback code (provided by the user) should be within the function.
@param element_id [String] The ID of the DIV element that the Google
Chart should be rendered in
@return [String] JavaScript function for rendering the chart
# File lib/daru/view/adapters/googlecharts/base_chart.rb, line 62 def draw_chart_js(element_id) js = '' js << "\n function #{chart_function_name(element_id)}() {" js << "\n #{@data_table.to_js}" js << "\n var chart = new google.#{chart_class}.#{chart_name}" js << "(document.getElementById('#{element_id}'));" js << add_listeners_js('chart') js << "\n chart.draw(data_table, #{js_parameters(@options)});" js << "\n };" js end
Generates JavaScript function for rendering the chart when data is URL of
the google spreadsheet
@param (see to_js_spreadsheet
) @return [String] JS function to render the google chart when data is URL
of the google spreadsheet
# File lib/daru/view/adapters/googlecharts/base_chart.rb, line 40 def draw_js_spreadsheet(data, element_id=SecureRandom.uuid) 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 chart = new google.#{chart_class}.#{chart_name}"\ "(document.getElementById('#{element_id}'));" js << add_listeners_js('chart') js << "\n chart.draw(data_table, #{js_parameters(@options)});" js << "\n };" js end
@see #GooleVisualr::DataTable.extract_option_view
# File lib/daru/view/adapters/googlecharts/base_chart.rb, line 16 def extract_option_view return js_parameters(@options.delete('view')) unless @options['view'].nil? '\'\'' end
@param element_id [String] The ID of the DIV element that the Google
ChartEditor should be rendered in
@return [String] Generates JavaScript for loading the charteditor package,
with callback to render ChartEditor
# File lib/daru/view/adapters/googlecharts/base_chart.rb, line 26 def load_js_chart_editor(element_id) js = '' js << "\n google.load('visualization', '#{version}', " js << " {packages: ['charteditor'], callback:" js << " #{chart_function_name(element_id)}});" js end