From caf6f54acd0b9f1cfbe2e34bb759031e5c387bb8 Mon Sep 17 00:00:00 2001 From: Brad Stewart Date: Tue, 3 Mar 2015 15:56:25 -0600 Subject: Allow legend position to be set on charts --- lib/axlsx/drawing/chart.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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 << '' if @show_legend str << '' - str << '' + str << '' str << '' str << '' str << '' -- cgit v1.2.3 From ed8d37a2766e729d60c513198c103f46be7716aa Mon Sep 17 00:00:00 2001 From: Brad Stewart Date: Tue, 3 Mar 2015 16:01:13 -0600 Subject: Fix comments --- lib/axlsx/drawing/chart.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb index fb96ed53..17106035 100644 --- a/lib/axlsx/drawing/chart.rb +++ b/lib/axlsx/drawing/chart.rb @@ -11,6 +11,7 @@ module Axlsx # @param [GraphicalFrame] frame The frame that holds this chart. # @option options [Cell, String] title # @option options [Boolean] show_legend + # @option options [Symbol] legend_position # @option options [Array|String|Cell] start_at The X, Y coordinates defining the top left corner of the chart. # @option options [Array|String|Cell] end_at The X, Y coordinates defining the bottom right corner of the chart. def initialize(frame, options={}) @@ -138,9 +139,7 @@ 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 + # @see legend_position 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 -- cgit v1.2.3 From 72ba558c20f671f65ea8ac77bf9497083d380b73 Mon Sep 17 00:00:00 2001 From: Brad Stewart Date: Tue, 3 Mar 2015 16:33:25 -0600 Subject: Minor change --- lib/axlsx/drawing/chart.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/axlsx/drawing/chart.rb b/lib/axlsx/drawing/chart.rb index 17106035..322f9463 100644 --- a/lib/axlsx/drawing/chart.rb +++ b/lib/axlsx/drawing/chart.rb @@ -183,7 +183,7 @@ module Axlsx str << '' if @show_legend str << '' - str << '' + str << ('') str << '' str << '' str << '' -- cgit v1.2.3