Class: Quacky::LineGraphBuilder
- Inherits:
-
Object
- Object
- Quacky::LineGraphBuilder
- Defined in:
- lib/quacky/line_graph_builder.rb
Instance Method Summary collapse
-
#draw ⇒ Object
Return a content tag that can be selected by the client-side, and drawn on.
- #get_data ⇒ Object
-
#initialize(init_data = []) ⇒ LineGraphBuilder
constructor
A new instance of LineGraphBuilder.
Constructor Details
#initialize(init_data = []) ⇒ LineGraphBuilder
Returns a new instance of LineGraphBuilder.
6 7 8 |
# File 'lib/quacky/line_graph_builder.rb', line 6 def initialize(init_data = []) @data = init_data end |
Instance Method Details
#draw ⇒ Object
Return a content tag that can be selected by the client-side, and drawn on. The data attribute of the HTML tag is @data.
12 13 14 |
# File 'lib/quacky/line_graph_builder.rb', line 12 def draw "<div class='line-graph-container'><div class='y-axis'></div><div class='line-graph' data-chart='#{self.get_data}'></div></div>".html_safe end |
#get_data ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/quacky/line_graph_builder.rb', line 16 def get_data output = [] @data.each do |event| output << { x: event[:time].to_i, y: event[:data] } end output.to_json end |