1###############################################################################
2#
3# ChartDoughnut - A class for writing the Excel XLSX Doughnut charts.
4#
5# SPDX-License-Identifier: BSD-2-Clause
6# Copyright 2013-2024, John McNamara, jmcnamara@cpan.org
7#
8
9from warnings import warn
10from . import chart_pie
11
12
13class ChartDoughnut(chart_pie.ChartPie):
14 """
15 A class for writing the Excel XLSX Doughnut charts.
16
17
18 """
19
20 ###########################################################################
21 #
22 # Public API.
23 #
24 ###########################################################################
25
26 def __init__(self, options=None):
27 """
28 Constructor.
29
30 """
31 super(ChartDoughnut, self).__init__()
32
33 self.vary_data_color = 1
34 self.rotation = 0
35 self.hole_size = 50
36
37 def set_hole_size(self, size):
38 """
39 Set the Doughnut chart hole size.
40
41 Args:
42 size: 10 <= size <= 90.
43
44 Returns:
45 Nothing.
46
47 """
48 if size is None:
49 return
50
51 # Ensure the size is in Excel's range.
52 if size < 10 or size > 90:
53 warn("Chart hole size %d outside Excel range: 10 <= size <= 90" % size)
54 return
55
56 self.hole_size = int(size)
57
58 ###########################################################################
59 #
60 # Private API.
61 #
62 ###########################################################################
63
64 def _write_chart_type(self, args):
65 # Override the virtual superclass method with a chart specific method.
66 # Write the c:doughnutChart element.
67 self._write_doughnut_chart(args)
68
69 ###########################################################################
70 #
71 # XML methods.
72 #
73 ###########################################################################
74
75 def _write_doughnut_chart(self, args):
76 # Write the <c:doughnutChart> element. Over-ridden method to remove
77 # axis_id code since Doughnut charts don't require val and cat axes.
78 self._xml_start_tag("c:doughnutChart")
79
80 # Write the c:varyColors element.
81 self._write_vary_colors()
82
83 # Write the series elements.
84 for data in self.series:
85 self._write_ser(data)
86
87 # Write the c:firstSliceAng element.
88 self._write_first_slice_ang()
89
90 # Write the c:holeSize element.
91 self._write_c_hole_size()
92
93 self._xml_end_tag("c:doughnutChart")
94
95 def _write_c_hole_size(self):
96 # Write the <c:holeSize> element.
97 attributes = [("val", self.hole_size)]
98
99 self._xml_empty_tag("c:holeSize", attributes)