diff options
| author | Randy Morgan <[email protected]> | 2011-11-20 23:22:04 +0900 |
|---|---|---|
| committer | Randy Morgan <[email protected]> | 2011-11-20 23:22:04 +0900 |
| commit | e53f04284618713b0a90b7a691425c380e829476 (patch) | |
| tree | 801fea138160f9af426d62bf94ad5bf97123ece9 /lib/axlsx/drawing/axis.rb | |
| download | caxlsx-e53f04284618713b0a90b7a691425c380e829476.tar.gz caxlsx-e53f04284618713b0a90b7a691425c380e829476.zip | |
first commit
Diffstat (limited to 'lib/axlsx/drawing/axis.rb')
| -rw-r--r-- | lib/axlsx/drawing/axis.rb | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/axlsx/drawing/axis.rb b/lib/axlsx/drawing/axis.rb new file mode 100644 index 00000000..facc2a67 --- /dev/null +++ b/lib/axlsx/drawing/axis.rb @@ -0,0 +1,78 @@ +module Axlsx + # the access class defines common properties and values for chart axis + class Axis + + + # the id of the axis + # @return [Integer] + attr_reader :axId + + # The perpendicular axis + # @return [Integer] + attr_reader :crossAx + + # The scaling of the axis + # @return [Scaling] + attr_reader :scaling + + # The position of the axis + # must be one of [:l, :r, :t, :b] + # @return [Symbol] + attr_accessor :axPos + + # the position of the tick labels + # must be one of [:nextTo, :high, :low] + # @return [Symbol] + attr_accessor :tickLblPos + + + # The number format format code for this axis + # @return [String] + attr_accessor :format_code + + # specifies how the perpendicular axis is crossed + # must be one of [:autoZero, :min, :max] + # @return [Symbol] + attr_accessor :crosses + + # Creates an Axis object + # @param [Integer] axId the id of this axis + # @param [Integer] crossAx the id of the perpendicular axis + # @option options [Symbol] axPos + # @option options [Symbol] crosses + # @option options [Symbol] tickLblPos + def initialize(axId, crossAx, options={}) + Axlsx::validate_unsigned_int(axId) + Axlsx::validate_unsigned_int(crossAx) + @axId = axId + @crossAx = crossAx + self.axPos = :l + self.tickLblPos = :nextTo + @scaling = Scaling.new(:orientation=>:minMax) + @formatCode = "" + self.crosses = :autoZero + options.each do |o| + self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}=" + end + end + + def axPos=(v) RestrictionValidator.validate "#{self.class}.axPos", [:l, :r, :b, :t], v; @axPos = v; end + def tickLblPos=(v) RestrictionValidator.validate "#{self.class}.tickLblPos", [:nextTo, :high, :low], v; @tickLblPos = v; end + def format_code=(v) Axlsx::validate_string(v); @formatCode = v; end + def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end + + # Serializes the common axis + # @param [Nokogiri::XML::Builder] xml The document builder instance this objects xml will be added to. + # @return [String] + def to_xml(xml) + xml.send('c:axId', :val=>@axId) + @scaling.to_xml(xml) + xml.send('c:axPos', :val=>@axPos) + xml.send('c:majorGridlines') + xml.send('c:numFmt', :formatCode => @format_code, :sourceLinked=>"1") + xml.send('c:tickLblPos', :val=>@tickLblPos) + xml.send('c:crossAx', :val=>@crossAx) + xml.send('c:crosses', :val=>@crosses) + end + end +end |
