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]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SerializedAttributes

#declared_attributes, 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:



28
29
30
31
32
33
34
35
# 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

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)


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

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)


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

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)


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

def show_value
  @show_value
end

Class Method Details

.default_cfvosObject

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



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

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:



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

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



100
101
102
103
104
# 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

#to_xml_string(str = "") ⇒ String

Serialize this object to an xml string

Parameters:

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

Returns:



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)
    self.color.to_xml_string(str)
  end
end

#value_objectsSimpleTypedList

A simple typed list of cfvos

Returns:

  • (SimpleTypedList)

See Also:



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

def value_objects
  @value_objects ||= Cfvos.new
end