Class: Writexlsx::Chart::Bar

Inherits:
Writexlsx::Chart show all
Includes:
Utility
Defined in:
lib/write_xlsx/chart/bar.rb

Constant Summary

Constants included from Utility

Utility::COL_MAX, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Attribute Summary

Attributes inherited from Writexlsx::Chart

#embedded, #formula_data, #formula_ids, #id, #index, #palette

Instance Method Summary collapse

Methods included from Utility

#absolute_char, delete_files, #put_deprecate_message, #substitute_cellref, #underline_attributes, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xml_str

Methods inherited from Writexlsx::Chart

#add_series, #assemble_xml_file, factory, #set_chartarea, #set_embedded_config_data, #set_legend, #set_plotarea, #set_style, #set_title, #set_x_axis, #set_xml_writer, #set_y_axis, #write_bar_chart

Constructor Details

#initializeBar

Returns a new instance of Bar.



22
23
24
25
26
27
28
29
# File 'lib/write_xlsx/chart/bar.rb', line 22

def initialize
  super(self.class)
  @subtype = 'clustered'
  @cat_axis_position = 'l'
  @val_axis_position = 'b'
  @horiz_val_axis    = 0
  @horiz_cat_axis    = 1
end

Instance Method Details

#write_bar_dirObject

Write the <c:barDir> element.



45
46
47
48
49
50
51
# File 'lib/write_xlsx/chart/bar.rb', line 45

def write_bar_dir
  val  = 'bar'

  attributes = ['val', val]

  @writer.empty_tag('c:barDir', attributes)
end

#write_chart_typeObject

Override the virtual superclass method with a chart specific method.



34
35
36
37
38
39
40
# File 'lib/write_xlsx/chart/bar.rb', line 34

def write_chart_type
  # Reverse X and Y axes for Bar charts.
  @x_axis, @y_axis = @y_axis, @x_axis

  # Write the c:barChart element.
  write_bar_chart
end

#write_number_format(format_code = 'General') ⇒ Object

Over-ridden to add % format. TODO. This will be refactored back up to the SUPER class later.

Write the <c:numFmt> element.



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/write_xlsx/chart/bar.rb', line 69

def write_number_format(format_code = 'General')
  source_linked = 1

  format_code = '0%' if @subtype == 'percent_stacked'

  attributes = [
                'formatCode',   format_code,
                'sourceLinked', source_linked
               ]

  @writer.empty_tag('c:numFmt', attributes)
end

#write_seriesObject

Over-ridden to add c:overlap.

Write the series elements.



58
59
60
# File 'lib/write_xlsx/chart/bar.rb', line 58

def write_series
  write_series_base {write_overlap if @subtype =~ /stacked/}
end