Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/xlsxwriter/chart_doughnut.py: 28%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

29 statements  

1############################################################################### 

2# 

3# ChartDoughnut - A class for writing the Excel XLSX Doughnut charts. 

4# 

5# SPDX-License-Identifier: BSD-2-Clause 

6# 

7# Copyright (c) 2013-2025, John McNamara, jmcnamara@cpan.org 

8# 

9 

10from warnings import warn 

11 

12from . import chart_pie 

13 

14 

15class ChartDoughnut(chart_pie.ChartPie): 

16 """ 

17 A class for writing the Excel XLSX Doughnut charts. 

18 

19 

20 """ 

21 

22 ########################################################################### 

23 # 

24 # Public API. 

25 # 

26 ########################################################################### 

27 

28 def __init__(self): 

29 """ 

30 Constructor. 

31 

32 """ 

33 super().__init__() 

34 

35 self.vary_data_color = 1 

36 self.rotation = 0 

37 self.hole_size = 50 

38 

39 def set_hole_size(self, size): 

40 """ 

41 Set the Doughnut chart hole size. 

42 

43 Args: 

44 size: 10 <= size <= 90. 

45 

46 Returns: 

47 Nothing. 

48 

49 """ 

50 if size is None: 

51 return 

52 

53 # Ensure the size is in Excel's range. 

54 if size < 10 or size > 90: 

55 warn("Chart hole size '{size}' outside Excel range: 10 <= size <= 90") 

56 return 

57 

58 self.hole_size = int(size) 

59 

60 ########################################################################### 

61 # 

62 # Private API. 

63 # 

64 ########################################################################### 

65 

66 def _write_chart_type(self, args): 

67 # Override the virtual superclass method with a chart specific method. 

68 # Write the c:doughnutChart element. 

69 self._write_doughnut_chart() 

70 

71 ########################################################################### 

72 # 

73 # XML methods. 

74 # 

75 ########################################################################### 

76 

77 def _write_doughnut_chart(self): 

78 # Write the <c:doughnutChart> element. Over-ridden method to remove 

79 # axis_id code since Doughnut charts don't require val and cat axes. 

80 self._xml_start_tag("c:doughnutChart") 

81 

82 # Write the c:varyColors element. 

83 self._write_vary_colors() 

84 

85 # Write the series elements. 

86 for data in self.series: 

87 self._write_ser(data) 

88 

89 # Write the c:firstSliceAng element. 

90 self._write_first_slice_ang() 

91 

92 # Write the c:holeSize element. 

93 self._write_c_hole_size() 

94 

95 self._xml_end_tag("c:doughnutChart") 

96 

97 def _write_c_hole_size(self): 

98 # Write the <c:holeSize> element. 

99 attributes = [("val", self.hole_size)] 

100 

101 self._xml_empty_tag("c:holeSize", attributes)