Class: Axlsx::Axis

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

Overview

the access class defines common properties and values for a chart axis.

Direct Known Subclasses

CatAxis, SerAxis, ValAxis

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Creates an Axis 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)
  • crosses (Symbol)
  • tickLblPos (Symbol)

Raises:

  • (ArgumentError)

    If axId or crossAx are not unsigned integers



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/axlsx/drawing/axis.rb', line 50

def initialize(axId, crossAx, options={})
  Axlsx::validate_unsigned_int(axId)
  Axlsx::validate_unsigned_int(crossAx)
  @axId = axId
  @crossAx = crossAx
  @format_code = "General"
  @scaling = Scaling.new(:orientation=>:minMax)
  self.axPos = :b
  self.tickLblPos = :nextTo
  self.format_code = "General"
  self.crosses = :autoZero
  self.gridlines = true
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
end

Instance Attribute Details

#axIdInteger (readonly)

the id of the axis.

Returns:

  • (Integer)


8
9
10
# File 'lib/axlsx/drawing/axis.rb', line 8

def axId
  @axId
end

#axPosSymbol

The position of the axis must be one of [:l, :r, :t, :b]

Returns:

  • (Symbol)


22
23
24
# File 'lib/axlsx/drawing/axis.rb', line 22

def axPos
  @axPos
end

#crossAxInteger (readonly)

The perpendicular axis

Returns:

  • (Integer)


12
13
14
# File 'lib/axlsx/drawing/axis.rb', line 12

def crossAx
  @crossAx
end

#crossesSymbol

specifies how the perpendicular axis is crossed must be one of [:autoZero, :min, :max]

Returns:

  • (Symbol)


37
38
39
# File 'lib/axlsx/drawing/axis.rb', line 37

def crosses
  @crosses
end

#format_codeString

The number format format code for this axis default :General

Returns:

  • (String)


32
33
34
# File 'lib/axlsx/drawing/axis.rb', line 32

def format_code
  @format_code
end

#gridlinesBoolean

specifies if gridlines should be shown in the chart

Returns:

  • (Boolean)


41
42
43
# File 'lib/axlsx/drawing/axis.rb', line 41

def gridlines
  @gridlines
end

#scalingScaling (readonly)

The scaling of the axis

Returns:

See Also:



17
18
19
# File 'lib/axlsx/drawing/axis.rb', line 17

def scaling
  @scaling
end

#tickLblPosSymbol

the position of the tick labels must be one of [:nextTo, :high, :low]

Returns:

  • (Symbol)


27
28
29
# File 'lib/axlsx/drawing/axis.rb', line 27

def tickLblPos
  @tickLblPos
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/axlsx/drawing/axis.rb', line 90

def to_xml_string(str = '')
  str << '<c:axId val="' << @axId.to_s << '"/>'
  @scaling.to_xml_string str
  str << '<c:delete val="0"/>'
  str << '<c:axPos val="' << @axPos.to_s << '"/>'
  str << '<c:majorGridlines>'
  if self.gridlines == false
    str << '<c:spPr>'
    str << '<a:ln>'
    str << '<a:noFill/>'
    str << '</a:ln>'
    str << '</c:spPr>'
  end
  str << '</c:majorGridlines>'
  str << '<c:numFmt formatCode="' << @format_code << '" sourceLinked="1"/>'
  str << '<c:majorTickMark val="none"/>'
  str << '<c:minorTickMark val="none"/>'
  str << '<c:tickLblPos val="' << @tickLblPos.to_s << '"/>'
  str << '<c:crossAx val="' << @crossAx.to_s << '"/>'
  str << '<c:crosses val="' << @crosses.to_s << '"/>'
end