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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/axlsx/drawing/axis.rb', line 58

def initialize(axId, crossAx, options={})
  Axlsx::validate_unsigned_int(axId)
  Axlsx::validate_unsigned_int(crossAx)
  @axId = axId
  @crossAx = crossAx
  @format_code = "General"
  @delete = @label_rotation = 0
  @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

#deleteBoolean

specifies if gridlines should be shown in the chart

Returns:

  • (Boolean)


49
50
51
# File 'lib/axlsx/drawing/axis.rb', line 49

def delete
  @delete
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)


45
46
47
# File 'lib/axlsx/drawing/axis.rb', line 45

def gridlines
  @gridlines
end

#label_rotationInteger

specifies how the degree of label rotation

Returns:

  • (Integer)


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

def label_rotation
  @label_rotation
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)


113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/axlsx/drawing/axis.rb', line 113

def to_xml_string(str = '')
  str << '<c:axId val="' << @axId.to_s << '"/>'
  @scaling.to_xml_string str
  str << '<c:delete val="'<< @delete.to_s << '"/>'
  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 << '"/>'
  # some potential value in implementing this in full. Very detailed!
  str << '<c:txPr><a:bodyPr rot="' << @label_rotation.to_s << '"/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr/></a:p></c:txPr>'
  str << '<c:crossAx val="' << @crossAx.to_s << '"/>'
  str << '<c:crosses val="' << @crosses.to_s << '"/>'
end