class Axlsx::DataBar

@note The recommended way to manage these rules is via Worksheet#add_conditional_formatting @see Worksheet#add_conditional_formatting @see ConditionalFormattingRule#initialize

Constants

CHILD_ELEMENTS

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

Attributes

maxLength[R]

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

max_length[R]

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

minLength[R]

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

min_length[R]

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

showValue[R]

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]

show_value[R]

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]

Public Class Methods

default_cfvos() click to toggle source

This differs from ColorScale. There must be exactly two cfvos one color

# File lib/axlsx/workbook/worksheet/data_bar.rb, line 15
def default_cfvos
  [{:type => :min, :val => "0"},
   {:type => :max, :val => "0"}]
end
new(options = {}, *cfvos) { |self| ... } click to toggle source

Creates a new data bar conditional formatting object @param [Hash] options @option options [Integer] minLength @option options [Integer] maxLength @option options [Boolean] showValue @option options [String] color - the rbg value used to color the bars @param [Array] cfvos hashes defining the gradient interpolation points for this formatting.

# File lib/axlsx/workbook/worksheet/data_bar.rb, line 28
def initialize(options = {}, *cfvos)
  @min_length = 10
  @max_length = 90
  @show_value = true
  parse_options options
  initialize_cfvos(cfvos)
  yield self if block_given?
end

Public Instance Methods

color() click to toggle source

color the color object used in the data bar formatting @return [Color]

# File lib/axlsx/workbook/worksheet/data_bar.rb, line 73
def color
  @color ||= Color.new :rgb => "FF0000FF"
end
color=(v) click to toggle source

Sets the color for the data bars. @param [Color|String] v The color object, or rgb string value to apply

# File lib/axlsx/workbook/worksheet/data_bar.rb, line 100
def color=(v)
  @color = v if v.is_a? Color
  self.color.rgb = v if v.is_a? String
  @color
end
maxLength=(v)
Alias for: max_length=
max_length=(v) click to toggle source

@see maxLength

# File lib/axlsx/workbook/worksheet/data_bar.rb, line 85
def max_length=(v)
  Axlsx.validate_unsigned_int(v)
  @max_length = v
end
Also aliased as: maxLength=
minLength=(v)
Alias for: min_length=
min_length=(v) click to toggle source

@see minLength

# File lib/axlsx/workbook/worksheet/data_bar.rb, line 78
def min_length=(v)
  Axlsx.validate_unsigned_int(v)
  @min_length = v
end
Also aliased as: minLength=
showValue=(v)
Alias for: show_value=
show_value=(v) click to toggle source

@see showValue

# File lib/axlsx/workbook/worksheet/data_bar.rb, line 92
def show_value=(v)
  Axlsx.validate_boolean(v)
  @show_value = v
end
Also aliased as: showValue=
to_xml_string(str="") click to toggle source

Serialize this object to an xml string @param [String] str @return [String]

# File lib/axlsx/workbook/worksheet/data_bar.rb, line 109
def to_xml_string(str="")
  serialized_tag('dataBar', str) do
    value_objects.to_xml_string(str)
    self.color.to_xml_string(str)
  end
end
value_objects() click to toggle source

A simple typed list of cfvos @return [SimpleTypedList] @see Cfvo

# File lib/axlsx/workbook/worksheet/data_bar.rb, line 66
def value_objects
  @value_objects ||= Cfvos.new
end

Private Instance Methods

initialize_cfvos(cfvos) click to toggle source
# File lib/axlsx/workbook/worksheet/data_bar.rb, line 118
def initialize_cfvos(cfvos)
  self.class.default_cfvos.each_with_index.map do |default, index|
    if index < cfvos.size
      value_objects << Cfvo.new(default.merge(cfvos[index]))
    else
      value_objects << Cfvo.new(default)
    end
  end
end