class Axlsx::Axis

the access class defines common properties and values for a chart axis.

Attributes

axID[R]

the id of the axis. @return [Integer]

axPos[R]

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

ax_pos[R]

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

color[R]

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]

crossAx[R]

The perpendicular axis @return [Integer]

cross_axis[R]

The perpendicular axis @return [Integer]

crosses[R]

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

delete[R]

specifies if gridlines should be shown in the chart @return [Boolean]

format_code[R]

The number format format code for this axis default :General @return [String]

gridlines[R]

specifies if gridlines should be shown in the chart @return [Boolean]

id[R]

the id of the axis. @return [Integer]

label_rotation[R]

specifies how the degree of label rotation @return [Integer]

scaling[R]

The scaling of the axis @see Scaling @return [Scaling]

tickLblPos[R]

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

tick_lbl_pos[R]

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

title[R]

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

Public Class Methods

new(options={}) click to toggle source

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

axPos=(v)
Alias for: ax_pos=
ax_pos=(v) click to toggle source

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
Also aliased as: axPos=
color=(color_rgb) click to toggle source

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
cross_axis=(axis) click to toggle source

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
crosses=(v) click to toggle source

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
delete=(v) click to toggle source

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
format_code=(v) click to toggle source

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
gridlines=(v) click to toggle source

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
label_rotation=(v) click to toggle source

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
tickLblPos=(v)
Alias for: tick_lbl_pos=
tick_lbl_pos=(v) click to toggle source

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
Also aliased as: tickLblPos=
title=(v) click to toggle source

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
to_xml_string(str = '') click to toggle source

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
  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_axis.id.to_s << '"/>'
  str << '<c:crosses val="' << @crosses.to_s << '"/>'
end