Class: Axlsx::CatAxis

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

Overview

A CatAxis object defines a chart category axis

Constant Summary collapse

LBL_OFFSET_REGEX =

regex for validating label offset

/0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)%/

Instance Attribute Summary collapse

Attributes inherited from Axis

#axId, #axPos, #crossAx, #crosses, #format_code, #scaling, #tickLblPos

Instance Method Summary collapse

Constructor Details

#initialize(axId, crossAx, options = {}) ⇒ CatAxis

Creates a new CatAxis object

Parameters:

  • axId (Integer)

    the id of this axis

  • crossAx (Integer)

    the id of the perpendicular axis

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

    a customizable set of options

Options Hash (options):

  • axPos (Symbol)
  • tickLblPos (Symbol)
  • crosses (Symbol)
  • auto (Boolean)
  • lblAlgn (Symbol)
  • lblOffset (Integer)


30
31
32
33
34
35
36
37
38
# File 'lib/axlsx/drawing/cat_axis.rb', line 30

def initialize(axId, crossAx, options={})
  super(axId, crossAx, options)
  self.auto = true
  self.lblAlgn = :ctr
  self.lblOffset = "100%"
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
end

Instance Attribute Details

#autoBoolean

From the docs: This element specifies that this axis is a date or text axis based on the data that is used for the axis labels, not a specific choice.

Returns:

  • (Boolean)


6
7
8
# File 'lib/axlsx/drawing/cat_axis.rb', line 6

def auto
  @auto
end

#lblAlgnSymbol

specifies how the perpendicular axis is crossed must be one of [:ctr, :l, :r]

Returns:

  • (Symbol)


11
12
13
# File 'lib/axlsx/drawing/cat_axis.rb', line 11

def lblAlgn
  @lblAlgn
end

#lblOffsetInteger

The offset of the labels must be between a string between 0 and 1000

Returns:

  • (Integer)


16
17
18
# File 'lib/axlsx/drawing/cat_axis.rb', line 16

def lblOffset
  @lblOffset
end

Instance Method Details

#to_xml(xml) ⇒ String

Serializes the category axis

Parameters:

  • xml (Nokogiri::XML::Builder)

    The document builder instance this objects xml will be added to.

Returns:

  • (String)


47
48
49
50
51
52
53
54
# File 'lib/axlsx/drawing/cat_axis.rb', line 47

def to_xml(xml)
  xml.send('c:catAx') {
    super(xml)
    xml.send('c:auto', :val=>@auto)
    xml.send('c:lblAlgn', :val=>@lblAlgn)
    xml.send('c:lblOffset', :val=>@lblOffset)                 
  }
end