Class: Flotr::Data

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#dataObject

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].

Raises:

  • (ArgumentError)


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

#inspectObject

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 = ""
  OPTIONS.each do |o|
    if self.send o then
      options += "#{o}: \"#{self.send o}\", "
    end
  end
  "{ #{options}data: #{@data.inspect}}"
end