Class: Writexlsx::Chart::Pie

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

Overview

A Pie chart doesn’t have an X or Y axis so the following common chart methods are ignored.

chart.set_x_axis
chart.set_y_axis

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, #name, #palette, #protection

Instance Method Summary collapse

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #convert_date_time, delete_files, #ptrue?, #put_deprecate_message, #row_col_notation, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #write_color, #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_x2_axis, #set_x_axis, #set_xml_writer, #set_y2_axis, #set_y_axis, #show_blanks_as, #show_hidden_data, #write_bar_chart

Constructor Details

#initialize(subtype) ⇒ Pie



29
30
31
32
# File 'lib/write_xlsx/chart/pie.rb', line 29

def initialize(subtype)
  super(subtype)
  @vary_data_color = 1
end

Instance Method Details

#write_a_p_legendObject

Write the <a:p> element for legends.



129
130
131
132
133
134
135
136
# File 'lib/write_xlsx/chart/pie.rb', line 129

def write_a_p_legend
  @writer.tag_elements('a:p') do
    # Write the a:pPr element.
    write_a_p_pr_legend
    # Write the a:endParaRPr element.
    write_a_end_para_rpr
  end
end

#write_a_p_pr_legendObject

Write the <a:pPr> element for legends.



141
142
143
144
145
146
147
148
149
150
# File 'lib/write_xlsx/chart/pie.rb', line 141

def write_a_p_pr_legend
  rtl  = 0

  attributes = ['rtl', rtl]

  @writer.tag_elements('a:pPr', attributes) do
    # Write the a:defRPr element.
    write_a_def_rpr
  end
end

#write_chart_type(params = {}) ⇒ Object

Override the virtual superclass method with a chart specific method.



37
38
39
40
# File 'lib/write_xlsx/chart/pie.rb', line 37

def write_chart_type(params = {})
  # Write the c:areaChart element.
  write_pie_chart
end

#write_first_slice_angObject

Write the <c:firstSliceAng> element.



166
167
168
169
170
171
172
# File 'lib/write_xlsx/chart/pie.rb', line 166

def write_first_slice_ang
  val  = 0

  attributes = ['val', val]

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

#write_legendObject

Over-ridden method to add <c:txPr> to legend.

Write the <c:legend> element.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/write_xlsx/chart/pie.rb', line 77

def write_legend
  position = @legend_position
  overlay  = 0

  if position =~ /^overlay_/
    positon.sub!(/^overlay_/, '')
    overlay = 1
  end

  allowed = {
      'right'  => 'r',
      'left'   => 'l',
      'top'    => 't',
      'bottom' => 'b'
  }

  return if position == 'none'
  return unless allowed.has_key?(position)

  position = allowed[position]

  @writer.tag_elements('c:legend') do
    # Write the c:legendPos element.
    write_legend_pos(position)
    # Write the c:layout element.
    write_layout
    # Write the c:overlay element.
    write_overlay if overlay != 0
    # Write the c:txPr element. Over-ridden.
    write_tx_pr_legend
  end
end

#write_pie_chartObject

Write the <c:pieChart> element. Over-ridden method to remove axis_id code since pie charts don’t require val and vat axes.



46
47
48
49
50
51
52
53
54
55
# File 'lib/write_xlsx/chart/pie.rb', line 46

def write_pie_chart
  @writer.tag_elements('c:pieChart') do
    # Write the c:varyColors element.
    write_vary_colors
    # Write the series elements.
    @series.each {|s| write_series(s)}
    # Write the c:firstSliceAng element.
    write_first_slice_ang
  end
end

#write_plot_areaObject

Over-ridden method to remove the cat_axis() and val_axis() code since Pie charts don’t require those axes.

Write the <c:plotArea> element.



63
64
65
66
67
68
69
70
# File 'lib/write_xlsx/chart/pie.rb', line 63

def write_plot_area
  @writer.tag_elements('c:plotArea') do
    # Write the c:layout element.
    write_layout
    # Write the subclass chart type element.
    write_chart_type
  end
end

#write_tx_pr_legendObject

Write the <c:txPr> element for legends.



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/write_xlsx/chart/pie.rb', line 113

def write_tx_pr_legend
  horiz = 0

  @writer.tag_elements('c:txPr') do
    # Write the a:bodyPr element.
    write_a_body_pr(horiz)
    # Write the a:lstStyle element.
    write_a_lst_style
    # Write the a:p element.
    write_a_p_legend
  end
end

#write_vary_colorsObject

Write the <c:varyColors> element.



155
156
157
158
159
160
161
# File 'lib/write_xlsx/chart/pie.rb', line 155

def write_vary_colors
  val  = 1

  attributes = ['val', val]

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