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

Constant Summary collapse

VALID_TICK_MARK_VALUES =
[:cross, :in, :none, :out].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(options = {}) ⇒ Axis

Creates an Axis object

Parameters:

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

    a customizable set of options

Options Hash (options):

  • cross_axis (Axis)

    the perpendicular axis

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

Raises:

  • (ArgumentError)

    If axi_id or cross_ax are not unsigned integers



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

def initialize(options = {})
  @id = rand(8**8)
  @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.major_tick_mark = :cross
  self.minor_tick_mark = :none
  self.format_code = "General"
  self.crosses = :autoZero
  self.gridlines = true
  parse_options options
end

Instance Attribute Details

#ax_posSymbol Also known as: axPos

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

Returns:

  • (Symbol)


53
54
55
# File 'lib/axlsx/drawing/axis.rb', line 53

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

Returns:

  • (String)


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

def color
  @color
end

#cross_axisInteger Also known as: crossAx

The perpendicular axis

Returns:

  • (Integer)


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

def cross_axis
  @cross_axis
end

#crossesSymbol

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

Returns:

  • (Symbol)


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

def crosses
  @crosses
end

#deleteBoolean

specifies if gridlines should be shown in the chart

Returns:

  • (Boolean)


94
95
96
# File 'lib/axlsx/drawing/axis.rb', line 94

def delete
  @delete
end

#format_codeString

The number format format code for this axis default :General

Returns:

  • (String)


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

def format_code
  @format_code
end

#gridlinesBoolean

specifies if gridlines should be shown in the chart

Returns:

  • (Boolean)


90
91
92
# File 'lib/axlsx/drawing/axis.rb', line 90

def gridlines
  @gridlines
end

#idInteger (readonly) Also known as: axID

the id of the axis.

Returns:

  • (Integer)


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

def id
  @id
end

#label_rotationInteger

specifies how the degree of label rotation

Returns:

  • (Integer)


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

def label_rotation
  @label_rotation
end

#major_tick_markSymbol Also known as: majorTickMark

the type of major tick mark must be one of [:cross, :in, :none, :out]

Returns:

  • (Symbol)


65
66
67
# File 'lib/axlsx/drawing/axis.rb', line 65

def major_tick_mark
  @major_tick_mark
end

#minor_tick_markSymbol Also known as: minorTickMark

the type of minor tick mark must be one of [:cross, :in, :none, :out]

Returns:

  • (Symbol)


71
72
73
# File 'lib/axlsx/drawing/axis.rb', line 71

def minor_tick_mark
  @minor_tick_mark
end

#scalingScaling (readonly)

The scaling of the axis

Returns:

See Also:



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

def scaling
  @scaling
end

#tick_lbl_posSymbol Also known as: tickLblPos

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

Returns:

  • (Symbol)


59
60
61
# File 'lib/axlsx/drawing/axis.rb', line 59

def tick_lbl_pos
  @tick_lbl_pos
end

#titleObject

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



97
98
99
# File 'lib/axlsx/drawing/axis.rb', line 97

def title
  @title
end

Instance Method Details

#to_xml_string(str = +'')) ⇒ String

Serializes the object

Parameters:

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

Returns:

  • (String)


201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/axlsx/drawing/axis.rb', line 201

def to_xml_string(str = +'')
  str << '<c:axId val="' << @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?
  # Need to set sourceLinked to 0 if we're setting a format code on this row
  # otherwise it will never take, as it will always prefer the 'General' formatting
  # of the cells themselves
  str << '<c:numFmt formatCode="' << @format_code << '" sourceLinked="' << (@format_code.eql?('General') ? '1' : '0') << '"/>'
  str << '<c:majorTickMark val="' << @major_tick_mark.to_s << '"/>'
  str << '<c:minorTickMark val="' << @minor_tick_mark.to_s << '"/>'
  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_axis.id.to_s << '"/>'
  str << '<c:crosses val="' << @crosses.to_s << '"/>'
end