summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/axlsx')
-rw-r--r--lib/axlsx/workbook/workbook.rb1
-rw-r--r--lib/axlsx/workbook/worksheet/cfvos.rb18
-rw-r--r--lib/axlsx/workbook/worksheet/color_scale.rb20
-rw-r--r--lib/axlsx/workbook/worksheet/data_bar.rb53
4 files changed, 56 insertions, 36 deletions
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb
index 0941f0d1..c9556c4d 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -11,6 +11,7 @@ require 'axlsx/workbook/worksheet/page_set_up_pr.rb'
require 'axlsx/workbook/worksheet/page_setup.rb'
require 'axlsx/workbook/worksheet/print_options.rb'
require 'axlsx/workbook/worksheet/cfvo.rb'
+require 'axlsx/workbook/worksheet/cfvos.rb'
require 'axlsx/workbook/worksheet/color_scale.rb'
require 'axlsx/workbook/worksheet/data_bar.rb'
require 'axlsx/workbook/worksheet/icon_set.rb'
diff --git a/lib/axlsx/workbook/worksheet/cfvos.rb b/lib/axlsx/workbook/worksheet/cfvos.rb
new file mode 100644
index 00000000..06d9bdd4
--- /dev/null
+++ b/lib/axlsx/workbook/worksheet/cfvos.rb
@@ -0,0 +1,18 @@
+module Axlsx
+
+ #A collection of Cfvo objects that initializes with the required
+ #first two items
+ class Cfvos < SimpleTypedList
+
+ def initialize
+ super(Cfvo)
+ @list << Cfvo.new(:type => :min, :val => 0)
+ @list << Cfvo.new(:type => :max, :val => 0)
+ lock
+ end
+
+ def to_xml_string(str='')
+ @list.each { |cfvo| cfvo.to_xml_string(str) }
+ end
+ end
+end
diff --git a/lib/axlsx/workbook/worksheet/color_scale.rb b/lib/axlsx/workbook/worksheet/color_scale.rb
index 11f97e21..60a2efa3 100644
--- a/lib/axlsx/workbook/worksheet/color_scale.rb
+++ b/lib/axlsx/workbook/worksheet/color_scale.rb
@@ -10,7 +10,9 @@ module Axlsx
# A simple typed list of cfvos
# @return [SimpleTypedList]
# @see Cfvo
- attr_reader :value_objects
+ def value_objects
+ @value_objects ||= Cfvos.new
+ end
# A simple types list of colors
# @return [SimpleTypedList]
@@ -23,7 +25,6 @@ module Axlsx
# @see Cfvo
# @see Color
def initialize
- initialize_value_objects
initialize_colors
yield self if block_given?
end
@@ -32,9 +33,9 @@ module Axlsx
# a reference to the newly created cfvo and color objects so you can alter the default properties.
# @return [Hash] a hash with :cfvo and :color keys referencing the newly added objects.
def add(options={})
- @value_objects << Cfvo.new(:type => options[:type] || :min, :val => options[:val] || 0)
+ value_objects << Cfvo.new(:type => options[:type] || :min, :val => options[:val] || 0)
@colors << Color.new(:rgb => options[:color] || "FF000000")
- {:cfvo => @value_objects.last, :color => @colors.last}
+ {:cfvo => value_objects.last, :color => @colors.last}
end
@@ -42,7 +43,7 @@ module Axlsx
# @param [Integer] index The index of the cfvo and color object to delete
# @note you cannot remove the first two cfvo and color pairs
def delete_at(index=2)
- @value_objects.delete_at index
+ value_objects.delete_at index
@colors.delete_at index
end
@@ -51,20 +52,13 @@ module Axlsx
# @return [String]
def to_xml_string(str = '')
str << '<colorScale>'
- @value_objects.each { |cfvo| cfvo.to_xml_string(str) }
+ value_objects.to_xml_string(str)
@colors.each { |color| color.to_xml_string(str) }
str << '</colorScale>'
end
private
- # creates the initial cfvo objects
- def initialize_value_objects
- @value_objects = SimpleTypedList.new Cfvo
- @value_objects.concat [Cfvo.new(:type => :min, :val => 0), Cfvo.new(:type => :max, :val => 0)]
- @value_objects.lock
- end
-
# creates the initial color objects
def initialize_colors
@colors = SimpleTypedList.new Color
diff --git a/lib/axlsx/workbook/worksheet/data_bar.rb b/lib/axlsx/workbook/worksheet/data_bar.rb
index bca24bf7..90cd417a 100644
--- a/lib/axlsx/workbook/worksheet/data_bar.rb
+++ b/lib/axlsx/workbook/worksheet/data_bar.rb
@@ -16,15 +16,14 @@ module Axlsx
# @option options [Boolean] showValue
# @option options [String] color - the rbg value used to color the bars
def initialize(options = {})
- @minLength = 10
- @maxLength = 90
- @showValue = true
- initialize_value_objects
+ @min_length = 10
+ @max_length = 90
+ @show_value = true
parse_options options
yield self if block_given?
end
- serializable_attributes :minLength, :maxLength, :showValue
+ serializable_attributes :min_length, :max_length, :show_value
# instance values that must be serialized as their own elements - e.g. not attributes.
CHILD_ELEMENTS = [:value_objects, :color]
@@ -33,24 +32,29 @@ module Axlsx
# The minimum length of the data bar, as a percentage of the cell width.
# The default value is 10
# @return [Integer]
- attr_reader :minLength
+ attr_reader :min_length
+ alias :minLength :min_length
# maxLength attribute
# The maximum length of the data bar, as a percentage of the cell width.
# The default value is 90
# @return [Integer]
- attr_reader :maxLength
+ attr_reader :max_length
+ alias :maxLength :max_length
# maxLength attribute
# Indicates whether to show the values of the cells on which this data bar is applied.
# The default value is true
# @return [Boolean]
- attr_reader :showValue
+ attr_reader :show_value
+ alias :showValue :show_value
# A simple typed list of cfvos
# @return [SimpleTypedList]
# @see Cfvo
- attr_reader :value_objects
+ def value_objects
+ @value_objects ||= Cfvos.new
+ end
# color
# the color object used in the data bar formatting
@@ -60,12 +64,25 @@ module Axlsx
end
# @see minLength
- def minLength=(v); Axlsx.validate_unsigned_int(v); @minLength = v end
+ def min_length=(v)
+ Axlsx.validate_unsigned_int(v)
+ @min_length = v
+ end
+ alias :minLength= :min_length=
+
# @see maxLength
- def maxLength=(v); Axlsx.validate_unsigned_int(v); @maxLength = v end
+ def max_length=(v)
+ Axlsx.validate_unsigned_int(v)
+ @max_length = v
+ end
+ alias :maxLength= :max_length=
# @see showValue
- def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end
+ def show_value=(v)
+ Axlsx.validate_boolean(v)
+ @show_value = v
+ end
+ alias :showValue= :show_value=
# Sets the color for the data bars.
# @param [Color|String] v The color object, or rgb string value to apply
@@ -82,19 +99,9 @@ module Axlsx
str << '<dataBar '
serialized_attributes str
str << '>'
- @value_objects.each { |cfvo| cfvo.to_xml_string(str) }
+ value_objects.to_xml_string(str)
self.color.to_xml_string(str)
str << '</dataBar>'
end
-
- private
-
- # Initalize the simple typed list of value objects
- # I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do.
- def initialize_value_objects
- @value_objects = SimpleTypedList.new Cfvo
- @value_objects.concat [Cfvo.new(:type => :min, :val => 0), Cfvo.new(:type => :max, :val => 0)]
- @value_objects.lock
- end
end
end