Class: Axlsx::Axes

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/drawing/axes.rb

Overview

The Axes class creates and manages axis information and serialization for charts.

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Axes

should be an axis name like :val_axix and its value should be the class of the axis type to construct.

Parameters:

  • options (Hash) (defaults to: {})

    options used to generate axis each key



10
11
12
13
14
# File 'lib/axlsx/drawing/axes.rb', line 10

def initialize(options={})
  options.each do |name, axis_class|
    add_axis(name, axis_class)
  end
end

Instance Method Details

#[](name) ⇒ Axis

[] provides assiciative access to a specic axis store in an axes instance.

Returns:



19
20
21
# File 'lib/axlsx/drawing/axes.rb', line 19

def [](name)
  axes.assoc(name)[1]
end

#add_axis(name, axis_class) ⇒ Object

Adds an axis to the collection

Parameters:

  • name (Symbol)

    The name of the axis

  • axis_class (Axis)

    The axis class to generate



40
41
42
43
44
# File 'lib/axlsx/drawing/axes.rb', line 40

def add_axis(name, axis_class)
  axis = axis_class.new
  set_cross_axis(axis)
  axes << [name, axis]
end

#to_xml_string(str = '', options = {}) ⇒ Object

Serializes the object If the ids option is specified only the axis identifier is serialized. Otherwise, each axis is serialized in full.

Parameters:

  • str (String) (defaults to: '')
  • options (Hash) (defaults to: {})

Options Hash (options):

  • ids (Object)


29
30
31
32
33
34
35
# File 'lib/axlsx/drawing/axes.rb', line 29

def to_xml_string(str = '', options = {})
  if options[:ids]
    axes.inject(str) { |string, axis| string << '<c:axId val="' << axis[1].id.to_s << '"/>' }
  else
    axes.each { |axis| axis[1].to_xml_string(str) }
  end
end