diff options
| author | Ian Anderson <[email protected]> | 2014-08-12 17:33:38 -0400 |
|---|---|---|
| committer | Ian Anderson <[email protected]> | 2014-08-12 17:33:38 -0400 |
| commit | 54e654648923212fb128214578fe502eaefd4eb9 (patch) | |
| tree | 59eaf7cce02e2d624b9247abe015f3020ddcc660 | |
| parent | 7cf747675097be13df633f1b2a5c45391df52b33 (diff) | |
| download | caxlsx-54e654648923212fb128214578fe502eaefd4eb9.tar.gz caxlsx-54e654648923212fb128214578fe502eaefd4eb9.zip | |
Add support for enabling or disabling smoothed lines in a scatter chart series
| -rw-r--r-- | lib/axlsx/drawing/scatter_series.rb | 19 | ||||
| -rw-r--r-- | test/drawing/tc_scatter_series.rb | 26 |
2 files changed, 44 insertions, 1 deletions
diff --git a/lib/axlsx/drawing/scatter_series.rb b/lib/axlsx/drawing/scatter_series.rb index 28962230..c0d6e8f1 100644 --- a/lib/axlsx/drawing/scatter_series.rb +++ b/lib/axlsx/drawing/scatter_series.rb @@ -21,9 +21,21 @@ module Axlsx # @return [String] attr_reader :color + # Line smoothing between data points + # @return [Boolean] + attr_reader :smooth + # Creates a new ScatterSeries def initialize(chart, options={}) @xData, @yData = 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) + else + # Set smoothing according to the option provided + Axlsx::validate_boolean(options[:smooth]) + @smooth = options[:smooth] + end 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? @@ -34,6 +46,12 @@ module Axlsx @color = v end + # @see smooth + def smooth=(v) + Axlsx::validate_boolean(v) + @smooth = v + end + # Serializes the object # @param [String] str # @return [String] @@ -58,6 +76,7 @@ module Axlsx end @xData.to_xml_string(str) unless @xData.nil? @yData.to_xml_string(str) unless @yData.nil? + str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>') end str end diff --git a/test/drawing/tc_scatter_series.rb b/test/drawing/tc_scatter_series.rb index b43ed171..0f038022 100644 --- a/test/drawing/tc_scatter_series.rb +++ b/test/drawing/tc_scatter_series.rb @@ -6,13 +6,37 @@ class TestScatterSeries < Test::Unit::TestCase p = Axlsx::Package.new @ws = p.workbook.add_worksheet :name=>"hmmm" @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Scatter Chart" - @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"exponents", :color => 'FF0000' + @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"exponents", :color => 'FF0000', :smooth => true end def test_initialize assert_equal(@series.title.text, "exponents", "series title has been applied") end + def test_smoothed_chart_default_smoothing + @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Smooth Chart", :scatter_style => :smoothMarker + @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"smoothed exponents" + assert(@series.smooth, "series is smooth by default on smooth charts") + end + + def test_unsmoothed_chart_default_smoothing + @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart", :scatter_style => :line + @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"unsmoothed exponents" + assert([email protected], "series is not smooth by default on non-smooth charts") + end + + def test_explicit_smoothing + @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Unsmooth Chart, Smooth Series", :scatter_style => :line + @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"smoothed exponents", :smooth => true + assert(@series.smooth, "series is smooth when overriding chart default") + end + + def test_explicit_unsmoothing + @chart = @ws.add_chart Axlsx::ScatterChart, :title => "Smooth Chart, Unsmooth Series", :scatter_style => :smoothMarker + @series = @chart.add_series :xData=>[1,2,4], :yData=>[1,3,9], :title=>"unsmoothed exponents", :smooth => false + assert([email protected]"series is not smooth when overriding chart default") + end + def test_to_xml_string doc = Nokogiri::XML(@chart.to_xml_string) assert_equal(doc.xpath("//a:srgbClr[@val='#{@series.color}']").size,4) |
