summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJonathan Tron <[email protected]>2015-07-05 15:42:11 +0200
committerJonathan Tron <[email protected]>2015-07-05 15:42:11 +0200
commit1549f3fbacc72a7c091313860558114124962c81 (patch)
tree3c506ee6d5b9e39f4680b7b135b111a27e659b81
parentebb8c19b6231dc24a3ca280fc4c0f78e78b91ef5 (diff)
parentf0f372165beb37a6d91f6c98bc9b2268cb4eda74 (diff)
downloadcaxlsx-1549f3fbacc72a7c091313860558114124962c81.tar.gz
caxlsx-1549f3fbacc72a7c091313860558114124962c81.zip
Merge branch 'mfrank01-marker_symbols'
-rw-r--r--lib/axlsx/drawing/line_series.rb19
-rw-r--r--lib/axlsx/util/validators.rb4
-rw-r--r--test/drawing/tc_line_series.rb43
-rw-r--r--test/util/tc_validators.rb44
4 files changed, 94 insertions, 16 deletions
diff --git a/lib/axlsx/drawing/line_series.rb b/lib/axlsx/drawing/line_series.rb
index 50df27b8..666e67c8 100644
--- a/lib/axlsx/drawing/line_series.rb
+++ b/lib/axlsx/drawing/line_series.rb
@@ -23,6 +23,10 @@ module Axlsx
# @return [Boolean]
attr_reader :show_marker
+ # custom marker symbol
+ # @return [String]
+ attr_reader :marker_symbol
+
# line smoothing on values
# @return [Boolean]
attr_reader :smooth
@@ -33,6 +37,7 @@ module Axlsx
# @param [Chart] chart
def initialize(chart, options={})
@show_marker = false
+ @marker_symbol = options[:marker_symbol] ? options[:marker_symbol] : :default
@smooth = false
@labels, @data = nil, nil
super(chart, options)
@@ -51,6 +56,12 @@ module Axlsx
@show_marker = v
end
+ # @see marker_symbol
+ def marker_symbol=(v)
+ Axlsx::validate_marker_symbol(v)
+ @marker_symbol = v
+ end
+
# @see smooth
def smooth=(v)
Axlsx::validate_boolean(v)
@@ -74,7 +85,13 @@ module Axlsx
str << '<a:round/>'
str << '</c:spPr>'
end
- str << '<c:marker><c:symbol val="none"/></c:marker>' unless @show_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
+
@labels.to_xml_string(str) unless @labels.nil?
@data.to_xml_string(str) unless @data.nil?
str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
diff --git a/lib/axlsx/util/validators.rb b/lib/axlsx/util/validators.rb
index c9ee2e6e..9c6f34aa 100644
--- a/lib/axlsx/util/validators.rb
+++ b/lib/axlsx/util/validators.rb
@@ -304,4 +304,8 @@ module Axlsx
RestrictionValidator.validate :visibility, [:visible, :hidden, :very_hidden], v
end
+ # Requires that the value is one of :default, :circle, :dash, :diamond, :dot, :picture, :plus, :square, :star, :triangle, :x
+ def self.validate_marker_symbol(v)
+ RestrictionValidator.validate :marker_symbol, [:default, :circle, :dash, :diamond, :dot, :picture, :plus, :square, :star, :triangle, :x], v
+ end
end
diff --git a/test/drawing/tc_line_series.rb b/test/drawing/tc_line_series.rb
index 3d023a12..d939096f 100644
--- a/test/drawing/tc_line_series.rb
+++ b/test/drawing/tc_line_series.rb
@@ -6,14 +6,20 @@ class TestLineSeries < Test::Unit::TestCase
p = Axlsx::Package.new
@ws = p.workbook.add_worksheet :name=>"hmmm"
chart = @ws.add_chart Axlsx::Line3DChart, :title => "fishery"
- @series = chart.add_series :data=>[0,1,2], :labels=>["zero", "one", "two"], :title=>"bob", :color => "#FF0000", :show_marker => true, :smooth => true
+ @series = chart.add_series(
+ :data => [0,1,2],
+ :labels => ["zero", "one", "two"],
+ :title => "bob",
+ :color => "#FF0000",
+ :show_marker => true,
+ :smooth => true
+ )
end
def test_initialize
assert_equal(@series.title.text, "bob", "series title has been applied")
assert_equal(@series.labels.class, Axlsx::AxDataSource)
assert_equal(@series.data.class, Axlsx::NumDataSource)
-
end
def test_show_marker
@@ -28,11 +34,38 @@ class TestLineSeries < Test::Unit::TestCase
assert_equal(false, @series.smooth)
end
+ def test_marker_symbol
+ assert_equal(:default, @series.marker_symbol)
+ @series.marker_symbol = :circle
+ assert_equal(:circle, @series.marker_symbol)
+ end
+
def test_to_xml_string
- doc = Nokogiri::XML(@series.to_xml_string)
+ doc = Nokogiri::XML(wrap_with_namespaces(@series))
assert(doc.xpath("//srgbClr[@val='#{@series.color}']"))
- assert(doc.xpath("//marker"))
+ assert_equal(xpath_with_namespaces(doc, "//c:marker").size, 0)
assert(doc.xpath("//smooth"))
+
+ @series.marker_symbol = :diamond
+ doc = Nokogiri::XML(wrap_with_namespaces(@series))
+ assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='diamond']").size, 1)
+
+ @series.show_marker = false
+ doc = Nokogiri::XML(wrap_with_namespaces(@series))
+ assert_equal(xpath_with_namespaces(doc, "//c:marker/c:symbol[@val='none']").size, 1)
+ end
+
+ def wrap_with_namespaces(series)
+ '<c:chartSpace xmlns:c="' <<
+ Axlsx::XML_NS_C <<
+ '" xmlns:a="' <<
+ Axlsx::XML_NS_A <<
+ '">' <<
+ series.to_xml_string <<
+ '</c:chartSpace>'
+ end
+
+ def xpath_with_namespaces(doc, xpath)
+ doc.xpath(xpath, "a" => Axlsx::XML_NS_A, "c" => Axlsx::XML_NS_C)
end
- #TODO serialization testing
end
diff --git a/test/util/tc_validators.rb b/test/util/tc_validators.rb
index 7a82f90d..6effac51 100644
--- a/test/util/tc_validators.rb
+++ b/test/util/tc_validators.rb
@@ -91,7 +91,7 @@ class TestValidators < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 10.0 }
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 400.1 }
assert_raise(ArgumentError) { Axlsx.validate_scale_10_400 "99" }
-
+
#scale_0_10_400
assert_nothing_raised { Axlsx.validate_scale_0_10_400 0 }
assert_nothing_raised { Axlsx.validate_scale_0_10_400 10 }
@@ -101,7 +101,7 @@ class TestValidators < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 10.0 }
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 400.1 }
assert_raise(ArgumentError) { Axlsx.validate_scale_0_10_400 "99" }
-
+
#page_orientation
assert_nothing_raised { Axlsx.validate_page_orientation :default }
assert_nothing_raised { Axlsx.validate_page_orientation :landscape }
@@ -109,7 +109,7 @@ class TestValidators < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx.validate_page_orientation nil }
assert_raise(ArgumentError) { Axlsx.validate_page_orientation 1 }
assert_raise(ArgumentError) { Axlsx.validate_page_orientation "landscape" }
-
+
#data_validation_error_style
[:information, :stop, :warning].each do |sym|
assert_nothing_raised { Axlsx.validate_data_validation_error_style sym }
@@ -117,7 +117,7 @@ class TestValidators < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'warning' }
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
-
+
#data_validation_operator
[:lessThan, :lessThanOrEqual, :equal, :notEqual, :greaterThanOrEqual, :greaterThan, :between, :notBetween].each do |sym|
assert_nothing_raised { Axlsx.validate_data_validation_operator sym }
@@ -125,7 +125,7 @@ class TestValidators < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'lessThan' }
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
-
+
#data_validation_type
[:custom, :data, :decimal, :list, :none, :textLength, :time, :whole].each do |sym|
assert_nothing_raised { Axlsx.validate_data_validation_type sym }
@@ -133,7 +133,7 @@ class TestValidators < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'decimal' }
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
-
+
#sheet_view_type
[:normal, :page_break_preview, :page_layout].each do |sym|
assert_nothing_raised { Axlsx.validate_sheet_view_type sym }
@@ -141,7 +141,7 @@ class TestValidators < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style :other_symbol }
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 'page_layout' }
assert_raise(ArgumentError) { Axlsx.validate_data_validation_error_style 0 }
-
+
#active_pane_type
[:bottom_left, :bottom_right, :top_left, :top_right].each do |sym|
assert_nothing_raised { Axlsx.validate_pane_type sym }
@@ -149,7 +149,7 @@ class TestValidators < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx.validate_pane_type :other_symbol }
assert_raise(ArgumentError) { Axlsx.validate_pane_type 'bottom_left' }
assert_raise(ArgumentError) { Axlsx.validate_pane_type 0 }
-
+
#split_state_type
[:frozen, :frozen_split, :split].each do |sym|
assert_nothing_raised { Axlsx.validate_split_state_type sym }
@@ -157,8 +157,32 @@ class TestValidators < Test::Unit::TestCase
assert_raise(ArgumentError) { Axlsx.validate_split_state_type :other_symbol }
assert_raise(ArgumentError) { Axlsx.validate_split_state_type 'frozen_split' }
assert_raise(ArgumentError) { Axlsx.validate_split_state_type 0 }
+
+ #display_blanks_as
+ [:gap, :span, :zero].each do |sym|
+ assert_nothing_raised { Axlsx.validate_display_blanks_as sym }
+ end
+ assert_raise(ArgumentError) { Axlsx.validate_display_blanks_as :other_symbol }
+ assert_raise(ArgumentError) { Axlsx.validate_display_blanks_as 'other_blank' }
+ assert_raise(ArgumentError) { Axlsx.validate_display_blanks_as 0 }
+
+ #view_visibility
+ [:visible, :hidden, :very_hidden].each do |sym|
+ assert_nothing_raised { Axlsx.validate_view_visibility sym }
+ end
+ assert_raise(ArgumentError) { Axlsx.validate_view_visibility :other_symbol }
+ assert_raise(ArgumentError) { Axlsx.validate_view_visibility 'other_visibility' }
+ assert_raise(ArgumentError) { Axlsx.validate_view_visibility 0 }
+
+ #marker_symbol
+ [:default, :circle, :dash, :diamond, :dot, :picture, :plus, :square, :star, :triangle, :x].each do |sym|
+ assert_nothing_raised { Axlsx.validate_marker_symbol sym }
+ end
+ assert_raise(ArgumentError) { Axlsx.validate_marker_symbol :other_symbol }
+ assert_raise(ArgumentError) { Axlsx.validate_marker_symbol 'other_marker' }
+ assert_raise(ArgumentError) { Axlsx.validate_marker_symbol 0 }
end
-
+
def test_validate_integerish
assert_raise(ArgumentError) { Axlsx.validate_integerish Axlsx }
[1, 1.4, "a"].each { |test_value| assert_nothing_raised { Axlsx.validate_integerish test_value } }
@@ -179,7 +203,7 @@ class TestValidators < Test::Unit::TestCase
def test_range_validation
# exclusive
- assert_raise(ArgumentError) { Axlsx::RangeValidator.validate('foo', 1, 10, 10, false) }
+ assert_raise(ArgumentError) { Axlsx::RangeValidator.validate('foo', 1, 10, 10, false) }
# inclusive by default
assert_nothing_raised { Axlsx::RangeValidator.validate('foo', 1, 10, 10) }
end