Class: Axlsx::ColorScale

Inherits:
Object
  • Object
show all
Defined in:
lib/axlsx/workbook/worksheet/color_scale.rb

Overview

Note:

The recommended way to manage these rules is via Worksheet#add_conditional_formatting

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*cfvos) {|_self| ... } ⇒ ColorScale

creates a new ColorScale object.

Examples:

color_scale = Axlsx::ColorScale.new({:type => :num, :val => 0.55, :color => 'fff7696c'})

Yields:

  • (_self)

Yield Parameters:

See Also:



56
57
58
59
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 56

def initialize(*cfvos)
  initialize_default_cfvos(cfvos)
  yield self if block_given?
end

Class Method Details

.default_cfvosObject

These are the default conditional formatting value objects that define a two tone color gradient.



12
13
14
15
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 12

def default_cfvos
  [{ :type => :min, :val => 0, :color => 'FFFF7128' },
   { :type => :max, :val => 0, :color => 'FFFFEF9C' }]
end

.three_toneObject

A builder for three tone color gradient

Examples:

#this creates a three tone color scale
color_scale = Axlsx::ColorScale.three_tone

See Also:

  • conditional formatting examples.


31
32
33
34
35
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 31

def three_tone
  self.new({ :type => :min, :val => 0, :color => 'FFF8696B' },
           { :type => :percent, :val => '50', :color => 'FFFFEB84' },
           { :type => :max, :val => 0, :color => 'FF63BE7B' })
end

.two_toneObject

A builder for two tone color gradient

Examples:

# this creates a two tone color scale
color_scale = Axlsx::ColorScale.two_tone

See Also:

  • conditional formatting examples.


22
23
24
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 22

def two_tone
  self.new
end

Instance Method Details

#add(options = {}) ⇒ Hash

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.

Parameters:

  • options (Hash) (defaults to: {})

    options for the new cfvo and color objects

  • [Symbol] (Hash)

    a customizable set of options

  • [Any] (Hash)

    a customizable set of options

  • [String] (Hash)

    a customizable set of options

Returns:

  • (Hash)

    a hash with :cfvo and :color keys referencing the newly added objects.



68
69
70
71
72
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 68

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

#colorsSimpleTypedList

A simple types list of colors

Returns:

  • (SimpleTypedList)

See Also:



47
48
49
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 47

def colors
  @colors ||= SimpleTypedList.new Color
end

#delete_at(index = 2) ⇒ Object

Note:

you cannot remove the first two cfvo and color pairs

removes the cfvo and color pair at the index specified.

Parameters:

  • index (Integer) (defaults to: 2)

    The index of the cfvo and color object to delete



77
78
79
80
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 77

def delete_at(index = 2)
  value_objects.delete_at index
  colors.delete_at index
end

#to_xml_string(str = '') ⇒ String

Serialize this color_scale object data to an xml string

Parameters:

  • str (String) (defaults to: '')

Returns:

  • (String)


85
86
87
88
89
90
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 85

def to_xml_string(str = '')
  str << '<colorScale>'
  value_objects.to_xml_string(str)
  colors.each { |color| color.to_xml_string(str) }
  str << '</colorScale>'
end

#value_objectsSimpleTypedList

A simple typed list of cfvos

Returns:

  • (SimpleTypedList)

See Also:



40
41
42
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 40

def value_objects
  @value_objects ||= Cfvos.new
end