summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorOleg Yakovenko <[email protected]>2021-03-01 18:37:28 +0200
committerOleg Yakovenko <[email protected]>2021-03-01 18:37:28 +0200
commit8dd92ebff726f60fbd31f5f0dcb05849745dea39 (patch)
tree031dd95c741e7828cae93e8c0012afefa8586cd5
parentd74a588a2f5b3e15a4fe94a946f058d0dfaa1c5e (diff)
downloadcaxlsx-8dd92ebff726f60fbd31f5f0dcb05849745dea39.tar.gz
caxlsx-8dd92ebff726f60fbd31f5f0dcb05849745dea39.zip
feature: marker symbol management for scatter series
-rw-r--r--lib/axlsx/drawing/scatter_series.rb24
-rw-r--r--test/drawing/tc_scatter_series.rb14
2 files changed, 30 insertions, 8 deletions
diff --git a/lib/axlsx/drawing/scatter_series.rb b/lib/axlsx/drawing/scatter_series.rb
index 1e116860..b62fc006 100644
--- a/lib/axlsx/drawing/scatter_series.rb
+++ b/lib/axlsx/drawing/scatter_series.rb
@@ -30,11 +30,15 @@ module Axlsx
# Line markers presence
# @return [Boolean]
- attr_reader :marker
+ attr_reader :show_marker
+
+ # custom marker symbol
+ # @return [String]
+ attr_reader :marker_symbol
# Creates a new ScatterSeries
def initialize(chart, options={})
- @xData, @yData = nil
+ @xData, @yData, @marker_symbol = nil
if options[:smooth].nil?
# If caller hasn't specified smoothing or not, turn smoothing on or off based on scatter style
@smooth = [:smooth, :smoothMarker].include?(chart.scatter_style)
@@ -44,7 +48,7 @@ module Axlsx
@smooth = options[:smooth]
end
@ln_width = options[:ln_width] unless options[:ln_width].nil?
- @marker = [:lineMarker, :marker, :smoothMarker].include?(chart.scatter_style)
+ @show_marker = [:lineMarker, :marker, :smoothMarker].include?(chart.scatter_style)
super(chart, options)
@xData = AxDataSource.new(:tag_name => :xVal, :data => options[:xData]) unless options[:xData].nil?
@@ -67,6 +71,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]
@@ -87,7 +97,13 @@ module Axlsx
str << '<a:ln><a:solidFill>'
str << ('<a:srgbClr val="' << color << '"/></a:solidFill></a:ln>')
str << '</c:spPr>'
- str << '<c:symbol val="none"/>' unless marker
+
+ if !@show_marker
+ str << '<c:marker><c:symbol val="none"/></c:marker>'
+ elsif @marker_symbol != :default
+ str << '<c:marker><c:symbol val="' + @marker_symbol.to_s + '"/></c:marker>'
+ end
+
str << '</c:marker>'
end
if ln_width
diff --git a/test/drawing/tc_scatter_series.rb b/test/drawing/tc_scatter_series.rb
index 2139d65f..bf2fb958 100644
--- a/test/drawing/tc_scatter_series.rb
+++ b/test/drawing/tc_scatter_series.rb
@@ -53,16 +53,22 @@ class TestScatterSeries < Test::Unit::TestCase
assert_equal(doc.xpath("//a:ln[@w='#{@series.ln_width}']").length, 1)
end
- def test_chart_style_with_marker
+ 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.marker, "markers are enabled for marker-related styles")
+ assert(@series.show_marker, "markers are enabled for marker-related styles")
end
- def test_chart_style_without_marker
+ 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], "markers are disabled for markerless scatter styles")
+ 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, "markers are disabled for markerless scatter styles")
end
end