Module: Bitcharts::ApplicationHelper

Defined in:
app/helpers/bitcharts/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#bitchart(keys, from: 7.days.ago, to: 0.days.ago, interval: '1 day', type: 'line', colors: nil, legend: true, **options) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/bitcharts/application_helper.rb', line 3

def bitchart(keys, from: 7.days.ago, to: 0.days.ago, interval: '1 day', type: 'line', colors: nil, legend: true, **options)
  keys     = keys.join(' ')   if keys.respond_to?(:join)
  from     = from.to_date     if from.respond_to?(:to_date)
  to       = to.to_date       if to.respond_to?(:to_date)
  interval = interval.inspect if interval.is_a?(ActiveSupport::Duration)
  colors   = colors.join(' ') if keys.respond_to?(:join)
  legend   = legend = 'on'    if legend == true
  legend   = legend = 'off'   if legend == false
  data     = {
    bitchart:          keys,
    bitchart_type:     type,
    bitchart_from:     from.try(:to_s),
    bitchart_to:       to.try(:to_s),
    bitchart_interval: interval,
    bitchart_colors:   colors,
    bitchart_legend:   legend,
  }
  tag(:canvas, options.merge(data: data.compact))
end