Class: Chart

Inherits:
Object
  • Object
show all
Defined in:
app/models/chart.rb

Overview

class to encapsulate the definition of a chart in browser

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(div, lines, options = {}) ⇒ Chart

constructor taking a div id and an array of Lines options should contain :xaxis with :method :xaxis may also contain :min and :max



8
9
10
11
12
# File 'app/models/chart.rb', line 8

def initialize( div, lines, options = {} )
  @div = div
  @lines = lines
  @options = options
end

Instance Attribute Details

#divObject (readonly)

Returns the value of attribute div.



3
4
5
# File 'app/models/chart.rb', line 3

def div
  @div
end

#linesObject (readonly)

Returns the value of attribute lines.



3
4
5
# File 'app/models/chart.rb', line 3

def lines
  @lines
end

#optionsObject (readonly)

Returns the value of attribute options.



3
4
5
# File 'app/models/chart.rb', line 3

def options
  @options
end

Class Method Details

.value_methods(charts) ⇒ Object

class method, given an array of Charts, returns an array of unique value methods for the lines



20
21
22
# File 'app/models/chart.rb', line 20

def self.value_methods( charts )
  charts.map { |c| ChartLine.value_methods( c.lines ) }.flatten.uniq
end

Instance Method Details

#as_hashObject

returns the values that are to be passed to the client browser, as a hash, inluding the lines



15
16
17
# File 'app/models/chart.rb', line 15

def as_hash
  {:div => @div, :lines => @lines.map { |l| l.as_hash }, :options => @options }
end