summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2012-04-25 20:30:24 +0900
committerRandy Morgan <[email protected]>2012-04-25 20:30:24 +0900
commit672aae6fd76c761006868c42062e153e56da2a09 (patch)
treead570fda83c7d4a818518e59e7c01a4780e047d6 /lib
parentbb9d3279c500164e9a958c168ca3bea5e4e6d76c (diff)
downloadcaxlsx-672aae6fd76c761006868c42062e153e56da2a09.tar.gz
caxlsx-672aae6fd76c761006868c42062e153e56da2a09.zip
label rotation and conditional formatting examples
Diffstat (limited to 'lib')
-rw-r--r--lib/axlsx/drawing/axis.rb16
-rw-r--r--lib/axlsx/util/constants.rb5
-rw-r--r--lib/axlsx/util/validators.rb3
3 files changed, 22 insertions, 2 deletions
diff --git a/lib/axlsx/drawing/axis.rb b/lib/axlsx/drawing/axis.rb
index 9206e848..ea093391 100644
--- a/lib/axlsx/drawing/axis.rb
+++ b/lib/axlsx/drawing/axis.rb
@@ -36,6 +36,10 @@ module Axlsx
# @return [Symbol]
attr_reader :crosses
+ # specifies how the degree of label rotation
+ # @return [Integer]
+ attr_reader :label_rotation
+
# specifies if gridlines should be shown in the chart
# @return [Boolean]
attr_reader :gridlines
@@ -53,6 +57,7 @@ module Axlsx
@axId = axId
@crossAx = crossAx
@format_code = "General"
+ @label_rotation = 0
@scaling = Scaling.new(:orientation=>:minMax)
self.axPos = :b
self.tickLblPos = :nextTo
@@ -83,6 +88,15 @@ module Axlsx
# must be one of [:autoZero, :min, :max]
def crosses=(v) RestrictionValidator.validate "#{self.class}.crosses", [:autoZero, :min, :max], v; @crosses = v; end
+ # Specify the degree of label rotation to apply to labels
+ # default true
+ def label_rotation=(v)
+ Axlsx::validate_int(v)
+ adjusted = v.to_i * 60000
+ Axlsx::validate_angle(adjusted)
+ @label_rotation = adjusted
+ end
+
# Serializes the object
# @param [String] str
@@ -105,6 +119,8 @@ module Axlsx
str << '<c:majorTickMark val="none"/>'
str << '<c:minorTickMark val="none"/>'
str << '<c:tickLblPos val="' << @tickLblPos.to_s << '"/>'
+ # some potential value in implementing this in full. Very detailed!
+ str << "<c:txPr><a:bodyPr rot='#{@label_rotation}'/><a:lstStyle/><a:p><a:pPr><a:defRPr/></a:pPr><a:endParaRPr/></a:p></c:txPr>"
str << '<c:crossAx val="' << @crossAx.to_s << '"/>'
str << '<c:crosses val="' << @crosses.to_s << '"/>'
end
diff --git a/lib/axlsx/util/constants.rb b/lib/axlsx/util/constants.rb
index 4ec6f4d6..0699a482 100644
--- a/lib/axlsx/util/constants.rb
+++ b/lib/axlsx/util/constants.rb
@@ -235,8 +235,9 @@ module Axlsx
# error message when user does not provide color and or style options for border in Style#add_sytle
ERR_INVALID_BORDER_OPTIONS = "border hash must include both style and color. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s"
- ERR_INVALID_DXF_BORDER_OPTIONS = "border options required for dxf style stypes. e.g. :border => { :color => 'FF000000', :style => :thin }. You provided: %s"
-
+ # error message for invalid border id reference
ERR_INVALID_BORDER_ID = "The border id you specified (%s) does not exist. Please add a border with Style#add_style before referencing its index."
+ # error message for invalid angles
+ ERR_ANGLE = "Angles must be a value between -90 and 90. You provided: %s"
end
diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb
index 6826803b..5dc1f66e 100644
--- a/lib/axlsx/util/validators.rb
+++ b/lib/axlsx/util/validators.rb
@@ -45,6 +45,9 @@ module Axlsx
true
end
+ def self.validate_angle(v)
+ raise ArgumentError, (ERR_ANGLE % v.inspect) unless (v >= -5400000 && v <= 5400000)
+ end
# Requires that the value is a Fixnum or Integer and is greater or equal to 0
# @param [Any] v The value validated
# @raise [ArgumentError] raised if the value is not a Fixnum or Integer value greater or equal to 0