Class: Axlsx::DataBar

Inherits:
Object
  • Object
show all
Includes:
OptionsParser, SerializedAttributes
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].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializedAttributes

included, #serialized_attributes, #serialized_element_attributes, #serialized_tag

Methods included from OptionsParser

#parse_options

Constructor Details

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

Creates a new data bar conditional formatting object

Parameters:

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

    hashes defining the gradient interpolation points for this formatting.

Options Hash (options):

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

Yields:

  • (_self)

Yield Parameters:



29
30
31
32
33
34
35
36
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 29

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

Instance Attribute Details

#max_lengthInteger Also known as: maxLength

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

Returns:

  • (Integer)


54
55
56
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 54

def max_length
  @max_length
end

#min_lengthInteger Also known as: minLength

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

Returns:

  • (Integer)


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

def min_length
  @min_length
end

#show_valueBoolean Also known as: showValue

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)


61
62
63
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 61

def show_value
  @show_value
end

Class Method Details

.default_cfvosObject

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



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

def default_cfvos
  [{ type: :min, val: "0" },
   { type: :max, val: "0" }]
end

Instance Method Details

#colorColor

color the color object used in the data bar formatting

Returns:



74
75
76
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 74

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



101
102
103
104
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 101

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

#to_xml_string(str = +'')) ⇒ String

Serialize this object to an xml string

Parameters:

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

Returns:

  • (String)


109
110
111
112
113
114
# 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)
    color.to_xml_string(str)
  end
end

#value_objectsSimpleTypedList

A simple typed list of cfvos

Returns:

  • (SimpleTypedList)

See Also:



67
68
69
# File 'lib/axlsx/workbook/worksheet/data_bar.rb', line 67

def value_objects
  @value_objects ||= Cfvos.new
end