Class: Grapher::Graph

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::JavaScriptHelper, ActionView::Helpers::TagHelper
Defined in:
lib/grapher/graph.rb,
app/helpers/grapher/application_helper.rb

Instance Method Summary collapse

Constructor Details

#initialize(time_units, options, block) ⇒ Graph

Returns a new instance of Graph.



5
6
7
# File 'lib/grapher/graph.rb', line 5

def initialize(block)
  block.call(self)
end

Instance Method Details

#add_missing_timesObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/helpers/grapher/application_helper.rb', line 56

def add_missing_times
  start_date = ''
  end_date = ''
  @data.each do |data|
    start_date = Time.parse(data.keys[0]) if !start_date.present? || start_date < Time.parse(data.keys[0])
    end_date = Time.parse(data.keys[data.count-1]) if !end_date.present? || end_date > Time.parse(data.keys[data.count-1])
  end

  @data.each_with_index do |data, index|
    dates = {}
    current_date = start_date
    loop do
      dates[current_date.strftime(@strf)] = data[current_date.strftime(@strf)] || 0
      current_date += 1.send(@time_units.singularize.to_sym)

      break if current_date > end_date || dates.count > 999
    end
    break if dates.count > 999
    @data[index] = dates
  end
end

#htmlObject



13
14
15
16
# File 'lib/grapher/graph.rb', line 13

def html
  div_class = rand(9999999)
  (:div, 'test', :class => div_class)
end

#line(relation, options = {}) ⇒ Object



9
10
11
# File 'lib/grapher/graph.rb', line 9

def line(a)

end