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

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

48 statements  

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

2# 

3# ChartColumn - A class for writing the Excel XLSX Column charts. 

4# 

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

6# 

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

8# 

9 

10from . import chart 

11 

12 

13class ChartColumn(chart.Chart): 

14 """ 

15 A class for writing the Excel XLSX Column 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().__init__() 

32 

33 if options is None: 

34 options = {} 

35 

36 self.subtype = options.get("subtype") 

37 

38 if not self.subtype: 

39 self.subtype = "clustered" 

40 

41 self.horiz_val_axis = 0 

42 

43 if self.subtype == "percent_stacked": 

44 self.y_axis["defaults"]["num_format"] = "0%" 

45 

46 # Set the available data label positions for this chart type. 

47 self.label_position_default = "outside_end" 

48 self.label_positions = { 

49 "center": "ctr", 

50 "inside_base": "inBase", 

51 "inside_end": "inEnd", 

52 "outside_end": "outEnd", 

53 } 

54 

55 self.set_y_axis({}) 

56 

57 ########################################################################### 

58 # 

59 # Private API. 

60 # 

61 ########################################################################### 

62 

63 def _write_chart_type(self, args): 

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

65 

66 # Write the c:barChart element. 

67 self._write_bar_chart(args) 

68 

69 def _write_bar_chart(self, args): 

70 # Write the <c:barChart> element. 

71 

72 if args["primary_axes"]: 

73 series = self._get_primary_axes_series() 

74 else: 

75 series = self._get_secondary_axes_series() 

76 

77 if not series: 

78 return 

79 

80 subtype = self.subtype 

81 if subtype == "percent_stacked": 

82 subtype = "percentStacked" 

83 

84 # Set a default overlap for stacked charts. 

85 if "stacked" in self.subtype and self.series_overlap_1 is None: 

86 self.series_overlap_1 = 100 

87 

88 self._xml_start_tag("c:barChart") 

89 

90 # Write the c:barDir element. 

91 self._write_bar_dir() 

92 

93 # Write the c:grouping element. 

94 self._write_grouping(subtype) 

95 

96 # Write the c:ser elements. 

97 for data in series: 

98 self._write_ser(data) 

99 

100 # Write the c:gapWidth element. 

101 if args["primary_axes"]: 

102 self._write_gap_width(self.series_gap_1) 

103 else: 

104 self._write_gap_width(self.series_gap_2) 

105 

106 # Write the c:overlap element. 

107 if args["primary_axes"]: 

108 self._write_overlap(self.series_overlap_1) 

109 else: 

110 self._write_overlap(self.series_overlap_2) 

111 

112 # Write the c:axId elements 

113 self._write_axis_ids(args) 

114 

115 self._xml_end_tag("c:barChart") 

116 

117 ########################################################################### 

118 # 

119 # XML methods. 

120 # 

121 ########################################################################### 

122 

123 def _write_bar_dir(self): 

124 # Write the <c:barDir> element. 

125 val = "col" 

126 

127 attributes = [("val", val)] 

128 

129 self._xml_empty_tag("c:barDir", attributes) 

130 

131 def _write_err_dir(self, val): 

132 # Overridden from Chart class since it is not used in Column charts. 

133 pass