class Axlsx::Axis
the access class defines common properties and values for a chart axis.
Attributes
the id of the axis. @return [Integer]
The position of the axis must be one of [:l, :r, :t, :b] @return [Symbol]
The position of the axis must be one of [:l, :r, :t, :b] @return [Symbol]
the fill color to use in the axis shape properties. This should be a 6 character long hex string e.g. FF0000 for red @return [String]
The perpendicular axis @return [Integer]
The perpendicular axis @return [Integer]
specifies how the perpendicular axis is crossed must be one of [:autoZero, :min, :max] @return [Symbol]
specifies if gridlines should be shown in the chart @return [Boolean]
The number format format code for this axis default :General @return [String]
specifies if gridlines should be shown in the chart @return [Boolean]
the id of the axis. @return [Integer]
specifies how the degree of label rotation @return [Integer]
The scaling of the axis @see Scaling
@return [Scaling]
the position of the tick labels must be one of [:nextTo, :high, :low] @return [Symbol]
the position of the tick labels must be one of [:nextTo, :high, :low] @return [Symbol]
the title for the axis. This can be a cell or a fixed string.
Public Class Methods
Creates an Axis
object @option options [Axis] cross_axis
the perpendicular axis @option options [Symbol] ax_pos
@option options [Symbol] crosses @option options [Symbol] tick_lbl_pos
@raise [ArgumentError] If axi_id or cross_ax are not unsigned integers
# File lib/axlsx/drawing/axis.rb, line 15 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.format_code = "General" self.crosses = :autoZero self.gridlines = true parse_options options end
Public Instance Methods
The position of the axis must be one of [:l, :r, :t, :b]
# File lib/axlsx/drawing/axis.rb, line 103 def ax_pos=(v) RestrictionValidator.validate "#{self.class}.ax_pos", [:l, :r, :b, :t], v; @ax_pos = v; end
The color for this axis. This value is used when rendering the axis line in the chart. colors should be in 6 character rbg format @return [String] the rbg color assinged. @see color
# File lib/axlsx/drawing/axis.rb, line 90 def color=(color_rgb) @color = color_rgb end
The crossing axis for this axis @param [Axis] axis
# File lib/axlsx/drawing/axis.rb, line 96 def cross_axis=(axis) DataTypeValidator.validate "#{self.class}.cross_axis", [Axis], axis @cross_axis = axis end
specifies how the perpendicular axis is crossed must be one of [:autoZero, :min, :max]
# File lib/axlsx/drawing/axis.rb, line 125 def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end
Specify if axis should be removed from the chart default false
# File lib/axlsx/drawing/axis.rb, line 121 def delete=(v) Axlsx::validate_boolean(v); @delete = v; end
The number format format code for this axis default :General
# File lib/axlsx/drawing/axis.rb, line 113 def format_code=(v) Axlsx::validate_string(v); @format_code = v; end
Specify if gridlines should be shown for this axis default true
# File lib/axlsx/drawing/axis.rb, line 117 def gridlines=(v) Axlsx::validate_boolean(v); @gridlines = v; end
Specify the degree of label rotation to apply to labels default true
# File lib/axlsx/drawing/axis.rb, line 129 def label_rotation=(v) Axlsx::validate_int(v) adjusted = v.to_i * 60000 Axlsx::validate_angle(adjusted) @label_rotation = adjusted end
the position of the tick labels must be one of [:nextTo, :high, :low1]
# File lib/axlsx/drawing/axis.rb, line 108 def tick_lbl_pos=(v) RestrictionValidator.validate "#{self.class}.tick_lbl_pos", [:nextTo, :high, :low, :none], v; @tick_lbl_pos = v; end
The title object for the chart. @param [String, Cell] v @return [Title]
# File lib/axlsx/drawing/axis.rb, line 139 def title=(v) DataTypeValidator.validate "#{self.class}.title", [String, Cell], v @title ||= Title.new if v.is_a?(String) @title.text = v elsif v.is_a?(Cell) @title.cell = v end end
Serializes the object @param [String] str @return [String]
# File lib/axlsx/drawing/axis.rb, line 152 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