summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/drawing/chart.rb
diff options
context:
space:
mode:
authorBrad Stewart <[email protected]>2015-03-03 15:56:25 -0600
committerBrad Stewart <[email protected]>2015-03-03 15:56:25 -0600
commitcaf6f54acd0b9f1cfbe2e34bb759031e5c387bb8 (patch)
tree2dc067e8128ce723c6984d9d9f151328e36c0895 /lib/axlsx/drawing/chart.rb
parentc24ec92ab6495b6b0c36e8e139d3d3ce350fc5c5 (diff)
downloadcaxlsx-caf6f54acd0b9f1cfbe2e34bb759031e5c387bb8.tar.gz
caxlsx-caf6f54acd0b9f1cfbe2e34bb759031e5c387bb8.zip
Allow legend position to be set on charts
Diffstat (limited to 'lib/axlsx/drawing/chart.rb')
-rw-r--r--lib/axlsx/drawing/chart.rb19
1 files changed, 18 insertions, 1 deletions
diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb
index 1d6b9293..fb96ed53 100644
--- a/lib/axlsx/drawing/chart.rb
+++ b/lib/axlsx/drawing/chart.rb
@@ -20,6 +20,7 @@ module Axlsx
@graphic_frame.anchor.drawing.worksheet.workbook.charts << self
@series = SimpleTypedList.new Series
@show_legend = true
+ @legend_position = :r
@display_blanks_as = :gap
@series_type = Series
@title = Title.new
@@ -71,6 +72,17 @@ module Axlsx
# @return [Boolean]
attr_reader :show_legend
+ # Set the location of the chart's legend
+ # @return [Symbol] The position of this legend
+ # @note
+ # The following are allowed
+ # :b
+ # :l
+ # :r
+ # :t
+ # :tr
+ attr_reader :legend_position
+
# How to display blank values
# Options are
# * gap: Display nothing
@@ -126,6 +138,11 @@ module Axlsx
# @param [Integer] v must be between 1 and 48
def style=(v) DataTypeValidator.validate "Chart.style", Integer, v, lambda { |arg| arg >= 1 && arg <= 48 }; @style = v; end
+ # Set the position of the chart's legend.
+ # see ECMA Part 1 ยง21.2.2.196
+ # @param [Symbol] v must be between 1 and 48
+ def legend_position=(v) RestrictionValidator.validate "Chart.legend_position", [:b, :l, :r, :t, :tr], v; @legend_position = v; end
+
# backwards compatibility to allow chart.to and chart.from access to anchor markers
# @note This will be disconinued in version 2.0.0. Please use the end_at method
def to
@@ -167,7 +184,7 @@ module Axlsx
str << '</c:plotArea>'
if @show_legend
str << '<c:legend>'
- str << '<c:legendPos val="r"/>'
+ str << '<c:legendPos val="' << @legend_position << '"/>'
str << '<c:layout/>'
str << '<c:overlay val="0"/>'
str << '</c:legend>'