summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJonathan Tron <[email protected]>2015-08-05 13:14:16 +0200
committerJonathan Tron <[email protected]>2015-08-05 13:14:16 +0200
commitde10419812c4d1a4e57e0e43d67bfecc22df3885 (patch)
tree510d2169660a7ee0e182d4982f428b7312ca846f
parentf3df653c1385e6ecc9e6074a221711e916833068 (diff)
parent2b19dba7cc8f19f47594b90ea9fb7888678b0224 (diff)
downloadcaxlsx-de10419812c4d1a4e57e0e43d67bfecc22df3885.tar.gz
caxlsx-de10419812c4d1a4e57e0e43d67bfecc22df3885.zip
Merge pull request #410 from kernesti/master
Add `Chart#title_size`, `ScatterSeries#ln_width` and `Worksheet#is_reversed`
-rw-r--r--lib/axlsx/drawing/chart.rb5
-rw-r--r--lib/axlsx/drawing/num_val.rb4
-rw-r--r--lib/axlsx/drawing/scatter_series.rb14
-rw-r--r--lib/axlsx/drawing/str_val.rb4
-rw-r--r--lib/axlsx/drawing/title.rb20
-rw-r--r--lib/axlsx/workbook/workbook.rb15
6 files changed, 58 insertions, 4 deletions
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb
index e7fcc9e8..de87b91a 100644
--- a/lib/axlsx/drawing/chart.rb
+++ b/lib/axlsx/drawing/chart.rb
@@ -128,6 +128,11 @@ module Axlsx
end
end
+ # The size of the Title object of the chart.
+ def title_size=(v)
+ @title.text_size = v unless v.to_s.empty?
+ end
+
# Show the legend in the chart
# @param [Boolean] v
# @return [Boolean]
diff --git a/lib/axlsx/drawing/num_val.rb b/lib/axlsx/drawing/num_val.rb
index bd733cb7..b430c4b6 100644
--- a/lib/axlsx/drawing/num_val.rb
+++ b/lib/axlsx/drawing/num_val.rb
@@ -26,7 +26,9 @@ module Axlsx
# serialize the object
def to_xml_string(idx, str = "")
Axlsx::validate_unsigned_int(idx)
- str << ('<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>')
+ if !v.to_s.empty?
+ str << ('<c:pt idx="' << idx.to_s << '" formatCode="' << format_code << '"><c:v>' << v.to_s << '</c:v></c:pt>')
+ end
end
end
end
diff --git a/lib/axlsx/drawing/scatter_series.rb b/lib/axlsx/drawing/scatter_series.rb
index c0d6e8f1..6b71227c 100644
--- a/lib/axlsx/drawing/scatter_series.rb
+++ b/lib/axlsx/drawing/scatter_series.rb
@@ -21,6 +21,9 @@ module Axlsx
# @return [String]
attr_reader :color
+ # @return [String]
+ attr_reader :ln_width
+
# Line smoothing between data points
# @return [Boolean]
attr_reader :smooth
@@ -36,6 +39,7 @@ module Axlsx
Axlsx::validate_boolean(options[:smooth])
@smooth = options[:smooth]
end
+ @ln_width = options[:ln_width] unless options[:ln_width].nil?
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?
@@ -52,6 +56,11 @@ module Axlsx
@smooth = v
end
+ # @see ln_width
+ def ln_width=(v)
+ @ln_width = v
+ end
+
# Serializes the object
# @param [String] str
# @return [String]
@@ -74,6 +83,11 @@ module Axlsx
str << '</c:spPr>'
str << '</c:marker>'
end
+ if ln_width
+ str << '<c:spPr>'
+ str << '<a:ln w="' << ln_width << '"/>'
+ str << '</c:spPr>'
+ end
@xData.to_xml_string(str) unless @xData.nil?
@yData.to_xml_string(str) unless @yData.nil?
str << ('<c:smooth val="' << ((smooth) ? '1' : '0') << '"/>')
diff --git a/lib/axlsx/drawing/str_val.rb b/lib/axlsx/drawing/str_val.rb
index b0692784..10a4fe91 100644
--- a/lib/axlsx/drawing/str_val.rb
+++ b/lib/axlsx/drawing/str_val.rb
@@ -26,7 +26,9 @@ module Axlsx
# serialize the object
def to_xml_string(idx, str = "")
Axlsx::validate_unsigned_int(idx)
- str << ('<c:pt idx="' << idx.to_s << '"><c:v>' << v.to_s << '</c:v></c:pt>')
+ if !v.to_s.empty?
+ str << ('<c:pt idx="' << idx.to_s << '"><c:v>' << v.to_s << '</c:v></c:pt>')
+ end
end
end
end
diff --git a/lib/axlsx/drawing/title.rb b/lib/axlsx/drawing/title.rb
index 4e278689..7f2ff9f4 100644
--- a/lib/axlsx/drawing/title.rb
+++ b/lib/axlsx/drawing/title.rb
@@ -7,15 +7,24 @@ module Axlsx
# @return [String]
attr_reader :text
+ # Text size property
+ # @return [String]
+ attr_reader :text_size
+
# The cell that holds the text for the title. Setting this property will automatically update the text attribute.
# @return [Cell]
attr_reader :cell
# Creates a new Title object
# @param [String, Cell] title The cell or string to be used for the chart's title
- def initialize(title="")
+ def initialize(title="", title_size="")
self.cell = title if title.is_a?(Cell)
self.text = title.to_s unless title.is_a?(Cell)
+ if title_size.to_s.empty?
+ self.text_size = "1600"
+ else
+ self.text_size = title_size.to_s
+ end
end
# @see text
@@ -26,6 +35,14 @@ module Axlsx
v
end
+ # @see text_size
+ def text_size=(v)
+ DataTypeValidator.validate 'Title.text_size', String, v
+ @text_size = v
+ @cell = nil
+ v
+ end
+
# @see cell
def cell=(v)
DataTypeValidator.validate 'Title.text', Cell, v
@@ -62,6 +79,7 @@ module Axlsx
str << '<a:lstStyle/>'
str << '<a:p>'
str << '<a:r>'
+ str << ('<a:rPr sz="' << @text_size.to_s << '"/>')
str << ('<a:t>' << @text.to_s << '</a:t>')
str << '</a:r>'
str << '</a:p>'
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb
index 784ee0b4..ddb13600 100644
--- a/lib/axlsx/workbook/workbook.rb
+++ b/lib/axlsx/workbook/workbook.rb
@@ -96,6 +96,15 @@ require 'axlsx/workbook/worksheet/selection.rb'
@use_shared_strings = v
end
+ # If true reverse the order in which the workbook is serialized
+ # @return [Boolean]
+ attr_reader :is_reversed
+
+ def is_reversed=(v)
+ Axlsx::validate_boolean(v)
+ @is_reversed = v
+ end
+
# A collection of worksheets associated with this workbook.
# @note The recommended way to manage worksheets is add_worksheet
@@ -344,7 +353,11 @@ require 'axlsx/workbook/worksheet/selection.rb'
str << ('<workbookPr date1904="' << @@date1904.to_s << '"/>')
views.to_xml_string(str)
str << '<sheets>'
- worksheets.each { |sheet| sheet.to_sheet_node_xml_string(str) }
+ if is_reversed
+ worksheets.reverse_each { |sheet| sheet.to_sheet_node_xml_string(str) }
+ else
+ worksheets.each { |sheet| sheet.to_sheet_node_xml_string(str) }
+ end
str << '</sheets>'
defined_names.to_xml_string(str)
unless pivot_tables.empty?