class Axlsx::ColorScale
@note The recommended way to manage these rules is via Worksheet#add_conditional_formatting
@see Worksheet#add_conditional_formatting
@see ConditionalFormattingRule#initialize
Public Class Methods
These are the default conditional formatting value objects that define a two tone color gradient.
# File lib/axlsx/workbook/worksheet/color_scale.rb, line 14 def default_cfvos [{:type => :min, :val => 0, :color => 'FFFF7128'}, {:type => :max, :val => 0, :color => 'FFFFEF9C'}] end
creates a new ColorScale
object. @see Cfvo
@see Color
@example
color_scale = Axlsx::ColorScale.new({:type => :num, :val => 0.55, :color => 'fff7696c'})
# File lib/axlsx/workbook/worksheet/color_scale.rb, line 58 def initialize(*cfvos) initialize_default_cfvos(cfvos) yield self if block_given? end
A builder for three tone color gradient @example
#this creates a three tone color scale color_scale = Axlsx::ColorScale.three_tone
@see examples/example.rb conditional formatting examples.
# File lib/axlsx/workbook/worksheet/color_scale.rb, line 33 def three_tone self.new({:type => :min, :val => 0, :color => 'FFF8696B'}, {:type => :percent, :val => '50', :color => 'FFFFEB84'}, {:type => :max, :val => 0, :color => 'FF63BE7B'}) end
A builder for two tone color gradient @example
# this creates a two tone color scale color_scale = Axlsx::ColorScale.two_tone
@see examples/example.rb conditional formatting examples.
# File lib/axlsx/workbook/worksheet/color_scale.rb, line 24 def two_tone self.new end
Public Instance Methods
adds a new cfvo / color pair to the color scale and returns a hash containing 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. @param [Hash] options options for the new cfvo and color objects @option [Symbol] type The type of cfvo you to add @option [Any] val The value of the cfvo to add @option [String] The rgb color for the cfvo
# File lib/axlsx/workbook/worksheet/color_scale.rb, line 70 def add(options={}) 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} end
A simple types list of colors @return [SimpleTypedList] @see Color
# File lib/axlsx/workbook/worksheet/color_scale.rb, line 49 def colors @colors ||= SimpleTypedList.new Color end
removes the cfvo and color pair at the index specified. @param [Integer] index The index of the cfvo and color object to delete @note you cannot remove the first two cfvo and color pairs
# File lib/axlsx/workbook/worksheet/color_scale.rb, line 80 def delete_at(index=2) value_objects.delete_at index colors.delete_at index end
Serialize this color_scale object data to an xml string @param [String] str @return [String]
# File lib/axlsx/workbook/worksheet/color_scale.rb, line 88 def to_xml_string(str = '') str << '<colorScale>' value_objects.to_xml_string(str) colors.each { |color| color.to_xml_string(str) } str << '</colorScale>' end
A simple typed list of cfvos @return [SimpleTypedList] @see Cfvo
# File lib/axlsx/workbook/worksheet/color_scale.rb, line 42 def value_objects @value_objects ||= Cfvos.new end
Private Instance Methods
There has got to be cleaner way of merging these arrays.
# File lib/axlsx/workbook/worksheet/color_scale.rb, line 97 def initialize_default_cfvos(user_cfvos) defaults = self.class.default_cfvos user_cfvos.each_with_index do |cfvo, index| if index < defaults.size cfvo = defaults[index].merge(cfvo) end add cfvo end while colors.size < defaults.size add defaults[colors.size - 1] end end