Class: Flotr::Data
- Inherits:
-
Object
- Object
- Flotr::Data
- Defined in:
- lib/flotr.rb
Overview
Series to be plotted are instance of the Flotr::Data class. Initialize a new
Data object with a set of OPTIONS, then add points with the << method.
Constant Summary collapse
- OPTIONS =
[:color, :label, :lines, :bars, :points, :hints, :shadowSize]
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
-
#<<(other) ⇒ Object
Adds other to the data array.
-
#initialize(opts = {}) ⇒ Data
constructor
Creates a new serie of points.
-
#inspect ⇒ Object
Provides a JavaScript-formatted description of the data array.
Constructor Details
#initialize(opts = {}) ⇒ Data
Creates a new serie of points. opts is a Hash with a subset of the keys
given in OPTIONS.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/flotr.rb', line 38 def initialize(opts={}) @data = [] opts.each do |k,v| if OPTIONS.include? k self.send(k.to_s+'=', v) else warn "Warning: data option '#{k}' does not exist, ignored" end end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
32 33 34 |
# File 'lib/flotr.rb', line 32 def data @data end |
Instance Method Details
#<<(other) ⇒ Object
Adds other to the data array. other must be a two element array like [0,0].
65 66 67 68 69 70 |
# File 'lib/flotr.rb', line 65 def <<(other) other = other.to_a raise ArgumentError unless other[0].kind_of? Numeric raise ArgumentError unless other[1].kind_of? Numeric @data << other end |
#inspect ⇒ Object
Provides a JavaScript-formatted description of the data array.
52 53 54 55 56 57 58 59 60 |
# File 'lib/flotr.rb', line 52 def inspect = "" OPTIONS.each do |o| if self.send o then += "#{o}: \"#{self.send o}\", " end end "{ #{}data: #{@data.inspect}}" end |