lib/write_xlsx/chart.rb in write_xlsx-0.97.0 vs lib/write_xlsx/chart.rb in write_xlsx-0.99.0

- old
+ new

@@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- require 'write_xlsx/package/xml_writer_simple' require 'write_xlsx/gradient' +require 'write_xlsx/chart/legend' require 'write_xlsx/utility' require 'write_xlsx/chart/axis' require 'write_xlsx/chart/caption' require 'write_xlsx/chart/series' @@ -160,10 +161,11 @@ end end class Chart include Writexlsx::Utility + include Writexlsx::Gradient attr_accessor :id, :name # :nodoc: attr_writer :index, :palette, :protection # :nodoc: attr_reader :embedded, :formula_ids, :formula_data # :nodoc: attr_reader :x_scale, :y_scale, :x_offset, :y_offset # :nodoc: @@ -350,20 +352,12 @@ # # Set the properties of the chart legend. # def set_legend(params) - if params[:none] - @legend_position = 'none' - else - @legend_position = params[:position] || 'right' - end - @legend_delete_series = params[:delete_series] - @legend_font = convert_font_args(params[:font]) - - # Set the legend layout. - @legend_layout = layout_properties(params[:layout]) + # Convert the user default properties to internal properties. + legend_properties(params) end # # Set the properties of the chart plotarea. # @@ -609,11 +603,11 @@ @height = 288 @x_scale = 1 @y_scale = 1 @x_offset = 0 @y_offset = 0 - @legend_position = 'right' + @legend = Legend.new @smooth_allowed = 0 @cross_between = 'between' @date_category = false @show_blanks = 'gap' @show_hidden_data = false @@ -1238,11 +1232,11 @@ write_crossing(y_axis.crossing) end # Write the c:auto element. write_auto(1) unless x_axis.text_axis # Write the c:labelAlign element. - write_label_align('ctr') + write_label_align(x_axis.label_align) # Write the c:labelOffset element. write_label_offset(100) # Write the c:tickLblSkip element. write_tick_lbl_skip(x_axis.interval_unit) # Write the c:tickMarkSkip element. @@ -1572,10 +1566,16 @@ # # Write the <c:labelAlign> element. # def write_label_align(val) # :nodoc: + val ||= 'ctr' + if val == 'right' + val = 'r' + elsif val == 'left' + val = 'l' + end @writer.empty_tag('c:lblAlgn', [ ['val', val] ]) end # # Write the <c:labelOffset> element. @@ -1674,34 +1674,37 @@ # # Write the <c:legend> element. # def write_legend # :nodoc: - position = @legend_position.sub(/^overlay_/, '') + position = @legend.position.sub(/^overlay_/, '') return if position == 'none' || (not position_allowed.has_key?(position)) - @delete_series = @legend_delete_series if @legend_delete_series.kind_of?(Array) + @delete_series = @legend.delete_series if @legend.delete_series.kind_of?(Array) @writer.tag_elements('c:legend') do # Write the c:legendPos element. write_legend_pos(position_allowed[position]) # Remove series labels from the legend. # Write the c:legendEntry element. @delete_series.each { |i| write_legend_entry(i) } if @delete_series # Write the c:layout element. - write_layout(@legend_layout, 'legend') - # Write the c:txPr element. - write_tx_pr(nil, @legend_font) if ptrue?(@legend_font) + write_layout(@legend.layout, 'legend') # Write the c:overlay element. - write_overlay if @legend_position =~ /^overlay_/ + write_overlay if @legend.position =~ /^overlay_/ + # Write the c:spPr element. + write_sp_pr(@legend) + # Write the c:txPr element. + write_tx_pr(nil, @legend.font) if ptrue?(@legend.font) end end def position_allowed { - 'right' => 'r', - 'left' => 'l', - 'top' => 't', - 'bottom' => 'b' + 'right' => 'r', + 'left' => 'l', + 'top' => 't', + 'bottom' => 'b', + 'top_right' => 'tr' } end # # Write the <c:legendPos> element.