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:


58
59
60
61
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 58

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.


14
15
16
17
# 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

.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.

33
34
35
36
37
# 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

.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.

24
25
26
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 24

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.


70
71
72
73
74
# 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

#colorsSimpleTypedList

A simple types list of colors

Returns:

  • (SimpleTypedList)

See Also:


49
50
51
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 49

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


80
81
82
83
# 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

#to_xml_string(str = '') ⇒ String

Serialize this color_scale object data to an xml string

Parameters:

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

Returns:

  • (String)

88
89
90
91
92
93
# 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

#value_objectsSimpleTypedList

A simple typed list of cfvos

Returns:

  • (SimpleTypedList)

See Also:


42
43
44
# File 'lib/axlsx/workbook/worksheet/color_scale.rb', line 42

def value_objects
  @value_objects ||= Cfvos.new
end