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

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

35 statements  

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

2# 

3# ChartArea - A class for writing the Excel XLSX Area 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 ChartArea(chart.Chart): 

14 """ 

15 A class for writing the Excel XLSX Area 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 = "standard" 

40 

41 self.cross_between = "midCat" 

42 self.show_crosses = False 

43 

44 # Override and reset the default axis values. 

45 if self.subtype == "percent_stacked": 

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

47 

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

49 self.label_position_default = "center" 

50 self.label_positions = {"center": "ctr"} 

51 

52 self.set_y_axis({}) 

53 

54 ########################################################################### 

55 # 

56 # Private API. 

57 # 

58 ########################################################################### 

59 

60 def _write_chart_type(self, args): 

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

62 # Write the c:areaChart element. 

63 self._write_area_chart(args) 

64 

65 ########################################################################### 

66 # 

67 # XML methods. 

68 # 

69 ########################################################################### 

70 # 

71 def _write_area_chart(self, args): 

72 # Write the <c:areaChart> element. 

73 

74 if args["primary_axes"]: 

75 series = self._get_primary_axes_series() 

76 else: 

77 series = self._get_secondary_axes_series() 

78 

79 if not series: 

80 return 

81 

82 subtype = self.subtype 

83 

84 if subtype == "percent_stacked": 

85 subtype = "percentStacked" 

86 

87 self._xml_start_tag("c:areaChart") 

88 

89 # Write the c:grouping element. 

90 self._write_grouping(subtype) 

91 

92 # Write the series elements. 

93 for data in series: 

94 self._write_ser(data) 

95 

96 # Write the c:dropLines element. 

97 self._write_drop_lines() 

98 

99 # Write the c:axId elements 

100 self._write_axis_ids(args) 

101 

102 self._xml_end_tag("c:areaChart")