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

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

37 statements  

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

2# 

3# ChartRadar - A class for writing the Excel XLSX Radar charts. 

4# 

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

6# 

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

8# 

9 

10from typing import Any, Dict, Optional 

11 

12from . import chart 

13 

14 

15class ChartRadar(chart.Chart): 

16 """ 

17 A class for writing the Excel XLSX Radar charts. 

18 

19 

20 """ 

21 

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

23 # 

24 # Public API. 

25 # 

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

27 

28 def __init__(self, options: Optional[Dict[str, Any]] = None) -> None: 

29 """ 

30 Constructor. 

31 

32 """ 

33 super().__init__() 

34 

35 if options is None: 

36 options = {} 

37 

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

39 

40 if not self.subtype: 

41 self.subtype = "marker" 

42 self.default_marker = {"type": "none"} 

43 

44 # Override and reset the default axis values. 

45 self.x_axis["defaults"]["major_gridlines"] = {"visible": 1} 

46 self.set_x_axis({}) 

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 # Hardcode major_tick_mark for now until there is an accessor. 

53 self.y_axis["major_tick_mark"] = "cross" 

54 

55 ########################################################################### 

56 # 

57 # Private API. 

58 # 

59 ########################################################################### 

60 

61 def _write_chart_type(self, args) -> None: 

62 # Write the c:radarChart element. 

63 self._write_radar_chart(args) 

64 

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

66 # 

67 # XML methods. 

68 # 

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

70 

71 def _write_radar_chart(self, args) -> None: 

72 # Write the <c:radarChart> 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 self._xml_start_tag("c:radarChart") 

83 

84 # Write the c:radarStyle element. 

85 self._write_radar_style() 

86 

87 # Write the series elements. 

88 for data in series: 

89 self._write_ser(data) 

90 

91 # Write the c:axId elements 

92 self._write_axis_ids(args) 

93 

94 self._xml_end_tag("c:radarChart") 

95 

96 def _write_radar_style(self) -> None: 

97 # Write the <c:radarStyle> element. 

98 val = "marker" 

99 

100 if self.subtype == "filled": 

101 val = "filled" 

102 

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

104 

105 self._xml_empty_tag("c:radarStyle", attributes)