Class: Axlsx::Axes
- Inherits:
-
Object
- Object
- Axlsx::Axes
- Defined in:
- lib/axlsx/drawing/axes.rb
Overview
The Axes class creates and manages axis information and serialization for charts.
Instance Method Summary collapse
-
#[](name) ⇒ Axis
[] provides associative access to a specific axis store in an axes instance.
-
#add_axis(name, axis_class) ⇒ Object
Adds an axis to the collection.
-
#initialize(options = {}) ⇒ Axes
constructor
should be an axis name like :val_axis and its value should be the class of the axis type to construct.
-
#to_xml_string(str = +'',, options = {}) ⇒ Object
Serializes the object If the ids option is specified only the axis identifier is serialized.
Constructor Details
#initialize(options = {}) ⇒ Axes
should be an axis name like :val_axis and its value should be the class of the axis type to construct. The :cat_axis, if there is one, must come first (we assume a Ruby 1.9+ Hash or an OrderedHash).
11 12 13 14 15 16 17 |
# File 'lib/axlsx/drawing/axes.rb', line 11 def initialize( = {}) raise(ArgumentError, "CatAxis must come first") if .key?(:cat_axis) && .keys.first != :cat_axis .each do |name, axis_class| add_axis(name, axis_class) end end |
Instance Method Details
#[](name) ⇒ Axis
[] provides associative access to a specific axis store in an axes instance.
22 23 24 |
# File 'lib/axlsx/drawing/axes.rb', line 22 def [](name) axes.assoc(name)[1] end |
#add_axis(name, axis_class) ⇒ Object
Adds an axis to the collection
45 46 47 48 49 |
# File 'lib/axlsx/drawing/axes.rb', line 45 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.
32 33 34 35 36 37 38 39 40 |
# File 'lib/axlsx/drawing/axes.rb', line 32 def to_xml_string(str = +'', = {}) if [:ids] # CatAxis must come first in the XML (for Microsoft Excel at least) sorted = axes.sort_by { |_name, axis| axis.is_a?(CatAxis) ? 0 : 1 } sorted.each { |axis| str << '<c:axId val="' << axis[1].id.to_s << '"/>' } else axes.each { |axis| axis[1].to_xml_string(str) } end end |