diff options
| author | Noel Peden <[email protected]> | 2022-02-07 08:15:47 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-02-07 08:15:47 -0800 |
| commit | be9b3e6ee9dca0e0377ae8f3b14d007ad494b7e6 (patch) | |
| tree | 00cca6551838ca48dc297dd71338c14d8f8467b0 | |
| parent | 196862524f94c58b1521ef84a6cf0397b411a685 (diff) | |
| parent | f957baf68aae6ec06e94b5b7b4b1d281ab295ab3 (diff) | |
| download | caxlsx-be9b3e6ee9dca0e0377ae8f3b14d007ad494b7e6.tar.gz caxlsx-be9b3e6ee9dca0e0377ae8f3b14d007ad494b7e6.zip | |
Merge pull request #85 from olegykz/feature/manageable-scatter-markers
feature: manageable markers for scatter series
| -rw-r--r-- | CHANGELOG.md | 1 | ||||
| -rw-r--r-- | lib/axlsx/drawing/scatter_series.rb | 31 | ||||
| -rw-r--r-- | test/drawing/tc_scatter_series.rb | 18 |
3 files changed, 50 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3e642869..55366dd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ CHANGELOG --------- - **Unreleased** + - [PR #75](https://github.com/caxlsx/caxlsx/pull/85) - Added manageable markers for scatter series - [PR #117](https://github.com/caxlsx/caxlsx/pull/117) - Allow passing an Array of border hashes to the `border` style. Change previous behaviour where `border_top`, `border_*` styles would not be applied unless `border` style was also defined. - [PR #122](https://github.com/caxlsx/caxlsx/pull/122) - Improve error messages when incorrect ranges are provided to `Worksheet#[]` - [PR #123](https://github.com/caxlsx/caxlsx/pull/123) - Fix invalid xml when pivot table created with more than one column in data field. Solves [Issue #110](https://github.com/caxlsx/caxlsx/issues/110) diff --git a/lib/axlsx/drawing/scatter_series.rb b/lib/axlsx/drawing/scatter_series.rb index b9ca2c1d..8158c373 100644 --- a/lib/axlsx/drawing/scatter_series.rb +++ b/lib/axlsx/drawing/scatter_series.rb @@ -28,6 +28,14 @@ module Axlsx # @return [Boolean] attr_reader :smooth + # Line markers presence + # @return [Boolean] + attr_reader :show_marker + + # custom marker symbol + # @return [String] + attr_reader :marker_symbol + # Creates a new ScatterSeries def initialize(chart, options={}) @xData, @yData = nil @@ -40,6 +48,9 @@ module Axlsx @smooth = options[:smooth] end @ln_width = options[:ln_width] unless options[:ln_width].nil? + @show_marker = [:lineMarker, :marker, :smoothMarker].include?(chart.scatter_style) + @marker_symbol = :default + super(chart, options) @xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil? @yData = NumDataSource.new({:tag_name => :yVal, :data => options[:yData]}) unless options[:yData].nil? @@ -61,6 +72,12 @@ module Axlsx @ln_width = v end + # @see marker_symbol + def marker_symbol=(v) + Axlsx::validate_marker_symbol(v) + @marker_symbol = v + end + # Serializes the object # @param [String] str # @return [String] @@ -81,8 +98,12 @@ module Axlsx str << '<a:ln><a:solidFill>' str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>') str << '</c:spPr>' + str << marker_symbol_xml str << '</c:marker>' + else + str << "<c:marker>#{marker_symbol_xml}</c:marker>" end + if ln_width str << '<c:spPr>' str << '<a:ln w="' << ln_width.to_s << '"/>' @@ -94,5 +115,15 @@ module Axlsx end str end + + private + + def marker_symbol_xml + if !@show_marker + '<c:symbol val="none"/>' + elsif @marker_symbol != :default + '<c:symbol val="' + @marker_symbol.to_s + '"/>' + end.to_s + end end end diff --git a/test/drawing/tc_scatter_series.rb b/test/drawing/tc_scatter_series.rb index ea3611ab..3d1d294d 100644 --- a/test/drawing/tc_scatter_series.rb +++ b/test/drawing/tc_scatter_series.rb @@ -53,4 +53,22 @@ class TestScatterSeries < Test::Unit::TestCase assert_equal(doc.xpath("//a:ln[@w='#{@series.ln_width}']").length, 1) end + def test_false_show_marker + @chart = @ws.add_chart Axlsx::ScatterChart, :title => 'Smooth Chart', :scatter_style => :smoothMarker + @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9] + assert(@series.show_marker, 'markers are enabled for marker-related styles') + end + + def test_true_show_marker + @chart = @ws.add_chart Axlsx::ScatterChart, :title => 'Line chart', :scatter_style => :line + @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9] + assert([email protected]_marker, 'markers are disabled for markerless scatter styles') + end + + def test_marker_symbol + @chart = @ws.add_chart Axlsx::ScatterChart, :title => 'Line chart', :scatter_style => :line + @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :marker_symbol => :diamond + assert_equal(@series.marker_symbol, :diamond, 'series could have own custom marker symbol') + end + end |
