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, #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

#initializePie

Returns a new instance of Pie.



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

def initialize
  super(self.class)
  @vary_data_color = 1
end

Instance Method Details

#write_a_p_legendObject

Write the <a:p> element for legends.



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

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.



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

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_typeObject

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
  # Write the c:areaChart element.
  write_pie_chart
end

#write_first_slice_angObject

Write the <c:firstSliceAng> element.



180
181
182
183
184
185
186
# File 'lib/write_xlsx/chart/pie.rb', line 180

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.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/write_xlsx/chart/pie.rb', line 91

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.



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

def write_pie_chart
  @writer.tag_elements('c:pieChart') do
    # Write the c:varyColors element.
    write_vary_colors
    # Write the series elements.
    write_series
    # 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.



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

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_seriesObject

Over-ridden method to remove axis_id code since Pie charts don’t require val and cat axes.

Write the series elements.



77
78
79
80
81
82
83
84
# File 'lib/write_xlsx/chart/pie.rb', line 77

def write_series
  # Write each series with subelements.
  index = 0
  @series.each do |series|
    write_ser(index, series)
    index += 1
  end
end

#write_tx_pr_legendObject

Write the <c:txPr> element for legends.



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

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.



169
170
171
172
173
174
175
# File 'lib/write_xlsx/chart/pie.rb', line 169

def write_vary_colors
  val  = 1

  attributes = ['val', val]

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