Class: Axlsx::Axis
- Inherits:
-
Object
- Object
- Axlsx::Axis
- Includes:
- OptionsParser
- Defined in:
- lib/axlsx/drawing/axis.rb
Overview
the access class defines common properties and values for a chart axis.
Instance Attribute Summary collapse
-
#ax_pos ⇒ Symbol
(also: #axPos)
The position of the axis must be one of [:l, :r, :t, :b].
-
#color ⇒ String
the fill color to use in the axis shape properties.
-
#cross_axis ⇒ Integer
(also: #crossAx)
The perpendicular axis.
-
#crosses ⇒ Symbol
specifies how the perpendicular axis is crossed must be one of [:autoZero, :min, :max].
-
#delete ⇒ Boolean
specifies if gridlines should be shown in the chart.
-
#format_code ⇒ String
The number format format code for this axis default :General.
-
#gridlines ⇒ Boolean
specifies if gridlines should be shown in the chart.
-
#id ⇒ Integer
(also: #axID)
readonly
the id of the axis.
-
#label_rotation ⇒ Integer
specifies how the degree of label rotation.
-
#scaling ⇒ Scaling
readonly
The scaling of the axis.
-
#tick_lbl_pos ⇒ Symbol
(also: #tickLblPos)
the position of the tick labels must be one of [:nextTo, :high, :low].
-
#title ⇒ Object
the title for the axis.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Axis
constructor
Creates an Axis object.
-
#to_xml_string(str = +'')) ⇒ String
Serializes the object.
Methods included from OptionsParser
Constructor Details
#initialize(options = {}) ⇒ Axis
Creates an Axis object
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/axlsx/drawing/axis.rb', line 14 def initialize( = {}) @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.format_code = "General" self.crosses = :autoZero self.gridlines = true end |
Instance Attribute Details
#ax_pos ⇒ Symbol Also known as: axPos
The position of the axis must be one of [:l, :r, :t, :b]
51 52 53 |
# File 'lib/axlsx/drawing/axis.rb', line 51 def ax_pos @ax_pos end |
#color ⇒ String
the fill color to use in the axis shape properties. This should be a 6 character long hex string e.g. FF0000 for red
31 32 33 |
# File 'lib/axlsx/drawing/axis.rb', line 31 def color @color end |
#cross_axis ⇒ Integer Also known as: crossAx
The perpendicular axis
40 41 42 |
# File 'lib/axlsx/drawing/axis.rb', line 40 def cross_axis @cross_axis end |
#crosses ⇒ Symbol
specifies how the perpendicular axis is crossed must be one of [:autoZero, :min, :max]
68 69 70 |
# File 'lib/axlsx/drawing/axis.rb', line 68 def crosses @crosses end |
#delete ⇒ Boolean
specifies if gridlines should be shown in the chart
80 81 82 |
# File 'lib/axlsx/drawing/axis.rb', line 80 def delete @delete end |
#format_code ⇒ String
The number format format code for this axis default :General
63 64 65 |
# File 'lib/axlsx/drawing/axis.rb', line 63 def format_code @format_code end |
#gridlines ⇒ Boolean
specifies if gridlines should be shown in the chart
76 77 78 |
# File 'lib/axlsx/drawing/axis.rb', line 76 def gridlines @gridlines end |
#id ⇒ Integer (readonly) Also known as: axID
the id of the axis.
35 36 37 |
# File 'lib/axlsx/drawing/axis.rb', line 35 def id @id end |
#label_rotation ⇒ Integer
specifies how the degree of label rotation
72 73 74 |
# File 'lib/axlsx/drawing/axis.rb', line 72 def label_rotation @label_rotation end |
#scaling ⇒ Scaling (readonly)
The scaling of the axis
46 47 48 |
# File 'lib/axlsx/drawing/axis.rb', line 46 def scaling @scaling end |
#tick_lbl_pos ⇒ Symbol Also known as: tickLblPos
the position of the tick labels must be one of [:nextTo, :high, :low]
57 58 59 |
# File 'lib/axlsx/drawing/axis.rb', line 57 def tick_lbl_pos @tick_lbl_pos end |
#title ⇒ Object
the title for the axis. This can be a cell or a fixed string.
83 84 85 |
# File 'lib/axlsx/drawing/axis.rb', line 83 def title @title end |
Instance Method Details
#to_xml_string(str = +'')) ⇒ String
Serializes the object
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/axlsx/drawing/axis.rb', line 169 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="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_axis.id.to_s << '"/>' str << '<c:crosses val="' << @crosses.to_s << '"/>' end |