Class: Prawn::Graph::Series

Inherits:
Object
  • Object
show all
Defined in:
lib/prawn/graph/series.rb

Overview

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

Constant Summary collapse

DEFAULT_OPTIONS =
{
  title:            nil,
  type:             :bar,
  mark_average:     false,
  mark_minimum:     false,
  mark_maximum:     false,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values = [], options = {}) ⇒ Series

Returns a new instance of Series.


18
19
20
21
# File 'lib/prawn/graph/series.rb', line 18

def initialize(values = [], options = {})
  @values   = values
  @options  = OpenStruct.new(DEFAULT_OPTIONS.merge(options))
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options


8
9
10
# File 'lib/prawn/graph/series.rb', line 8

def options
  @options
end

#valuesObject

Returns the value of attribute values


8
9
10
# File 'lib/prawn/graph/series.rb', line 8

def values
  @values
end

Instance Method Details

#<<(value) ⇒ Array

Returns The modified values object.

Parameters:

  • value (Object)

    a value to be added to the series. Must be of the same kind as other values.

Returns:

  • (Array)

    The modified values object.


38
39
40
# File 'lib/prawn/graph/series.rb', line 38

def <<(value)
  @values << value
end

#avgNumeric

Returns The average value stored in the values of this Series.

Returns:

  • (Numeric)

    The average value stored in the values of this Series.


56
57
58
59
60
61
62
# File 'lib/prawn/graph/series.rb', line 56

def avg
  if size > 0
    @values.inject(:+) / size
  else
    0
  end
end

#maxNumeric

Returns The largest value stored in the values of this Series.

Returns:

  • (Numeric)

    The largest value stored in the values of this Series.


50
51
52
# File 'lib/prawn/graph/series.rb', line 50

def max
  @values.max || 0
end

#minNumeric

Returns The smallest value stored in the values of this Series.

Returns:

  • (Numeric)

    The smallest value stored in the values of this Series.


44
45
46
# File 'lib/prawn/graph/series.rb', line 44

def min
  @values.min || 0
end

#sizeNumeric

Returns The size of the values stored in this Series.

Returns:

  • (Numeric)

    The size of the values stored in this Series.


66
67
68
# File 'lib/prawn/graph/series.rb', line 66

def size
  @values.size
end

#titleString

Returns The value of options.title.

Returns:

  • (String)

    The value of options.title.


25
26
27
# File 'lib/prawn/graph/series.rb', line 25

def title
  options.title
end

#to_aArray

Deprecated.

Provided to allow for tempory backwards compatibilty with legacy graph drawing. Do not use.

Returns Series represented as an array in the format [ title, val1, val2… ].

Returns:

  • (Array)

    Series represented as an array in the format [ title, val1, val2… ]


73
74
75
76
# File 'lib/prawn/graph/series.rb', line 73

def to_a
  warn "[DEPRECATION] Series#to_a is deprecated and will be removed in a future version of prawn-graph."
  [options.title, @values].compact.flatten
end

#typeSymbol

Returns The value of options.type.

Returns:

  • (Symbol)

    The value of options.type.


31
32
33
# File 'lib/prawn/graph/series.rb', line 31

def type
  options.type
end