summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--.rubocop_todo.yml5
-rw-r--r--CHANGELOG.md1
-rw-r--r--lib/axlsx/workbook/worksheet/icon_set.rb23
-rw-r--r--test/workbook/worksheet/tc_icon_set.rb16
4 files changed, 36 insertions, 9 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 6e233ce4..00f831d9 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -117,11 +117,6 @@ Style/ClassVars:
- 'lib/axlsx/workbook/workbook.rb'
- 'lib/axlsx/workbook/worksheet/dimension.rb'
-# This cop supports unsafe autocorrection (--autocorrect-all).
-Style/ConcatArrayLiterals:
- Exclude:
- - 'lib/axlsx/workbook/worksheet/icon_set.rb'
-
# Configuration parameters: AllowedConstants.
Style/Documentation:
Exclude:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d09e3196..7896ea61 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ CHANGELOG
- Raise exception if `axlsx_styler` gem is present as its code was merged directly into `caxlsx` in v3.3.0
- Add 'SortState' and 'SortCondition' classes to the 'AutoFilter' class to add sorting to the generated file.
- [PR #189](https://github.com/caxlsx/caxlsx/pull/189) - Make `Axlsx::escape_formulas` true by default to mitigate [Formula Injection](https://www.owasp.org/index.php/CSV_Injection) vulnerabilities.
+ - [PR #269](https://github.com/caxlsx/caxlsx/pull/269) - Add optional interpolation points to icon sets
- **April.23.23**: 3.4.1
- [PR #209](https://github.com/caxlsx/caxlsx/pull/209) - Revert characters other than `=` being considered as formulas.
diff --git a/lib/axlsx/workbook/worksheet/icon_set.rb b/lib/axlsx/workbook/worksheet/icon_set.rb
index 64b0c21a..e5dbcb11 100644
--- a/lib/axlsx/workbook/worksheet/icon_set.rb
+++ b/lib/axlsx/workbook/worksheet/icon_set.rb
@@ -20,8 +20,10 @@ module Axlsx
@percent = @showValue = true
@reverse = false
@iconSet = "3TrafficLights1"
- initialize_value_objects
+ @interpolationPoints = [0, 33, 67]
+
parse_options options
+
yield self if block_given?
end
@@ -34,7 +36,7 @@ module Axlsx
attr_reader :iconSet
# Indicates whether the thresholds indicate percentile values, instead of number values.
- # The default falue is true
+ # The default value is true
# @return [Boolean]
attr_reader :percent
@@ -48,9 +50,21 @@ module Axlsx
# @return [Boolean]
attr_reader :showValue
+ # Sets the values of the interpolation points in the scale.
+ # The default value is [0, 33, 67]
+ # @return [Integer]
+ attr_reader :interpolationPoints
+
# @see iconSet
def iconSet=(v); Axlsx.validate_icon_set(v); @iconSet = v end
+ # @see interpolationPoints
+ def interpolationPoints=(v)
+ v.each { |point| Axlsx.validate_int(point) }
+ @value_objects = nil
+ @interpolationPoints = v
+ end
+
# @see showValue
def showValue=(v); Axlsx.validate_boolean(v); @showValue = v end
@@ -64,6 +78,8 @@ module Axlsx
# @param [String] str
# @return [String]
def to_xml_string(str = +'')
+ initialize_value_objects if @value_objects.nil?
+
serialized_tag('iconSet', str) do
@value_objects.each { |cfvo| cfvo.to_xml_string(str) }
end
@@ -72,10 +88,9 @@ module Axlsx
private
# Initalize the simple typed list of value objects
- # I am keeping this private for now as I am not sure what impact changes to the required two cfvo objects will do.
def initialize_value_objects
@value_objects = SimpleTypedList.new Cfvo
- @value_objects.concat [Cfvo.new(type: :percent, val: 0), Cfvo.new(type: :percent, val: 33), Cfvo.new(type: :percent, val: 67)]
+ @interpolationPoints.each { |point| @value_objects << Cfvo.new(type: :percent, val: point) }
@value_objects.lock
end
end
diff --git a/test/workbook/worksheet/tc_icon_set.rb b/test/workbook/worksheet/tc_icon_set.rb
index beb69919..b2ced29b 100644
--- a/test/workbook/worksheet/tc_icon_set.rb
+++ b/test/workbook/worksheet/tc_icon_set.rb
@@ -12,6 +12,7 @@ class TestIconSet < Test::Unit::TestCase
assert(@icon_set.percent)
refute(@icon_set.reverse)
assert(@icon_set.showValue)
+ assert_equal([0, 33, 67], @icon_set.interpolationPoints)
end
def test_icon_set
@@ -20,6 +21,12 @@ class TestIconSet < Test::Unit::TestCase
assert_equal("5Rating", @icon_set.iconSet)
end
+ def test_interpolation_points
+ assert_raise(ArgumentError) { @icon_set.interpolationPoints = ["invalid_value"] }
+ assert_nothing_raised { @icon_set.interpolationPoints = [0, 60, 80] }
+ assert_equal([0, 60, 80], @icon_set.interpolationPoints)
+ end
+
def test_percent
assert_raise(ArgumentError) { @icon_set.percent = :invalid_type }
assert_nothing_raised { @icon_set.percent = false }
@@ -44,4 +51,13 @@ class TestIconSet < Test::Unit::TestCase
assert_equal(1, doc.xpath(".//iconSet[@iconSet='3TrafficLights1'][@percent=1][@reverse=0][@showValue=1]").size)
assert_equal(3, doc.xpath(".//iconSet//cfvo").size)
end
+
+ def test_to_xml_string_with_interpolation_points
+ @icon_set.iconSet = '5Arrows'
+ @icon_set.interpolationPoints = [0, 20, 40, 60, 80]
+ doc = Nokogiri::XML.parse(@icon_set.to_xml_string)
+
+ assert_equal(1, doc.xpath(".//iconSet[@iconSet='5Arrows'][@percent=1][@reverse=0][@showValue=1]").size)
+ assert_equal(5, doc.xpath(".//iconSet//cfvo").size)
+ end
end