summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRandy Morgan <[email protected]>2013-01-23 08:22:16 +0900
committerRandy Morgan <[email protected]>2013-01-23 08:22:39 +0900
commit0e953a4f162bcd8a9d54a39504cea9c074551012 (patch)
tree2e416f627a4127578cc1f2b7aa59e5ca440fa8a6
parent92448544db44106853b3f20a998a36f34a062c4d (diff)
downloadcaxlsx-0e953a4f162bcd8a9d54a39504cea9c074551012.tar.gz
caxlsx-0e953a4f162bcd8a9d54a39504cea9c074551012.zip
Updated chart vary_colors
This sets the proper default for each chart type and lets us change it as we need.
-rw-r--r--lib/axlsx/drawing/bar_3D_chart.rb25
-rw-r--r--lib/axlsx/drawing/chart.rb8
-rw-r--r--lib/axlsx/drawing/line_3D_chart.rb3
-rw-r--r--lib/axlsx/drawing/pie_3D_chart.rb3
-rw-r--r--lib/axlsx/drawing/scatter_chart.rb3
-rw-r--r--test/drawing/tc_chart.rb7
6 files changed, 35 insertions, 14 deletions
diff --git a/lib/axlsx/drawing/bar_3D_chart.rb b/lib/axlsx/drawing/bar_3D_chart.rb
index 50dbecb2..6f69f703 100644
--- a/lib/axlsx/drawing/bar_3D_chart.rb
+++ b/lib/axlsx/drawing/bar_3D_chart.rb
@@ -21,7 +21,9 @@ module Axlsx
# The direction of the bars in the chart
# must be one of [:bar, :col]
# @return [Symbol]
- attr_reader :bar_dir
+ def bar_dir
+ @bar_dir ||= :bar
+ end
alias :barDir :bar_dir
# space between bar or column clusters, as a percentage of the bar or column width.
@@ -31,18 +33,24 @@ module Axlsx
# space between bar or column clusters, as a percentage of the bar or column width.
# @return [String]
- attr_reader :gap_width
+ 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]
- attr_reader :grouping
+ def grouping
+ @grouping ||= :clustered
+ end
# The shabe of the bars or columns
# must be one of [:cone, :coneToMax, :box, :cylinder, :pyramid, :pyramidToMax]
# @return [Symbol]
- attr_reader :shape
+ def shape
+ @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)%/
@@ -65,10 +73,7 @@ module Axlsx
# @see Chart
# @see View3D
def initialize(frame, options={})
- @bar_dir = :bar
- @grouping = :clustered
- @shape = :box
- @gap_width = 150
+ @vary_colors = true
@gap_width, @gap_depth, @shape = nil, nil, nil
@cat_ax_id = rand(8 ** 8)
@val_ax_id = rand(8 ** 8)
@@ -124,7 +129,7 @@ module Axlsx
str_inner << '<c:bar3DChart>'
str_inner << '<c:barDir val="' << bar_dir.to_s << '"/>'
str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
- str_inner << '<c:varyColors val="1"/>'
+ str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
@series.each { |ser| ser.to_xml_string(str_inner) }
@d_lbls.to_xml_string(str) if @d_lbls
str_inner << '<c:gapWidth val="' << @gap_width.to_s << '"/>' unless @gap_width.nil?
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb
index 081be949..79019a0a 100644
--- a/lib/axlsx/drawing/chart.rb
+++ b/lib/axlsx/drawing/chart.rb
@@ -49,6 +49,13 @@ module Axlsx
@d_lbls ||= DLbls.new(self.class)
end
+ # Indicates that colors should be varied by datum
+ # @return [Boolean]
+ attr_reader :vary_colors
+
+ # Configures the vary_colors options for this chart
+ # @param [Boolean] v The value to set
+ def vary_colors=(v) Axlsx::validate_boolean(v); @vary_colors = v; end
# The title object for the chart.
# @return [Title]
@@ -133,7 +140,6 @@ module Axlsx
str << '<c:style val="' << style.to_s << '"/>'
str << '<c:chart>'
@title.to_xml_string str
- # do these need the c: namespace as well???
str << '<c:autoTitleDeleted val="' << (@title == nil).to_s << '"/>'
@view_3D.to_xml_string(str) if @view_3D
str << '<c:floor><c:thickness val="0"/></c:floor>'
diff --git a/lib/axlsx/drawing/line_3D_chart.rb b/lib/axlsx/drawing/line_3D_chart.rb
index 387e0508..b843f48e 100644
--- a/lib/axlsx/drawing/line_3D_chart.rb
+++ b/lib/axlsx/drawing/line_3D_chart.rb
@@ -60,6 +60,7 @@ module Axlsx
# @see Chart
# @see View3D
def initialize(frame, options={})
+ @vary_colors = false
@gapDepth = nil
@grouping = :standard
@catAxId = rand(8 ** 8)
@@ -93,7 +94,7 @@ module Axlsx
super(str) do |str_inner|
str_inner << '<c:line3DChart>'
str_inner << '<c:grouping val="' << grouping.to_s << '"/>'
- str_inner << '<c:varyColors val="1"/>'
+ str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
@series.each { |ser| ser.to_xml_string(str_inner) }
@d_lbls.to_xml_string(str) if @d_lbls
str_inner << '<c:gapDepth val="' << @gapDepth.to_s << '"/>' unless @gapDepth.nil?
diff --git a/lib/axlsx/drawing/pie_3D_chart.rb b/lib/axlsx/drawing/pie_3D_chart.rb
index da51d08b..4e61f4a1 100644
--- a/lib/axlsx/drawing/pie_3D_chart.rb
+++ b/lib/axlsx/drawing/pie_3D_chart.rb
@@ -23,6 +23,7 @@ module Axlsx
# @see Chart
# @see View3D
def initialize(frame, options={})
+ @vary_colors = true
super(frame, options)
@series_type = PieSeries
@view_3D = View3D.new({:rot_x =>30, :perspective=>30}.merge(options))
@@ -36,7 +37,7 @@ module Axlsx
super(str) do |str_inner|
str_inner << '<c:pie3DChart>'
- str_inner << '<c:varyColors val="1"/>'
+ str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
@series.each { |ser| ser.to_xml_string(str_inner) }
d_lbls.to_xml_string(str) if @d_lbls
str_inner << '</c:pie3DChart>'
diff --git a/lib/axlsx/drawing/scatter_chart.rb b/lib/axlsx/drawing/scatter_chart.rb
index 5e106a04..2b801642 100644
--- a/lib/axlsx/drawing/scatter_chart.rb
+++ b/lib/axlsx/drawing/scatter_chart.rb
@@ -24,6 +24,7 @@ module Axlsx
# Creates a new scatter chart
def initialize(frame, options={})
+ @vary_colors = 0
@scatterStyle = :lineMarker
@xValAxId = rand(8 ** 8)
@yValAxId = rand(8 ** 8)
@@ -48,7 +49,7 @@ module Axlsx
super(str) do |str_inner|
str_inner << '<c:scatterChart>'
str_inner << '<c:scatterStyle val="' << scatterStyle.to_s << '"/>'
- str_inner << '<c:varyColors val="1"/>'
+ str_inner << '<c:varyColors val="' << vary_colors.to_s << '"/>'
@series.each { |ser| ser.to_xml_string(str_inner) }
d_lbls.to_xml_string(str) if @d_lbls
str_inner << '<c:axId val="' << @xValAxId.to_s << '"/>'
diff --git a/test/drawing/tc_chart.rb b/test/drawing/tc_chart.rb
index 8dbebabc..03e4fd6f 100644
--- a/test/drawing/tc_chart.rb
+++ b/test/drawing/tc_chart.rb
@@ -37,6 +37,13 @@ class TestChart < Test::Unit::TestCase
assert_nothing_raised { @chart.style = 2 }
assert_equal(@chart.style, 2)
end
+
+ def test_vary_colors
+ assert_equal(true, @chart.vary_colors)
+ assert_raise(ArgumentError) { @chart.vary_colors = 7 }
+ assert_nothing_raised { @chart.vary_colors = false }
+ assert_equal(false, @chart.vary_colors)
+ end
def test_start_at
@chart.start_at 15, 25