Class: Axlsx::DataBar

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

Overview

Note:

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

Constant Summary collapse

CHILD_ELEMENTS =

instance values that must be serialized as their own elements - e.g. not attributes.

[:value_objects, :color]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ DataBar

Creates a new data bar conditional formatting object

Parameters:

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

    a customizable set of options

Options Hash (options):

  • minLength (Integer)
  • maxLength (Integer)
  • showValue (Boolean)
  • color (String)
    • the rbg value used to color the bars

Yields:

  • (_self)

Yield Parameters:



48
49
50
51
52
53
54
55
56
57
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 48

def initialize(options = {})
  @minLength = 10
  @maxLength = 90
  @showValue = true
  initialize_value_objects
  options.each do |o|
    self.send("#{o[0]}=", o[1]) if self.respond_to? "#{o[0]}="
  end
  yield self if block_given?
end

Instance Attribute Details

#maxLengthInteger

maxLength attribute The maximum length of the data bar, as a percentage of the cell width. The default value is 90

Returns:

  • (Integer)


23
24
25
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 23

def maxLength
  @maxLength
end

#minLengthInteger

minLength attribute The minimum length of the data bar, as a percentage of the cell width. The default value is 10

Returns:

  • (Integer)


17
18
19
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 17

def minLength
  @minLength
end

#showValueBoolean

maxLength attribute Indicates whether to show the values of the cells on which this data bar is applied. The default value is true

Returns:

  • (Boolean)


29
30
31
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 29

def showValue
  @showValue
end

#value_objectsSimpleTypedList (readonly)

A simple typed list of cfvos

Returns:

  • (SimpleTypedList)

See Also:



34
35
36
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 34

def value_objects
  @value_objects
end

Instance Method Details

#colorColor

color the color object used in the data bar formatting

Returns:



39
40
41
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 39

def color
  @color ||= Color.new :rgb => "FF0000FF"
end

#color=(v) ⇒ Object

Sets the color for the data bars.

Parameters:

  • v (Color|String)

    The color object, or rgb string value to apply



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

def color=(v)
  @color = v if v.is_a? Color
  self.color.rgb = v if v.is_a? String
  @color
end

#to_xml_string(str = "") ⇒ String

Serialize this object to an xml string

Parameters:

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

Returns:

  • (String)


78
79
80
81
82
83
84
85
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 78

def to_xml_string(str="")
  str << '<dataBar '
  str << instance_values.map { |key, value| '' << key << '="' << value.to_s << '"' unless CHILD_ELEMENTS.include?(key.to_sym) }.join(' ')
  str << '>'
  @value_objects.each { |cfvo| cfvo.to_xml_string(str) }
  self.color.to_xml_string(str)
  str << '</dataBar>'
end