diff options
| author | Zsolt Kozaroczy <[email protected]> | 2021-07-25 01:37:29 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-25 01:37:29 +0200 |
| commit | c4d7279de2bd20bc98c15ea64e9074ded19124ca (patch) | |
| tree | 05653d98a5aead376ab378dc9fbc1274f56c9b75 /lib | |
| parent | 158942c16b249a269e77633dd261b87787d191af (diff) | |
| download | caxlsx-c4d7279de2bd20bc98c15ea64e9074ded19124ca.tar.gz caxlsx-c4d7279de2bd20bc98c15ea64e9074ded19124ca.zip | |
Fix gap width validator for bar charts (#108)
`gap_width` and `gap_depth` now allow only integers in the range of 0–500. The previous behaviour (requiring a percentage value) was according to the current version of the OOXML spec, but Excel seems to rely on an older version, where the gap amount was required to be a simple integer.
Also, `gapDepth` is only allowed in 3D bar charts, so it is now no longer available for 2D bar charts.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/drawing/bar_3D_chart.rb | 13 | ||||
| -rw-r--r-- | lib/axlsx/drawing/bar_chart.rb | 23 |
2 files changed, 8 insertions, 28 deletions
diff --git a/lib/axlsx/drawing/bar_3D_chart.rb b/lib/axlsx/drawing/bar_3D_chart.rb index 7d44eca6..ae6c2007 100644 --- a/lib/axlsx/drawing/bar_3D_chart.rb +++ b/lib/axlsx/drawing/bar_3D_chart.rb @@ -31,17 +31,17 @@ module Axlsx alias :barDir :bar_dir # space between bar or column clusters, as a percentage of the bar or column width. - # @return [String] + # @return [Integer] attr_reader :gap_depth alias :gapDepth :gap_depth # space between bar or column clusters, as a percentage of the bar or column width. - # @return [String] + # @return [Integer] def gap_width @gap_width ||= 150 end alias :gapWidth :gap_width - + #grouping for a column, line, or area chart. # must be one of [:percentStacked, :clustered, :standard, :stacked] # @return [Symbol] @@ -56,9 +56,6 @@ module Axlsx @shape ||= :box end - # validation regex for gap amount percent - GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/ - # Creates a new bar chart object # @param [GraphicFrame] frame The workbook that owns this chart. # @option options [Cell, String] title @@ -102,14 +99,14 @@ module Axlsx # space between bar or column clusters, as a percentage of the bar or column width. def gap_width=(v) - RegexValidator.validate "Bar3DChart.gap_width", GAP_AMOUNT_PERCENT, v + RangeValidator.validate "Bar3DChart.gap_width", 0, 500, v @gap_width=(v) end alias :gapWidth= :gap_width= # space between bar or column clusters, as a percentage of the bar or column width. def gap_depth=(v) - RegexValidator.validate "Bar3DChart.gap_didth", GAP_AMOUNT_PERCENT, v + RangeValidator.validate "Bar3DChart.gap_depth", 0, 500, v @gap_depth=(v) end alias :gapDepth= :gap_depth= diff --git a/lib/axlsx/drawing/bar_chart.rb b/lib/axlsx/drawing/bar_chart.rb index cb596fce..67787361 100644 --- a/lib/axlsx/drawing/bar_chart.rb +++ b/lib/axlsx/drawing/bar_chart.rb @@ -31,12 +31,7 @@ module Axlsx alias :barDir :bar_dir # space between bar or column clusters, as a percentage of the bar or column width. - # @return [String] - attr_reader :gap_depth - alias :gapDepth :gap_depth - - # space between bar or column clusters, as a percentage of the bar or column width. - # @return [String] + # @return [Integer] def gap_width @gap_width ||= 150 end @@ -62,9 +57,6 @@ module Axlsx @shape ||= :box end - # validation regex for gap amount percent - GAP_AMOUNT_PERCENT = /0*(([0-9])|([1-9][0-9])|([1-4][0-9][0-9])|500)%/ - # Creates a new bar chart object # @param [GraphicFrame] frame The workbook that owns this chart. # @option options [Cell, String] title @@ -72,12 +64,11 @@ module Axlsx # @option options [Symbol] bar_dir # @option options [Symbol] grouping # @option options [String] gap_width - # @option options [String] gap_depth # @option options [Symbol] shape # @see Chart def initialize(frame, options={}) @vary_colors = true - @gap_width, @gap_depth, @overlap, @shape = nil, nil, nil, nil + @gap_width, @overlap, @shape = nil, nil, nil super(frame, options) @series_type = BarSeries @d_lbls = nil @@ -100,18 +91,11 @@ module Axlsx # space between bar or column clusters, as a percentage of the bar or column width. def gap_width=(v) - RegexValidator.validate "BarChart.gap_width", GAP_AMOUNT_PERCENT, v + RangeValidator.validate "BarChart.gap_width", 0, 500, v @gap_width=(v) end alias :gapWidth= :gap_width= - # space between bar or column clusters, as a percentage of the bar or column width. - def gap_depth=(v) - RegexValidator.validate "BarChart.gap_didth", GAP_AMOUNT_PERCENT, v - @gap_depth=(v) - end - alias :gapDepth= :gap_depth= - def overlap=(v) RangeValidator.validate "BarChart.overlap", -100, 100, v @overlap=(v) @@ -137,7 +121,6 @@ module Axlsx @d_lbls.to_xml_string(str) if @d_lbls str << ('<c:overlap val="' << @overlap.to_s << '"/>') unless @overlap.nil? str << ('<c:gapWidth val="' << @gap_width.to_s << '"/>') unless @gap_width.nil? - str << ('<c:gapDepth val="' << @gap_depth.to_s << '"/>') unless @gap_depth.nil? str << ('<c:shape val="' << @shape.to_s << '"/>') unless @shape.nil? axes.to_xml_string(str, :ids => true) str << '</c:barChart>' |
