summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/cat_axis.rb
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2011-11-20 23:22:04 +0900
committerRandy Morgan <[email protected]>2011-11-20 23:22:04 +0900
commite53f04284618713b0a90b7a691425c380e829476 (patch)
tree801fea138160f9af426d62bf94ad5bf97123ece9 /lib/axlsx/drawing/cat_axis.rb
downloadcaxlsx-e53f04284618713b0a90b7a691425c380e829476.tar.gz
caxlsx-e53f04284618713b0a90b7a691425c380e829476.zip
first commit
Diffstat (limited to 'lib/axlsx/drawing/cat_axis.rb')
-rw-r--r--lib/axlsx/drawing/cat_axis.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/axlsx/drawing/cat_axis.rb b/lib/axlsx/drawing/cat_axis.rb
new file mode 100644
index 00000000..f2458ffc
--- /dev/null
+++ b/lib/axlsx/drawing/cat_axis.rb
@@ -0,0 +1,58 @@
+module Axlsx
+ #A CatAxis object defines a chart category axis
+ class CatAxis < Axis
+ # From the docs: This element specifies that this axis is a date or text axis based on the data that is used for the axis labels, not a specific choice.
+ # @return [Boolean]
+ attr_accessor :auto
+
+ # specifies how the perpendicular axis is crossed
+ # must be one of [:ctr, :l, :r]
+ # @return [Symbol]
+ attr_accessor :lblAlgn
+
+ # The offset of the labels
+ # must be between a string between 0 and 1000
+ # @return [Integer]
+ attr_accessor :lblOffset
+
+ # regex for validating label offset
+ LBL_OFFSET_REGEX = /0*(([0-9])|([1-9][0-9])|([1-9][0-9][0-9])|1000)%/
+
+ # Creates a new CatAxis 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] tickLblPos
+ # @option options [Symbol] crosses
+ # @option options [Boolean] auto
+ # @option options [Symbol] lblAlgn
+ # @option options [Integer] lblOffset
+ def initialize(axId, crossAx, options={})
+ super(axId, crossAx, options)
+ self.auto = true
+ self.lblAlgn = :ctr
+ self.lblOffset = "100%"
+ options.each do |o|
+ self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
+ end
+ end
+
+ def auto=(v) Axlsx::validate_boolean(v); @auto = v; end
+ def lblAlgn=(v) RestrictionValidator.validate "#{self.class}.lblAlgn", [:ctr, :l, :r], v; @lblAlgn = v; end
+ def lblOffset=(v) RegexValidator.validate "#{self.class}.lblOffset", LBL_OFFSET_REGEX, v; @lblOffset = v; end
+
+ # Serializes the category 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:catAx') {
+ super(xml)
+ xml.send('c:auto', :val=>@auto)
+ xml.send('c:lblAlgn', :val=>@lblAlgn)
+ xml.send('c:lblOffset', :val=>@lblOffset)
+ }
+ end
+ end
+
+
+end