class Prawn::Graph::Series

A Prawn::Graph::Series represents a series of data which are to be plotted on a chart.

Constants

DEFAULT_OPTIONS

Attributes

options[RW]
uuid[RW]
values[RW]

Public Class Methods

new(values = [], options = {}) click to toggle source
# File lib/prawn/graph/series.rb, line 20
def initialize(values = [], options = {})
  @values   = values
  @options  = OpenStruct.new(DEFAULT_OPTIONS.merge(options))
  @uuid = SecureRandom.uuid
end

Public Instance Methods

<<(value) click to toggle source

@param value [Object] a value to be added to the series. Must be of the same kind as other values. @return [Array] The modified values object.

# File lib/prawn/graph/series.rb, line 41
def <<(value)
  @values << value
end
avg() click to toggle source

@return [Numeric] The average value stored in the values of this Series.

# File lib/prawn/graph/series.rb, line 63
def avg
  if size > 0
    @values.inject(:+) / size
  else
    0
  end
end
mark_average?() click to toggle source
# File lib/prawn/graph/series.rb, line 77
def mark_average?
  options.mark_average == true
end
mark_maximum?() click to toggle source
# File lib/prawn/graph/series.rb, line 85
def mark_maximum?
  options.mark_maximum == true
end
mark_minimum?() click to toggle source
# File lib/prawn/graph/series.rb, line 81
def mark_minimum?
  options.mark_minimum == true
end
max() click to toggle source

@return [Numeric] The largest value stored in the values of this Series.

# File lib/prawn/graph/series.rb, line 57
def max
  @values.max || 0
end
min() click to toggle source

@return [Numeric] The smallest value stored in the values of this Series.

# File lib/prawn/graph/series.rb, line 47
def min
  if values.empty?
    0
  else
    values.sort.collect{ |x| x unless x.zero? }.compact.first
  end
end
size() click to toggle source

@return [Numeric] The size of the values stored in this Series.

# File lib/prawn/graph/series.rb, line 73
def size
  @values.size
end
title() click to toggle source

@return [String] The value of options.title.

# File lib/prawn/graph/series.rb, line 28
def title
  options.title
end
type() click to toggle source

@return [Symbol] The value of options.type.

# File lib/prawn/graph/series.rb, line 34
def type
  options.type
end