Module: FlotViewHelpers

Defined in:
lib/flot/rails/plus/flot_view_helpers.rb

Instance Method Summary collapse

Instance Method Details

#build_gon(chart_sets, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/flot/rails/plus/flot_view_helpers.rb', line 16

def build_gon( chart_sets, options = {} )
  gon.url = options[:url]
  gon.refresh = options[:refresh]
  gon.chart_sets = chart_sets.map { |c| c.as_hash }
  
  # generate gon data that will appear in the view
  include_gon
end

#build_json(chart_sets, options) ⇒ Object



25
26
27
28
# File 'lib/flot/rails/plus/flot_view_helpers.rb', line 25

def build_json( chart_sets, options )
  json = options[:json]
  json.chart_sets chart_sets.map{ |c| c.as_hash(:with_charts => false) } 
end

#setup_flot_view(chart_sets, options = {}) ⇒ Object

called by application to setup the view for display or the json for callback data for html leave options blank, for json pass the json object from the view builder as :json => json to enable that also pass :url as the full url to use for json callback in the initial call from the view, in which case samples may be nil as they will be picked up via json call after initial view has been rendered.



8
9
10
11
12
13
14
# File 'lib/flot/rails/plus/flot_view_helpers.rb', line 8

def setup_flot_view( chart_sets, options = {} )
  if options[:json]
    build_json chart_sets, options
  else
    build_gon chart_sets, options
  end
end