Class: Axlsx::Axis

Inherits:
Object
  • Object
show all
Includes:
OptionsParser
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

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(ax_id, cross_ax, options = {}) ⇒ Axis

Creates an Axis object

Options Hash (options):

  • ax_pos (Symbol)
  • crosses (Symbol)
  • tick_lbl_pos (Symbol)

Raises:

  • (ArgumentError)

    If axi_id or cross_ax are not unsigned integers



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/axlsx/drawing/axis.rb', line 16

def initialize(ax_id, cross_ax, options={})
  Axlsx::validate_unsigned_int(ax_id)
  Axlsx::validate_unsigned_int(cross_ax)
  @ax_id = ax_id
  @cross_ax = cross_ax
  @format_code = "General"
  @delete = @label_rotation = 0
  @scaling = Scaling.new(:orientation=>:minMax)
  @title = @color = nil
  self.ax_pos = :b
  self.tick_lbl_pos = :nextTo
  self.format_code = "General"
  self.crosses = :autoZero
  self.gridlines = true
  parse_options options
end

Instance Attribute Details

#ax_idInteger (readonly) Also known as: axID

the id of the axis.



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

def ax_id
  @ax_id
end

#ax_posSymbol Also known as: axPos

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



56
57
58
# File 'lib/axlsx/drawing/axis.rb', line 56

def ax_pos
  @ax_pos
end

#colorString

the fill color to use in the axis shape properties. This should be a 6 character long hex string e.g. FF0000 for red



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

def color
  @color
end

#cross_axInteger (readonly) Also known as: crossAx

The perpendicular axis



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

def cross_ax
  @cross_ax
end

#crossesSymbol

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



73
74
75
# File 'lib/axlsx/drawing/axis.rb', line 73

def crosses
  @crosses
end

#deleteBoolean

specifies if gridlines should be shown in the chart



85
86
87
# File 'lib/axlsx/drawing/axis.rb', line 85

def delete
  @delete
end

#format_codeString

The number format format code for this axis default :General



68
69
70
# File 'lib/axlsx/drawing/axis.rb', line 68

def format_code
  @format_code
end

#gridlinesBoolean

specifies if gridlines should be shown in the chart



81
82
83
# File 'lib/axlsx/drawing/axis.rb', line 81

def gridlines
  @gridlines
end

#label_rotationInteger

specifies how the degree of label rotation



77
78
79
# File 'lib/axlsx/drawing/axis.rb', line 77

def label_rotation
  @label_rotation
end

#scalingScaling (readonly)

The scaling of the axis

See Also:



51
52
53
# File 'lib/axlsx/drawing/axis.rb', line 51

def scaling
  @scaling
end

#tick_lbl_posSymbol Also known as: tickLblPos

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



62
63
64
# File 'lib/axlsx/drawing/axis.rb', line 62

def tick_lbl_pos
  @tick_lbl_pos
end

#titleObject

the title for the axis. This can be a cell or a fixed string.



88
89
90
# File 'lib/axlsx/drawing/axis.rb', line 88

def title
  @title
end

Instance Method Details

#to_xml_string(str = '') ⇒ String

Serializes the object



149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/axlsx/drawing/axis.rb', line 149

def to_xml_string(str = '')
  str << '<c:axId val="' << @ax_id.to_s << '"/>'
  @scaling.to_xml_string str
  str << '<c:delete val="'<< @delete.to_s << '"/>'
  str << '<c:axPos val="' << @ax_pos.to_s << '"/>'
  str << '<c:majorGridlines>'
  # TODO shape properties need to be extracted into a class
  if gridlines == false
    str << '<c:spPr>'
    str << '<a:ln>'
    str << '<a:noFill/>'
    str << '</a:ln>'
    str << '</c:spPr>'
  end
  str << '</c:majorGridlines>'
  @title.to_xml_string(str) unless @title == nil
  str << '<c:numFmt formatCode="' << @format_code << '" sourceLinked="1"/>'
  str << '<c:majorTickMark val="none"/>'
  str << '<c:minorTickMark val="none"/>'
  str << '<c:tickLblPos val="' << @tick_lbl_pos.to_s << '"/>'
  # TODO - this is also being used for series colors
  # time to extract this into a class spPr - Shape Properties
  if @color
    str << '<c:spPr><a:ln><a:solidFill>'
    str << '<a:srgbClr val="' << @color << '"/>'
    str << '</a:solidFill></a:ln></c:spPr>'
  end
  # 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="' << @cross_ax.to_s << '"/>'
  str << '<c:crosses val="' << @crosses.to_s << '"/>'
end